简体   繁体   English

如何修改gdb中的断点行?

[英]How to modify the line of a breakpoint in gdb?

I set a breakpoint and set its conditions and some other commands.我设置了一个断点并设置了它的条件和其他一些命令。 Now I realize that I should had set it a few lines ahead.现在我意识到我应该提前几行设置它。 How can I change the line of the breakpoint without deleting it and losing its settings?如何更改断点的行而不删除它并丢失其设置?

How can I change the line of the breakpoint without deleting it and losing its settings?如何更改断点的行而不删除它并丢失其设置?

You can't.你不能。

What you can do is use save breakpoints /tmp/bp.txt command to save current settings for all breakpoints, edit the /tmp/bp.txt file to update the line info (or anything else), and finally delete to remove current breakpoints and source /tmp/bp.txt to reload them.您可以做的是使用save breakpoints /tmp/bp.txt命令保存所有断点的当前设置,编辑/tmp/bp.txt文件以更新行信息(或其他任何内容),最后delete以删除当前断点和source /tmp/bp.txt重新加载它们。

Considering that you will probably want to do that on many occasions, I suggest adding the following to your .gdbinit :考虑到您可能在很多情况下都想这样做,我建议将以下内容添加到您的.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

To use those commands, you need to source .gdbinit or restart gdb .要使用这些命令,您需要获取.gdbinit或重新启动gdb Then, type savebp and hit Enter at the gdb command prompt, edit ./.gdbbp as desired, then type loadbp and hit Enter at the gdb command prompt.然后,在gdb命令提示符下键入savebp并按 Enter,根据需要编辑./.gdbbp ,然后键入loadbp并在gdb命令提示符下按 Enter。

Note that, as written, those commands save and load .gdbbp relative to the current directory.请注意,正如所写,这些命令相对于当前目录保存和加载.gdbbp Usually, that's the directory from which you started gdb , but you can change it from within gdb , so pay attention to where the file is save.通常,这是您启动gdb的目录,但您可以在gdb内更改它,因此请注意文件的保存位置。 (You can run the pwd command at the gdb command prompt to see what the current directory is.) (你可以在gdb命令提示符下运行pwd命令来查看当前目录是什么。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM