如何在gdb中修改断点的行?

时间:2016-05-07 01:24:11

标签: gdb breakpoints

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

2 个答案:

答案 0 :(得分:2)

  

如何更改断点的行而不删除断点并丢失其设置?

你不能。

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

答案 1 :(得分:1)

考虑到您可能希望在很多情况下都这样做,我建议在您的 .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 内更改它,因此请注意文件的保存位置。 (您可以在 pwd 命令提示符下运行 gdb 命令以查看当前目录是什么。)