2
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 .

1
  • 1
    How about setting a global variable in addition to defining TREE_GET? While you cannot check for A, or the definition of TREE_GET, you can check for the variable no problem... Commented Sep 4, 2014 at 12:47

2 Answers 2

4

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

C Preprocessor Macros

Sign up to request clarification or add additional context in comments.

Comments

2

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.