Blob


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