Add a description of $unsafecall and $unsafeassign; relate a few of the
[unix-history] / usr / src / old / dbx / dbx.1
CommitLineData
0b6ba29a
KM
1.\" Copyright (c) 1983 Regents of the University of California.
2.\" All rights reserved. The Berkeley software License Agreement
3.\" specifies the terms and conditions for redistribution.
4.\"
3e8dcebc 5.\" @(#)dbx.1 6.2 (Berkeley) %G%
0b6ba29a 6.\"
81ddc115 7.TH DBX 1 ""
0b6ba29a
KM
8.UC 5
9.ds dB dbx
10.ds DB Dbx
11.SH NAME
12dbx \- debugger
13.SH SYNOPSIS
14.B dbx
15[
16.B \-r
17] [
18.B \-i
19] [
81ddc115
KM
20.B \-k
21] [
0b6ba29a
KM
22.B \-I
23.I dir
24] [
81ddc115
KM
25.B \-c
26.I file
27] [
0b6ba29a
KM
28.I objfile
29[
30.I coredump
31]]
32.SH DESCRIPTION
33\fI\*(DB\fP is a tool for source level debugging and execution of
34programs under UNIX.
35The \fIobjfile\fP is an object file produced by a compiler
36with the appropriate flag (usually ``\-g'')
37specified to produce symbol information in the object file.
81ddc115
KM
38Currently, \fIcc\fP(1), \fIf77\fP(1), \fIpc\fP(1), and the DEC Western
39Research Laboratory Modula-2 compiler, \fImod\fP(l),
40produce the appropriate source information.
0b6ba29a
KM
41The machine level facilities of \fI\*(dB\fP
42can be used on any program.
43.PP
81ddc115 44The object file contains a symbol table that includes the name of the
0b6ba29a
KM
45all the source files translated by the compiler to create it.
46These files are available for perusal while using the debugger.
47.PP
48If a file named ``core'' exists in the current directory
49or a \fIcoredump\fP file is specified, \fI\*(dB\fP can be used
50to examine the state of the program when it faulted.
51.PP
52If the file ``.\*(dBinit'' exists in the current directory then the
53debugger commands in it are executed.
54\fI\*(DB\fP also checks for a ``.\*(dBinit'' in the user's home directory
55if there isn't one in the current directory.
56.PP
57The command line options and their meanings are:
81ddc115 58.nr In 8
0b6ba29a
KM
59.in +\n(Inn
60.ta \n(Inn
81ddc115 61.sp 1
0b6ba29a
KM
62.ti -\n(Inn
63\&\fB\-r\fP \c
64Execute \fIobjfile\fP immediately.
65If it terminates successfully \fI\*(dB\fP exits.
66Otherwise the reason for termination will be reported
67and the user offered the option of entering the debugger
68or letting the program fault.
69\fI\*(DB\fP will read from ``/dev/tty'' when \fB\-r\fP is specified
70and standard input is not a terminal.
81ddc115 71.sp 1
0b6ba29a
KM
72.ti -\n(Inn
73\&\fB\-i\fP \c
74Force \fI\*(dB\fP to act as though standard input is a terminal.
81ddc115
KM
75.sp 1
76.ti -\n(Inn
77\&\fB\-k\fP \c
78Map memory addresses, useful for kernel debugging.
79.sp 1
0b6ba29a
KM
80.ti -\n(Inn
81\&\fB\-I\fP \fIdir\fP \c
82Add \fIdir\fP to the list of directories
83that are searched when looking for a source file.
84Normally \fI\*(dB\fP looks for source files in the current directory
85and in the directory where \fIobjfile\fP is located.
86The directory search path can also be set with the \fBuse\fP command.
81ddc115
KM
87.sp 1
88.ti -\n(Inn
89\&\fB\-c\fP \fIfile\fP \c
90Execute the \fI\*(dB\fP commands in the \fIfile\fP before
91reading from standard input.
0b6ba29a 92.in -\n(Inn
81ddc115 93.sp 1
0b6ba29a
KM
94.PP
95Unless \fB\-r\fP is specified, \fI\*(dB\fP just prompts and waits for a command.
96.sp 1
97.ne 8
98.B Execution and Tracing Commands
99.sp 1
100.TP
101\fBrun\fP [\fIargs\fP] [\fB<\fP \fIfilename\fP] [\fB>\fP \fIfilename\fP]
81ddc115
KM
102.ns
103.TP
104\fBrerun\fP [\fIargs\fP] [\fB<\fP \fIfilename\fP] [\fB>\fP \fIfilename\fP]
0b6ba29a
KM
105Start executing \fIobjfile\fP, passing \fIargs\fP as command line arguments;
106\fB<\fP or \fB>\fP can be used to redirect input or output in the usual manner.
81ddc115
KM
107When \fBrerun\fP is used without any arguments the previous
108argument list is passed to the program;
109otherwise it is identical to \fBrun\fP.
0b6ba29a
KM
110If \fIobjfile\fP has been written since the last time the symbolic information
111was read in, \fI\*(dB\fP will read in the new information.
112.TP
113\fBtrace\fP [\fBin\fP \fIprocedure/function\fP] [\fBif\fP \fIcondition\fP]
114.ns
115.TP
116\fBtrace\fP \fIsource-line-number\fP [\fBif\fP \fIcondition\fP]
117.ns
118.TP
119\fBtrace\fP \fIprocedure/function\fP [\fBin\fP \fIprocedure/function\fP] [\fBif\fP \fIcondition\fP]
120.ns
121.TP
122\fBtrace\fP \fIexpression\fP \fBat\fP \fIsource-line-number\fP [\fBif\fP \fIcondition\fP]
123.ns
124.TP
125\fBtrace\fP \fIvariable\fP [\fBin\fP \fIprocedure/function\fP] [\fBif\fP \fIcondition\fP]
126Have tracing information printed when the program is executed.
127A number is associated with the command that is used
128to turn the tracing off (see the \fBdelete\fP command).
129.sp 1
130The first argument describes what is to be traced.
131If it is a \fIsource-line-number\fP, then the line is printed
132immediately prior to being executed.
133Source line numbers in a file other than the current one
134must be preceded by the name of the file in quotes and a colon, e.g.
135"mumble.p":17.
136.sp 1
137If the argument is a procedure or function name then
138every time it is called, information is printed telling
139what routine called it, from what source line it was called,
140and what parameters were passed to it.
141In addition, its return is noted, and if it's a function
142then the value it is returning is also printed.
143.sp 1
144If the argument is an \fIexpression\fP with an \fBat\fP clause
145then the value of the expression is printed whenever the
146identified source line is reached.
147.sp 1
148If the argument is a variable then the name and value of the variable
149is printed whenever it changes.
150Execution is substantially slower during this form of tracing.
151.sp 1
152If no argument is specified then all source lines are printed
153before they are executed.
154Execution is substantially slower during this form of tracing.
155.sp 1
156The clause ``\fBin\fP \fIprocedure/function\fP'' restricts tracing information
157to be printed only while executing inside the given procedure
158or function.
159.sp 1
160\fICondition\fP is a boolean expression and is
161evaluated prior to printing the tracing information;
162if it is false then the information is not printed.
163.br
164.ne 10
165.IP "\fBstop\fP \fBif\fP \fIcondition\fP"
166.ns
167.IP "\fBstop\fP \fBat\fP \fIsource-line-number\fP [\fBif\fP \fIcondition\fP]"
168.ns
169.IP "\fBstop\fP \fBin\fP \fIprocedure/function\fP [\fBif\fP \fIcondition\fP]"
170.ns
171.IP "\fBstop\fP \fIvariable\fP [\fBif\fP \fIcondition\fP]"
172Stop execution when the given line is reached, procedure or function
173called, variable changed, or condition true.
174.IP "\fBstatus\fP [\fB>\fP \fIfilename\fP]"
175Print out the currently active \fBtrace\fP and \fBstop\fP commands.
81ddc115
KM
176.IP "\fBdelete\fP \fIcommand-number\fP ..."
177The traces or stops corresponding to the given numbers are removed.
0b6ba29a
KM
178The numbers associated with traces and stops are printed by
179the \fBstatus\fP command.
180.IP "\fBcatch\fP \fInumber\fP"
181.ns
81ddc115
KM
182.IP "\fBcatch\fP \fIsignal-name\fP"
183.ns
0b6ba29a 184.IP "\fBignore\fP \fInumber\fP"
81ddc115
KM
185.ns
186.IP "\fBignore\fP \fIsignal-name\fP"
187Start or stop trapping a signal before it is sent
0b6ba29a
KM
188to the program.
189This is useful when a program being debugged
190handles signals such as interrupts.
81ddc115
KM
191A signal may be specified by number or by a name
192(e.g., SIGINT).
193Signal names are case insensitive and the ``SIG'' prefix is optional.
194By default all signals are trapped except SIGCONT, SIGCHILD,
0b6ba29a 195SIGALRM and SIGKILL.
81ddc115
KM
196.IP "\fBcont\fP \fIinteger\fP"
197.ns
198.IP "\fBcont\fP \fIsignal-name\fP"
0b6ba29a 199Continue execution from where it stopped.
81ddc115
KM
200If a signal is specified, the process continues as though
201it received the signal.
202Otherwise, the process is continued as though it had not been stopped.
203.PP
0b6ba29a
KM
204Execution cannot be continued if the process has ``finished'',
205that is, called the standard procedure ``exit''.
206\fI\*(DB\fP does not allow the process to exit, thereby
207letting the user to examine the program state.
208.IP \fBstep\fP
209Execute one source line.
210.IP \fBnext\fP
211Execute up to the next source line.
212The difference between this and \fBstep\fP is that
213if the line contains a call to a procedure or function
214the \fBstep\fP command will stop at the beginning of that
215block, while the \fBnext\fP command will not.
81ddc115
KM
216.IP "\fBreturn\fP [\fIprocedure\fP]"
217Continue until a return to \fIprocedure\fP is executed, or
218until the current procedure returns if none is specified.
219.IP "\fBcall\fP \fIprocedure(parameters)\fP"
220Execute the object code associated with the named procedure or function.
0b6ba29a
KM
221.sp 1
222.br
223.ne 8v
224.PP
81ddc115 225.B Printing Variables and Expressions
0b6ba29a 226.sp 1
81ddc115
KM
227.PP
228Names are resolved first using the static scope of the current function,
229then using the dynamic scope if the name is not defined
230in the static scope.
231If static and dynamic searches do not yield a result,
232an arbitrary symbol is chosen and
233the message ``[using\ \fIqualified\ name\fP]'' is printed.
234The name resolution procedure may be overridden by qualifying an identifier
235with a block name, e.g., ``\fImodule\fP.\fIvariable\fP''.
236For C, source files are treated as modules named
237by the file name without ``.c''.
238.PP
239Expressions are specified with an approximately
240common subset of C and Pascal (or equivalently Modula-2) syntax.
241Indirection can be denoted using either a prefix ``*'' or
242a postfix ``^'' and
243array expressions are subscripted by brackets (``[ ]'').
0b6ba29a
KM
244The field reference operator (``.'') can be used with pointers
245as well as records, making the C operator ``->'' unnecessary
246(although it is supported).
81ddc115
KM
247.PP
248Types of expressions are checked;
249the type of an expression may be overridden
250by using ``\fItype-name\fP(\fIexpression\fP)''.
251When there is no corresponding named type
252the special constructs ``&\fItype-name\fP'' and ``$$\fItag-name\fP''
253can be used to represent a pointer to a named type or C structure tag.
254.sp 1
255.IP "\fBassign\fP \fIvariable\fP \fB=\fP \fIexpression\fP"
256Assign the value of the expression to the variable.
257.IP "\fBdump\fP [\fIprocedure\fR] [\fB>\fP \fIfilename\fP]"
258Print the names and values of variables in the given procedure,
259or the current one if none is specified.
260If the procedure given is ``.'', then the all active variables
261are dumped.
262.IP "\fBprint\fP \fIexpression\fP [\fB,\fP \fIexpression\fP ...]"
263Print out the values of the expressions.
0b6ba29a
KM
264.IP "\fBwhatis\fP \fIname\fP"
265Print the declaration of the given name, which may be qualified
266with block names as above.
267.IP "\fBwhich\fP \fIidentifier\fP"
268Print the full qualification of the given identifer, i.e.
269the outer blocks that the identifier is associated with.
81ddc115
KM
270.IP "\fBup\fP [\fIcount\fP]"
271.ns
272.IP "\fBdown\fP [\fIcount\fP]"
273Move the current function, which is used for resolving names,
274up or down the stack \fIcount\fP levels.
275The default \fIcount\fP is 1.
276.IP \fBwhere\fP
277Print out a list of the active procedures and function.
0b6ba29a
KM
278.IP "\fBwhereis\fP \fIidentifier\fP"
279Print the full qualification of all the symbols whose
280name matches the given identifier.
281The order in which the symbols are printed is not meaningful.
0b6ba29a
KM
282.sp 1
283.br
284.ne 8v
285.PP
286.B Accessing Source Files
287.sp 1
81ddc115
KM
288.IP "/\fIregular\ expression\fP[/]"
289.ns
290.IP "?\fIregular\ expression\fP[?]"
291Search forward or backward in the current source file
292for the given pattern.
0b6ba29a
KM
293.IP "\fBedit\fP [\fIfilename\fP]"
294.ns
295.IP "\fBedit\fP \fIprocedure/function-name\fP"
296Invoke an editor on \fIfilename\fP or the current source file if none
297is specified.
298If a \fIprocedure\fP or \fIfunction\fP name is specified,
299the editor is invoked on the file that contains it.
300Which editor is invoked by default depends on the installation.
301The default can be overridden by setting the environment variable
302EDITOR to the name of the desired editor.
303.IP "\fBfile\fP [\fIfilename\fP]"
304Change the current source file name to \fIfilename\fP.
305If none is specified then the current source file name is printed.
306.IP "\fBfunc\fP [\fIprocedure/function\fP]"
307Change the current function.
308If none is specified then print the current function.
309Changing the current function implicitly changes the current source file
310to the one that contains the function; it also changes the current scope
311used for name resolution.
312.IP "\fBlist\fP [\fIsource-line-number\fP [\fB,\fP \fIsource-line-number\fP]]"
313.ns
314.IP "\fBlist\fP \fIprocedure/function\fP"
315List the lines in the current source file from the first line number to
316the second inclusive.
317If no lines are specified, the next 10 lines are listed.
318If the name of a procedure or function is given
319lines \fIn-k\fP to \fIn+k\fP are listed where \fIn\fP is the first statement
320in the procedure or function and \fIk\fP is small.
321.IP "\fBuse\fP \fIdirectory-list\fP"
322Set the list of directories to be searched
323when looking for source files.
324.sp 1
325.br
326.ne 8v
327.PP
81ddc115
KM
328.B Command Aliases and Variables
329.sp 1
330.TP
331\fBalias\fP \fIname\fP \fIname\fP
332.ns
333.TP
334\fBalias\fP \fIname\fP ``\fIstring\fP''
335.ns
336.TP
337\fBalias\fP \fIname\fP (\fIparameters\fP) ``\fIstring\fP''
338When commands are processed,
339\*(dB first checks to see if the word
340is an alias for either a command or a string.
341If it is an alias, then \*(dB treats the input as though
342the corresponding string (with values substituted for any parameters)
343had been entered.
344For example,
345to define an alias ``rr'' for the command ``rerun'',
346one can say
347.sp 1
348.in +8n
349alias rr rerun
350.in -8n
351.sp 1
352To define an alias called ``b'' that sets a stop at a particular line
353one can say
354.sp 1
355.in +8n
356alias b(x) ``stop at x''
357.in -8n
358.sp 1
359Subsequently, the command ``b(12)'' will expand to ``stop at 12''.
360.need 5
361.TP
362\fBset\fP \fIname\fP [= \fIexpression\fP]
363The \fBset\fP command defines values for debugger variables.
364The names of these variables cannot conflict with names in the program
365being debugged, and are expanded to the corresponding expression
366within other commands.
367The following variables have a special meaning:
368.sp 1
369.in +8n
370.ti -5n
371$frame
372.br
373Setting this variable to an address causes \*(dB to use the stack frame
374pointed to by the address for
375doing stack traces and accessing local variables.
376This facility is of particular use for kernel debugging.
377.sp 1
378.ti -5n
379$hexchars
380.ti -5n
381$hexints
382.ti -5n
383$hexoffsets
384.ti -5n
385$hexstrings
386.br
387When set, \*(dB prints out
388out characters, integers, offsets from registers, or character pointers
389respectively in hexadecimal.
390.sp 1
391.ti -5n
392$listwindow
393.br
394The value of this variable specifies the number
395of lines to list around a function or when the \fBlist\fP command
396is given without any parameters.
397Its default value is 10.
398.sp 1
399.ti -5n
400$mapaddrs
401.br
402Setting (unsetting) this variable causes \*(dB to start (stop)
403mapping addresses.
404As with ``$frame'', this is useful for kernel debugging.
3e8dcebc
DS
405.sp 1
406.ti -5n
407$unsafecall
408.ti -5n
409$unsafeassign
410.br
411When ``$unsafecall'' is set,
412strict type checking is turned off for arguments to
413subroutine or function calls (\fIe.g.\fP in the \fBcall\fP statement).
414When ``$unsafeassign'' is set,
415strict type checking between the two sides
416of an \fBassign\fP statement is turned off.
417These variables should be used only with great care,
418because they severely limit \*(dB's usefulness
419for detecting errors.
81ddc115
KM
420.in -8n
421.TP
422\fBunalias\fP \fIname\fP
423Remove the alias with the given name.
424.TP
425\fBunset\fP \fIname\fP
426Delete the debugger variable associated with \fIname\fP.
427.sp 1
428.br
429.ne 8v
430.PP
0b6ba29a
KM
431.B Machine Level Commands
432.sp 1
433.TP
434\fBtracei\fP [\fIaddress\fP] [\fBif\fP \fIcond\fP]
435.ns
436.TP
437\fBtracei\fP [\fIvariable\fP] [\fBat\fP \fIaddress\fP] [\fBif\fP \fIcond\fP]
438.ns
439.TP
440\fBstopi\fP [\fIaddress\fP] [\fBif\fP \fIcond\fP]
441.ns
442.TP
443\fBstopi\fP [\fBat\fP] [\fIaddress\fP] [\fBif\fP \fIcond\fP]
444Turn on tracing or set a stop using a machine instruction address.
445.TP
446\fBstepi\fP
447.ns
448.TP
449\fBnexti\fP
450Single step as in \fBstep\fP or \fBnext\fP, but do a single instruction
451rather than source line.
452.TP
453\fIaddress\fP \fB,\fP\fIaddress\fP\fB/\fP [\fImode\fP]
454.ns
455.TP
81ddc115 456\fIaddress\fP \fB/\fP [\fIcount\fP] [\fImode\fP]
0b6ba29a
KM
457Print the contents of memory starting at the first \fIaddress\fP
458and continuing up to the second \fIaddress\fP or until \fIcount\fP items are printed.
81ddc115 459If the address is ``.'', the address following the one
0b6ba29a
KM
460printed most recently is used.
461The \fImode\fP specifies how memory is to be printed;
462if it is omitted the previous mode specified is used.
463The initial mode is ``X''.
464The following modes are supported:
465.nr In 5
466.in +\n(Inn
467.ta \n(Inn
81ddc115 468.sp 1
0b6ba29a
KM
469.ti -\n(Inn
470\&\fBi\fP \c
471print the machine instruction
0b6ba29a
KM
472.ti -\n(Inn
473\&\fBd\fP \c
474print a short word in decimal
0b6ba29a
KM
475.ti -\n(Inn
476\&\fBD\fP \c
477print a long word in decimal
0b6ba29a
KM
478.ti -\n(Inn
479\&\fBo\fP \c
480print a short word in octal
0b6ba29a
KM
481.ti -\n(Inn
482\&\fBO\fP \c
483print a long word in octal
0b6ba29a
KM
484.ti -\n(Inn
485\&\fBx\fP \c
486print a short word in hexadecimal
0b6ba29a
KM
487.ti -\n(Inn
488\&\fBX\fP \c
489print a long word in hexadecimal
0b6ba29a
KM
490.ti -\n(Inn
491\&\fBb\fP \c
492print a byte in octal
0b6ba29a
KM
493.ti -\n(Inn
494\&\fBc\fP \c
495print a byte as a character
0b6ba29a
KM
496.ti -\n(Inn
497\&\fBs\fP \c
498print a string of characters terminated by a null byte
0b6ba29a
KM
499.ti -\n(Inn
500\&\fBf\fP \c
501print a single precision real number
0b6ba29a
KM
502.ti -\n(Inn
503\&\fBg\fP \c
504print a double precision real number
505.in -\n(Inn
81ddc115 506.sp 1
0b6ba29a
KM
507.PP
508Symbolic addresses are specified by preceding the name with an ``&''.
509Registers are denoted by ``$rN'' where N is the number of the register.
510Addresses may be expressions made up of other addresses and
511the operators ``+'', ``-'', and indirection (unary ``*'').
512.sp 1
513.br
514.ne 8v
515.PP
516.B Miscellaneous Commands
517.sp 1
81ddc115
KM
518.IP \fBgripe\fP
519Invoke a mail program to send a message to the person in charge of \fI\*(dB\fP.
520.IP \fBhelp\fP
521Print out a synopsis of \fI\*(dB\fP commands.
522.IP "\fBquit\fP"
523Exit \fI\*(dB\fP.
0b6ba29a
KM
524.IP "\fBsh\fP \fIcommand-line\fP"
525Pass the command line to the shell for execution.
526The SHELL environment variable determines which shell is used.
0b6ba29a
KM
527.TP
528\fBsource\fP \fIfilename\fP
529Read \fI\*(dB\fP commands from the given \fIfilename\fP.
0b6ba29a
KM
530.SH FILES
531.nr In 20
532.in +\n(Inn
533.ta \n(Inn
81ddc115 534.sp 1
0b6ba29a
KM
535.ti -\n(Inn
536\&a.out \c
537object file
0b6ba29a
KM
538.ti -\n(Inn
539\&\&.\*(dBinit \c
540initial commands
0b6ba29a 541.SH SEE ALSO
81ddc115 542cc(1), f77(1), pc(1), mod(l)
0b6ba29a 543.SH COMMENTS
81ddc115 544\fI\*(DB\fP suffers from the same ``multiple include'' malady as did \fIsdb\fP.
0b6ba29a
KM
545If you have a program consisting of a number of object files
546and each is built from source files that include header files,
547the symbolic information for the header files is replicated in
548each object file.
549Since about one debugger start-up is done for each link,
550having the linker (ld) re-organize the symbol information
81ddc115 551would not save much time, though it would reduce some of the
0b6ba29a 552disk space used.
81ddc115
KM
553.PP
554This problem is an artifact of the unrestricted semantics
0b6ba29a
KM
555of #include's in C; for example an include file can contain
556static declarations that are separate entities for each file
557in which they are included.
81ddc115
KM
558However, even with Modula-2 there is a substantial amount of duplication
559of symbol information necessary for inter-module type checking.
3e8dcebc
DS
560.PP
561Some problems remain with the support for individual languages.
562Fortran problems include:
563inability to assign to logical, logical*2, complex
564and double complex variables;
565inability to represent parameter constants
566which are not type integer or real;
567peculiar representation for the values of dummy procedures
568(the value shown for a dummy procedure is actually
569the first few bytes of the procedure text;
570to find the location of the procedure,
571use ``&'' to take the address of the variable).