Home      Discussion      Topics      Dictionary      Almanac
Signup       Login
GNU Debugger

GNU Debugger

Discussion
Ask a question about 'GNU Debugger'
Start a new discussion about 'GNU Debugger'
Answer questions from other users
Full Discussion Forum
 
Encyclopedia
The GNU Debugger, usually called just GDB and named gdb as an executable file, is the standard debugger
Debugger
A debugger or debugging tool is a computer program that is used to test and debug other programs . The code to be examined might alternatively be running on an instruction set simulator , a technique that allows great power in its ability to halt when specific conditions are encountered but which...

 for the GNU
GNU
GNU is a Unix-like computer operating system developed by the GNU project, ultimately aiming to be a "complete Unix-compatible software system"...

 software system. It is a portable debugger that runs on many Unix-like
Unix-like
A Unix-like operating system is one that behaves in a manner similar to a Unix system, while not necessarily conforming to or being certified to any version of the Single UNIX Specification....

 systems and works for many programming language
Programming language
A programming language is an artificial language designed to communicate instructions to a machine, particularly a computer. Programming languages can be used to create programs that control the behavior of a machine and/or to express algorithms precisely....

s, including Ada
Ada (programming language)
Ada is a structured, statically typed, imperative, wide-spectrum, and object-oriented high-level computer programming language, extended from Pascal and other languages...

, C
C (programming language)
C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....

, C++
C++
C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as an intermediate-level language, as it comprises a combination of both high-level and low-level language features. It was developed by Bjarne Stroustrup starting in 1979 at Bell...

, Objective-C
Objective-C
Objective-C is a reflective, object-oriented programming language that adds Smalltalk-style messaging to the C programming language.Today, it is used primarily on Apple's Mac OS X and iOS: two environments derived from the OpenStep standard, though not compliant with it...

, Free Pascal
Free Pascal
Free Pascal Compiler is a free Pascal and Object Pascal compiler.In addition to its own Object Pascal dialect, Free Pascal supports, to varying degrees, the dialects of several other compilers, including those of Turbo Pascal, Delphi, and some historical Macintosh compilers...

, Fortran
Fortran
Fortran is a general-purpose, procedural, imperative programming language that is especially suited to numeric computation and scientific computing...

, Java
Java (programming language)
Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...

 and partially others .

History


GDB was first written by Richard Stallman
Richard Stallman
Richard Matthew Stallman , often shortened to rms,"'Richard Stallman' is just my mundane name; you can call me 'rms'"|last= Stallman|first= Richard|date= N.D.|work=Richard Stallman's homepage...

 in 1986 as part of his GNU
GNU
GNU is a Unix-like computer operating system developed by the GNU project, ultimately aiming to be a "complete Unix-compatible software system"...

 system, after his GNU Emacs was "reasonably stable". GDB is free software
Free software
Free software, software libre or libre software is software that can be used, studied, and modified without restriction, and which can be copied and redistributed in modified or unmodified form either without restriction, or with restrictions that only ensure that further recipients can also do...

 released under the GNU General Public License
GNU General Public License
The GNU General Public License is the most widely used free software license, originally written by Richard Stallman for the GNU Project....

 (GPL). It was modeled after the DBX debugger, which came with Berkeley Unix distributions.

From 1990 to 1993 it was maintained by John Gilmore while he worked for Cygnus Solutions
Cygnus Solutions
Cygnus Solutions, originally Cygnus Support, was founded in 1989 by John Gilmore, Michael Tiemann and David Henkel-Wallace to provide commercial support for free software...

 . Now it is maintained by the GDB Steering Committee which is appointed by the Free Software Foundation
Free Software Foundation
The Free Software Foundation is a non-profit corporation founded by Richard Stallman on 4 October 1985 to support the free software movement, a copyleft-based movement which aims to promote the universal freedom to create, distribute and modify computer software...

.

Release history

  • 2011 July 26: GDB 7.3
  • 2010 September 2: GDB 7.2
  • 2010 March 18: GDB 7.1
  • 2009 October 6: GDB 7.0
  • 2008 March 27: GDB 6.8
  • 2003 October 3: GDB 6.0

Features


GDB offers extensive facilities for tracing and altering the execution of computer program
Computer program
A computer program is a sequence of instructions written to perform a specified task with a computer. A computer requires programs to function, typically executing the program's instructions in a central processor. The program has an executable form that the computer can use directly to execute...

s. The user can monitor and modify the values of programs' internal variables
Variable (programming)
In computer programming, a variable is a symbolic name given to some known or unknown quantity or information, for the purpose of allowing the name to be used independently of the information it represents...

, and even call functions
Subroutine
In computer science, a subroutine is a portion of code within a larger program that performs a specific task and is relatively independent of the remaining code....

 independently of the program's normal behavior.

GDB target processors (as of 2003) include: Alpha
DEC Alpha
Alpha, originally known as Alpha AXP, is a 64-bit reduced instruction set computer instruction set architecture developed by Digital Equipment Corporation , designed to replace the 32-bit VAX complex instruction set computer ISA and its implementations. Alpha was implemented in microprocessors...

, ARM
ARM architecture
ARM is a 32-bit reduced instruction set computer instruction set architecture developed by ARM Holdings. It was named the Advanced RISC Machine, and before that, the Acorn RISC Machine. The ARM architecture is the most widely used 32-bit ISA in numbers produced...

, AVR
Atmel AVR
The AVR is a modified Harvard architecture 8-bit RISC single chip microcontroller which was developed by Atmel in 1996. The AVR was one of the first microcontroller families to use on-chip flash memory for program storage, as opposed to one-time programmable ROM, EPROM, or EEPROM used by other...

, H8/300, System/370
System/370
The IBM System/370 was a model range of IBM mainframes announced on June 30, 1970 as the successors to the System/360 family. The series maintained backward compatibility with the S/360, allowing an easy migration path for customers; this, plus improved performance, were the dominant themes of the...

, System 390, X86 and its 64-bit extension X86-64
X86-64
x86-64 is an extension of the x86 instruction set. It supports vastly larger virtual and physical address spaces than are possible on x86, thereby allowing programmers to conveniently work with much larger data sets. x86-64 also provides 64-bit general purpose registers and numerous other...

, IA-64
Itanium
Itanium is a family of 64-bit Intel microprocessors that implement the Intel Itanium architecture . Intel markets the processors for enterprise servers and high-performance computing systems...

 "Itanium", Motorola 68000
Motorola 68000
The Motorola 68000 is a 16/32-bit CISC microprocessor core designed and marketed by Freescale Semiconductor...

, MIPS
MIPS architecture
MIPS is a reduced instruction set computer instruction set architecture developed by MIPS Technologies . The early MIPS architectures were 32-bit, and later versions were 64-bit...

, PA-RISC
PA-RISC
PA-RISC is an instruction set architecture developed by Hewlett-Packard. As the name implies, it is a reduced instruction set computer architecture, where the PA stands for Precision Architecture...

, PowerPC
PowerPC
PowerPC is a RISC architecture created by the 1991 Apple–IBM–Motorola alliance, known as AIM...

, SuperH
SuperH
SuperH is a 32-bit reduced instruction set computer instruction set architecture developed by Hitachi. It is implemented by microcontrollers and microprocessors for embedded systems....

, SPARC
SPARC
SPARC is a RISC instruction set architecture developed by Sun Microsystems and introduced in mid-1987....

, and VAX
VAX
VAX was an instruction set architecture developed by Digital Equipment Corporation in the mid-1970s. A 32-bit complex instruction set computer ISA, it was designed to extend or replace DEC's various Programmed Data Processor ISAs...

. Lesser-known target processors supported in the standard release have included A29K, ARC
Advanced RISC Computing
Advanced RISC Computing is a specification promulgated by a defunct consortium of computer manufacturers , setting forth a standard MIPS RISC-based computer hardware and firmware environment....

, ETRAX CRIS
ETRAX CRIS
The ETRAX CRIS is a series of CPUs designed and manufactured by Axis Communications for use in embedded systems since 1993. The name is an acronym of the chip's features: Ethernet, Token Ring, AXis - Code Reduced Instruction Set...

, D10V, D30V, FR-30, FR-V
FR-V
The Fujitsu FR-V is a VLIW-based RISC microprocessor, including FR-400 and FR-450 which runs Linux, and are also supported by the GNU Compiler Collection. Some processors include support with an MMU while others do not....

, Intel i960
Intel i960
Intel's i960 was a RISC-based microprocessor design that became popular during the early 1990s as an embedded microcontroller, becoming a best-selling CPU in that field, along with the competing AMD 29000...

, M32R
M32R
The M32R is a 32-bit RISC instruction set architecture developed by Mitsubishi for embedded microprocessors and microcontrollers. The ISA is now owned by Renesas Electronics Corporation, and the company designs and fabricates M32R implementations. M32R processors are used in embedded systems such...

, 68HC11, Motorola 88000
Motorola 88000
The 88000 is a RISC instruction set architecture developed by Motorola. The 88000 was Motorola's attempt at a home-grown RISC architecture, started in the 1980s. The 88000 arrived on the market some two years after the competing SPARC and MIPS...

, MCORE, MN10200, MN10300, NS32K, Stormy16, V850
V850
The Renesas Electronics V850 is a 32-bit RISC CPU core architecture for embedded microcontrollers originally developed and manufactured by NEC, succeeded by V850 variants named V850ES, V850E, and V850E2 which run uClinux. Compilers available for it include the GNU Compiler Collection, IAR Systems...

, and Z8000
Zilog Z8000
The Z8000 is a 16-bit microprocessor introduced by Zilog in 1979. The architecture was designed by Bernard Peuto while the logic and physical implementation was done by Masatoshi Shima, assisted by a small group of people. The Z8000 was not Z80-compatible, and although it saw steady use well into...

. (Newer releases will likely not support some of these.) GDB has compiled-in simulators
Instruction Set Simulator
An instruction set simulator is a simulation model, usually coded in a high-level programming language, which mimics the behavior of a mainframe or microprocessor by "reading" instructions and maintaining internal variables which represent the processor's registers.Instruction simulation is a...

 for even lesser-known target processors such like M32R
M32R
The M32R is a 32-bit RISC instruction set architecture developed by Mitsubishi for embedded microprocessors and microcontrollers. The ISA is now owned by Renesas Electronics Corporation, and the company designs and fabricates M32R implementations. M32R processors are used in embedded systems such...

 or V850
V850
The Renesas Electronics V850 is a 32-bit RISC CPU core architecture for embedded microcontrollers originally developed and manufactured by NEC, succeeded by V850 variants named V850ES, V850E, and V850E2 which run uClinux. Compilers available for it include the GNU Compiler Collection, IAR Systems...

.

GDB is still actively developed. As of version 7.0 new features include support for Python scripting , and at least since version 7.3 "reversible debugging" allowing a debugging session to step backward, much like rewinding a crashed program to see what happened, have been added.

Remote debugging


GDB offers a 'remote' mode often used when debugging embedded systems. Remote operation is when GDB runs on one machine and the program being debugged runs on another. GDB can communicate to the remote 'stub' which understands GDB protocol via Serial or TCP/IP.

A stub program can be created by linking to the appropriate stub files provided with GDB, which implement the target side of the communication protocol. Alternatively, gdbserver
Gdbserver
gdbserver is a computer program that makes it possible to remotely debug other programs. Running on the same system as the program to be debugged, it allows the GNU Debugger to connect from another system; that is, only the executable to be debugged needs to be resident on the target system, while...

 can be used to remotely debug the program without needing to change it in any way.

The same mode is also used by KGDB
KGDB
KGDB is a debugger for the Linux kernel. It requires two machines that are connected via a serial connection. The serial connection may either be an RS-232 interface using a null modem cable, or via the UDP/IP networking protocol .KGDB was originally implemented as a patch to Linux kernel, but it...

 for debugging a running Linux kernel
Linux kernel
The Linux kernel is an operating system kernel used by the Linux family of Unix-like operating systems. It is one of the most prominent examples of free and open source software....

 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
Serial cable
A serial cable is a cable that can be used to transfer information between two devices using serial communication. The form of connectors depends on the particular PHY used...

 or ethernet
Ethernet
Ethernet is a family of computer networking technologies for local area networks commercially introduced in 1980. Standardized in IEEE 802.3, Ethernet has largely replaced competing wired LAN technologies....

. On FreeBSD
FreeBSD
FreeBSD is a free Unix-like operating system descended from AT&T UNIX via BSD UNIX. Although for legal reasons FreeBSD cannot be called “UNIX”, as the direct descendant of BSD UNIX , FreeBSD’s internals and system APIs are UNIX-compliant...

, it is also possible to debug using Firewire direct memory access
Direct memory access
Direct memory access is a feature of modern computers that allows certain hardware subsystems within the computer to access system memory independently of the central processing unit ....

 (DMA).

Graphical User Interface


The debugger does not contain its own graphical user interface
Graphical user interface
In computing, a graphical user interface is a type of user interface that allows users to interact with electronic devices with images rather than text commands. GUIs can be used in computers, hand-held devices such as MP3 players, portable media players or gaming devices, household appliances and...

, and defaults to a command-line interface
Command-line interface
A command-line interface is a mechanism for interacting with a computer operating system or software by typing commands to perform specific tasks...

. Several front-ends have been built for it, such as Xxgdb
Xxgdb
Xxgdb is an open source X Window System front-end for gdb. It was adapted from xdbx, which uses the dbx debugger.- See also :* Data Display Debugger , a Motif front-end.* KDbg, a KDE debugger front-end.* ups ....

, Data Display Debugger
Data Display Debugger
Data Display Debugger, or DDD, is a popular free software graphical user interface for command-line debuggers such as GDB, DBX, JDB, , XDB, the Perl debugger, the Bash , the Python , and the GNU Make...

 (DDD), Nemiver
Nemiver
Nemiver is a standalone graphical C and C++ debugger that integrates in the GNOME desktop environment.It currently features a backend which uses the well known GNU Debugger .The creator and the current lead developer is Dodji Seketeli.- General :...

, KDbg
KDbg
KDbg is an open source graphical front-end for the GNU Debugger. KDbg is implemented using the KDE component architecture.- See also :* Data Display Debugger , a Motif debugger front-end* ups...

, Xcode
Xcode
Xcode is a suite of tools, developed by Apple, for developing software for Mac OS X and iOS. Xcode 4.2, the latest major version, is available on the Mac App Store for free for Mac OS X 10.7 , and on the Apple Developer Connection website for free to registered developers Xcode is a suite of tools,...

 debugger, GDBtk/Insight and the HP Wildebeest Debugger GUI (WDB GUI). IDE
Integrated development environment
An integrated development environment is a software application that provides comprehensive facilities to computer programmers for software development...

s such as Codelite
Codelite
CodeLite is a free, open-source, cross-platform IDE for the C/C++ programming languages.- History :On August 2006 Eran Ifrah, CodeLite's author, started a project named CodeLite...

, Code::Blocks
Code::Blocks
Code::Blocks is a free and open source, cross-platform IDE which supports multiple compilers including GCC and MSVC. It is developed in C++ using wxWidgets as the GUI toolkit. Using a plugin architecture, its capabilities and features are defined by the provided plugins.Currently, Code::Blocks is...

, GNAT Programming Studio
GNAT Programming Studio
GNAT Programming Studio is a free multi-language integrated development environment by AdaCore. GPS uses compilers from the GNU Compiler Collection, taking its name from GNAT, the GNU compiler for the Ada programming language.GPS is cross-platform, running on Linux, Microsoft Windows and Solaris...

 (GPS), KDevelop
KDevelop
KDevelop is a free software integrated development environment for the KDE Platform on Unix-like computer operating systems. KDevelop includes no compiler. Instead, it uses an external compiler such as gcc to produce executable code....

, Qt Creator
Qt Creator
Qt Creator is a cross-platform C++ integrated development environment which is part of the Qt SDK. It includes a visual debugger and an integrated GUI layout and forms designer. The editor's features includes syntax highlighting and autocompletion, but not tabs. Qt Creator uses the C++ compiler...

, MonoDevelop
MonoDevelop
MonoDevelop is an open source integrated development environment for the Linux platform, Mac OS X, and Microsoft Windows, primarily targeted for the development of software that uses both the Mono and Microsoft .NET frameworks...

, Eclipse, NetBeans
NetBeans
NetBeans refers to both a platform framework for Java desktop applications, and an integrated development environment for developing with Java, JavaScript, PHP, Python, Groovy, C, C++, Scala, Clojure, and others...

 and VisualStudio (see VS AddIn Gallery) can interface with GDB. GNU Emacs has a "GUD mode" and several tools for VIM exist. These offer facilities similar to debuggers found in IDEs.

Some other debugging tools have been designed to work with GDB, such as memory leak
Memory leak
A memory leak, in computer science , occurs when a computer program consumes memory but is unable to release it back to the operating system. In object-oriented programming, a memory leak happens when an object is stored in memory but cannot be accessed by the running code...

 detectors.

Examples of commands

gdb program debug "program" (from the shell)
run -v run the loaded program with the parameters
bt backtrace (in case the program crashed)
info registers dump all registers
disass $pc-32, $pc+32 disassemble

An example session


This is an example GDB session on the example program in Stack trace
Stack trace
A stack trace is a report of the active stack frames at a certain point in time during the execution of a program.It is commonly used during interactive and post-mortem debugging...

:


GNU gdb Red Hat Linux (6.3.0.0-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
GNU Compiler Collection
The GNU Compiler Collection is a compiler system produced by the GNU Project supporting various programming languages. GCC is a key component of the GNU toolchain...

 and then run.

See also



  • Binary File Descriptor library (libbfd)
  • dbx
  • gdbserver
    Gdbserver
    gdbserver is a computer program that makes it possible to remotely debug other programs. Running on the same system as the program to be debugged, it allows the GNU Debugger to connect from another system; that is, only the executable to be debugged needs to be resident on the target system, while...


External links


Documentation

  • Richard M. Stallman
    Richard Stallman
    Richard Matthew Stallman , often shortened to rms,"'Richard Stallman' is just my mundane name; you can call me 'rms'"|last= Stallman|first= Richard|date= N.D.|work=Richard Stallman's homepage...

    , Roland Pesch, Stan Shebs, et al., Debugging with GDB (Free Software Foundation
    Free Software Foundation
    The Free Software Foundation is a non-profit corporation founded by Richard Stallman on 4 October 1985 to support the free software movement, a copyleft-based movement which aims to promote the universal freedom to create, distribute and modify computer software...

    , 2011) ISBN 978-0-9831592-3-0
  • GDB Internals

Tutorials