gpt4 book ai didi

python - 通过python接口(interface)在gdb中的断点处执行命令

转载 作者:太空宇宙 更新时间:2023-11-04 03:30:08 25 4
gpt4 key购买 nike

不是 this question 的副本,因为我正在通过 gdb 的 python 接口(interface)工作。
This one类似但没有答案。

我在 python 中扩展了一个 gdb.breakpoint,这样它将某些寄存器写入文件,然后跳转到一个地址:在 0x4021ee , 我想写东西到文件,然后跳转到 0x4021f3

但是,command 中没有任何内容永远被处决。

import gdb
class DebugPrintingBreakpoint(gdb.Breakpoint):
def __init__(self, spec, command):
super(DebugPrintingBreakpoint, self).__init__(spec, gdb.BP_BREAKPOINT, internal = False)
self.command = command

def stop(self):
with open('tracer', 'a') as f:
f.write(chr(gdb.parse_and_eval("$rbx") ^ 0x71))
f.close()
return False



gdb.execute("start")
DebugPrintingBreakpoint("*0x4021ee", "jump *0x4021f3")
gdb.execute("continue")

如果我明确添加 gdb.execute(self.command)stop() 结束, 我得到 Python Exception <class 'gdb.error'> Cannot execute this command while the selected thread is running.:

有人在 python gdb 中有带断点的命令列表的工作示例吗?

最佳答案

尝试几个选项:

  1. 使用gdb.post_event从 stop() 稍后运行所需的命令。我相信您需要从您的函数返回 True,然后从您的事件中继续调用。
  2. 创建一个普通断点并监听events.stop检查您的断点是否命中。

关于python - 通过python接口(interface)在gdb中的断点处执行命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31380754/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com