The GNU Debugger, usually called just GDB, is the standard debugger for the GNU software system. It is a portable debugger that runs on many Unix-like systems and works for many programming languages, including Ada, C, C++, FreeBASIC, and Fortran.
Lesser-known target processors supported in the standard release have included A29K, ARC, CRIS, D10V, D30V, FR-30, FR-V, Intel i960, M32R, 68HC11, Motorola 88000, MCORE, MN10200, MN10300, NS32K, Stormy16, V850, and Z8000. (Newer releases will likely not support some of these.)
GDB has compiled-in simulators for target processors even for lesser-known target processors such like M32R or V850.
GDB is still actively developed. As of early 2007, the focus is on adding "reversible debugging" support — allowing a debugging session to step backwards, much like rewinding a crashed program to see what happened. Adding reversible debugging is one of the High Priority Free Software Projects.
The same mode is also used by KGDB for debugging a running Linux kernel on the source level with gdb. With kgdb, kernel developers can debug a kernel in much the same way as they debug application programs. It makes it possible to place breakpoints in kernel code, step through the code and observe variables. On architectures where hardware debugging registers are available, watchpoints can be set which trigger breakpoints when specified memory addresses are executed or accessed. kgdb requires an additional machine which is connected to the machine to be debugged using a serial cable or ethernet. On FreeBSD, it is also possible to debug using Firewire DMA.
Some other debugging tools have been designed to work with GDB, such as memory leak detectors.
|$ gdb prog.out||debug prog.out (from the shell)|
|gdb> run -v||run the loaded program with the parameters|
|gdb> bt||backtrace (in case the program crashed)|
|gdb> info registers||dump all registers|
|gdb> disass $pc-32 $pc+32||disassemble|
GNU gdb Red Hat Linux (22.214.171.124-1.21rh) Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "i386-redhat-linux-gnu"...Using host libthread_db library "/lib/libthread_db.so.1".
(gdb) run Starting program: /home/sam/programming/crash Reading symbols from shared object read from target memory...done. Loaded system supplied DSO at 0xc11000 This program will demonstrate gdb
Program received signal SIGSEGV, Segmentation fault. 0x08048428 in function_2 (x=24) at crash.c:22 22 return *y; (gdb) edit (gdb) shell gcc crash.c -o crash -gstabs+ (gdb) run The program being debugged has been started already. Start it from the beginning? (y or n) y warning: cannot close "shared object read from target memory": File in wrong format `/home/sam/programming/crash' has changed; re-reading symbols. Starting program: /home/sam/programming/crash Reading symbols from shared object read from target memory...done. Loaded system supplied DSO at 0xa3e000 This program will demonstrate gdb 24 Program exited normally. (gdb) quit
The program is being run. After the cause of the segmentation fault is found, the program is edited to use the correct behavior. The corrected program is recompiled with GCC and then run.