How can I access the cpu registers of in the current debugged instance? From gdb you can call for example printf "0x%x", $eax
and set $eax_b = $eax
is there also a way to do this via the python support gdb gives? Or should I create a python function which can be call like save-reg "eax" $eax
which on his hand stores the registers in an array where I want them to be stored?
On the other hand, with gdb script you can also set $eax = 1000
for example, this I would also like to do from within a python script, instead of a gdb script.
I don't believe the Python API to GDB offers direct access to the registers, but depending on what you want to do with it you can access it either by evaluating the gdb command with gdb.execute()
, or evaluate the "$eax"
expression with gdb.parse_and_eval()
:
(gdb) p $rbx
$23 = 140737488348072
(gdb) python print type(gdb.parse_and_eval("$rbx")), gdb.parse_and_eval("$rbx")
<type 'gdb.Value'> 140737488348072
(This example is at the gdb prompt, but the gdb
module isn't any different in other code executed in GDB.)
Recent gdb
versions (like Debian 7.12-6) have a read_register
method in the gdb.Frame
class.
(gdb) info register rip
rip 0x7f68656c142d 0x7f68656c142d <__lll_lock_wait+29>
(gdb) python print(gdb.selected_frame().read_register('rip'))
0x7f68656c142d <__lll_lock_wait+29>
(gdb)
That class has no corresponding method to modify a register value. It makes sense for that method to belong to that class because register values differ across stack frames, in the sense that gdb
shows saved register values in outer frames, such as the ones returned by the older
method, callers of the inner frames.
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