blob: 1b0369a8892d14ac1c3dbee27806cf695d9536c8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# Debugging with GDB
## Loading the program
To load a program for debugging simply pass it to gdb
gdb <executable>
### Debugging programs using libtool
To execute gdb for a program using libtool from it's build directory you can
use:
libtool --mode=execute gdb <executable>
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 <file>:<function>
break <file>:<linenumerber>
## 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
* print: print the value of a variable
* directory: specify source code location
* set substitute-path: define a source path substitution to look for the source at a different location
## 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 all history into one file
set history filename ~/.gdb_history
# 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:
<program> --g-fatal-warnings
## Printing Glib messages
Print all messages:
G_MESSAGES_DEBUG=all <program>
See the [Glib manual][] for details.
# Other tools
* valgrind
* strace, ltrace
## Packages
Debugging things in a vm is useful if you don't want to hose your production
system. 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
[Glib manual]: https://developer.gnome.org/glib/stable/glib-running.html
|