我可以阻止调试器进入 Boost 或 STL 头文件吗? [英] Can I prevent debugger from stepping into Boost or STL header files?

查看:17
本文介绍了我可以阻止调试器进入 Boost 或 STL 头文件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有 gdb 的 Qt Creator 在 Linux 平台上调试我的 C++ 代码.每当我使用 boost::shared_ptr 或类似代码时,调试器都会进入包含 boost 实现的头文件(即/usr/include/boost/shared_ptr.hpp).我想在调试方面忽略这些文件并简单地跳过它们.我知道我可以在它到达这些文件之一时立即退出,但是如果每个调试会话不这样做几次,调试会容易得多.

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.

我正在使用 gcc 编译器 (g++),在 OpenSuSE Linux 11.2 和 QtCreator 2.2 上运行(使用 gdb 作为调试器.)

I'm using the gcc compiler (g++), running on OpenSuSE Linux 11.2 with QtCreator 2.2 (which uses gdb as the debugger.)

编辑补充:该问题针对 Boost 文件,但也适用于 STL 文件.

Edit to add: The question is geared toward Boost files, but could also apply toward STL files as well.

推荐答案

GDB 无需进入 STL 和/usr 中的所有其他库:

将以下内容放入您的 .gdbinit 文件中.它搜索 gdb 已加载或可能加载的源(gdb 命令 info sources),并在它们的绝对路径以/usr"开头时跳过它们.它与 run 命令挂钩,因为符号在执行时可能会重新加载.

Put the following in your .gdbinit file. It searches through the sources that gdb has loaded or will potentially load (gdb command info sources), and skips them when their absolute path starts with "/usr". It's hooked to the run command, because symbols might get reloaded when executing it.

# skip all STL source files
define skipstl
python
# get all sources loadable by gdb
def GetSources():
    sources = []
    for line in gdb.execute('info sources',to_string=True).splitlines():
        if line.startswith("/"):
            sources += [source.strip() for source in line.split(",")]
    return sources

# skip files of which the (absolute) path begins with 'dir'
def SkipDir(dir):
    sources = GetSources()
    for source in sources:
        if source.startswith(dir):
            gdb.execute('skip file %s' % source, to_string=True)

# apply only for c++
if 'c++' in gdb.execute('show language', to_string=True):
    SkipDir("/usr")
end
end

define hookpost-run
    skipstl
end

要检查要跳过的文件列表,请在某处设置断点(例如,break main)并运行 gdb(例如,run),然后使用 <到达断点时的代码>信息源:

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 with info sources upon reaching the breakpoint:

(gdb) info skip
Num     Type           Enb What
1       file           y   /usr/include/c++/5/bits/unordered_map.h
2       file           y   /usr/include/c++/5/bits/stl_set.h
3       file           y   /usr/include/c++/5/bits/stl_map.h
4       file           y   /usr/include/c++/5/bits/stl_vector.h
...

通过添加对 SkipDir(<some/absolute/path>) 的调用,很容易扩展它以跳过其他目录.

Its easy to extend this to skip other directories as well by adding a call to SkipDir(<some/absolute/path>).

这篇关于我可以阻止调试器进入 Boost 或 STL 头文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆