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

7

我设置了一个断点,并设置了它的条件和其他一些命令。现在我意识到我应该在几行之前设置它。如何在不删除断点并且不失去其设置的情况下更改断点所在的行?

我设置了一个断点并设置了它的条件和其他命令。现在我意识到我应该将其设置在几行之前。如何在不删除它并保留其设置的情况下更改断点所在的行?
2个回答

10

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

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


5
谢谢!很令人沮丧的是这样一个简单的功能却不存在。也许我可以向gdb提出一个补丁。 - Gabriel Diego

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。然后,在gdb命令提示符处键入savebp并按Enter键,根据需要编辑./.gdbbp,然后在gdb命令提示符处键入loadbp并按Enter键。
请注意,如所述,这些命令相对于当前目录保存和加载.gdbbp。通常,这是您启动gdb的目录,但您可以从gdb内部更改它,因此请注意文件保存的位置。(您可以在gdb命令提示符处运行pwd命令以查看当前目录是什么。)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接