Debian 9: Debug package with dbgsym for debug symbol

This article will describe debugging package with dbgsym for debug symbol.

1 Append debian-debug repository

Append debian-debug repository to apt sources.list.d.

$ cat <<EOF | sudo tee /etc/apt/sources.list.d/dbgsym.list
deb http://debug.mirrors.debian.org/debian-debug/ stretch-debug main
EOF
$ sudo apt update -y

2 Install dbgsym

Packages which have dbgsym suffix are debug symbol.

<pkg>-dbgsym

This article installs debug symbol for coretuils.

$ sudo apt install -y coreutils-dbgsym

Debug symbol will be installed to /usr/lib/debug. GDB will search /usr/lib/debug automatically.

$ dpkg -L coreutils-dbgsym
/.
/usr
/usr/lib
/usr/lib/debug
/usr/lib/debug/.build-id
/usr/lib/debug/.build-id/04
/usr/lib/debug/.build-id/04/7a2dfd63f9e20b837c04e874b56b47b60f564a.debug
/usr/lib/debug/.build-id/09
/usr/lib/debug/.build-id/09/16ef8fc767ab302f1468c5c515929f313b9e54.debug
/usr/lib/debug/.build-id/0a
<snip>

3 Debug package with dbgsym

Install GDB.

$ sudo apt install -y gdb

Download coretuils source code.

$ mkdir coreutils
$ cd coreutils
$ apt source coreutils-dbgsym
$ cd ./coreutils-*

Debug ls command in coreutils.

$ gdb ls
(gdb) la src
(gdb) b main
(gdb) r

GDB breaks at main function.

0001_dbgsym.png