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.