From e8d123b76c216ca8dd40fd2a892f15a338247f73 Mon Sep 17 00:00:00 2001 From: Guido Günther Date: Mon, 22 Nov 2010 18:00:40 +0100 Subject: Add some debugging notes --- development/debugging.mdwn | 86 ++++++++++++++++++++++++++++++++++++++++++++++ index.mdwn | 1 + 2 files changed, 87 insertions(+) create mode 100644 development/debugging.mdwn diff --git a/development/debugging.mdwn b/development/debugging.mdwn new file mode 100644 index 0000000..1b7f531 --- /dev/null +++ b/development/debugging.mdwn @@ -0,0 +1,86 @@ +# Debugging with GDB + +## Loading the program +To load a program for debugging simply pass it to gdb + + gdb + +### Debugging programs using libtool +To execute gdb for a program using libtool from it's build directory you can +use: + + libtool --mode=execute gdb + +this makes sure *LD_LIBRARY_PATH* etc. is setup correctly. + +## Breaking +Once the program is loaded we can start to examin it. To stop program execution +at a certain position we can use a breakpoint. Once the program hits the +breakpoint you can step through the code. First set a breakpoint + + break : + break : + +## Stepping +Once you broke out of program execution you can step through the code. To show +the source code around the current execution point: + + list + +Step to the next statement in the current function: + + next + +Step to the next statement following function calls: + + step + +Other useful commands: + + finish: run until the function exits and print it's return value + +## Backtrace +The current stacktrace can be inspected using *bt*. *bt full* additionally +includes the values of local variables. In threaded programs use *thread apply +all bt* to see all threads. + +## Calling functions +To call functions use: + + call g_hash_table_lookup (priv->sockets_by_msg, msg) + +## Configuration +Add this to *~/.gdbinit* + + # save history + set history save on + +# Miscelanous + +## Generating a core file + +On some systems the limit for core files size is 0, change that to unlimited to +make the system generate core files on e.g. SEGV: + + ulimit -c unlimited + +## Aborting on GTK+ warning + +To abort on the first encountered glib/GTK+ warning use: + + --g-fatal-warnings + +# Other tools +* valgrind +* strace, ltrace + +## Packages + +Debugging things in a vm is useful, this needs the following packages in the guest: + + aptitude install vim-nox gdb gdb-doc build-essential exuberant-ctags libc6-dbg git git-buildpackage ccache strace valgrind + +And when debugging GTK+ related problems: + + aptitude install libglib2.0-0-dbg libgnutls26-dbg libgtk2.0-0-dbg libpcre3-dbg vim-syntax-gtk gtkparasite + diff --git a/index.mdwn b/index.mdwn index 097a096..409f252 100644 --- a/index.mdwn +++ b/index.mdwn @@ -26,3 +26,4 @@ In case you find any of these projects useful, you can