Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Mail Systems
Eclipse Documentation

How To Guides
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Problem Solutions
Privacy Policy




Debian GNU/Linux Reference Guide
Prev Home Next

13.7.2 Debugging Debugging with gdb


     # 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. Check dependency on libraries

Use ldd to find out a program's dependency on libraries:

     $ ldd /bin/ls
    => /lib/ (0x4001e000)
    => /lib/ (0x40030000)
    => /lib/ (0x40153000)
             /lib/ => /lib/ (0x40000000)

For ls to work in a chrooted environment, the above libraries must be available in your chrooted environment.

The following commands will also be useful:

  • strace: trace system calls and signals

  • ltrace: trace library calls 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.

Debian GNU/Linux Reference Guide
Prev Home Next

  Published under the terms of the GNU General Public License Design by Interspire