Table of Contents
- 1. Add repository of dbgsym
- 2. Install dbgsym package
- 3. Download package source code
- 4. Install GDB
- 5. Debug package
1 Add repository of dbgsym
dbgsym package is published in ddebs.ubuntu.com. Add ddebs.ubuntu.com to repository list.
$ D=`lsb_release -cs`$ sudo su -c “cat <<EOF > /etc/apt/sources.list.d/ddebs.listdeb http://ddebs.ubuntu.com ${D} main restricted universe multiversedeb http://ddebs.ubuntu.com ${D}-security main restricted universe multiversedeb http://ddebs.ubuntu.com ${D}-updates main restricted universe multiverse#deb http://ddebs.ubuntu.com ${D}-proposed main restricted universe multiverseEOF”
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.
<package>-dbgsym
In case of bash is as below.
$ sudo apt install -y bash-dbgsym$ dpkg -L bash-dbgsym/./usr/usr/lib/usr/lib/debug/usr/lib/debug/usr/usr/lib/debug/usr/bin/usr/lib/debug/usr/bin/clear_console/usr/lib/debug/bin/usr/lib/debug/bin/bash
GDB will search /usr/lib/debug automatically even if you do not specify path of debug symbol.
3 Download package source code
Ubuntu 16.04 disables deb-src by default. You need to enable deb-src for downloading package source code.
$ sudo su -c “grep ‘^deb ‘ /etc/apt/sources.list | sed ‘s/^deb/deb-src/g’ > /etc/apt/sources.list.d/src.list”
Update repository database.
$ sudo apt update -y
Download package source code.
$ mkdir <package>$ cd <package>$ apt source <package>
In case of bash is as below.
$ mkdir ~/bash$ cd ~/bash$ apt source bash$ lsbash-4.3 bash_4.3-14ubuntu1.1.dscbash_4.3-14ubuntu1.1.debian.tar.xz bash_4.3.orig.tar.gz
4 Install GDB
Install gdb64 for 64bit system or gdb for 32bit system.
$ sudo apt install -y gdb64
5 Debug package
Run GDB with command and path of source code.
$ gdb64 <command> –directory /path/to/source<snip>(gdb)
In case of bash is as below.
$ gdb64 bash –directory ~/bash/bash-4.3/<snip>(gdb) b mainBreakpoint 1 at 0x41eed0: file .././shell.c, line 361.(gdb) rStarting program: /bin/bashwarning: the debug information found in “/lib64/ld-2.23.so” does notmatch “/lib64/ld-linux-x86-64.so.2” (CRC mismatch).Breakpoint 1, main (argc=1, argv=0x7fffffffe1d8, env=0x7fffffffe1e8) at .././shell.c:361warning: Source file is more recent than executable.361 {(gdb) l356 int357 main (argc, argv, env)358 int argc;359 char **argv, **env;360 #endif /* !NO_MAIN_ENV_ARG */361 {362 register int i;363 int code, old_errexit_flag;364 #if defined (RESTRICTED_SHELL)365 int saverst;
GDB command “la src” is useful for tracing source code.
(gdb) la src