本文介绍了在由Python脚本控制的GDB中添加断点命令列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Python通过批处理命令来控制GDB。这是我打电话给GDB的方式:

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

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

 来源cmd.py 

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



<$ p
gdb.execute(commands+ str(bp.number))
在函数myprogram中$ break $ my $那么什么?我想至少在达到断点时执行continue...
gdb.execute(run)

问题在于如何从Python脚本附加任何GDB命令到断点。有没有办法做到这一点,或者我错过了一些更容易,更明显的自动执行断点特定命令的工具吗?

解决方案

def stop

  gdb.execute('file a.out',to_string = True)
class MyBreakpoint(gdb.Breakpoint):
def stop(self):
gdb。写('MyBreakpoint \\\
')
#自动继续。
返回False
#其实停止。
return True
MyBreakpoint('main')
gdb.execute('run')

记录在:



另请参阅:如何脚本gdb(用python )?示例添加断点,运行,我们碰到了什么断点?


I'm using Python to control GDB via batch commands. Here's how I'm calling GDB:

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

The cmd.gdb listing just contains the line calling the Python script

source cmd.py

And the cmd.py script tries to create a breakpoint and attached command list

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")

The problem is I'm at a loss as to how to attach any GDB commands to the breakpoint from the Python script. Is there a way to do this, or am I missing some much easier and more obvious facility for automatically executing breakpoint-specific commands?

解决方案

def stop from GDB 7.7.1 can be used:

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')

Documented at: https://sourceware.org/gdb/onlinedocs/gdb/Breakpoints-In-Python.html#Breakpoints-In-Python

See also: How to script gdb (with python)? Example add breakpoints, run, what breakpoint did we hit?

这篇关于在由Python脚本控制的GDB中添加断点命令列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 22:09