Reading variables while debugging with GDB (C)

I am beginner with GDB debbuging. I need read variables in GDB, I use the command info variable and get this information:

 0x000007c4 variable1.0
 0x000007c8 variable2.1

I set a breakpoint inside the variables function and these are defined how type long *. How can I read the value inside these correctly? I tried with show, display, print $variable1, p/x variable and so on commands.

Sorry for my grammar, i am not native speaker.

Upvotes: 3

Views: 1467

Answers (1)

Carlos O'Donell
Carlos O'Donell

Reputation: 614

To view the contents of memory use gdb's x/FMT ADDRESS command e.g. x/d 0x000007c4 (to display an integer sized object from address 0x000007c4 and format it in decimal).

The info variables command in gdb will list all global and static variables and their program addresses. You don't describe the language or implementation you're using, but in C the variable name "variable1.0" is not valid. Therefore it must have been created by some link editor or the compiler in a post-process. Therefore the symbol may not exist in debug information and is only accessible by directly viewing the contents of memory, which is why the gdb p command doesn't work (there is no valid expression to show you that variable because it's not a variable, but just a symbol at an address).

Upvotes: 3

Related Questions