I've got a pretty complicated macro inside my (unmanaged) C++ code. Is there any way to expand macros in VS debugger? Or maybe there is another way to debug macros there?
F.e. I'd like to place a breakpoint inside it.
(Yes, I know macros are bad.)
Start debugging in Visual Studio by pressing F5. In Excel, open up your worksheet and start debugging your VBA code using Excel's debugger. When the managed code gets executed where you set the breakpoint, you'll stop in Visual Studio.
To debug a memory dump, open your launch. json file and add the coreDumpPath (for GDB or LLDB) or dumpPath (for the Visual Studio Windows Debugger) property to the C++ Launch configuration, set its value to be a string containing the path to the memory dump.
Go to either project or source file properties by right-clicking and going to "Properties". Under Configuration Properties->C/C++->Preprocessor, set "Generate Preprocessed File" to either with or without line numbers, whichever you prefer. This will show what your macro expands to in context. If you need to debug it on live compiled code, just cut and paste that, and put it in place of your macro while debugging.
I heard all possible negative answers on the topic:
They are all true, but IMO they collide with the reality of everydays programming.
In fact, working on old C project, where macros were mostly simply used as functions, this became of crucial importance for me. Generating all preprocessed files with /P works, but is overkilling and time consuming. I just needed a tool that expands a simple macro defined a few lines above or at maximum in other file.
How to do that?
So, Yes, in a practical sense, it is possible.
The compiler expands macros nicely. Get a compilation listing with the macros expanded.
Insert the expanded macro into your code. Recompile and you should be able to step through it, to do a simple test.
Generally when I am building a complicated macro, I hard code it first, and test it. Then I turn it into a macro.
For 2008, this may be of help
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With