CS-FreeStyle / 10000-How-To-Do-in-CS

1 stars 0 forks source link

Debug libray using ubuntu debug symbols #21

Open liuty10 opened 5 years ago

liuty10 commented 5 years ago

For reference: https://www.hiroom2.com/2016/07/14/ubuntu-16-04-debug-package-with-debug-symbol/

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 < /etc/apt/sources.list.d/ddebs.list deb http://ddebs.ubuntu.com ${D} main restricted universe multiverse deb http://ddebs.ubuntu.com ${D}-security main restricted universe multiverse deb http://ddebs.ubuntu.com ${D}-updates main restricted universe multiverse

deb http://ddebs.ubuntu.com ${D}-proposed main restricted universe multiverse

EOF "

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.

-dbgsym In case of gtk is as below. $ sudo apt install -y libgtk-3-0-dbg $ 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 $ cd $ apt source In case of bash is as below. $ mkdir ./libgtk3 $ cd ./libgtk3 $ apt source ./libgtk3 $ ls gtk+3.0-3.18.9 gtk+3.0_3.18.9-1ubuntu3.3.dsc gtk+3.0_3.18.9-1ubuntu3.3.debian.tar.xz gtk+3.0_3.18.9.orig.tar.xz $ gdb ./example-1 --directory ../libgtk3/gtk+3.0-3.18.9/ GDB command "la src" is useful for tracing source code. (gdb) la src
liuty10 commented 5 years ago

https://wiki.ubuntu.com/Debug%20Symbol%20Packages

https://askubuntu.com/questions/487222/how-to-install-debug-symbols-for-installed-packages

https://www.hiroom2.com/2018/04/27/ubuntu-1804-dbgsym-en/

https://stackoverflow.com/questions/14344654/how-to-use-debug-libraries-on-ubuntu

https://gist.github.com/NLKNguyen/2fd920e2a50fd4b9701f

liuty10 commented 5 years ago

Install libglib2 debug symbols. when I install libglib2 debug symbols, other symbols, like gdk are also installed automatically.

$ mkdir libglib2.0-0 $ cd libglib2.0-0 $ sudo apt install -y libglib2.0-0-dbgsym $ dpkg -L libglib2.0-0-dbgsym $ apt source libglib2.0-0 $ ls

Then, you need to find the PID of the process that you are going to debug. $ top or $ pstree -p $ sudo gdb -p PID --directory ./glib2.0-2.48.2

Now, you can set break points and see the stack backtrace (gdb) b cairo_surface_set_mime_data (gdb) c (gdb) bt

You can check the source code of your process: (gdb) la src or use CTRL + x + a to enter or exit TUI(text user interface) of gdb.