Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
360 views
in Technique[技术] by (71.8m points)

c++ - Debug through libstdc++

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...