通过libstdc ++进行调试

时间:2013-04-15 20:11:53

标签: c++ debugging libstdc++

我在GNU / Linux上使用gcc,并且安装了libc和libstd ++的调试文件和头文件。但我不知道如何告诉gdb使用它们的源代码,特别是调试到libstd ++。 libstdc ++本身的源代码似乎是以复杂的结构提供的。我认为目录命令是正确的选择。我在这里使用Debian / Ubuntu并将 apt-get source libstdc ++ 6 下载到我的主目录。

我很确定我不需要在Fedora(几年前)采取特殊措施。也许Fedora是以特殊方式准备的。因此,我会对适用于每个发行版的一般说明感到高兴。

谢谢

更新
我想,除了-D_GLIBCXX_DEBUG之外,我需要使用-g进行编译,因此编译命令看起来像$ g++ -o test test.cpp -g -D_GLIBCXX_DEBUG

此外,我收到了关于缺少漂亮打印机的警告,我按照此处的描述解决了这个问题: http://gcc.gnu.org/onlinedocs/libstdc++/manual/debug.html#debug.gdb

现在我可以调试到libstdc ++,但我总是收到这条消息:

Breakpoint 1, main () at test.cpp:9
9       string str = "str";
(gdb) s
std::allocator<char>::allocator (this=0x7fffffffe1e0)
    at /build/buildd/gcc-4.7-4.7.2/build/x86_64-linux-gnu/libstdc++-v3/include/bits/allocator.h:104
104 /build/buildd/gcc-4.7-4.7.2/build/x86_64-linux-gnu/libstdc++-v3/include/bits/allocator.h: No such file or directory.
(gdb) s
std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string (
    this=0x7fffffffe1c0, __s=0x402930 "str", __a=...)
    at /usr/include/c++/4.7/bits/basic_string.tcc:217
217                    __s + npos, __a), __a)

我不需要将gdb中的目录设置为我下载的源代码(我想它通过我的主目录搜索)。所以我认为我需要一个不同的命令来解决这个问题并找到“set substitute-path”并将其指向 /home/username/gcc-4.7-4.7.2/gcc-4.7.2/libstdc ++ - v3 但我不行。为什么gdb在完全错误的地方寻找 allocator.h

1 个答案:

答案 0 :(得分:0)

首先找出来源: - https://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/index.html

稍后使用DEBUG_FLAGS编译libstdc ++将其设置为ON。

然后,尝试使用gdb进行调试。

相关问题