A.E. Drew
A.E. Drew

Reputation: 2137

Can I use Visual Studio debugger within #define functions?

I am using Visual Studio 2010 (writing C++) and have isolated an exception coming from a call to a #define function. The defined function is a bit complex and I would like to be able to step through it with the debugger to find out where the exception occurs. Is there any way to do this?

The relationships are like this: my.h defines a class that inherits from a third-party class declared in their.h. The third-party class in their.h includes the macro of interest, which is defined in another header, say `macro.h'.

Upvotes: 2

Views: 1162

Answers (2)

UweBaemayr
UweBaemayr

Reputation: 2329

I'm facing the same problem and am surprised that the VS2017 doesn't resolve macros during debugging. Resharper for C/C++ is great in that it can expand macros partially or completely -- you can expand a macro and grok it or rebuild and debug it, and then revert the change. I'm pretty sure there is a trial version one can play with.

Upvotes: 1

AlexK
AlexK

Reputation: 1281

You need to expand the macro into your source code before you can debug it. You can either do it manually or make Visual Studio generate preprocessor output. http://msdn.microsoft.com/en-us/library/8z9z0bx6(v=vs.80).aspx describes the process for VS 2005. You will then have to create a new "debug" project with sources replaced with .i files generated by Visual Studio's preprocessor. This is a pain for any nontrivial project so I would try doing it manually first, especially since you identified the specific macro that causes exception, so you can try and manually expand just that one. You can also use those preprocessor-generated .i files for cross-reference.
UPD: If the macro in question is used in several locations, you may want to find out which location is responsible for exception. Run it under debugger (I assume you have full debug info generated, if not, you should) and check call stack at the time of exception. Expand just that location.
Be warned: certain projects in open source community are notorious for using macros as code obfuscation tools (I guess to keep their trade secrets from being discovered by reverse engineering) so good luck...

Upvotes: 2

Related Questions