0

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?

random
  • 3,868
  • 3
  • 22
  • 39
  • From outside gdb see [debugging - How to get the symbol name for a memory address in GDB? - Stack Overflow](https://stackoverflow.com/questions/762628/how-to-get-the-symbol-name-for-a-memory-address-in-gdb) ■ Reverse question: [Get address of a global symbol from symbol name with GDB Python API - Stack Overflow](https://stackoverflow.com/questions/54070055/get-address-of-a-global-symbol-from-symbol-name-with-gdb-python-api?rq=1) – user202729 Dec 07 '21 at 01:42

1 Answers1

2

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
Employed Russian
  • 199,314
  • 34
  • 295
  • 362
  • It looks like iteration is not required in my case, since I know in advance that pointer holds valid address of function or method – random Dec 22 '17 at 01:02
  • Hmm.. also it seems that documentation is not correct. Instead of returning None for invalid address, it throws run-time exception – random Dec 22 '17 at 01:08
  • This does not work for things like `_start` symbol. (because it doesn't have debugging information? – user202729 Dec 19 '21 at 02:32