Recently, I want to use GDB to debug my C++ program. But I find when I use CTRL+X+A to see the source code of my program, it cannot show the library code of C++. For example, when I want to trace "cout", it dosen't show me the class code, it just skips the line of "cout", So, what should I do to trace the C++ library? Should I install the souce code package of libstdc++ like install source eglibc?

This is the code of the example C++ program:

    #include <iostream>
    int main(void)
        std::cout << "Hello World!" << std::endl;
        return 0;

Compling with:

g++ test.cpp -g


OK, I have installed the gcc source file. But when I run gdb, it searches symbols in /build/buildd/gcc-4.8-4.8.2/...This is not match with the default gcc source file name. And the default path of gdb is different from the directory of gcc. For example, when gdb loads the 'cout', it searches in /build/buildd/gcc-4.8-4.8.2/build/x86_64-linux-gnu/libstdc++-v3/include. But the default is /build/buildd/gcc-4.8.2/libstdc++-v3/include/std, How to solve this?

GCC source file install with:

sudo apt-get install gcc-4.8-source

(When I run sudo apt-get source libstdc++, is recomments like this) Then:

sudo tar -C /build/buildd -xf /usr/src/gcc-4.8/gcc-4.8.2.tar.xz

BTW, There seems to be a same bug like https://bugs.launchpad.net/ubuntu/+source/gdb/+bug/921839

  • Close-voters: This is a question about how to use a software development tool in Ubuntu (that is provided officially for Ubuntu and widely used). I'd be reluctant to close this as off-topic for being about programming. – Eliah Kagan Sep 16 '14 at 19:39

You need the debugging files package of the stdlibc++ you're using, and optionally the source files. They're available through the package manager or apt-get.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.