Blob


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