Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting symbol information for value held in GDB convenience variable

Tags:

c++

c

debugging

gdb

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.

like image 630
shroudednight Avatar asked Oct 17 '12 18:10

shroudednight


People also ask

What does P do in GDB?

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).

Which command in GDB is used to find the type of variable in C?

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.

What is symbol in GDB?

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.

How do I declare a variable in GDB?

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.


1 Answers

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.

like image 64
Alexey Feldgendler Avatar answered Oct 13 '22 01:10

Alexey Feldgendler