blob: 03355508c7bbb4f537291faa8c8330b6645e99d4 [file] [log] [blame]
rsc6e18e032004-04-11 04:22:00 +00001.TH DB 1
2.SH NAME
rsc16d2fe72005-01-31 07:14:18 +00003db, stack \- debugger
rsc6e18e032004-04-11 04:22:00 +00004.SH SYNOPSIS
5.B db
6[
7.I option ...
8]
9[
rsc6e18e032004-04-11 04:22:00 +000010.I pid
11|
12.I corefile
13]
rsc69e002b2006-06-26 01:11:46 +000014[
15.I textfile
16]
rsc3264d2e2005-01-23 22:55:46 +000017.PP
18.B stack
19[
rsc3264d2e2005-01-23 22:55:46 +000020.I pid
21|
22.I corefile
rsc69e002b2006-06-26 01:11:46 +000023|
24.I name
25]
26[
27.I textfile
rsc3264d2e2005-01-23 22:55:46 +000028]
rsc6e18e032004-04-11 04:22:00 +000029.SH DESCRIPTION
30.I Db
31is a general purpose debugging program.
32It may be used to examine files and to provide
33a controlled environment for the execution
34of programs.
35.PP
36A
37.I textfile
38is a file containing the text and initialized
39data of an executable program.
40A
41.I pid
42or
43.I corefile
44specifies the memory image of a process.
45A
46.I pid
47gives the id of an executing process to be accessed via
rsc058b0112005-01-03 06:40:20 +000048.IR ptrace (2).
rsc6e18e032004-04-11 04:22:00 +000049A
50.I corefile
51specifies the name of a core dump (see
52.IR core (5)
53on your system of choice) containing the
54memory image of a terminated process.
55This manual refers to the memory image specified by
56.I pid
57or
58.I corefile
59as a
60.IR memfile .
61.PP
62A
63.I map
64associated with each
65.I textfile
66or
67.I memfile
68supports accesses to instructions and data in the file;
69see `Addresses'.
70.PP
71An argument consisting entirely of digits is assumed
72to be a process id; otherwise, it is the name of a
73.I textfile
74or
75.IR corefile .
76When a
77.I textfile
78is given, the textfile map
79is associated with it.
80If only a
81.I memfile
82is given, the textfile map is
83derived from the corresponding
84.IR textfile ,
85if it can be determined
86(this varies from system to system).
87When a
88.I memfile
89is given, the memfile map is associated with it;
90otherwise the map is undefined and accesses to it
91are not permitted.
92.PP
rsc3264d2e2005-01-23 22:55:46 +000093.I Stack
94takes the same arguments as
95.IR db .
96It prints a stack trace (see the
97.B $c
98command below) and then exits.
rsc69e002b2006-06-26 01:11:46 +000099If the first argument is a process name,
100then
101.I stack
102prints the stack trace of every running process
103with the given name
104that is
105owned by the current user.
rsc3264d2e2005-01-23 22:55:46 +0000106.PP
rsc6e18e032004-04-11 04:22:00 +0000107Commands to
108.I db
109are read from the standard input and
110responses are to the standard output.
111The options are
112.TP
rsc8b0e19f2005-01-23 22:56:20 +0000113.B -q
114Quiet mode:
115suppress informational prints at startup.
116.TP
rsc6e18e032004-04-11 04:22:00 +0000117.B -w
118Open
119.I textfile
120and
121.I memfile
122for writing as well as reading.
123.TP
124.BI -I path
125Directory in which to look for relative path names in
126.B $<
127and
128.B $<<
129commands.
130.TP
131.BI -m machine
132Assume instructions are for the given CPU type
133(possible names include
134.B 386
135and
136.BR powerpc ;
137adding
138the suffix
139.B -co
140as in
141.B 386-co
142and
143.B powerpc-co
144selects disassembly in the manufacturer's syntax, if
145available,
146rather than the default Plan 9 syntax).
147.PP
148Most
149.I db
150commands have the following form:
151.IP
152.RI [ address ]
153.RB [ ,
154.IR count ]
155.RI [ command ]
156.PP
157If
158.I address
159is present then the current position, called `dot',
160is set to
161.IR address .
162Initially dot
163is set to 0.
164Most commands are repeated
165.I count
166times with
167dot advancing between repetitions.
168The default
169.I count
170is 1.
171.I Address
172and
173.I count
174are expressions.
175Multiple commands on one line must be separated by
176.LR ; .
177.SS Expressions
178Expressions are evaluated as long
179.IR ints .
180.TP 7.2n
181.B .
182The value of dot.
183.TP 7.2n
184.B +
185The value of dot
186incremented by the current increment.
187.TP 7.2n
188.B ^
189The value of dot
190decremented by the current increment.
191.TP 7.2n
192.B \&"
193The last
194.I address
195typed.
196.TP 7.2n
197.I integer
198A number, in decimal radix by default.
199The prefixes
200.L 0
201and
202.L 0o
203and
204.L 0O
205(zero oh) force interpretation
206in octal radix; the prefixes
207.L 0t
208and
209.L 0T
210force interpretation in
211decimal radix; the prefixes
212.LR 0x ,
213.LR 0X ,
214and
215.L #
216force interpretation in
217hexadecimal radix.
218Thus
219.LR 020 ,
220.LR 0o20 ,
221.LR 0t16 ,
222and
223.L #10
224all represent sixteen.
225.TP 7.2n
226.IB integer . fraction
227A single-precision floating point number.
228.TP 7.2n
229.BI \' c\| \'
230The
23116-bit
232value of a character.
233.L \e
234may be used to escape a
235.LR \' .
236.TP 7.2n
237.BI < name
238The value of
239.IR name ,
240which is a register name.
241The register names are
242those printed by the
243.B $r
244command.
245.TP 7.2n
246.I symbol
247A
248.I symbol
249is a sequence
250of upper or lower case letters, underscores or
251digits, not starting with a digit.
252.L \e
253may be used to escape other characters.
254The location of the
255.I symbol
256is calculated from the symbol table
257in
258.IR textfile .
259.TP 7.2n
260.IB routine . name
261The address of the variable
262.I name
263in the specified
264C routine.
265Both
266.I routine
267and
268.I name
269are
270.IR symbols .
271If
272.I name
273is omitted the value is the address of the
274most recently activated stack frame
275corresponding to
276.IR routine ;
277if
278.I routine
279is omitted,
280the active procedure
281is assumed.
282.TP 7.2n
283.IB file : integer
284The address of the instruction corresponding
285to the source statement at the indicated
286line number of the file. If the source line contains
287no executable statement, the address of the
288instruction associated with the nearest
289executable source line is returned. Files
290begin at line 1. If multiple files of the same
291name are loaded, an expression of this form resolves
292to the first file encountered in the symbol table.
293.TP 7.2n
294.BI ( exp )
295The value of the expression
296.IR exp .
297.LP
298.I Monadic operators
299.RS
300.TP 7.2n
301.BI * exp
302The contents of the location addressed
303by
304.I exp
305in
306.IR memfile .
307.TP 7.2n
308.BI @ exp
309The contents of the location addressed by
310.I exp
311in
312.IR textfile .
313.TP 7.2n
314.BI - exp
315Integer negation.
316.TP 7.2n
317.BI ~ exp
318Bitwise complement.
319.TP 7.2n
320.BI % exp
321When used as an
322.IR address ,
323.I exp
324is an offset into the segment named
325.IR ublock ;
326see `Addresses'.
327.RE
328.LP
329.I "Dyadic\ operators"
330are left-associative
331and are less binding than monadic operators.
332.RS
333.TP 7.2n
334.IB e1 + e2
335Integer addition.
336.TP 7.2n
337.IB e1 - e2
338Integer subtraction.
339.TP 7.2n
340.IB e1 * e2
341Integer multiplication.
342.TP 7.2n
343.IB e1 % e2
344Integer division.
345.TP 7.2n
346.IB e1 & e2
347Bitwise conjunction.
348.TP 7.2n
349.IB e1 | e2
350Bitwise disjunction.
351.TP 7.2n
352.IB e1 # e2
353.I E1
354rounded up to the next multiple of
355.IR e2 .
356.RE
357.DT
358.SS Commands
359Most commands have the following syntax:
360.TP .5i
361.BI ? f
362Locations starting at
363.I address
364in
365.I textfile
366are printed according to the format
367.IR f .
368.TP
369.BI / f
370Locations starting at
371.I address
372in
373.I memfile
374are printed according to the format
375.IR f .
376.TP
377.BI = f
378The value of
379.I address
380itself is printed according to the format
381.IR f .
382.PP
383A
384.I format
385consists of one or more characters that specify a style
386of printing.
387Each format character may be preceded by a decimal integer
388that is a repeat count for the format character.
389If no format is given then the last format is used.
390.PP
391Most format letters fetch some data,
392print it,
393and advance (a local copy of) dot
394by the number of bytes fetched.
395The total number of bytes in a format becomes the
396.IR current increment .
397.ta 2.5n .5i
398.RS
399.TP
400.PD 0
401.B o
402Print two-byte integer in octal.
403.TP
404.B O
405Print four-byte integer in octal.
406.TP
407.B q
408Print two-byte integer in signed octal.
409.TP
410.B Q
411Print four-byte integer in signed octal.
412.TP
413.B d
414Print two-byte integer in decimal.
415.TP
416.B D
417Print four-byte integer in decimal.
418.TP
419.B V
420Print eight-byte integer in decimal.
421.TP
422.B Z
423Print eight-byte integer in unsigned decimal.
424.TP
425.B x
426Print two-byte integer in hexadecimal.
427.TP
428.B X
429Print four-byte integer in hexadecimal.
430.TP
431.B Y
432Print eight-byte integer in hexadecimal.
433.TP
434.B u
435Print two-byte integer in unsigned decimal.
436.TP
437.B U
438Print four-byte integer in unsigned decimal.
439.TP
440.B f
441Print
442as a single-precision floating point number.
443.TP
444.B F
445Print double-precision floating point.
446.TP
447.B b
448Print the addressed byte in hexadecimal.
449.TP
450.B c
451Print the addressed byte as an
452.SM ASCII
453character.
454.TP
455.B C
456Print the addressed byte as a character.
457Printable
458.SM ASCII
459characters
460are represented normally; others
461are printed in the form
462.BR \exnn .
463.TP
464.B s
465Print the addressed characters, as a
466.SM UTF
467string, until a zero byte
468is reached.
469Advance dot
470by the length of the string,
471including the zero terminator.
472.TP
473.B S
474Print a string using
475the escape convention (see
476.B C
477above).
478.TP
479.B r
480Print as
481.SM UTF
482the addressed two-byte integer (rune).
483.TP
484.B R
485Print as
486.SM UTF
487the addressed two-byte integers as runes
488until a zero rune is reached.
489Advance dot
490by the length of the string,
491including the zero terminator.
492.TP
493.B i
494Print as machine instructions. Dot is
495incremented by the size of the instruction.
496.TP
497.B I
498As
499.B i
500above, but print the machine instructions in
501an alternate form if possible.
502.TP
503.B M
504Print the addressed machine instruction in a
505machine-dependent hexadecimal form.
506.TP
507.B a
508Print the value of dot
509in symbolic form.
510Dot is unaffected.
511.TP
512.B A
513Print the value of dot
514in hexadecimal.
515Dot is unaffected.
516.TP
517.B z
518Print the function name, source file, and line number
519corresponding to dot (textfile only). Dot is unaffected.
520.TP
521.B p
522Print the addressed value in symbolic form.
523Dot is advanced by the size of a machine address.
524.TP
525.B t
526When preceded by an integer, tabs to the next
527appropriate tab stop.
528For example,
529.B 8t
530moves to the next 8-space tab stop.
531Dot is unaffected.
532.TP
533.B n
534Print a newline.
535Dot is unaffected.
536.tr '"
537.TP
538.BR ' ... '
539Print the enclosed string.
540Dot is unaffected.
541.br
542.tr ''
543.TP
544.B ^
545Dot is decremented by the current increment.
546Nothing is printed.
547.TP
548.B +
549Dot is incremented by 1.
550Nothing is printed.
551.TP
552.B -
553Dot is decremented by 1.
554Nothing is printed.
555.RE
556.PD
557.LP
558Other commands include:
559.TP
560newline
561Update dot by the current increment.
562Repeat the previous command with a
563.I count
564of 1.
565.TP
566.RB [ ?/ ] l "\fI value mask\fR"
567Words starting at dot
568are masked with
569.I mask
570and compared with
571.I value
572until
573a match is found.
574If
575.B l
576is used,
577the match is for a two-byte integer;
578.B L
579matches four bytes.
580If no match is found then dot
581is unchanged; otherwise dot
582is set to the matched location.
583If
584.I mask
585is omitted then ~0 is used.
586.TP
587.RB [ ?/ ] w "\fI value ...\fR"
588Write the two-byte
589.I value
590into the addressed
591location.
592If the command is
593.BR W ,
594write four bytes.
595.TP
596.RB [ ?/ ] "m\fI s b e f \fP" [ ?\fR]
597.br
598New values for
599.RI ( b,\ e,\ f )
600in the segment named
601.I s
602are recorded. Valid segment names are
603.IR text ,
604.IR data ,
605or
606.IR ublock .
607If less than three address expressions are given,
608the remaining parameters are left unchanged.
609If the list is terminated by
610.L ?
611or
612.L /
613then the file
614.RI ( textfile
615or
616.I memfile
617respectively) is used
618for subsequent requests.
619For example,
620.L /m?
621causes
622.L /
623to refer to
624.IR textfile .
625.TP
626.BI > name
627Dot is assigned to the variable or register named.
628.TP
629.B !
630The rest of the line is passed to
631.IR rc (1)
632for execution.
633.TP
634.BI $ modifier
635Miscellaneous commands.
636The available
637.I modifiers
638are:
639.RS
640.TP
641.PD 0
642.BI < f
643Read commands from the file
644.IR f .
645If this command is executed in a file, further commands
646in the file are not seen.
647If
648.I f
649is omitted, the current input stream is terminated.
650If a
651.I count
652is given, and is zero, the command is ignored.
653.TP
654.BI << f
655Similar to
656.B <
657except it can be used in a file of commands without
658causing the file to be closed.
659There is a (small) limit to the number of
660.B <<
661files that can be open at once.
662.br
663.ns
664.TP
665.BI > f
666Append output to the file
667.IR f ,
668which is created if it does not exist.
669If
670.I f
671is omitted, output is returned to the terminal.
672.TP
673.B ?
674Print process id, the condition which caused stopping or termination,
675the registers and the instruction addressed by
676.BR pc .
677This is the default if
678.I modifier
679is omitted.
680.TP
681.B r
682Print the general registers and
683the instruction addressed by
684.BR pc .
685Dot is set to
686.BR pc .
687.TP
688.B R
689Like
690.BR $r ,
691but include miscellaneous processor control registers
692and floating point registers.
693.TP
694.B f
695Print floating-point register values as
696single-precision floating point numbers.
697.TP
698.B F
699Print floating-point register values as
700double-precision floating point numbers.
701.TP
702.B b
703Print all breakpoints
704and their associated counts and commands. `B' produces the same results.
705.TP
706.B c
707Stack backtrace.
708If
709.I address
710is given, it specifies the address of a pair of 32-bit
711values containing the
712.B sp
713and
714.B pc
715of an active process. This allows selecting
716among various contexts of a multi-threaded
717process.
718If
719.B C
720is used, the names and (long) values of all
721parameters,
722automatic
723and static variables are printed for each active function.
724If
725.I count
726is given, only the first
727.I count
728frames are printed.
729.TP
730.B a
731Attach to the running process whose pid
732is contained in
733.IR address .
734.TP
735.B e
736The names and values of all
737external variables are printed.
738.TP
739.B w
740Set the page width for output to
741.I address
742(default 80).
743.TP
744.B q
745Exit from
746.IR db .
747.TP
748.B m
749Print the address maps.
750.TP
751.B k
752Simulate kernel memory management.
753.TP
754.BI M machine
755Set the
756.I machine
757type used for disassembling instructions.
758.PD
759.RE
760.TP
761.BI : modifier
762Manage a subprocess.
763Available modifiers are:
764.RS
765.TP
766.PD 0
767.BI h
768Halt
769an asynchronously running process to allow breakpointing.
770Unnecessary for processes created under
771.IR db ,
772e.g. by
773.BR :r .
774.TP
775.BI b c
776Set breakpoint at
777.IR address .
778The breakpoint is executed
779.IR count \-1
780times before
781causing a stop.
782Also, if a command
783.I c
784is given it is executed at each
785breakpoint and if it sets dot to zero
786the breakpoint causes a stop.
787.TP
788.B d
789Delete breakpoint at
790.IR address .
791.TP
792.B r
793Run
794.I textfile
795as a subprocess.
796If
797.I address
798is given the
799program is entered at that point; otherwise
800the standard entry point is used.
801.I Count
802specifies how many breakpoints are to be
803ignored before stopping.
804Arguments to the subprocess may be supplied on the
805same line as the command.
806An argument starting with < or > causes the standard
807input or output to be established for the command.
808.TP
809.BI c s
810The subprocess is continued.
811If
812.I s
813is omitted
814or nonzero,
815the subprocess
816is sent the note that caused it to stop.
817If 0
818is specified,
819no note is sent.
820(If the stop was due to a breakpoint or single-step,
821the corresponding note is elided before continuing.)
822Breakpoint skipping is the same
823as for
824.BR r .
825.TP
826.BI s s
827As for
828.B c
829except that
830the subprocess is single stepped for
831.I count
832machine instructions.
833If a note is pending,
834it is received
835before the first instruction is executed.
836If there is no current subprocess then
837.I textfile
838is run
839as a subprocess as for
840.BR r .
841In this case no note can be sent; the remainder of the line
842is treated as arguments to the subprocess.
843.TP
844.BI S s
845Identical to
846.B s
847except the subprocess is single stepped for
848.I count
849lines of C source. In optimized code, the correspondence
850between C source and the machine instructions is
851approximate at best.
852.TP
853.BI x
854The current subprocess, if any, is released by
855.I db
856and allowed to continue executing normally.
857.TP
858.B k
859The current subprocess, if any, is terminated.
860.TP
861.BI n c
862Display the pending notes for the process.
863If
864.I c
865is specified, first delete
866.I c'th
867pending note.
868.PD
869.RE
870.SS Addresses
871The location in a file or memory image associated with
872an address is calculated from a map
873associated with the file.
874Each map contains one or more quadruples
875.RI ( "t, f, b, e, o" ),
876defining a segment named
877.I t
878(usually,
879.IR text ,
880.IR data ,
881or
882.IR core )
883in file
884.I f
885mapping addresses in the range
886.I b
887through
888.IR e
889to the part of the file
890beginning at
891offset
892.IR o .
893If segments overlap, later segments obscure earlier ones.
894An address
895.I a
896is translated
897to a file address
898by finding the last segment in the list
899for which
900.IR b ≤ a < e ;
901the location in the file
902is then
903.IR address + f \- b .
904.PP
905Usually,
906the text and initialized data of a program
907are mapped by segments called
908.IR text ,
909.IR data ,
910and
911.IR bss .
912Since a program file does not contain stack data,
913this data is
914not mapped.
915The text segment is mapped similarly in
916a normal (i.e., non-kernel)
917.IR memfile .
918However, one or more segments called
919.I data
920provide access to process memory.
921This region contains the program's static data, the bss, the
922heap and the stack.
923.PP
924Sometimes it is useful to define a map with a single segment
925mapping the region from 0 to 0xFFFFFFFF; a map of this type
926allows an entire file to be examined
927without address translation.
928.PP
929The
930.B $m
931command dumps the currently active maps. The
932.B ?m
933and
934.B /m
935commands modify the segment parameters in the
936.I textfile
937and
938.I memfile
939maps, respectively.
940.SH EXAMPLES
941To set a breakpoint at the beginning of
942.B write()
943in extant process 27:
944.IP
rsc6e18e032004-04-11 04:22:00 +0000945.EX
946% db 27
947:h
948write:b
949:c
950.EE
951.PP
952To set a breakpoint at the entry of function
953.B parse
954when the local variable
955.B argc
956in
957.B main
958is equal to 1:
959.IP
960.EX
961parse:b *main.argc-1=X
962.EE
963.PP
964This prints the value of
965.B argc-1
966which as a side effect sets dot; when
967.B argc
968is one the breakpoint will fire.
969Beware that local variables may be stored in registers; see the
970BUGS section.
971.SH "SEE ALSO"
rsc3264d2e2005-01-23 22:55:46 +0000972.IR acid (1),
973.IR core (1)
rsc6e18e032004-04-11 04:22:00 +0000974.SH SOURCE
rscc3674de2005-01-11 17:37:33 +0000975.B \*9/src/cmd/db
rsc6e18e032004-04-11 04:22:00 +0000976.SH DIAGNOSTICS
977Exit status is 0, unless the last command failed or
978returned non-zero status.
979.SH BUGS
980Examining a local variable with
981.I routine.name
982returns the contents of the memory allocated for the variable, but
983with optimization, variables often reside in registers.
984Also, on some architectures, the first argument is always
985passed in a register.
986.PP
987Variables and parameters that have been
988optimized away do not appear in the
989symbol table, returning the error
990.IR "bad local variable"
991when accessed by
992.IR db .
993.PP
994Breakpoints should not be set on instructions scheduled
995in delay slots. When a program stops on such a breakpoint,
996it is usually impossible to continue its execution.