1

I really like how gdb allows me to script a routine for breakpoints using the command command. Often times, I add print statements to just print a message, and I like how all of this works without modifying the source file.

I had to use Visual Studio and I found out that the way to insert debug print statements is using OutputDebugString. But, I don't like how I need to modify my source code in order to debug. Is there a way to print debug messages in VS like in gdb, i.e. without modifying source.

Also, how does the VC compiler process the OutputDebugString call? Does it actually compile that line in the program's assembly? Do I need to compile my code if the only change I made is to add a call to OutputDebugString?

4
  • you can always use macros for debug builds like #ifdef _DEBUG OutputDebugString() #endif so that when you're compiling on release mode none of this functions will actually compile and will be left out of the program. And yes, the function generates assembly(generated machine) code. The lasts question I don't fully understand, I think you need to compile your code if you make ANY changes to it... Commented Jan 4, 2017 at 3:48
  • @ViniyoShouta Thank you, that answers everything. Commented Jan 4, 2017 at 3:50
  • @ViniyoShouta Is it unreasonable to be annoyed by this? I wonder why MS did it this way, the gdb way seems so much better. Commented Jan 4, 2017 at 3:53
  • Well it's actually great if you need to output a lot of stuff when debugging, on loops for example, if you had to set a breakpoint and check the values of things every single time the loop runs that'd be terrible. Commented Jan 4, 2017 at 4:01

1 Answer 1

2

You're looking for Visual Studio tracepoints.

I haven't used them, but they appear to be well documented.

A tracepoint can print a message, and doesn't involve modifying your source code.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.