I often find it useful to walk the stack when I'm debugging a program and get the symbols for any properly aligned, pointer-sized value I encounter. I've gotten sick of doing this manually and so I tried writing a command that does it for me. The problem is that "info symbol" doesn't seem to like using a convenience variable as its parameter when its parameter was set via pointer dereference. IE:
(gdb) info symbol 0xb6ca4d28
[Useful Symbol Information]
(gdb) set $pointer = $esp
(gdb) while ( *(int*)$pointer != 0xb6ca4d28)
>set $pointer += 4
>end
(gdb) x/x $pointer
0x6ebee064: 0xb6ca4d28
(gdb) set $dereferencePointer = *(int *)$pointer
(gdb) p/x $dereferencePointer
$103 = 0xb6ca4d28
(gdb) info symbol $dereferencePointer
No symbol matches $dereferencePointer.
(gdb) set $dereferencePointer = 0xb6ca4d28
(gdb) p/x $dereferencePointer
$104 = 0xb6ca4d28
(gdb) info symbol $dereferencePointer
[Useful symbol information]
(gdb)
Why is this? Is this a bug? Is there a different way to do this?
Thanks!
Luc
PS: Using vanilla GDB 7.5
Update from list:
This is most likely a bug.
The usual way to examine data in your program is with the print command (abbreviated p ), or its synonym inspect . It evaluates and prints the value of an expression of the language your program is written in (see section Using GDB with Different Languages).
The ptype [ARG] command will print the type. Show activity on this post. This question may be related: vtable in polymorphic class of C++ using gdb: (gdb) help set print object Set printing of object's derived type based on vtable info.
The symbol table contains debugging information that tells a debugger what memory locations correspond to which symbols (like function names and variable names) in the original source code file. The symbol table is usually stored inside the executable, yes.
GDB provides convenience variables that you can use within GDB to hold on to a value and refer to it later. These variables exist entirely within GDB; they are not part of your program, and setting a convenience variable has no direct effect on further execution of your program. That is why you can use them freely.
Bug or not, I recommend using the /a format specifier with p and x commands. This always works for me, and is faster to type, too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With