In GDB shell I can get symbol name from address like this:
(gdb) info symbol 0x405ece
top::test_thread() in section .text of test_procs
How can I do the same using Python GDB API (https://sourceware.org/gdb/onlinedocs/gdb/Python-API.html)? Is it possible at all?
Something like this should work (untested):
block = gdb.block_for_pc(0x405ece)
while block and not block.function:
block = block.superblock
print block.function.print_name
Related
I would like to do use a variable from my bash/ gdb environment and set it as a convenience variable in gdb.
(gdb) show environment
bar=1
(gdb) set $foo = (show environment bar)
(gdb) show convenience
foo=1
Of course, my second (gdb) command returns an error. I have looked quite a bit to see if something like this is possible. But perhaps I am looking in the wrong direction. Could anyone be of help?
You could do it using builtin Python, like so:
(gdb) py import os
(gdb) py gdb.set_convenience_variable("home", os.environ["HOME"])
(gdb) p $home
$1 = "/home/me"
I used T32 to load bin files and elf and wrote scripts to extract the Pc , Lr register values from the ELF file. Now I have the address for e.g say PC's address is 0xccccdddd. Now I need to get the symbol corresponding to that.
I ran gdb and used gdb info symbol 0xccccdddd and got the symbol name.
But I need to know if there is any command in T32 itself to get the symbol name. Or can I get the symbol name from some commands like readelf or objdump.
Thanks in advance.
The command to open a window to see all the static symbols is
sYmbol.Browse
To learn more about that window, I recommend to check the "Training HLL Debugging" (training_hll.pdf) from your TRACE32 installation.
To get only the symbol related to one single address use the PRACTICE function sYmbol.Name(<addr>). Functions have to be used together with a command. To simply display the name use the command PRINT.
E.g.:
PRINT sYmbol.Name(P:0xccccdddd)
Note that the address-offset has to be prefixed by an access class. Usually the access class "P:" stands for program memory, while "D:" stands for data memory. See the "Processor Architecture Manual" for more CPU specific access classes (Menu > Help > Processor Architecture Manual)
I found a suspicious deadlock at address myfile.exe+0x144c7 (from list of threads in ProcessExplorer). Now, I want to know which function it is.
info symbol addr
requires that addr is absolute. Is there a command that takes the relative address given by ProcessExplorer. I can add 0x400000 but it would be better if GDB could do it for me.
gdb accepts an expression for the symbol address, so you can do something like this:
info symbol 0x40000000 + 0x144c7
If you check "info variables" (or use nm on the executable) there's probably a symbolic name for the text segment containing your code, so you can also do something like:
info symbol _init + 0x144c7
Note that symbol might not work as expected if your problem is in a DLL or other text segment.
Let's say I'm debugging with valgrind and gdb by doing:
$ valgrind --vgdb-error=0 ./magic
...and then in a second terminal:
$ gdb ./magic
...
(gdb) target remote | /usr/lib/valgrind/../../bin/vgdb
If I want to examine the defined-ness of some memory, I can use:
(gdb) p &batman
$1 = (float *) 0xffeffe20c
(gdb) p sizeof(batman)
$2 = 4
(gdb) monitor get_vbits 0xffeffe20c 4
ffffffff
Using three commands to do one thing is kind of annoying, especially since I usually want to do this a few times for many different variables in the same stack frame. But if I try the obvious thing, I get:
(gdb) monitor get_vbits &batman sizeof(batman)
missing or malformed address
Is it possible to get gdb to evaluate &batman and sizeof(batman) on the same line as my monitor command?
But if I try the obvious thing, I get: missing or malformed address
This is from GDB doc (http://sourceware.org/gdb/onlinedocs/gdb/Connecting.html#index-monitor-1210) for the monitor cmd:
monitor cmd
This command allows you to send arbitrary commands
directly to the remote monitor. Since gdb doesn't care about the
commands it sends like this, this command is the way to extend gdb—you
can add new commands that only the external monitor will understand
and implement.
As you can see "gdb doesn't care about the commands it sends like this". It probably means that the command after monitor is not processed in any way and sent AS IS.
What you can do to evaluate your variable on the same line is to use user defined commands in gdb (http://sourceware.org/gdb/onlinedocs/gdb/Define.html). Define your own comand and use the eval gdb command to prepare your command with necessary values (http://sourceware.org/gdb/current/onlinedocs/gdb/Output.html#index-eval-1744):
define monitor_var
eval "monitor get_vbits %p %d", &$arg0, sizeof($arg0)
end
And then use it like this:
(gdb) monitor_var batman
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.
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.