DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
sdb: symbolic debugger

Using sdb

In order to use sdb to its full capabilities, it is necessary to compile the source program with the -g option. This causes the compiler to generate additional information about the variables and statements of the compiled program. When the -g option has been specified, sdb can be used to obtain a trace of the called functions at the time of the abort and interactively display the values of variables.

A typical sequence of shell commands for debugging a core image is:

   cc -g prgm.c -o prgm
   prgm
   Bus error - core dumped
   sdb prgm
   main:25:      x[i] = 0;
    *
The program prgm was compiled with the -g option and then executed. An error occurred, causing a core dump. The sdb program is then invoked to examine the core dump to determine the cause of the error. It reports that the bus error occurred in function main at line 25 (line numbers are always relative to the beginning of the file) and outputs the source text of the offending line. The sdb program then prompts the user with an *, which shows that it is waiting for a command.

It is useful to know that sdb has a notion of current function and current line. In this example, they are initially set to main and 25, respectively.

Here sdb was called with one argument, prgm. In general, sdb takes three arguments on the command line:

  1. The first argument is the name of the executable file that is to be debugged. It defaults to a.out when not specified.

  2. The second argument is the name of the core file, defaulting to core.

  3. The third argument is the list of the directories (separated by colons) containing the source of the program being debugged. The default is the current working directory.
In the example, the second and third arguments defaulted to the correct values, so only the first was specified.

If the error occurred in a function that was not compiled with the -g option, sdb prints the function name and the address at which the error occurred.

The current line and function are set to the first line where execution stopped. (The default is the first executable line in main.) If main was not compiled with the -g option, sdb will print a warning message, but debugging can continue for those routines that were compiled with the -g option.

To see a more extensive example of sdb use, see ``An sdb session''.


Next topic: Printing a stack trace
Previous topic: sdb: symbolic debugger

© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003