User guide
Chapter 5.
53
Debugging
Useful, well-written software generally goes through different phases of application development,
and mistakes can occur in each phase. Some phases come with their own set of mechanisms to
detect certain mistakes; during compilation, for example, most compilers perform elementary semantic
analysis, making sure objects such as variables and functions are adequately described.
The error-checking mechanisms of each application development phase helps catch simple and
obvious mistakes in code. The debugging phase helps catch more subtle errors; ones that fell through
the cracks during routine code inspection.
5.1. Installing Debuginfo Packages
Red Hat Enterprise Linux also provides -debuginfo packages for all architecture-dependent RPMs
included in the operating system. A -debuginfo package contains accurate debugging information
for its corresponding package. To install the -debuginfo package of a package (i.e. typically
packagename-debuginfo), use the following command:
debuginfo-install packagename
Note
Attempting to debug a package without having its -debuginfo equivalent installed may fail,
although GDB will try to provide any helpful diagnostics it can.
5.2. GDB
Fundamentally, like most debuggers, GDB manages the execution of compiled code in a very closely
controlled environment. This environment makes possible the following fundamental mechanisms
necessary to the operation of GDB:
• Inspect and modify memory within the code being debugged (e.g. reading and setting variables).
• Control the execution state of the code being debugged, principally whether it's running or stopped.
• Detect the execution of particular sections of code (e.g. stop running code when it reaches a
specified area of interest to the programmer).
• Detect access to particular areas of memory (e.g. stop running code when it accesses a specified
variable).
• Execute portions of code (from an otherwise stopped program) in a controlled manner.
• Detect various programmatic asynchronous events such as signals.
The operation of these mechanisms rely mostly on information produced by a compiler. For example,
to view the value of a variable, GDB has to know:
• The location of the variable in memory
• The nature of the variable
This means that displaying a double-precision floating point value requires a very different process
from displaying a string of characters. For something complex like a structure, GDB has to know