Skip to content

How to use GDB to gather debug information on a program

Michael Webster edited this page Aug 18, 2019 · 5 revisions
Install debug symbols:

sudo apt-get install gnome-dbg nemo-dbg cinnamon-dbg muffin-dbg

Kill any existing instances of the program if necessary - for nemo you might simply do:

sudo killall nemo

Start up the debugger.

For a binary program (nemo for instance):

gdb nemo

For a python program:

gdb python

Debugging the program:

For a binary:

run

For a python program:

run *path to .py or python-shebanged file*

****************** Make the program crash **********************
Now get a trace:

thread apply all bt

Be prepared to supply the entire contents of the backtrace - there may (and probably will) be multiple pages, that you'll have to spacebar down to get to the end up - be sure to save all of this. You can enter set logging on and then set pagination off from the gdb prompt to save all of the output to a gdb.txt file

One you're done you can just type:

quit

Debugging warnings

Run this instead:

G_DEBUG=fatal_warnings gdb nemo

Execution will halt at every glib warning - you can get a backtrace (bt), or keep going (c).

Debugging Cinnamon

To debug things that actually constitute your environment (the DE), you should ssh in from another PC (or smartphone) - it can be done in tty, but you'll want to throw your computer out the window shortly after.

From another computer/phone:

(ssh into the computer running Cinnamon) (get the cinnamon process id - use ps -A | grep cinnamon or something)

sudo gdb
set logging on              (this will log everything to gdb.txt on the main pc's home folder - useful later)
attach <cinnamon pid>
c (or continue)
.... follow remaining steps above

to do this using the G_DEBUG flag I find it easier to actually be root than using sudo, to make sure that environment variable is respected:

sudo su (for ubuntu, otherwise just su should be fine)
G_DEBUG=fatal_warnings gdb
......