在gdb中命中断点后如何继续执行?

在gdb中命中断点后如何继续执行?,gdb,Gdb,在gdb中调试一个简单的程序时,我希望在遇到断点后自动继续执行。据我所知,有两种方法可以实现它: 1.使用吊钩挡块 但似乎钩挡只触发一次。下次命中另一个断点时,执行仍然停止 2使用gdb.events.stop.connect 这种方法效果很好。但如果遇到太多断点,则会出现一个错误致命的Python错误:无法从堆栈溢出中恢复。发生。 这似乎是因为递归调用。我想知道为什么gdb.execute'continue'会导致这个问题 我在网上搜索,仍然没有找到解决方案 PS:Ubuntu 16.04上的

在gdb中调试一个简单的程序时,我希望在遇到断点后自动继续执行。据我所知,有两种方法可以实现它:

1.使用吊钩挡块

但似乎钩挡只触发一次。下次命中另一个断点时,执行仍然停止

2使用gdb.events.stop.connect

这种方法效果很好。但如果遇到太多断点,则会出现一个错误致命的Python错误:无法从堆栈溢出中恢复。发生。 这似乎是因为递归调用。我想知道为什么gdb.execute'continue'会导致这个问题

我在网上搜索,仍然没有找到解决方案

PS:Ubuntu 16.04上的gdb 7.11.1版

任何建议都将不胜感激!提前感谢。

看来,在吊钩止动块内继续工作不正常。你看到我昨天发的邮件了吗

我认为,这里最好的方法是用python编写一个方便的函数并设置一个条件断点。或使用命令-请参阅GDB用户手册的断点命令列表部分

以下是如何操作,手册中也有描述

python模块:

import gdb

class should_skip_f(gdb.Function):
    def __init__ (self):
        super (should_skip_f, self).__init__("should_skip")

    def invoke(self):
        return True  # Your condition here

should_skip_f()
至于递归——是的,如果一个人谈论一次性的东西的设计,那么这是一个糟糕的调试器脚本设计。如果像这样扩展python脚本,您可以检查那里发生了什么

import inspect
...
  def handle_stop_event(event):
    ...
    print(len(inspect.stack())) # Or you can print the frames themselves...
Python解释器不知道执行不会从gdb.executecontinue返回,因此调用此函数的Python堆栈帧永远不会被销毁


您可以增加解释器的最大堆栈大小,但正如我所说,这个脚本对我来说似乎不是最好的解决方案。

非常感谢。向断点添加条件不是我想要的。正如您所提到的,我以前试图增加最大堆栈大小,这对我来说也不是一个更好的解决方案。但在我的例子中,使用命令效果很好。我以前好像误用了命令。尽管如此,我还是不知道如何在一个gdb.execute调用中使用命令。
import gdb

class should_skip_f(gdb.Function):
    def __init__ (self):
        super (should_skip_f, self).__init__("should_skip")

    def invoke(self):
        return True  # Your condition here

should_skip_f()
(gdb) b <your target> if !$should_skip()
(gdb) condition <BNUM> !$should_skip()
'commands [LIST...]'
'... COMMAND-LIST ...'
'end'
     Specify a list of commands for the given breakpoints.  The commands
     themselves appear on the following lines.  Type a line containing
     just 'end' to terminate the commands.
import inspect
...
  def handle_stop_event(event):
    ...
    print(len(inspect.stack())) # Or you can print the frames themselves...