136Chapter5 • Working with GNU Debugger
5.1Introduction to GDB
GNU debugger or more commonly known as GDB is the most commonly used debugger in open
source as well as commercial development on UNIX type platforms. It can be used as a native as
well as cross debugger. GNU debugger supports many object file formats. The most commonly
used formats are as follows:
•ELF
•a.out
•
S-record
It is part of almost all of the Linux distributions available these days. In its command line
form, it is started using the
gdb
command. The command provides an interactive text based
prompt for the user. The default prompt for the debugger is
(gdb)
. You can use commands avail-
able on this command prompt. Most of the commands can be abbreviated as long as they are not
confused with any other command. For example, the
next
command can be used as single char-
acter
n
. This abbreviation will be more clear when you go through examples in this book.
All examples in this book use the GNU debugger that came with RedHat 7.1. The chapter
also includes information about how to get the latest version of the debugger and install it on
your system.
5.2Getting Started with GDB
The GNU debugger is started using the
gdb
command. Upon startup, it displays initial informa-
tion about the platform. It stops at the
(gdb)
command prompt where GDB commands can be
used. A typical GDB screen is as shown below:
[rrehman@laptop gdb]$ gdb
GNU gdb 5.0rh-5 Red Hat Linux 7.1
Copyright 2001 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".
(gdb)
General help about GDB commands can be displayed using the
help
command on
(gdb)
prompt as shown below:
(gdb) help
List of classes of commands: