1 Introduction to Debugging

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).

1.1 Overview of Debugging Concepts

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:


C
C++
Fortran 77
Fortran 90
Ada
COBOL
Machine code

See your compiler documentation for information about the current extent of support for your language.

1.2 Key Features of the Ladebug Debugger

Key features of the debugger allow you to:

You can customize the debugger environment or a debugger session by using:

1.3 Basic Debugging Technique

Programmers use debuggers most often to extract important pieces of information during program execution. A simple debugging procedure might include these steps:

  1. Compile and link the program. (See Section 1.4.) Your program must compile and link without any errors; the debugger only operates on programs that successfully compile into executable files.

  2. Invoke the debugger on your program.

  3. Set a breakpoint at the line number or function suspected to be at fault.

  4. Run the program from the debugger prompt.

  5. Examine the values of program variables.

    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.

1.4 Preparation for Debugging: Compiling and Linking a Program

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.

1.5 Overview of the Two Debugger Interfaces

The debugger has the following user interface options to accommodate different needs and debugging styles: