gpt4 book ai didi

python - 在 Python 脚本控制的 GDB 中添加断点命令列表

转载 作者:太空狗 更新时间:2023-10-30 00:10:52 26 4
gpt4 key购买 nike

我正在使用 Python 通过批处理命令控制 GDB。这是我调用 GDB 的方式:

$ gdb --batch --command=cmd.gdb myprogram

cmd.gdb 列表仅包含调用 Python 脚本的行

source cmd.py

cmd.py 脚本尝试创建断点和附加的命令列表

bp = gdb.Breakpoint("myFunc()") # break at function in myprogram
gdb.execute("commands " + str(bp.number))
# then what? I'd like to at least execute a "continue" on reaching breakpoint...
gdb.execute("run")

问题是我不知道如何将任何 GDB 命令附加到 Python 脚本的断点。有没有办法做到这一点,还是我错过了一些更简单、更明显的自动执行断点特定命令的工具?

最佳答案

可以使用来自 GDB 7.7.1 的

def stop:

gdb.execute('file a.out', to_string=True)
class MyBreakpoint(gdb.Breakpoint):
def stop (self):
gdb.write('MyBreakpoint\n')
# Continue automatically.
return False
# Actually stop.
return True
MyBreakpoint('main')
gdb.execute('run')

记录在:https://sourceware.org/gdb/onlinedocs/gdb/Breakpoints-In-Python.html#Breakpoints-In-Python

另请参阅:How to script gdb (with python)? Example add breakpoints, run, what breakpoint did we hit?

关于python - 在 Python 脚本控制的 GDB 中添加断点命令列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25431341/

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