struct tree{
#ifdef A
#define TREE_GET(x,y) &x->y
#else
#define TREE_GET(x,y) x->y
#endif
};
I want to know whether macro A was defined . Is there any command I can use in gdb .
In compilation time we pass the -gdwarf-2 and -g3 flags to ensure the compiler includes information about preprocessor macros in the debugging information.
For example, g++ -gdwarf-2 -g3 program.cpp -o program
Compile using -g3 and in gdb issue:
info macro A
From the gcc documentation on -g3:
-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.
From the gdb documenation on info macro & friends:
info macro [-a|-all] [--] macro
Show the current definition or all definitions of the named macro, and describe the source location or compiler command-line where that definition was established. The optional double dash is to signify the end of argument processing and the beginning of macro for non C-like macros where the macro may begin with a hyphen.
TREE_GET? While you cannot check forA, or the definition ofTREE_GET, you can check for the variable no problem...