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