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

Asked

Viewed 69 times

4

I have the following line of code:

int a = MAX(b,c);

How to verify macro definition MAX(b,c)? 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.

1 answer

5


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

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

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

In gdb:

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

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.