Ubuntu 19.04: Debug package with debug symbol

Ubuntu provides debug symbol as dbgsym package. This article will describe installing dbgsym and debugging package. This article will debug bash with debug symbol.

1 Add repository of dbgsym

dbgsym package is published in ddebs.ubuntu.com. Add ddebs.ubuntu.com to repository list.

$ U=http://ddebs.ubuntu.com
$ D=$(lsb_release -cs)
$ cat <<EOF | sudo tee /etc/apt/sources.list.d/ddebs.list
deb ${U} ${D} main restricted universe multiverse
#deb ${U} ${D}-security main restricted universe multiverse
deb ${U} ${D}-updates main restricted universe multiverse
deb ${U} ${D}-proposed main restricted universe multiverse

Import GPG key of ddebs.ubuntu.com.

$ wget -O - http://ddebs.ubuntu.com/dbgsym-release-key.asc | \
sudo apt-key add -

Update repository database.

$ sudo apt update -y

2 Install dbgsym package

The package which has a suffix of dbgsym provides debug symbol.


In case of bash is as below.

$ sudo apt install -y bash-dbgsym
$ dpkg -L bash-dbgsym

GDB will search /usr/lib/debug automatically even if you do not specify path of debug symbol.

3 Download package source code

Ubuntu disables deb-src by default. You need to enable deb-src for downloading package source code.

Enable deb-src.

$ grep '^deb ' /etc/apt/sources.list | \
  sed 's/^deb /deb-src /g' | \
  sudo tee /etc/apt/sources.list.d/deb-src.list
$ sudo apt update  -y

Install dpkg-dev package for dpkg-source command.

$ sudo apt install -y dpkg-dev

Download package source code.

$ mkdir <package>
$ cd <package>
$ apt source <package>

In case of bash is as below. bash-5.0 is a source tree.

$ mkdir ~/bash
$ cd ~/bash
$ apt source bash
$ ls
bash-5.0                 bash_5.0-3ubuntu1.1.debian.tar.xz
bash_5.0-3ubuntu1.1.dsc  bash_5.0.orig.tar.xz

4 Install GDB

Install gdb.

$ sudo apt install -y gdb

5 Debug package

Run GDB with command and path of source code.

$ gdb <command> --directory /path/to/source

In case of bash is as below.

$ gdb bash --directory ~/bash/bash-5.0/
(gdb) b main
Breakpoint 1 at 0x2de30: file .././shell.c, line 364.
(gdb) r
Starting program: /usr/bin/bash

Breakpoint 1, main (argc=1, argv=0x7fffffffe3b8, env=0x7fffffffe3c8) at
364     {
(gdb) l
359     int
360     main (argc, argv, env)
361          int argc;
362          char **argv, **env;
363     #endif /* !NO_MAIN_ENV_ARG */
364     {
365       register int i;
366       int code, old_errexit_flag;
367     #if defined (RESTRICTED_SHELL)
368       int saverst;

GDB command "la src" is useful for tracing source code.

(gdb) la src