|
|
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:
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''.