For example:
#include <stdlib.h>
#define A 20
#define B 22
#define C (A+B)
int main()
{
srand(time(0));
int i = (rand()&1) + C;
return i;
}
In gdb,
(gdb) print C
No symbol "C" in current context.
How can I know what C
is? Can gdb
tell me? (I added rand()
so we can't easily deduce what it was)
The preprocessor will have replaced C with (20+22)
. Is this value available in the debuginfo to print somehow?
In a real example where the macro could be exceedingly complex, I don't want to waste my time doing the job of the preprocessor.
First of all you need to build the program with
-g3
flag so that macro information is included in debugging information, start the program and show macro definition withinfo macro
:You can also expand macro: