问题描述
我在GNU / Linux上使用gcc,并安装了libc和libstd ++的调试文件和头文件。但是我不知道如何让gdb使用它们的源代码,特别是调试到libstd ++。libstdc ++本身的源代码似乎以复杂的结构提供。我认为目录命令是正确的选择。我在这里使用Debian / Ubuntu,并将源代码下载到我的主目录中。
我很确定我不需要为Fedora(几年前)采取特别的步骤。 Fedora也许是以一种特殊的方式准备的。所以我会很高兴一般的说明,适合每一个发行。
谢谢
更新
我想出来,除了 -g 之外,我需要使用
-D_GLIBCXX_DEBUG
code>,所以编译命令看起来像 $ g ++ -o test test.cpp -g -D_GLIBCXX_DEBUG
。
此外,我得到了关于缺少漂亮打印机的警告,我按照这里所述解决了:
现在我可以调试到libstdc ++,但是我总是得到这个消息:
断点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:没有这样的文件或目录。
(gdb)s
std :: basic_string< char,std :: char_traits< char>,std :: allocator< char> > :: basic_string(
this = 0x7fffffffe1c0,__s = 0x402930str,__a = ...)
at /usr/include/c++/4.7/bits/basic_string.tcc:217
217 __s + npos,__a),__a)
我不需要设置目录在我的下载源(我认为通过我的主目录搜索)。所以我想我需要一个不同的命令来解决这个问题,并发现set substitute-path并将其指向 /home/username/gcc-4.7-4.7.2/gcc-4.7.2/libstdc ++ - v3 强>但我不工作。为什么gdb在完全错误的地方寻找 allocator.h ?
首先找出来源: -
稍后将DEBUG_FLAGS编译libstdc ++设置为ON。
然后,尝试使用gdb调试。
I'm using gcc on GNU/Linux and the debug-files and headers of libc and libstd++ are installed. But I don't know how to tell gdb to use the source-code of them, especially to debug into libstd++.The source-code of libstdc++ itself seems to be provided in a complicated structure. I think the directory command is the right choice. I'm using here Debian/Ubuntu and downloaded the source with apt-get source libstdc++6 into my home-directory.
I'm pretty sure I didn't need take special steps for this with Fedora (some years ago). Maybe Fedora was prepared in a special way for this. So I will be glad about general instructions, which fit for every distribution.
Thank you
Update
I figured out, that I need to compile with -D_GLIBCXX_DEBUG
in addition to -g
, so compile command looks like $ g++ -o test test.cpp -g -D_GLIBCXX_DEBUG
.
Furthermore I got warning about missing pretty printers, which I solved as described here:http://gcc.gnu.org/onlinedocs/libstdc++/manual/debug.html#debug.gdb
Now I can debug into libstdc++, but I always got this message:
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)
I don't need to set the directory in gdb to the my downloaded source (I' think it search through my home-directory). So I thought I need a different command to fix this and found "set substitute-path" and pointed it to /home/username/gcc-4.7-4.7.2/gcc-4.7.2/libstdc++-v3 but I doesn't work. Why does gdb look for allocator.h in the completely wrong place?
First find out the sources from :-https://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/index.html
Later compile libstdc++ with DEBUG_FLAGS set it ON.
Then, try it out to debug with gdb.
这篇关于通过libstdc ++进行调试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!