GDB complaining about missing raise.c

梦想的初衷 提交于 2019-12-28 02:58:25

问题


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?


回答1:


To do full source code debugging of the C library on Ubuntu, there are just a few steps to take.

1) install the debuginfo version of libc6.

It's probably already installed, but in case it isn't, run sudo apt install libc6-dbg.

2) 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:

sudo apt install dpkg-dev # need to do this only once, so that apt source will work
cd /opt/src
apt source libc6
find $PWD -maxdepth 1 -type d -name 'glibc*'

Remember this name - it'll be something like /opt/src/glibc-2.23

3) 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:

a) move or use a symlink so that the source code is (or appears to be) in /build/glibc-KM3i_a/glibc-2.23 .

b) 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);


来源:https://stackoverflow.com/questions/48278881/gdb-complaining-about-missing-raise-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!