How to see the value of a define or macro in gdb?

4

I have the following line of code:

int a = MAX(b,c);

How to check the definition of the MAX(b,c) macro? Sometimes the same macro is defined in several different ways in a code (for example, depending on the architecture). This would help in these cases.

    
asked by anonymous 13.02.2015 / 15:27

1 answer

5

First, compile the program with the -g3 flag, to ask gcc to include all levels of debug information, including macro expansions.

In gdb, use the macro expand command to expand the macro. For example,

#define MAX(x, y) (((x) > (y)) ? (x) : (y))

No gdb:

(gdb) expand macro MAX(a,b)
>> (((a) > (b)) ? (a) : (b))

To see the value of a define, use the command info macro MACRO .

    
13.02.2015 / 15:27