我可以阻止调试器单步执行 Boost 或 STL 头文件吗?
我使用 Qt Creator 和 gdb 在 Linux 平台上调试我的 C++ 代码。每当我使用 boost::shared_ptr 等时,调试器都会进入包含 boost 实现的头文件(即 /usr/include/boost/shared_ptr.hpp
) 。我想在调试时忽略这些文件并简单地跳过它们。我知道,一旦到达这些文件之一,我就可以退出,但调试起来会更容易,而无需在每个调试会话中多次执行此操作。
我正在使用 gcc 编译器 (g++
),在带有 QtCreator 2.2 的 OpenSuSE Linux 11.2 上运行(使用 gdb
作为调试器。)
编辑添加:问题是适合的适用于 Boost 文件,但也适用于 STL 文件。
I'm using Qt Creator with gdb to debug my C++ code on a Linux Platform. Whenever I use a boost::shared_ptr
or the like, the debugger steps into the header files containing the boost implementation (i.e. /usr/include/boost/shared_ptr.hpp
). I would like to ignore these files in terms of debugging and simply step over them. I know that I can step out as soon as it reaches one of these files, but it would be much easier to debug without doing so several times per debugging session.
I'm using the gcc compiler (g++
), running on OpenSuSE Linux 11.2 with QtCreator 2.2 (which uses gdb
as the debugger.)
Edit to add: The question is geared toward Boost files, but could also apply toward STL files as well.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
GDB 不进入 STL 和 /usr 中的所有其他库:
将以下内容放入
.gdbinit
文件中。它搜索 gdb 已加载或可能加载的源(gdb 命令infosource
),并在其绝对路径以“/usr”开头时跳过它们。它与run
命令挂钩,因为执行它时可能会重新加载符号。要检查要跳过的文件列表,请在某处设置断点(例如,
break main
)并运行 gdb(例如,run
),然后使用info 检查到达断点时的sources
:通过添加对
SkipDir()
的调用,可以轻松扩展它以跳过其他目录。GDB without stepping into STL and all other libraries in /usr:
Put the following in your
.gdbinit
file. It searches through the sources that gdb has loaded or will potentially load (gdb commandinfo sources
), and skips them when their absolute path starts with "/usr". It's hooked to therun
command, because symbols might get reloaded when executing it.To check the list of files to be skipped, set a breakpoint somewhere (e.g.,
break main
) and run gdb (e.g.,run
), then check withinfo sources
upon reaching the breakpoint:Its easy to extend this to skip other directories as well by adding a call to
SkipDir(<some/absolute/path>)
.gdb 是可编写脚本的。它有 while、if、变量、shell 子命令、用户定义函数 (define) 等。它有用于脚本化的 python 接口。
通过一些工作,您可以按照以下方式制作 gdb 脚本:
或者查找是否有人已经制作了这样的脚本
gdb is scriptable. it has while, if, variables, shell subcommands, user-defined functions (define) etc etc. it has python interface for scriptability.
With a bit of work, you can to make gdb script along these lines:
or find whether somebody already made such script
来自 https://stackoverflow.com/a/31629136/5155476:
我有同样的需求。我扩展了 gdb 中的“skip”命令以支持新类型“dir”。我现在可以在 gdb 中执行此操作:
然后我就不会在任何第 3 方标头中停止。
这是一个包含此信息+补丁的网页(如果它对任何人有帮助的话): info &跳过 GDB 中的目录的补丁
From https://stackoverflow.com/a/31629136/5155476:
I had this same need. I extended the 'skip' command in gdb to support a new type 'dir'. I can now do this in gdb:
and then I'm never stopped in any of my 3rd party headers.
Here's a webpage w/ this info + the patch if it helps anyone: info & patch to skip directories in GDB
您可以不执行 s(步骤)
b 在您想要停止的函数的第一行(b Class::method 或 b file.cpp:line),
然后c。
gdb 将绕过 boost 代码并在 b 中给出的点处中断,您希望它
可以工作,但看起来很乏味。这是习惯问题。通过重复变得更容易。
msvc 的行为与 gdb 类似
Instead of doing s (step), you can
b on first line of your function where you want to stop (b Class::method, or b file.cpp:line),
then c.
gdb will bypass the boost code and break at the point given in b, where you want it
this works but can seem tedious. it's matter of habit. becomes easier with repetition.
msvc behaves similar to gdb