3 ms·
DWARF 3 and 4 can contain information about macros, and GDB can expand them (macro exp foo(bar,...)). Compile with the somewhat under-mentioned flags -gdwarf-4
by PeCaN 11y ago
DWARF 3 and 4 can contain information about macros, and GDB can expand them (macro exp foo(bar,...)). Compile with the somewhat under-mentioned flags -gdwarf-4 -g3 to retain macro definitions. This lets you debug expansions easily, but doesn't map already-compiled macro expansions back to their macro definitions.
If you want to step through execution of a function defined by a macro, preprocess with -E -P and compile that. For more advanced (and pleasant) macro debugging, you can do a little trick:
1. Create an e.g. include/dummy directory and create empty versions of whatever headers you don't want to expand.
2. Run your files through $CC -E -P -Iinclude/dummy
3. clang-format is your friend for making the output much nicer.
4. Compile with explicit -include of the real versions of files in include/dummy.
5. Debug normally.
It takes a little bit of effort to get right, but after that you can just throw it in a Makefile and forget about it (e.g. https://github.com/alpha123/yu/blob/master/Makefile#L96-L126 https://github.com/alpha123/yu/blob/master/Makefile#L96-L126).