This chapter introduces some fundamental debugging concepts, briefly describes key Ladebug features, explains how to compile and link a program for debugging, and introduces the two Ladebug interfaces (window and command).
The debugger helps you locate run-time programming or logic errors, also known as bugs. You use the debugger with a program that has been compiled and linked successfully, but does not run correctly. For example, the program might give incorrect output, go into an infinite loop, or terminate prematurely.
You locate errors with the debugger by observing and manipulating your program interactively as it executes. The debugger lets you:
As you use the debugger and its documentation, you will discover variations on the basic techniques. You can also customize the debugger to meet your own needs.
Because the debugger is a symbolic debugger, you can specify variable names, routine names, and so on, precisely as they appear in your source code. You do not need to specify memory addresses or registers when referring to program locations, but you can if you want.
You can use the debugger with programs written in any of the supported languages:
See your compiler documentation for information about the current extent of support for your language.
Key features of the debugger allow you to:
You can customize the debugger environment or a debugger session by using:
Programmers use debuggers most often to extract important pieces of information during program execution. A simple debugging procedure might include these steps:
When program execution suspends at the specified breakpoint, examine the values of program variables. If the variables do not provide you with any clues, try setting other breakpoints, executing program statements line by line, or tracing a variable's value during program execution.
Direct the compiler (normally with the -g
flag; use
the appropriate flag for your compiler) to produce an executable
file that includes full symbolic debugging information.
Some systems provide variants of the flag (-g1, -g2, and so on). These give different levels of symbol information and optimization.
Some compilers optimize the object code to reduce the size of the program or to make it run faster. For example, some optimization techniques eliminate certain variables. In addition to building symbolic information, the -g flag disables optimization of your program so that you an debug it more easily. For detailed information on compiling and linking, see the chapter on your language or your compiler documentation.
Ladebug can debug programs with less than complete symbolic information. (See Chapter 17 for details.)
The following example shows how to compile and link a C program named eightqueens before using the debugger. The compiler is invoked from the C shell (%). In the following example, the file eightqueens.c contains the program's source code.
% cc -g eightqueens.c -o eightqueens
The cc command invokes both the compiler and the linker. (For more information about compiling that is specific to a particular language, see the documentation furnished with that language.)
The -g flag directs the compiler to write the symbolic information associated with eightqueens.c into the program file eightqueens (in addition to the code and data for the program). This symbol information allows you to use the names of variables and other symbols declared in eightqueens.c when using the debugger. If your program's source code is in several files, you must compile each file whose symbols you want to reference with the -g flag.
The debugger has the following user interface options to accommodate different needs and debugging styles:
The window interface has a command-entry prompt (in the Command Message View of the main window) that enables you to enter debugger commands for the following purposes:
You can customize the window interface with many of the special features of the debugger by modifying the push buttons and their associated debugger commands or by adding new push buttons.
Choose Help:On Commands for online help on debugger commands or type help at the command line.