【问题标题】:How to modify the line of a breakpoint in gdb?如何修改gdb中的断点行?
【发布时间】:2016-05-07 01:24:11
【问题描述】:

我设置了一个断点并设置了它的条件和其他一些命令。现在我意识到我应该把它提前几行。如何更改断点的行而不删除它并丢失其设置?

【问题讨论】:

    标签: gdb breakpoints


    【解决方案1】:

    如何在不删除断点并丢失其设置的情况下更改断点的行?

    你不能。

    您可以做的是使用save breakpoints /tmp/bp.txt 命令保存所有断点的当前设置,编辑/tmp/bp.txt 文件以更新行信息(或其他任何内容),最后使用delete 删除当前断点和@987654324 @ 重新加载它们。

    【讨论】:

    • 谢谢!令人沮丧的是,如此简单的功能不存在。可能是我向 gdb 提出了一个补丁。
    【解决方案2】:

    考虑到您可能在很多情况下都希望这样做,我建议将以下内容添加到您的.gdbinit

    define loadbp
      delete breakpoints
      source .gdbbp
    end
    document loadbp
      Set stored breakpoints after deleting any current breakpoints.
    
    The breakpoints to load (set) are expected in ./.gdbbp which is the file created by savebp, but can
    be edited manually.
    
    Some breakpoints may not be set because the needed shared object hasn't been loaded yet.  gdb
    doesn't prompt when such breakpoint commands are not set interactively.  Consequently, it may be
    necessary to run this command again, once the shared object has been loaded.  To account for cases
    in which shared objects are loaded automatically by the dynamic loader, this command also sets a
    breakpoint in main.  This ensures that there is an early opportunity to call this command again to
    set shared object breakpoints.
    end
    
    define savebp
      save breakpoints .gdbbp
    end
    document savebp
      Store current breakpoints in .gdbbp for retrieval using loadbp.
    end
    

    要使用这些命令,您需要获取.gdbinit 或重新启动gdb。然后,输入savebp 并在gdb 命令提示符下按Enter,根据需要编辑./.gdbbp,然后输入loadbp 并在gdb 命令提示符下按Enter。

    请注意,正如所写,这些命令会相对于当前目录保存和加载.gdbbp。通常,这是您启动gdb 的目录,但您可以从gdb 中更改它,因此请注意文件的保存位置。 (您可以在gdb 命令提示符下运行pwd 命令查看当前目录是什么。)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-06-27
      • 1970-01-01
      • 2011-02-01
      • 2022-11-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多