xref: /netbsd-src/share/man/man4/ddb.4 (revision 5b84b3983f71fd20a534cfa5d1556623a8aaa717)
1.\"	$NetBSD: ddb.4,v 1.81 2005/02/14 18:14:27 fredb Exp $
2.\"
3.\" Copyright (c) 1997 - 2003 The NetBSD Foundation, Inc.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to The NetBSD Foundation
7.\" by Luke Mewburn
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\"    notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\"    notice, this list of conditions and the following disclaimer in the
16.\"    documentation and/or other materials provided with the distribution.
17.\" 3. All advertising materials mentioning features or use of this software
18.\"    must display the following acknowledgement:
19.\"        This product includes software developed by the NetBSD
20.\"        Foundation, Inc. and its contributors.
21.\" 4. Neither the name of The NetBSD Foundation nor the names of its
22.\"    contributors may be used to endorse or promote products derived
23.\"    from this software without specific prior written permission.
24.\"
25.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
26.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
29.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35.\" POSSIBILITY OF SUCH DAMAGE.
36.\"
37.\" ---
38.\"	This manual page was derived from a -man.old document which bore
39.\"	the following copyright message:
40.\" ---
41.\"
42.\" Mach Operating System
43.\" Copyright (c) 1991,1990 Carnegie Mellon University
44.\" All Rights Reserved.
45.\"
46.\" Permission to use, copy, modify and distribute this software and its
47.\" documentation is hereby granted, provided that both the copyright
48.\" notice and this permission notice appear in all copies of the
49.\" software, derivative works or modified versions, and any portions
50.\" thereof, and that both notices appear in supporting documentation.
51.\"
52.\" CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
53.\" CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
54.\" ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
55.\"
56.\" Carnegie Mellon requests users of this software to return to
57.\"
58.\"  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
59.\"  School of Computer Science
60.\"  Carnegie Mellon University
61.\"  Pittsburgh PA 15213-3890
62.\"
63.\" any improvements or extensions that they make and grant Carnegie Mellon
64.\" the rights to redistribute these changes.
65.\"
66.Dd February 14, 2005
67.Dt DDB 4
68.Os
69.Sh NAME
70.Nm ddb
71.Nd in-kernel debugger
72.Sh SYNOPSIS
73.Cd options DDB
74.Pp
75To enable history editing:
76.Cd options DDB_HISTORY_SIZE=integer
77.Pp
78To disable entering
79.\" XXX: hack; .Nm automatically introduces newline in SYNOPSIS
80.Ic ddb
81upon kernel panic:
82.Cd options DDB_ONPANIC=0
83.Pp
84To enable teeing all
85.\" XXX: hack; .Nm automatically introduces newline in SYNOPSIS
86.Ic ddb
87output to the kernel msgbuf:
88.Cd options DDB_TEE_MSGBUF=1
89.Sh DESCRIPTION
90.Nm
91is the in-kernel debugger.
92It may be entered at any time via a special key sequence, and
93optionally may be invoked when the kernel panics.
94.Sh ENTERING THE DEBUGGER
95Unless
96.Dv DDB_ONPANIC
97is set to 0,
98.Nm
99will be activated whenever the kernel would otherwise panic.
100.Pp
101.Nm
102may also be activated from the console.
103In general, sending a break on a serial console will activate
104.Nm .
105There are also key sequences for each port that will activate
106.Nm
107from the keyboard:
108.Bl -tag -offset indent -width "mvme68k" -compact
109.It alpha
110\*[Lt]Ctrl\*[Gt]-\*[Lt]Alt\*[Gt]-\*[Lt]Esc\*[Gt] on PC style keyboards.
111.It amiga
112\*[Lt]LAlt\*[Gt]-\*[Lt]LAmiga\*[Gt]-\*[Lt]F10\*[Gt]
113.It atari
114\*[Lt]Alt\*[Gt]-\*[Lt]LeftShift\*[Gt]-\*[Lt]F9\*[Gt]
115.It hp300
116\*[Lt]Shift\*[Gt]-\*[Lt]Reset\*[Gt]
117.It hpcarm
118\*[Lt]Ctrl\*[Gt]-\*[Lt]Alt\*[Gt]-\*[Lt]Esc\*[Gt]
119.It hpcmips
120\*[Lt]Ctrl\*[Gt]-\*[Lt]Alt\*[Gt]-\*[Lt]Esc\*[Gt]
121.It hpcsh
122\*[Lt]Ctrl\*[Gt]-\*[Lt]Alt\*[Gt]-\*[Lt]Esc\*[Gt]
123.It i386
124\*[Lt]Ctrl\*[Gt]-\*[Lt]Alt\*[Gt]-\*[Lt]Esc\*[Gt]
125.br
126\*[Lt]Break\*[Gt] on serial console.
127.It mac68k
128\*[Lt]Command\*[Gt]-\*[Lt]Power\*[Gt], or the Interrupt switch.
129.It macppc
130Some models:
131\*[Lt]Command\*[Gt]-\*[Lt]Option\*[Gt]-\*[Lt]Power\*[Gt]
132.It mvme68k
133Abort switch on CPU card.
134.It pmax
135\*[Lt]Do\*[Gt] on
136.Tn LK-201
137rcons console.
138.br
139\*[Lt]Break\*[Gt] on serial console.
140.It sparc
141\*[Lt]L1\*[Gt]-A, or \*[Lt]Stop\*[Gt]-A on a
142.Tn Sun
143keyboard.
144.br
145\*[Lt]Break\*[Gt] on serial console.
146.It sparc64
147\*[Lt]L1\*[Gt]-A, or \*[Lt]Stop\*[Gt]-A on a
148.Tn Sun
149keyboard.
150.br
151\*[Lt]Break\*[Gt] on serial console.
152.It sun3
153\*[Lt]L1\*[Gt]-A, or \*[Lt]Stop\*[Gt]-A on a
154.Tn Sun
155keyboard.
156.br
157\*[Lt]Break\*[Gt] on serial console.
158.It vax
159\*[Lt]Esc\*[Gt]-\*[Lt]Shift\*[Gt]-D on serial console.
160.It x68k
161Interrupt switch on the body.
162.El
163.Pp
164The key sequence to activate
165.Nm
166can be changed by modifying
167.Dq hw.cnmagic
168with
169.Xr sysctl 8 .
170If the console is not dedicated to
171.Nm
172the sequence should not be easily typed by accident.
173In addition,
174.Nm
175may be explicitly activated by the debugging code in the kernel
176if
177.Cm DDB
178is configured.
179.Sh COMMAND SYNTAX
180The general command syntax is:
181.Bd -ragged -offset indent
182.Ic command Ns Op Cm / Ns Ar modifier
183.Ar address
184.Op Cm , Ns Ar count
185.Ed
186.Pp
187The current memory location being edited is referred to as
188.Ar dot ,
189and the next location is
190.Ar next .
191They are displayed as hexadecimal numbers.
192.Pp
193Commands that examine and/or modify memory update
194.Ar dot
195to the address of the last line examined or the last location
196modified, and set
197.Ar next
198to the next location to be examined or modified.
199Other commands don't change
200.Ar dot ,
201and set
202.Ar next
203to be the same as
204.Ar dot .
205.Pp
206A blank line repeats the previous command from the address
207.Ar next
208with the previous
209.Cm count
210and no modifiers.
211Specifying
212.Cm address
213sets
214.Em dot
215to the address.
216If
217.Cm address
218is omitted,
219.Em dot
220is used.
221A missing
222.Cm count
223is taken to be 1 for printing commands, and infinity for stack traces.
224.Pp
225The syntax:
226.Bd -ragged -offset indent
227.Cm , Ns Ar count
228.Ed
229.Pp
230repeats the previous command, just as a blank line does, but with
231the specified
232.Cm count .
233.Pp
234.Nm
235has a
236.Xr more 1 Ns -like
237functionality; if a number of lines in a command's output exceeds the number
238defined in the
239.Va lines
240variable, then
241.Nm
242displays
243.Dq "--db more--"
244and waits for a response, which may be one of:
245.Bl -tag -offset indent -width "\*[Lt]return\*[Gt]"
246.It \*[Lt]return\*[Gt]
247one more line.
248.It \*[Lt]space\*[Gt]
249one more page.
250.It Ic q
251abort the current command, and return to the command input mode.
252.El
253.Pp
254If
255.Nm
256history editing is enabled (by defining the
257.D1 Cd options DDB_HISTORY_SIZE=num
258kernel option), then a history of the last
259.Cm num
260commands is kept.
261The history can be manipulated with the following key sequences:
262.Bl -tag -offset indent -width "\*[Lt]Ctrl\*[Gt]-P"
263.It \*[Lt]Ctrl\*[Gt]-P
264retrieve previous command in history (if any).
265.It \*[Lt]Ctrl\*[Gt]-N
266retrieve next command in history (if any).
267.El
268.Sh COMMANDS
269.Nm
270supports the following commands:
271.Bl -tag -width 5n
272.It Xo
273.Sm off
274.Ic \&!
275.Ar address
276.Oo
277.Cm ( Ar expression
278.Op Ar ,...
279.Cm )
280.Oc
281.Sm on
282.Xc
283A synonym for
284.Ic call .
285.It Xo
286.Ic break Ns Op Cm /u
287.Ar address Ns Op Cm , Ns Ar count
288.Xc
289Set a breakpoint at
290.Ar address .
291If
292.Ar count
293is supplied, continues
294.Pq Ar count Ns -1
295times before stopping at the breakpoint.
296If the breakpoint is set, a breakpoint number is printed with
297.Sq \&# .
298This number can be used to
299.Ic delete
300the breakpoint, or to add
301conditions to it.
302.Pp
303If
304.Cm /u
305is specified,
306set a breakpoint at a user-space address.
307Without
308.Cm /u ,
309.Ar address
310is considered to be in the kernel-space, and an address in the wrong
311space will be rejected, and an error message will be emitted.
312This modifier may only be used if it is supported by machine dependent
313routines.
314.Pp
315Warning: if a user text is shadowed by a normal user-space debugger,
316user-space breakpoints may not work correctly.
317Setting a breakpoint at the low-level code paths may also cause
318strange behavior.
319.It Xo
320.Ic bt Ns Op Cm /u
321.Sm off
322.Op Ar frame-address
323.Op Cm , Ar count
324.Sm on
325.Xc
326A synonym for
327.Ic trace .
328.It Xo
329.Ic bt/t
330.Sm off
331.Op Ar pid
332.Op Cm , Ar count
333.Sm on
334.Xc
335A synonym for
336.Ic trace .
337.It Xo
338.Ic call
339.Sm off
340.Ar address
341.Oo
342.Cm ( Ar expression
343.Op Ar ,...
344.Cm )
345.Oc
346.Sm on
347.Xc
348Call the function specified by
349.Ar address
350with the argument(s) listed in parentheses.
351Parentheses may be omitted if the function takes no arguments.
352The number of arguments is currently limited to 10.
353.It Ic continue Ns Op Cm /c
354Continue execution until a breakpoint or watchpoint.
355If
356.Cm /c
357is specified, count instructions while executing.
358Some machines (e.g., pmax) also count loads and stores.
359.Pp
360Warning: when counting, the debugger is really silently
361single-stepping.
362This means that single-stepping on low-level may cause strange
363behavior.
364.It Xo
365.Ic delete
366.Ar "address" |
367.Cm # Ns Ar number
368.Xc
369Delete a breakpoint.
370The target breakpoint may be specified by
371.Ar address ,
372as per
373.Ic break ,
374or by the breakpoint number returned by
375.Ic break
376if it's prefixed with
377.Sq Cm \&# .
378.It Xo
379.Ic dmesg Op Ar count
380.Xc
381Prints the contents of the kernel message buffer.
382The optional
383.Ar count
384argument will limit printing to at most the last
385.Ar count
386bytes of the message buffer.
387.It Xo
388.Ic dwatch
389.Ar address
390.Xc
391Delete the watchpoint at
392.Ar address
393that was previously set with
394.Ic watch
395command.
396.It Xo
397.Ic examine Ns Op Cm / Ns Ar modifier
398.Ar address Ns Op Cm , Ns Ar count
399.Xc
400Display the address locations according to the format in
401.Ar modifier .
402Multiple modifier formats display multiple locations.
403If
404.Ar modifier
405isn't specified, the modifier from the last use of
406.Ic examine
407is used.
408.Pp
409The valid format characters for
410.Ar modifier
411are:
412.Bl -tag -offset indent -width 2n -compact
413.It Cm b
414examine bytes (8 bits).
415.It Cm h
416examine half-words (16 bits).
417.It Cm l
418examine words (legacy
419.Dq long ,
42032 bits).
421.It Cm L
422examine long words (implementation dependent)
423.It Cm a
424print the location being examined.
425.It Cm A
426print the location with a line number if possible.
427.It Cm x
428display in unsigned hex.
429.It Cm z
430display in signed hex.
431.It Cm o
432display in unsigned octal.
433.It Cm d
434display in signed decimal.
435.It Cm u
436display in unsigned decimal.
437.It Cm r
438display in current radix, signed.
439.It Cm c
440display low 8 bits as a character.
441Non-printing characters as displayed as an octal escape code
442(e.g.,
443.Sq \e000 ) .
444.It Cm s
445display the NUL terminated string at the location.
446Non-printing characters are displayed as octal escapes.
447.It Cm m
448display in unsigned hex with a character dump at the end of each line.
449The location is displayed as hex at the beginning of each line.
450.It Cm i
451display as a machine instruction.
452.It Cm I
453display as a machine instruction, with possible alternative formats
454depending upon the machine:
455.Bl -tag -offset indent -width "sparc" -compact
456.It alpha
457print register operands
458.It m68k
459use Motorola syntax
460.It pc532
461print instruction bytes in hex
462.It vax
463don't assume that each external label is a procedure entry mask
464.El
465.El
466.It Xo
467.Ic kill
468.Ar pid Ns Op Cm , Ns Ar signal_number
469.Xc
470Send a signal to the process specified by the
471.Ar pid .
472Note that
473.Ar pid
474is interpreted using the current radix (see
475.Cm trace/t
476command for details).
477If
478.Ar signal_number
479isn't specified, the SIGTERM signal is sent.
480.It Ic match Ns Op Cm /p
481A synonym for
482.Ic next .
483.It Ic next Ns Op Cm /p
484Stop at the matching return instruction.
485If
486.Cm /p
487is specified, print the call nesting depth and the
488cumulative instruction count at each call or return.
489Otherwise, only print when the matching return is hit.
490.It Xo
491.Ic print Ns Op Cm /axzodurc
492.Ar address Op Ar address ...
493.Xc
494Print addresses
495.Ar address
496according to the modifier character, as per
497.Ic examine .
498Valid modifiers are:
499.Cm /a ,
500.Cm /x ,
501.Cm /z ,
502.Cm /o ,
503.Cm /d ,
504.Cm /u ,
505.Cm /r ,
506and
507.Cm /c
508(as per
509.Ic examine ) .
510If no modifier is specified, the most recent one specified is used.
511.Ar address
512may be a string, and is printed
513.Dq as-is .
514For example:
515.Bd -literal -offset indent
516print/x "eax = " $eax "\enecx = " $ecx "\en"
517.Ed
518.Pp
519will produce:
520.Bd -literal -offset indent
521eax = xxxxxx
522ecx = yyyyyy
523.Ed
524.It Xo
525.Sm off
526.Ic ps
527.Op Cm /a
528.Op Cm /n
529.Op Cm /w
530.Sm on
531.Xc
532A synonym for
533.Ic "show all procs" .
534.It Ic reboot Op Ar flags
535Reboot, using the optionally supplied boot
536.Ar flags ,
537which is a bitmask supporting the same values as for
538.Xr reboot 2 .
539Some of the more useful flags:
540.Bl -column "Value" "RB_AUTOBOOT" "Description"
541.It Sy "Value" Ta Sy "Name" Ta Sy "Description"
542.It 0x1 Ta RB_ASKNAME Ta Ask for file name to reboot from
543.It 0x2 Ta RB_SINGLE Ta Reboot to single user mode
544.It 0x4 Ta RB_NOSYNC Ta Don't sync before reboot
545.It 0x8 Ta RB_HALT Ta Halt instead of reboot
546.It 0x40 Ta RB_KDB Ta Boot into kernel debugger
547.It 0x100 Ta RB_DUMP Ta Dump unconditionally before reboot
548.It 0x808 Ta RB_POWERDOWN Ta Power off (or at least halt)
549.El
550.Pp
551Note: Limitations of the command line interface preclude
552specification of a boot string.
553.It Xo
554.Ic search Ns Op Cm /bhl
555.Ar address
556.Ar value
557.Op Ar mask
558.Op Cm , Ns Ar count
559.Xc
560Search memory from
561.Ar address
562for
563.Ar value .
564The unit size is specified with a modifier character, as per
565.Ic examine .
566Valid modifiers are:
567.Cm /b ,
568.Cm /h ,
569and
570.Cm /l .
571If no modifier is specified,
572.Cm /l
573is used.
574.Pp
575This command might fail in interesting ways if it doesn't find
576.Ar value .
577This is because
578.Nm
579doesn't always recover from touching bad memory.
580The optional
581.Ar count
582limits the search.
583.It Xo
584.Ic set
585.Cm $ Ns Ar variable
586.Op Cm =
587.Ar expression
588.Xc
589Set the named variable or register to the value of
590.Ar expression .
591Valid variable names are described in
592.Sx VARIABLES .
593.It Xo
594.Sm off
595.Ic "show\ all\ procs"
596.Op Cm /a
597.Op Cm /n
598.Op Cm /w
599.Sm on
600.Xc
601Display all process information.
602Valid modifiers:
603.Bl -tag -width 3n
604.It Cm /n
605show process information in a
606.Xr ps 1
607style format (this is the default).
608Information printed includes: process ID, parent process ID,
609process group, UID, process status, process flags, process
610command name, and process wait channel message.
611.It Cm /a
612show the kernel virtual addresses of each process'
613proc structure, u-area, and vmspace structure.
614The vmspace address is also the address of the process'
615vm_map structure, and can be used in the
616.Ic "show map"
617command.
618.It Cm /w
619show each process' PID, command, system call emulation, wait channel
620address, and wait channel message.
621.El
622.It Ic "show breaks"
623Display all breakpoints.
624.It Xo
625.Ic "show buf" Ns Op Cm /f
626.Ar address
627.Xc
628Print the struct buf at
629.Ar address .
630The
631.Cm /f
632does nothing at this time.
633.It Xo
634.Ic "show event" Ns Op Cm /f
635.Xc
636Print all the non-zero
637.Xr evcnt 9
638event counters.
639If
640.Cm /f
641is specified, all event counters with a count of zero are printed as well.
642.It Xo
643.Ic "show map" Ns Op Cm /f
644.Ar address
645.Xc
646Print the vm_map at
647.Ar address .
648If
649.Cm /f
650is specified, the complete map is printed.
651.It Xo
652.Ic "show mount" Ns Op Cm /f
653.Ar address
654.Xc
655Print the mount structure at
656.Ar address .
657If
658.Cm /f
659is specified, the complete vnode list is printed.
660.It Ic "show ncache" Ar address
661Dump the namecache list associated with vnode at
662.Ar address .
663.It Xo
664.Ic "show object" Ns Op Cm /f
665.Ar address
666.Xc
667Print the vm_object at
668.Ar address .
669If
670.Cm /f
671is specified, the complete object is printed.
672.It Xo
673.Ic "show page" Ns Op Cm /f
674.Ar address
675.Xc
676Print the vm_page at
677.Ar address .
678If
679.Cm /f
680is specified, the complete page is printed.
681.It Xo
682.Ic "show pool" Ns Op Cm /clp
683.Ar address
684.Xc
685Print the pool at
686.Ar address .
687Valid modifiers:
688.Bl -tag -width 4n -compact
689.It Cm /c
690Print the cachelist and its statistics for this pool.
691.It Cm /l
692Print the log entries for this pool.
693.It Cm /p
694Print the pagelist for this pool.
695.El
696.It Ic "show registers" Ns Op Cm /u
697Display the register set.
698If
699.Cm /u
700is specified, display user registers instead of kernel registers
701or the currently save one.
702.Pp
703Warning: support for
704.Cm /u
705is machine dependent.
706If not supported, incorrect information will be displayed.
707.It Ic "show sched_qs"
708Print the state of the scheduler's run queues.
709For each run queue that has an LWP, the run queue index and the list
710of LWPs will be shown.
711If the run queue has LWPs, but the sched_whichqs bit is not set for that
712queue, the queue index will be prefixed with a
713.Sq \&! .
714.It Ic "show uvmexp"
715Print a selection of UVM counters and statistics.
716.It Xo
717.Ic "show vnode" Ns Op Cm /f
718.Ar address
719.Xc
720Print the vnode at
721.Ar address .
722If
723.Cm /f
724is specified, the complete vnode is printed.
725.It Ic "show watches"
726Display all watchpoints.
727.It Xo
728.Ic sifting Ns Op Cm /F
729.Ar string
730.Xc
731Search the symbol tables for all symbols of which
732.Ar string
733is a substring, and display them.
734If
735.Cm /F
736is specified, a character is displayed immediately after each symbol
737name indicating the type of symbol.
738.Pp
739For
740.Xr a.out 5 Ns -format
741symbol tables,
742absolute symbols display
743.Sy @ ,
744text segment symbols display
745.Sy * ,
746data segment symbols display
747.Sy + ,
748.Tn BSS
749segment symbols display
750.Sy - ,
751and filename symbols display
752.Sy / .
753For
754.Tn ELF Ns -format
755symbol tables,
756object symbols display
757.Sy + ,
758function symbols display
759.Sy * ,
760section symbols display
761.Sy \*[Am] ,
762and file symbols display
763.Sy / .
764.Pp
765To sift for a string beginning with a number, escape the first
766character with a backslash as:
767.Bd -literal -offset indent
768sifting \\386
769.Ed
770.It Xo
771.Ic step Ns Op Cm /p
772.Op Cm , Ns Ar count
773.Xc
774Single-step
775.Ar count
776times.
777If
778.Cm /p
779is specified, print each instruction at each step.
780Otherwise, only print the last instruction.
781.Pp
782Warning: depending on the machine type, it may not be possible
783to single-step through some low-level code paths or user-space
784code.
785On machines with software-emulated single-stepping (e.g., pmax),
786stepping through code executed by interrupt handlers will probably
787do the wrong thing.
788.It Ic sync
789Force a crash dump, and then reboot.
790.It Xo
791.Ic trace
792.Ns Op Cm /u Ns Op Cm l
793.Sm off
794.Op Ar frame-address
795.Op Cm , Ar count
796.Sm on
797.Xc
798Stack trace from
799.Ar frame-address .
800If
801.Cm /u
802is specified, trace user-space, otherwise trace kernel-space.
803.Ar count
804is the number of frames to be traced.
805If
806.Ar count
807is omitted, all frames are printed.
808If
809.Cm /l
810is specified, the trace is printed and also stored in the kernel
811message buffer.
812.Pp
813Warning: user-space stack trace is valid only if the machine dependent
814code supports it.
815.It Xo
816.Ic trace/t Ns Op Cm l
817.Sm off
818.Op Ar pid
819.Op Cm , Ar count
820.Sm on
821.Xc
822Stack trace by
823.Dq thread
824(process, on
825.Nx )
826rather than by stack frame address.
827Note that
828.Ar pid
829is interpreted using the current radix, whilst
830.Ic ps
831displays pids in decimal; prefix
832.Ar pid
833with
834.Sq 0t
835to force it to be interpreted as decimal (see
836.Sx VARIABLES
837section for radix).
838If
839.Cm /l
840is specified, the trace is printed and also stored in the kernel
841message buffer.
842.Pp
843Warning: trace by pid is valid only if the machine dependent code
844supports it.
845.It Ic until Ns Op Cm /p
846Stop at the next call or return instruction.
847If
848.Cm /p
849is specified, print the call nesting depth and the
850cumulative instruction count at each call or return.
851Otherwise, only print when the matching return is hit.
852.It Xo
853.Ic watch
854.Sm off
855.Ar address
856.Op Cm , Ar size
857.Sm on
858.Xc
859Set a watchpoint for a region.
860Execution stops when an attempt to modify the region occurs.
861.Ar size
862defaults to 4.
863.Pp
864If you specify a wrong space address, the request is
865rejected with an error message.
866.Pp
867Warning: attempts to watch wired kernel memory may cause
868an unrecoverable error in some systems such as i386.
869Watchpoints on user addresses work the best.
870.It Xo
871.Ic write Ns Op Cm /bhl
872.Ar address
873.Ar expression Op Ar expression ...
874.Xc
875Write the
876.Ar expression Ns s
877at succeeding locations.
878The unit size is specified with a modifier character, as per
879.Ic examine .
880Valid modifiers are:
881.Cm /b ,
882.Cm /h ,
883and
884.Cm /l .
885If no modifier is specified,
886.Cm /l
887is used.
888.Pp
889Warning: since there is no delimiter between
890.Ar expression Ns s ,
891strange things may occur.
892It's best to enclose each
893.Ar expression
894in parentheses.
895.It Xo
896.Ic x Ns Op Cm / Ns Ar modifier
897.Ar address Ns Op Cm , Ns Ar count
898.Xc
899A synonym for
900.Ic examine .
901.\" XXX - these commands aren't implemented; jhawk 19 May 2000
902.\" .It Ic xf
903.\" Examine forward.
904.\" .Ic xf
905.\" re-executes the most recent
906.\" .Ic execute
907.\" command with the same parameters except that
908.\" .Ar address
909.\" is set to
910.\" .Ar next .
911.\" .It Ic xb
912.\" Examine backward.
913.\" .Ic xb
914.\" re-executes the most recent
915.\" .Ic execute
916.\" command with the same parameters, except that
917.\" .Ar address
918.\" is set to the last start address minus its size.
919.El
920.Sh MACHINE-SPECIFIC COMMANDS
921The "glue" code that hooks
922.Nm
923into the
924.Nx
925kernel for any given port can also add machine specific commands
926to the
927.Nm
928command parser.
929All of these commands are preceded by the command word
930.Em machine
931to indicate that they are part of the machine-specific command
932set (e.g.
933.Ic "machine reboot" ) .
934Some of these commands are:
935.Ss ALPHA
936.Bl -tag -width "intrchain" -compact
937.It Ic halt
938Call the PROM monitor to halt the CPU.
939.It Ic reboot
940Call the PROM monitor to reboot the CPU.
941.El
942.Ss ARM32
943.Bl -tag -width "intrchain" -compact
944.It Ic vmstat
945Equivalent to
946.Xr vmstat 1
947output with "-s" option (statistics).
948.It Ic vnode
949Print out a description of a vnode.
950.It Ic intrchain
951Print the list of IRQ handlers.
952.It Ic panic
953Print the current "panic" string.
954.It Ic frame
955Given a trap frame address, print out the trap frame.
956.El
957.Ss MIPS
958.Bl -tag -width "intrchain" -compact
959.It Ic kvtop
960Print the physical address for a given kernel virtual address.
961.It Ic tlb
962Print out the Translation Lookaside Buffer (TLB).
963Only works in
964.Nx
965kernels compiled with
966.Dv DEBUG
967option.
968.El
969.Ss SH3
970.Bl -tag -width "intrchain" -compact
971.It Ic tlb
972Print TLB entries
973.It Ic cache
974Print cache entries
975.It Ic frame
976Print switch frame and trap frames.
977.It Ic stack
978Print kernel stack usage.
979Only works in
980.Nx
981kernels compiled with the
982.Dv KSTACK_DEBUG
983option.
984.El
985.Ss SPARC
986.Bl -tag -width "intrchain" -compact
987.It Ic prom
988Exit to the Sun PROM monitor.
989.El
990.Ss SPARC64
991.Bl -tag -width "intrchain" -compact
992.It Ic buf
993Print buffer information.
994.It Ic ctx
995Print process context information.
996.It Ic dtlb
997Print data translation look-aside buffer context information.
998.It Ic dtsb
999Display data translation storage buffer information.
1000.It Ic kmap
1001Display information about the listed mapping in the kernel pmap.
1002Use the
1003.Dq f
1004modifier to get a full listing.
1005.It Ic pcb
1006Display information about the
1007.Dq struct pcb
1008listed.
1009.It Ic pctx
1010Attempt to change process context.
1011.It Ic page
1012Display the pointer to the
1013.Dq struct vm_page
1014for this physical address.
1015.It Ic phys
1016Display physical memory.
1017.It Ic pmap
1018Display the pmap.
1019Use the
1020.Dq f
1021modifier to get a fuller listing.
1022.It Ic proc
1023Display some information about the process pointed to, or curproc.
1024.It Ic prom
1025Enter the OFW PROM.
1026.It Ic pv
1027Display the
1028.Dq struct pv_entry
1029pointed to.
1030.It Ic stack
1031Dump the window stack.
1032Use the
1033.Dq u
1034modifier to get userland information.
1035.It Ic tf
1036Display full trap frame state.
1037This is most useful for inclusion with bug reports.
1038.It Ic ts
1039Display trap state.
1040.It Ic traptrace
1041Display or set trap trace information.
1042Use the
1043.Dq r
1044and
1045.Dq f
1046modifiers to get reversed and full information, respectively.
1047.It Ic uvmdump
1048Dumps the UVM histories.
1049.It Ic watch
1050Set or clear a physical or virtual hardware watchpoint.
1051Pass the address to be watched, or
1052.Dq 0
1053to clear the watchpoint.
1054Append
1055.Dq p
1056to the watch point to use the physical watchpoint registers.
1057.It Ic window
1058Print register window information about given address.
1059.El
1060.Ss SUN3 and SUN3X
1061.Bl -tag -width "intrchain" -compact
1062.It Ic abort
1063Drop into monitor via abort (allows continue).
1064.It Ic halt
1065Exit to Sun PROM monitor as in
1066.Xr halt 8 .
1067.It Ic reboot
1068Reboot the machine as in
1069.Xr reboot 8 .
1070.It Ic pgmap
1071Given an address, print the address, segment map, page map, and
1072Page Table Entry (PTE).
1073.El
1074.Sh VARIABLES
1075.Nm
1076accesses registers and variables as
1077.Cm $ Ns Ar name .
1078Register names are as per the
1079.Ic "show registers"
1080command.
1081Some variables are suffixed with numbers, and may have a modifier
1082following a colon immediately after the variable name.
1083For example, register variables may have a
1084.Sq u
1085modifier to indicate user register
1086(e.g.,
1087.Li "$eax:u" ) .
1088.Pp
1089Built-in variables currently supported are:
1090.Bl -tag -offset indent -width "maxwidth" -compact
1091.It Va lines
1092The number of lines.
1093This is used by the
1094.Ic more
1095feature.
1096.It Va maxoff
1097Addresses are printed as
1098.Li 'symbol'+offset
1099unless
1100.Li offset
1101is greater than
1102.Va maxoff .
1103.It Va maxwidth
1104The width of the displayed line.
1105.It Va onpanic
1106If non-zero (the default),
1107.Nm
1108will be invoked when the kernel panics.
1109If the kernel configuration option
1110.D1 Cd options DDB_ONPANIC=0
1111is used,
1112.Va onpanic
1113will be initialized to off.
1114.It Va fromconsole
1115If non-zero (the default),
1116the kernel allows to enter
1117.Nm
1118from the console (by break signal or special key sequence).
1119If the kernel configuration option
1120.D1 Cd options DDB_FROMCONSOLE=0
1121is used,
1122.Va fromconsole
1123will be initialized to off.
1124.It Va radix
1125Input and output radix.
1126.It Va tabstops
1127Tab stop width.
1128.It Va tee_msgbuf
1129If explictly set to non zero (zero is the default) all
1130.Nm
1131output will not only be displayed on screen but
1132also be fed to the msgbuf.
1133The default of the variable can be set using the kernel configuration option
1134.D1 Cd options DDB_TEE_MSGBUF=1
1135wich will initialise
1136.Va tee_msgbuf
1137to be 1.
1138This option is especially handy for poor souls
1139who don't have a serial console but want to recall
1140.Nm
1141output from a crash investigation.
1142This option is more generic than the /l command modifier possible for
1143selected commands as discussed above to log the output.
1144Mixing both /l
1145and this setting can give double loggings.
1146.\" .It Va work Ns Sy xx
1147.\" Temporary work variable.
1148.\" .Sq Sy xx
1149.\" is between 0 and 31.
1150.El
1151.Pp
1152All built-in variables are accessible via
1153.Xr sysctl 3 .
1154.Sh EXPRESSIONS
1155Almost all expression operators in C are supported, except
1156.Sq \&~ ,
1157.Sq \&^ ,
1158and unary
1159.Sq \&\*[Am] .
1160Special rules in
1161.Nm
1162are:
1163.Bl -tag -offset indent -width "identifier"
1164.It Ar identifier
1165name of a symbol.
1166It is translated to the address (or value) of it.
1167.Sq \&.
1168and
1169.Sq \&:
1170can be used in the identifier.
1171If supported by an object format dependent routine,
1172.Sm off
1173.Xo
1174.Oo Ar filename : Oc
1175.Ar function
1176.Oo : Ar "line number" Oc ,
1177.Xc
1178.Xo
1179.Oo Ar filename : Oc
1180.Ar variable ,
1181.Xc
1182and
1183.Xo
1184.Ar filename
1185.Oo : Ar "line number" Oc ,
1186.Xc
1187.Sm on
1188can be accepted as a symbol.
1189The symbol may be prefixed with
1190.Ar symbol_table_name : :
1191(e.g.,
1192.Li emulator::mach_msg_trap )
1193to specify other than kernel symbols.
1194.It Ar number
1195number.
1196Radix is determined by the first two characters:
1197.Sq 0x
1198- hex,
1199.Sq 0o
1200- octal,
1201.Sq 0t
1202- decimal,
1203otherwise follow current radix.
1204.It Cm .
1205.Ar dot
1206.It Cm +
1207.Ar next
1208.It Cm ..
1209address of the start of the last line examined.
1210Unlike
1211.Ar dot
1212or
1213.Ar next ,
1214this is only changed by the
1215.Ic examine
1216or
1217.Ic write
1218commands.
1219.It Cm \&"
1220last address explicitly specified.
1221.It Cm $ Ns Ar name
1222register name or variable.
1223It is translated to the value of it.
1224It may be followed by a
1225.Sq \&:
1226and modifiers as described above.
1227.It Cm a
1228multiple of right-hand side.
1229.It Cm * Ns Ar expr
1230expression indirection.
1231It may be followed by a
1232.Sq \&:
1233and modifiers as described above.
1234.El
1235.Sh SEE ALSO
1236.Xr options 4 ,
1237.Xr reboot 2 ,
1238.Xr reboot 8 ,
1239.Xr sysctl 8 ,
1240.Xr cnmagic 9
1241.Sh HISTORY
1242The
1243.Nm
1244kernel debugger was written as part of the MACH project at
1245Carnegie-Mellon University.
1246