gdbgdb-python

Get address of a global symbol from symbol name with GDB Python API


Is there a way by which I can get the address of a global symbol in my binary if I know its name with the GDB Python API ?

Is python print(gdb.parse_and_eval('symbol').address) the correct method t o obtain this value ?


Solution

  • Well, you answered yourself already correctly. Easy enough to verify:

    (gdb) p &t
    $2 = (time_t *) 0x562076476018 <t>
    (gdb) python print(gdb.parse_and_eval('t').address)
    0x562076476018 <t>
    (gdb)