2

I'm debugging this program which raises an exception. This makes my debugger look for some source code, e.g. ../sysdeps/unix/sysv/linux/raise.c - and fail to find it.

Now, I realize it's not necessary for me to have these sources, but still - I would like them there.

I'm working on a Devuan Chimaera GNU/Linux system.

What's the least-complicated way for me to have these sources available and locatable by gdb?

einpoklum
  • 8,772
  • 19
  • 65
  • 129

2 Answers2

4

The simplest way is to extract the package source code somewhere: go to an appropriate directory, then run

apt source glibc

In gdb, add the corresponding directory to the source path by using the directory command.

You may also want the detached debug symbols; I don’t know whether Devuan provides debug symbol packages in general (dbgsym packages), but I see it ships libc6-dbg which has the same purpose:

sudo apt install libc6-dbg

Here’s an example gdb session:

$ gdb ls
...
(gdb) directory ~/Debian/glibc
Source directories searched: /home/steve/Debian/glibc:$cdir:$cwd
(gdb) break malloc
Breakpoint 1 at 0x46c8
(gdb) run
Starting program: /bin/ls 

Breakpoint 1, malloc (n=1441) at dl-minimal.c:50
50    if (alloc_end == 0)
Stephen Kitt
  • 411,918
  • 54
  • 1,065
  • 1,164
0

Some further indications for Ubuntu 22.04 beyond what Stephen said.

To get debug symbols and source, some setup is needed as in:

# Get debug symbols.
printf "deb http://ddebs.ubuntu.com %s main restricted universe multiverse\n" $(lsb_release -cs){,-updates,-security,-proposed} | \
 sudo tee -a /etc/apt/sources.list.d/ddebs.list
sudo apt install ubuntu-dbgsym-keyring
sudo apt update
sudo apt install coreutils-dbgsym

# Get source as per: https://askubuntu.com/questions/496549/error-you-must-put-some-source-uris-in-your-sources-list
# Produces directory "coreutils-8.32"
sudo cp /etc/apt/sources.list /etc/apt/sources.list~
sudo sed -Ei 's/^# deb-src /deb-src /'
/etc/apt/sources.list sudo apt-get update
apt source coreutils

Then, to get GDB to actually find the sources, you might need to either cd into the downloaded source, or play with stuff like:

set substitute-path . glibc-2.35

as mentioned at: https://askubuntu.com/questions/487222/how-to-install-debug-symbols-for-installed-packages/1434174#1434174