I have a macro that fetch's the J-th bit of an integer:
#define TWO_TO_THE(POWER) (1 << POWER)
#define JTH_BIT(BITS, J) ((TWO_TO_THE((J-1)) & BITS) != 0)
However, I can't use it from gdb by issuing the command print JTH_BIT(i,j)
, can macros in C even be used while debugging?
Macros are handled by the pre-processor. The compiler doesn't even know about them.
However, if lucky, GCC's option -g3
would do the job and generate code allowing gdb
to expand a macro.
From the gdb documentation (emphasis by me):
-glevel
[...] Level 3 includes extra information, such as all the macro definitions present in the program. Some debuggers support macro expansion when you use -g3.
It should work, if you compile your program with the right options. In gcc, you need to say "-g3" when you compile
See here and here.
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