Handling Errors and Exceptions 747
20
All compilers let you compile with or without symbols. Compiling with symbols tells the
compiler to create the necessary mapping between your source code and the generated
program; the debugger uses this to point to the line of source code that corresponds to
the next action in the program.
Full-screen symbolic debuggers make this chore a delight. When you load your debug-
ger, it reads through all your source code and shows the code in a window. You can step
over function calls or direct the debugger to step into the function, line by line.
With most debuggers, you can switch between the source code and the output to see the
results of each executed statement. More powerfully, you can examine the current state
of each variable, look at complex data structures, examine the value of member data
within classes, and look at the actual values in memory of various pointers and other
memory locations. You can execute several types of control within a debugger that
include setting breakpoints, setting watch points, examining memory, and looking at the
assembler code.
Breakpoints ....................................................................................................
Breakpoints are instructions to the debugger that when a particular line of code is ready
to be executed, the program should stop. This allows you to run your program unim-
peded until the line in question is reached. Breakpoints help you analyze the current con-
dition of variables just before and after a critical line of code.
Watch Points ..................................................................................................
It is possible to tell the debugger to show you the value of a particular variable or to
break when a particular variable is read or written to. Watch points enable you to set
these conditions, and, at times, even to modify the value of a variable while the program
is running.
Examining Memory........................................................................................
At times, it is important to see the actual values held in memory. Modern debuggers can
show values in the form of the actual variable; that is, strings can be shown as characters,
longs as numbers rather than as four bytes, and so forth. Sophisticated C++ debuggers
can even show complete classes and provide the current value of all the member vari-
ables, including the thispointer.
Assembler ......................................................................................................
Although reading through the source can be all that is required to find a bug, when all
else fails, it is possible to instruct the debugger to show you the actual assembly code