1 #define FOO foo_value
2 #define STR(val) "STR of "#val
3 #define VAL STR(FOO)
4
5 int main(int argc, const char *argv[])
6 {
7 const char* t = VAL;
8 #undef VAL
9 #define VAL "test" // define VAL to a different value
10 const char* t2 = VAL;
11
12 return 0;
13 }
We compile the code with gcc -g3 command, and debug it in gdb. Then we can examine the actual value of VAL macro with macro exp command.2 #define STR(val) "STR of "#val
3 #define VAL STR(FOO)
4
5 int main(int argc, const char *argv[])
6 {
7 const char* t = VAL;
8 #undef VAL
9 #define VAL "test" // define VAL to a different value
10 const char* t2 = VAL;
11
12 return 0;
13 }
(gdb) macro exp VAL // run when break on line 7
expands to: "STR of ""FOO"
....
(gdb) macro exp VAL // run when break on line 10
expands to: "test"
It's worthy of note that the macro expansion is context awareness in gdb, so we can get different value when the application breaks on line 7 and 10.