Cha*_*nce 19 debugging gcc boost gdb qt-creator
我正在使用Qt Creator和gdb在Linux平台上调试我的C++代码.每当我使用a boost::shared_ptr等时,调试器都会进入包含boost实现的头文件(即/ usr/include /boost/shared_ptr.hpp).我想在调试方面忽略这些文件,然后简单地跳过它们.我知道我可以在它到达其中一个文件时立即退出,但是如果不在每个调试会话中多次这样做,那么调试会更容易.
我正在使用gcc编译器(g++),在带有QtCreator 2.2的OpenSuSE Linux 11.2上运行(gdb用作调试器).
编辑添加:问题适用于Boost文件,但也可以应用于STL文件.
GDB没有进入STL和/ usr中的所有其他库:
将以下内容放入您的.gdbinit文件中.它搜索gdb已加载或可能加载的源(gdb命令info sources),并在其绝对路径以"/ usr"开头时跳过它们.它被挂钩到run命令,因为符号可能在执行时被重新加载.
# 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
Run Code Online (Sandbox Code Playgroud)
要检查要跳过的文件列表,请在某处设置断点(例如break main)并运行gdb(例如run),然后info sources在到达断点时进行检查:
(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
...
Run Code Online (Sandbox Code Playgroud)
它很容易扩展这个以通过添加调用来跳过其他目录SkipDir(<some/absolute/path>).
And*_*rei -1
您可以在
要停止的函数的第一行上执行 b(b Class::method 或 b file.cpp:line),
然后执行 c,而不是执行 s(步骤)。
gdb 将绕过 boost 代码并在 b 中指定的位置处中断(您想要的位置)
这可行,但看起来很乏味。这是习惯问题。通过重复变得更容易。
msvc 的行为与 gdb 类似
| 归档时间: |
|
| 查看次数: |
2001 次 |
| 最近记录: |