I'm getting an an annoying error every time gdb catches an exception. I've run the following example program
#include <stdexcept>
int main() {
throw std::invalid_argument("");
return 0;
}
And the result from running gdb is
terminate called after throwing an instance of 'std::invalid_argument'
what():
Program received signal SIGABRT, Aborted.
__GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
51 ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
It's not all that bad, as I do get the information I need, it's just bugging me...
Do anyone know how to fix this?
To do full source code debugging of the C library on Ubuntu, there are just a few steps to take:
Install the debuginfo version of libc6.
It's probably already installed - the gdb package on Ubuntu has a dependency on it - but in case it isn't, run sudo apt install libc6-dbg
.
Prepare the package system to download and process source code packages, if this hasn't previously been done.
sudo apt install dpkg-dev
grep deb-src /etc/apt/sources.list
Grep's output should show (and there may be additional matches that we don't need to worry about):
deb-src http://archive.ubuntu.com/ubuntu/ bionic main restricted deb-src http://archive.ubuntu.com/ubuntu/ bionic-updates main restricted
If the grep shows that these deb-src
lines are commented out with #
:
# deb-src http://archive.ubuntu.com/ubuntu/ bionic main restricted # deb-src http://archive.ubuntu.com/ubuntu/ bionic-updates main restricted
then edit /etc/apt/sources.list
to remove the #
at the beginning of these lines and then run sudo apt update
.
Download the source code corresponding to the installed version of the C library.
First, create a directory anywhere - I'll use /opt/src
here.
Then do the following:
cd /opt/src
apt source libc6
If the apt
command gives an error message like
E: You must put some 'source' URIs in your sources.list
then my instructions in step 2 may have become outdated; post a comment here.
When the download is complete, run this:
find $PWD -maxdepth 1 -type d -name 'glibc*'
Remember this name - it'll be something like /opt/src/glibc-2.23
Determine where gdb expects to find the source code and make appropriate adjustments.
Run gdb, have it run your program until it stops, and at the gdb prompt do this:
(gdb) info source
Current source file is ../sysdeps/unix/sysv/linux/raise.c
Compilation directory is /build/glibc-KM3i_a/glibc-2.23/signal
So gdb is expecting the source code to be in /build/glibc-KM3i_a/glibc-2.23
. There are two ways to fix this:
/build/glibc-KM3i_a/glibc-2.23
.
or
Tell gdb how to substitute the correct source directory pathname:
(gdb) set substitute-path /build/glibc-KM3i_a/glibc-2.23 /opt/src/glibc-2.23
Now, go back to your frame, and gdb should show the source code line:
(gdb) frame 1
#1 0xb7e2fea9 in __GI_raise (sig=6) at ../sysdeps/unix/sysv/linux/raise.c:54
return INLINE_SYSCALL (tgkill, 3, pid, selftid, sig);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With