GDB complaining about missing raise.c

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