Полезная информация

UNIX in a Nutshell: System V Edition

UNIX in a Nutshell: System V EditionSearch this book
Previous: 19.5 Sample Default Macros, Suffixes, and RulesChapter 20Next: 20.2 The Dbx Debugger

20. Program Debugging

The Sdb Debugger
The Dbx Debugger

This section presents the debugging utilities for the UNIX environment:

These debuggers take an executable object file and its corefile-the core image file produced when objfile is executed. The debuggers then provide a controlled environment for the execution of the program.

If objfile and corefile are not specified, a.out is taken as the default object file and core as the default core image file.

Each debugging utility is listed among the UNIX commands in Section 2 of this guide.

20.1 The Sdb Debugger

Sdb, the symbolic debugger, is used for checking assembly programs, executable C and FORTRAN programs, and core files resulting from aborted programs. It has the following command-line syntax:

sdb [options] [objfile [corefile [dir]]]

A - in place of corefile will force sdb to ignore any core image file.

20.1.1 Options


Ignore symbolic data; treat addresses as file offsets.

-s n

Don't stop processes that receive signal number n. See the signal system call for values of n. -s may be used more than once.


Print version information (and exit if no objfile is given).


Make objfile and corefile writable.


Suppress warning messages about older files.

20.1.2 Command Specifiers

In the "Commands" section below, commands use the specifiers m, l, and n. m is the display format of an address. (Addresses are specified by a variable or a line number.) l is the address length. n stands for the line number. Values for m


Characters starting at variable's address.






32-bit floating.


64-bit double precision floating.


Disassemble machine-language instructions; print address using numbers and symbols.


Same as i, but print address using numbers only.




Pointer to procedure.


Print character(s) at address pointed to by (string pointer) variable.


Unsigned decimal.


Hexadecimal. Values for l

Length specifiers are meaningful only with m values of c, d, o, u, or x.


One byte.


Two bytes (half word).


Four bytes (long word).

20.1.3 Commands

Refer to the previous specifiers when reviewing the sdb commands, which are grouped below:

20.1.4 Formatted Printing

tPrint a stack trace.
TPrint the top line of the stack trace.
variable/clmPrint variable according to length l and format m. Number c specifies how much memory (in units of l) to display.
n?lm variable:?lmPrint from a.out and procedure variable according to length l and format m. Default lm is i.
variable=lm n=lm number=lm

Print the address of variable or line number n, in the format specified by l and m. Use the last form to convert number to the format specified by l and m. Default lm is lx.

variable!valueAssign value to variable.
xDisplay the machine registers and the machine instructions.
XDisplay the machine instructions.

20.1.5 Examining the Source

ePrint name of current file.
eprocSet current file to file containing procedure proc.
efileSet current file to file.
edir/Append directory dir to directory list.
pPrint current line.
wPrint ten lines surrounding the current line.

Print ten lines (starting at current); reset current line to last line.

/regexp/Search ahead for regular expression regexp.
?regexp?Search back for regular expression regexp.
nSet current line to n and print it.
count+Advance count lines; print new current line.
count-Go back count lines; print new current line.

20.1.6 Executing the Source

n aSet a breakpoint at line number n and inform the user.
[n] b commands

Set breakpoint at line number n and optionally execute sdb commands (separated by ;) at breakpoint.

[n] c count

Continue after a breakpoint or, if count is given, stop after count breakpoints. If n is specified, set a temporary breakpoint at line number n.

[n] C count

Same as c, but reactivate any signal that stopped program.

n g count

Continue at line number n after a breakpoint. If count is given, ignore count breakpoints.

[count] r args

Run the program with the specified arguments. Ignore count breakpoints.

[count] r

Rerun the program with the previously specified arguments. Ignore count breakpoints.

[count] R

Run the program with the no arguments. Ignore count breakpoints.

[level] [v]

This command is used when single-stepping via s, S, or m. v turns off verbose mode; omit v to turn on verbose mode. If level is omitted, print only source file or function name when either changes; otherwise, set level to 1 (print C source lines before execution) or 2 or higher (print C source lines and assembler statements).


Execute procedure proc with arguments a1, a2, etc. Arguments can be constants, local variable names, or register names. Append /m in order to print the returned value in format m (default is d).

20.1.7 Breakpoint and Program Control

BPrint active breakpoints.
[n] dDelete breakpoint at line number n.
DRemove all breakpoints.
i countSingle-step count machine-language instructions.
I countSame as i, but reactivate any signal that stopped program.
kKill the program you're debugging.
lPrint the previous line executed.
MPrint the address maps.
var$m count addr:m count

Single-step count lines until the specified variable or address is modified. Omitting count specifies an infinite count.

qExit sdb.
s [count]Single-step count lines.
S [count]Same as s, but skip called functions.

20.1.8 Miscellaneous Commands

#textSupply a text comment ignored by sdb.
!cmdExecute cmd with sh.

Display the next line or memory location, or disassemble the next instruction.

EOFScroll the display ten lines.
< fileExecute commands contained in file.
stringPrint a quoted string. C escape characters are recognized.
VPrint the sdb version number.

Previous: 19.5 Sample Default Macros, Suffixes, and RulesUNIX in a Nutshell: System V EditionNext: 20.2 The Dbx Debugger
19.5 Sample Default Macros, Suffixes, and RulesBook Index20.2 The Dbx Debugger

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System