SDB(1) — UNIX Programmer’s Manual
NAME
sdb − C symbolic debugger
SYNOPSIS
sdb [ objfil [ corfil [ directory ] ] ]
DESCRIPTION
Sdb is a symbolic debugger for C programs. It may be used to examine their files and to provide a controlled environment for their execution.
Objfil is an executable C program file which has been compiled with the -g (debug) option. The default for objfil is a.out. Corfil is assumed to be a core image file produced after executing objfil; the default for corfil is core. The core file need not be present.
It is useful to know that at any time there is a current line and current file. If corfil exists then they are initially set to the line and file containing the source statement at which the process terminated or stopped. Otherwise, they are set to the first line in main. The current line and file may be changed with the source file examination commands.
Names of variables are written just as they are in C. Variables local to a procedure may be accessed using the form ‘procedure:variable’. If no procedure name is given, the procedure containing the current line is used by default. It is also possible to refer to structure members as ‘variable.member’, pointers to structure members as ‘variable−>member’ and array elements as ‘variable[number]’. Combinations of these forms may also be used.
It is also possible to specify a variable by its address. All forms of integer constants which are valid in C may be used, so that addresses may be input in decimal, octal or hexadecimal.
Line numbers in the source program are referred to as ‘filename:number’ or ‘procedure:number’. In either case the number is relative to the beginning of the file. If no procedure or file name is given, the current file is used by default.
The commands for examining data in the program are:
t Print a stack trace of the terminated or stopped program.
variable/m
Print the value of variable according to format m. If m is omitted, sdb chooses a format suitable for the variable’s type as declared in the C program. Legal values for m are
c character
h 16 bit integer in decimal
d int size integer in decimal
l 32 bit integer in decimal
u int size bit integer in decimal, unsigned
o int size bit integer in octal
x int size bit integer in hexadecimal
f 32 bit single precision floating point
g 64 bit double precision floating point
s Assume variable is a string pointer and print characters until a null is reached.
a Print characters starting at the variable’s address until a null is reached.
The last variable may be redisplayed with the command ‘./’.
variable=
Print the address of variable.
variable!value
Set the variable to the given value. The value may be a number, character constant or a variable.
The commands for examining source files are
e procedure
e filename.c
Set the current file to the file containing the named procedure or the named filename. Set the current line to the first line in the named procedure or file. All source files are assumed to be in directory. The default for directory is the working directory. If no procedure or file name is given, the current procedure and file names are reported.
/regular expression/
Search forward from the current line for a line containing a string matching the regular expression as in ed (1). The trailing ‘/’ may be elided.
?regular expression?
Search backward from the current line for a line containing a string matching the regular expression as in ed (1). The trailing ‘?’ may be elided.
p Print the current line.
z Print the current line followed by the next 9 lines. Set the current line to the last line printed.
control-D
Scroll. Print the next 10 lines. Set the current line to the last line printed.
w Window. Print the 10 lines around the current line.
number
Set the current line to the given line number. Print the new current line.
count +
Advance the current line by count lines. Print the new current line.
count −
Retreat the current line by count lines. Print the new current line.
newline
Advance the current line by 1 line. Print the new current line.
The commands for controlling the execution of the source program are
count r args
Run the program with the given arguments. An argument beginning with ‘<’ or ‘>’ causes redirection for the standard input or output respectively. If count is given, it specifies the number of breakpoints to be ignored.
count c
Continue after a breakpoint or interrupt. If count is given, it specifies the number of breakpoints to be ignored.
count s
Run the program through count lines. Count defaults to one if it is omitted.
n Run the program until it reaches the next line.
procedure(arg1,arg2,...)
procedure(arg1,arg2,...)/m
Execute the named procedure with the given arguments. Arguments can be integer, character or string constants or names of variables accessible from the current procedure. The current implementation is limited to 14 arguments and a total length of 448 for string constants. The second form causes the value returned by the procedure to be printed according to format m. If no format is given, it defaults to ‘d’.
linenumber b
Set a breakpoint at the given line. If a procedure name without a line number is given (e.g. ‘proc:’), a breakpoint is placed at the first line in the procedure. If no linenumber is given, a list of the currently active breakpoints is printed.
linenumber d
Delete a breakpoint at the given line. If no linenumber is given then the breakpoints are deleted interactively: Each breakpoint location is printed and a line is read from the standard input. If the line begins with a ‘y’ or ‘d’ then the breakpoint is deleted.
Miscellaneous commands.
q Exit the debugger.
! command
The command is interpreted by sh (1).
The following commands also exist and are intended only for debugging the debugger.
a Toggle debug output.
x Print a list of procedures and files being debugged.
FILES
a.out
core
SEE ALSO
DIAGNOSTICS
Comments about inaccessible files, syntax errors, abnormal termination of commands, etc.
BUGS
Undoubtedly, some features are actually bugs and vice versa.
7th Edition — UNIX/32V