debugging 通过libstdc++调试

gg0vcinb  于 2023-04-21  发布在  其他
关注(0)|答案(1)|浏览(143)

我在GNU/Linux上使用gcc,安装了libc和libstd的调试文件和头文件。但我不知道如何告诉gdb使用它们的源代码,特别是调试libstd。libstdc本身的源代码似乎是以复杂的结构提供的。我认为 directory 命令是正确的选择。我在这里使用Debian/Ubuntu并下载了源代码与 *apt-将libstdc6* 源文件放到我的主目录中。
我很确定我不需要在Fedora上为此采取特殊的步骤(几年前)。也许Fedora为此做了特殊的准备。所以我很高兴有适合每个发行版的通用说明。
谢谢你

更新

我发现,除了-g,我还需要用-D_GLIBCXX_DEBUG编译,所以编译命令看起来像$ 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在完全错误的地方

j0pj023g

j0pj023g1#

首先查找来源:-https://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/index.html
稍后编译libstdc++,并将DEBUG_FLAGS设置为ON。
然后,尝试使用gdb进行调试。

相关问题