[英]Adding breakpoint command lists in GDB controlled from Python script
我正在使用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
我认为这可能是一种更好的方法,而不是使用GDB的“命令列表”工具。
bp1 = gdb.Breakpoint("myFunc()")
# Define handler routines
def stopHandler(stopEvent):
for b in stopEvent.breakpoints:
if b == bp1:
print "myFunc() breakpoint"
else:
print "Unknown breakpoint"
gdb.execute("continue")
# Register event handlers
gdb.events.stop.connect (stopHandler)
gdb.execute("run")
您也可以将gdb.Breakpoint子类化为添加“句柄”例程,而不是在循环内进行相等性检查。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.