Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

c++ - GDB complaining about missing raise.c

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?

Question&Answers:os

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

1 Reply

0 votes
by (71.8m points)

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 - the gdb package on Ubuntu has a dependency on it - but in case it isn't, run sudo apt install libc6-dbg.

  2. 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 .

  3. 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

  4. 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:

    • Move (or use a symlink) so that the source code is (or appears to be) in /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);
    

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...