13.7.2 Debugging
13.7.2.1 Debugging with gdb
Preparation:
# apt-get install gdb
References for gdb
:
Use gdb
to debug a program compiled with the -g
option. Many commands can be abbreviated. Tab expansion works as in the
shell.
$ gdb program
(gdb) b 1 # set breakpoint at line 1
(gdb) run arg1 arg2 arg3 # run program
(gdb) next # next line
...
(gdb) step # step forward
...
(gdb) p parm # print parm
...
(gdb) p parm=12 # set value to 12
For debugging from within Emacs, refer to Editor command summary (Emacs, Vim), Section
11.3.4.
Since all installed binaries should be stripped on the Debian system by
default, most debugging symbols are removed. In order to make gdb
useful for debugging Debian packages, pertinent packages need to be rebuild
with following care:
-
Edit debian/control
to bump the package version
.
-
Check build scripts and ensure to use CFLAGS=-g -Wall for
compiling binaries.
-
Export DEB_BUILD_OPTIONS=nostrip,noopt for building the Debian
package.
See Policy
10.1
for more info.
13.7.2.2 Check dependency on libraries
Use ldd
to find out a program's dependency on libraries:
$ ldd /bin/ls
librt.so.1 => /lib/librt.so.1 (0x4001e000)
libc.so.6 => /lib/libc.so.6 (0x40030000)
libpthread.so.0 => /lib/libpthread.so.0 (0x40153000)
/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)
For ls
to work in a chroot
ed environment, the above
libraries must be available in your chroot
ed environment.
The following commands will also be useful:
13.7.2.3 Debugging with memory leak detection tools
There are several memory leak detection tools available in Debian.
-
njamd
-
valgrind
-
dmalloc
-
electric-fence
-
memprof
-
memwatch
(not packaged, get this from memwatch
.)
-
mpatrol
-
leaktracer
-
libgc6
-
Insure++ from Parasoft
. (non-free, commercial for
fee)
Also check out Debugging
Tools for Dynamic Storage Allocation and Memory Management
.