Kurt Wagner Kurt Wagner - 24 days ago 8
C Question

How to print #define value in gdb?

So I'm doing some stack/heap digging with gdb and trying to grab the value for

, but have thrown my limited gdb knowledge to get at it w/o effect. I need to get the value of
using gdb, and it's only referenced at one location outside of the #define, line 20

#define someInt 0x11111111

void someFunc() {
// ...
int a = 0;
if(a==someInt) { //line 20

After calling gdb on the compiled program I've tried
gdb break 20
and then
gdb x\dw $someInt
I get No symbol 'someInt' in current context.
If I try
x/dw 0x11111111
I get 'Cannot access memory at address 0x11111111'. I can't recompile the code a la How do I print a #defined constant in GDB? and thus am lost as to how to print the value at that space.

How do I use gdb (most likely with x) to print out the value of someInt?

Answer Source

The answer is here: GCC -g vs -g3 GDB Flag: What is the Difference?

Compile with -O0 -ggdb3:

gcc -O0 -ggdb3 source.c

From doc

-ggdblevel - Request debugging information and also use level to specify how much information. The default level is 2.

Level 3 includes extra information, such as all the macro definitions present in the program. Some debuggers support macro expansion when you use -g3.

9               if(a == someInt)
(gdb) list
5       int main()
6       {
7               int a=0;
9               if(a == someInt)
10              {
11                      printf("!\n");
12              }
13      }
(gdb) p someInt
$1 = 1111