Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print #define value in gdb?

Tags:

c

gdb

So I'm doing some stack/heap digging with gdb and trying to grab the value for someInt, but have thrown my limited gdb knowledge to get at it w/o effect. I need to get the value of someInt 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?

like image 403
Kurt Wagner Avatar asked Nov 12 '14 07:11

Kurt Wagner


1 Answers

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
4
5       int main()
6       {
7               int a=0;
8
9               if(a == someInt)
10              {
11                      printf("!\n");
12              }
13      }
(gdb) p someInt
$1 = 1111
like image 175
fukanchik Avatar answered Oct 20 '22 00:10

fukanchik