如何在 gdb 中使用 python 访问寄存器
如何访问当前调试实例的cpu寄存器?从 gdb 中,您可以调用例如 printf "0x%x", $eax
和 set $eax_b = $eax
是否还有一种方法可以通过 python 支持 gdb 来执行此操作给?或者我应该创建一个 python 函数,可以像 save-reg "eax" $eax
这样调用,它在他手上将寄存器存储在我希望将它们存储的数组中?
另一方面,使用 gdb 脚本,您还可以set $eax = 1000
例如,我也想在 python 脚本中而不是 gdb 脚本中执行此操作。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不相信 GDB 的 Python API 提供对寄存器的直接访问,但是根据您想要用它做什么,您可以通过使用 gdb 评估 gdb 命令来访问它。 execute(),或者使用
gdb.parse_and_eval()
计算"$eax"
表达式:(这个例子是在 gdb 提示符下,但是
>gdb
模块与 GDB 中执行的其他代码没有任何不同。)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 withgdb.parse_and_eval()
:(This example is at the gdb prompt, but the
gdb
module isn't any different in other code executed in GDB.)最近的 gdb 版本(如 Debian 7.12-6)在 gdb.Frame 类中有一个 read_register 方法。
该类没有相应的方法来修改寄存器值。该方法属于该类是有意义的,因为寄存器值在堆栈帧之间有所不同,从某种意义上说,gdb 显示了外部帧中保存的寄存器值,例如由较旧的寄存器返回的值 方法,内部框架的调用者。
Recent
gdb
versions (like Debian 7.12-6) have aread_register
method in thegdb.Frame
class.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 theolder
method, callers of the inner frames.