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