home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


UNIX in a Nutshell: System V Edition

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

20. Program Debugging

This section presents the debugging utilities for the UNIX environment:

  • Sdb (available in SVR4 but not Solaris 2.0)

  • Dbx (Solaris 2.0 only)

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

-e

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.

-V

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

-w

Make objfile and corefile writable.

-W

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.

20.1.2.1 Values for m

a

Characters starting at variable's address.

c

Character.

d

Decimal.

f

32-bit floating.

g

64-bit double precision floating.

i

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

I

Same as i , but print address using numbers only.

o

Octal.

p

Pointer to procedure.

s

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

u

Unsigned decimal.

x

Hexadecimal.

20.1.2.2 Values for l

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

b

One byte.

h

Two bytes (half word).

l

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

t Print a stack trace.
T Print the top line of the stack trace.
variable / clm Print variable according to length l and format m . Number c specifies how much memory (in units of l ) to display.
n ? lm variable :? lm Print 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 ! value Assign value to variable .
x Display the machine registers and the machine instructions.
X Display the machine instructions.

20.1.5 Examining the Source

e Print name of current file.
e proc Set current file to file containing procedure proc .
e file Set current file to file .
e dir / Append directory dir to directory list.
p Print current line.
w Print ten lines surrounding the current line.
z

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 .
n Set 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 a Set 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).

proc ( a1 , a2 ,...)

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

B Print active breakpoints.
[ n ] d Delete breakpoint at line number n .
D Remove all breakpoints.
i count Single-step count machine-language instructions.
I count Same as i , but reactivate any signal that stopped program.
k Kill the program you're debugging.
l Print the previous line executed.
M Print 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.

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

20.1.8 Miscellaneous Commands

# text Supply a text comment ignored by sdb.
! cmd Execute cmd with sh .
newline

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

EOF Scroll the display ten lines.
< file Execute commands contained in file .
string Print a quoted string . C escape characters are recognized.
V Print the sdb version number.


Previous: 19.5 Sample Default Macros, Suffixes, and Rules UNIX in a Nutshell: System V Edition Next: 20.2 The Dbx Debugger
19.5 Sample Default Macros, Suffixes, and Rules Book Index 20.2 The Dbx Debugger

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