Can C macros be expanded in gdb when the program was compiled using clang?

I have a macro that extracts the Jth 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 cannot use it from gdb by issuing a command print JTH_BIT(i,j), can macros in C be used during debugging?

+4
source share
2 answers

Macros are processed by the preprocessor. The compiler does not even know about them.

However, with luck, the gcc option -g3will complete the task and generate code that allows gdb to expand the macro.

From the gdb documentation (highlighted by me):

-glevel

[...]     3 , ​​ , . -g3.

+6

, . gcc "-g3"

.

+2

Source: https://habr.com/ru/post/1526062/


All Articles