4

For example, take the following minimal example:

#include <cstdio>
#include <stdexcept>

int main(int argc, char* argv[]){
#ifdef __GLIBCPP__
    std::printf("GLIBCPP: %d\n",__GLIBCPP__);
#endif
#ifdef __GLIBCXX__
    std::printf("GLIBCXX: %d\n",__GLIBCXX__);
#endif
    throw std::runtime_error("Were are libstdc++.so.6 debug symbols?");
    return 0;
}

When running it inside my gdb, it does not show the debug symbols for libstdc++.so.6:

$ g++ -o testmain test.cpp -ggdb --std=c++98 && gdb ./testmain
GNU gdb (Ubuntu 9.1-0ubuntu1) 9.1
Copyright (C) 2020 Free Software Foundation, Inc.
...
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./testmain...
(gdb) r
Starting program: /home/user/Downloads/testmain 
GLIBCXX: 20200408
terminate called after throwing an instance of 'std::runtime_error'
  what():  Were are libstdc++.so.6 debug symbols?
Program received signal SIGABRT, Aborted.
__GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
50  ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) bt f
#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
        set = {__val = {0, 0, 0, 0, 0, 0, 0, 0, 29295, 0, 0, 0, 0, 0, 0, 0}}
        pid = <optimized out>
        tid = <optimized out>
        ret = <optimized out>
#1  0x00007ffff7be1859 in __GI_abort () at abort.c:79
        save_stage = 1
        act = {__sigaction_handler = {sa_handler = ... <stderr>}
        sigs = {__val = {32, 0 <repeats 15 times>}}
#2  0x00007ffff7e67951 in ?? () from /lib/x86_64-linux-gnu/libstdc++.so.6
No symbol table info available.
#3  0x00007ffff7e7347c in ?? () from /lib/x86_64-linux-gnu/libstdc++.so.6
No symbol table info available.
#4  0x00007ffff7e734e7 in std::terminate() () from /lib/x86_64-linux-gnu/libstdc++.so.6
No symbol table info available.
#5  0x00007ffff7e73799 in __cxa_throw () from /lib/x86_64-linux-gnu/libstdc++.so.6
No symbol table info available.
#6  0x000055555555524a in main (argc=1, argv=0x7fffffffdef8) at test.cpp:11
No locals.
(gdb) 

It just shows No symbol table info available for the libstdc++.so.6 frames.

How can I show the symbols for the libstdc++.so.6?

Searching on this list https://packages.ubuntu.com/search?keywords=libstdc%2B%2B6, I already tried installing the following packages, but none of them fixed the problem:

  1. libgcc-10-dev:amd64 <none> 10.2.0-5ubuntu1~20.0
  2. libstdc++-10-dev:amd64 <none> 10.2.0-5ubuntu1~20.0
  3. libstdc++6-10-dbg:amd64 <none> 10.2.0-5ubuntu1~20.0
  4. libc6-amd64-cross:all <none> 2.31-0ubuntu7cross
  5. linux-libc-dev-amd64-cross:all <none> 5.4.0-21.25cross
  6. libc6-dev-amd64-cross:all <none> 2.31-0ubuntu7cross
  7. libstdc++6-amd64-cross:all <none> 10.2.0-5ubuntu1~20.04cross
  8. libgcc-10-dev-amd64-cross:all <none> 10.2.0-5ubuntu1~20.04cross
  9. libstdc++-10-dev-amd64-cross:all <none> 10.2.0-5ubuntu1~20.04cross
  10. libstdc++6-10-dbg-amd64-cross:all <none> 10.2.0-5ubuntu1~20.04cross
  11. libx32stdc++6-10-dbg:amd64 <none> 10.2.0-5ubuntu1~20.0

Related questions:

  1. How do you find what version of libstdc++ library is installed on your linux machine?
  2. /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.15' not found
$ cat /etc/os-release 
NAME="Ubuntu"
VERSION="20.04.1 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.1 LTS"
VERSION_ID="20.04"

Update 1

$ dpkg --list | grep libstdc++6
ii  libstdc++6:amd64                              10.2.0-5ubuntu1~20.04                 amd64        GNU Standard C++ Library v3
ii  libstdc++6-10-dbg-amd64-cross                 10.2.0-5ubuntu1~20.04cross1           all          GNU Standard C++ Library v3 (debug build) (amd64)
ii  libstdc++6-7-dbg:amd64                        7.5.0-6ubuntu2                        amd64        GNU Standard C++ Library v3 (debug build)
ii  libstdc++6-amd64-cross                        10.2.0-5ubuntu1~20.04cross1           all          GNU Standard C++ Library v3 (amd64)

Update 2

$ dpkg --list | grep libstdc++6
ii  libstdc++6:amd64                              10.2.0-5ubuntu1~20.04                 amd64        GNU Standard C++ Library v3
ii  libstdc++6-10-dbg:amd64                       10.2.0-5ubuntu1~20.04                 amd64        GNU Standard C++ Library v3 (debug build)
ii  libstdc++6-10-dbg-amd64-cross                 10.2.0-5ubuntu1~20.04cross1           all          GNU Standard C++ Library v3 (debug build) (amd64)
ii  libstdc++6-amd64-cross                        10.2.0-5ubuntu1~20.04cross1           all          GNU Standard C++ Library v3 (amd64)
Evandro Coan
  • 8,560
  • 11
  • 83
  • 144
  • ```sudo apt-get install libstdc++6``` maybe fixes the problem – secdet Nov 18 '20 at 13:10
  • Check what package provides your libstdc++6 and install the corresponding "-dbg" package. For Ubuntu 20.04 it should be libstdc++6-7-dbg or libstdc++6-10-dbg – Botje Nov 18 '20 at 13:26
  • @Botje , How can I check which package provides my `libstdc++6` ? I already have installed `libstdc++6-7-dbg`, `libstdc++6-10-dbg` and `libstdc++6`, but the problem persists. I updated the question with the output of `dpkg --list | grep libstdc++6` – Evandro Coan Nov 18 '20 at 13:34
  • 1
    That output says your libstdc++ is 10.2.0, so logically you must install the libstdc++6-10-dbg package, which is not yet installed according to your dpkg output. That -amd64-cross package you installed is used for cross-compiling. – Botje Nov 18 '20 at 13:37
  • @Botje , Now I run `sudo apt-get install libstdc++6-10-dbg` and updated the output of `dpkg --list | grep libstdc++6` on the question. But when I run my program, it still not showing the symbols on the stack frame. – Evandro Coan Nov 18 '20 at 13:47
  • FYI it's a stack _trace_ – Asteroids With Wings Nov 18 '20 at 13:50
  • Why do you need them? If you are debugging libstdc++, you probably should have it built from sources, and only link to the debug version when actually debugging it. Otherwise, every single C++ program on your machine will use the debug build of libstdc++, which will more likely than not slow it down to a grinding halt. – n. m. could be an AI Feb 16 '22 at 19:28
  • To see the ower of a mutex, and they are probably required to see the message of std::exception, and other low-level structures. – Evandro Coan Feb 16 '22 at 19:31
  • gdb can print values of stdlibc++ structures, low level or otherwise, just fine without libstdc++ debug symbols. Can you show a gdb command you want to use and cannot because there are no debug symbols? – n. m. could be an AI Feb 16 '22 at 22:23

3 Answers3

6

Background Story:

Days ago, I was also curious about the same question as yours. But that's on CentOS.

What can I do differently after I install those missing debug info packages for gdb?

You can check the question to see what I learnt during searching, I solve your question with those prior knowledge.

In short, for the same thing, in CentOS the difficulties come down to installing the debug info packages. Because the gdb in CentOS tells what exact version of some debug info files you need to install and it gives the full command.

debuginfo-install glibc-2.17-307.el7.1.x86_64 libgcc-4.8.5-44.el7.x86_64 libstdc++-4.8.5-44.el7.x86_64

But this command just can't work and you need to manually add some package sources to install that .

However, as soon as you succeed installing the debug info packages, everything else is set up nicely, even the source files! You can s step into e.g. abort() and list around the source code!


In Ubuntu:

  1. You have to find the exact version of your libstdc++.so.xxx and install the corresponding debug info files.

  2. No libarary(e.g. libstdc++) source files will be installed and set up after install the corresponding debug info files packages. But you can manually do it with set substitute-path.

Answer Part:

I made my gdb work under Ubuntu 18.04.5 LTS. I think that may applies to yours too.

  1. I assume you know this https://sourceware.org/gdb/onlinedocs/gdb/Separate-Debug-Files.html .

So firstly I ldd my.a.out.

libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fbfa6f84000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fbfa697b000)
...

In my Ubuntu, reading debug symbol for libc.so.6 is successful. So I want to check both .so files' .gnu_debuglink section.

libc.so.6 is a link to libc-2.27.so

so I read the above section with readelf -x.gnu_debuglink libc-2.27.so and gives me:

Hex dump of section '.gnu_debuglink':
  0x00000000 6c696263 2d322e32 372e736f 00000000 libc-2.27.so....
  0x00000010 32e033a0                            2.3.

This means its debug info file's name is libc-2.27.so, which exists in /usr/lib/debug/lib/x86_64-linux-gnu directory.

Now check libstdc++.so.6, which is a link to libstdc++.so.6.0.25 in my machine.

readelf -x.gnu_debuglink libstdc++.so.6.0.25 gives:

Hex dump of section '.gnu_debuglink':
  0x00000000 31313961 34346139 39373538 31313436 119a44a997581146
  0x00000010 32306338 65396438 65323433 64373039 20c8e9d8e243d709
  0x00000020 34663737 66362e64 65627567 00000000 4f77f6.debug....
  0x00000030 30573da0                            0W=.

This 119a44a99758114620c8e9d8e243d7094f77f6.debug is a build-id debug file.

  1. Learnt from your question and comments below, I do dpkg --list | grep libstdc++ and shows
ii  libstdc++-7-dev:amd64                      7.5.0-3ubuntu1~18.04                             amd64        GNU Standard C++ Library v3 (development files)
ii  libstdc++-8-dev:amd64                      8.4.0-1ubuntu1~18.04                             amd64        GNU Standard C++ Library v3 (development files)
ii  libstdc++6:amd64                           8.4.0-1ubuntu1~18.04                             amd64        GNU Standard C++ Library v3
ii  libstdc++6:i386                            8.4.0-1ubuntu1~18.04                             i386         GNU Standard C++ Library v3

So I sudo apt install libstdc++6-8-dbg.

Then I used dpgk-query -L libstdc++6-8-dbg to see what files are installed with this packages.

tianhe@tianhe-windy:/lib/x86_64-linux-gnu$ dpkg -L libstdc++6-8-dbg
/.
/usr
/usr/lib
/usr/lib/debug
/usr/lib/debug/.build-id
/usr/lib/debug/.build-id/f2
/usr/lib/debug/.build-id/f2/119a44a99758114620c8e9d8e243d7094f77f6.debug
/usr/lib/x86_64-linux-gnu
/usr/lib/x86_64-linux-gnu/debug
/usr/lib/x86_64-linux-gnu/debug/libstdc++.a
/usr/lib/x86_64-linux-gnu/debug/libstdc++.so.6.0.25
/usr/lib/x86_64-linux-gnu/debug/libstdc++fs.a
/usr/share
/usr/share/doc
/usr/share/gdb
/usr/share/gdb/auto-load
/usr/share/gdb/auto-load/usr
/usr/share/gdb/auto-load/usr/lib
/usr/share/gdb/auto-load/usr/lib/x86_64-linux-gnu
/usr/share/gdb/auto-load/usr/lib/x86_64-linux-gnu/debug
/usr/share/gdb/auto-load/usr/lib/x86_64-linux-gnu/debug/libstdc++.so.6.0.25-gdb.py
/usr/lib/x86_64-linux-gnu/debug/libstdc++.so
/usr/lib/x86_64-linux-gnu/debug/libstdc++.so.6
/usr/share/doc/libstdc++6-8-dbg

And I think I got the debug files when I saw this line:

/usr/lib/debug/.build-id/f2/119a44a99758114620c8e9d8e243d7094f77f6.debug.

Then I open gdb again and it works. I can now s step into string s = "hello";.

So try check what I describe above see if they match.

Rick
  • 7,007
  • 2
  • 49
  • 79
4

I followed these instructions https://www.hiroom2.com/ubuntu-2004-dbgsym-en/.

Adding the debug symbols repo:

#!/bin/sh -e

U=http://ddebs.ubuntu.com
C=$(lsb_release -cs)

cat <<EOF | sudo tee /etc/apt/sources.list.d/ddebs.list
deb ${U} ${C} main restricted universe multiverse
#deb ${U} ${C}-security main restricted universe multiverse
deb ${U} ${C}-updates main restricted universe multiverse
deb ${U} ${C}-proposed main restricted universe multiverse
EOF

wget -O - http://ddebs.ubuntu.com/dbgsym-release-key.asc | \
    sudo apt-key add -

sudo apt update -y

Then install symbols for libstdc++6

sudo apt-get install libstdc++6-dbgsym
Sogartar
  • 2,035
  • 2
  • 19
  • 35
1

In addtion to @Rick's answer.

In ubuntu 20.04+, you need to install libstdc++6-dbgsym, and before this you need to add debug symbol repo to apt.

To get the source code, you should run apt source libstdc++6, then run ./debian/rules patch as described in debian/README.source.

(Personally I feel installing debug info and source code in ubuntu is much more complex than centOS. I suggest you to use centOS if you just want to have a look into libstdc++'s source code.

Lixin Wei
  • 441
  • 5
  • 17