xref: /netbsd-src/share/man/man4/ddb.4 (revision 87d689fb734c654d2486f87f7be32f1b53ecdbec)
1.\"	$NetBSD: ddb.4,v 1.170 2017/12/28 23:16:42 wiz 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 December 28, 2017
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 Cm / Ns Ar modifier
209.Ar address
210.Op Cm , 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 Cm ( Ar expression Ns Oo Ar ,... Oc Ns Cm ) Oc
303A synonym for
304.Ic call .
305.It Ic break Ns Oo Cm /u Oc Ar address Ns Op Cm , 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 Cm , 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 Cm , 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 Cm , Ns Ar count Oc
343A synonym for
344.Ic trace/a .
345.It Ic call Ar address Ns Oo Cm ( Ns Ar expression Ns Oo Ar ,... Oc Ns Cm ) 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 Cm , 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 Cm , 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 Cm , 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 pages
560Display basic information about all physical pages managed by the VM system.
561For more detailed information about a single page, use
562.Ic show page .
563.It Ic show all pools Ns Op Cm /clp
564Display all pool information.
565Modifiers are the same as
566.Ic show pool .
567.It Ic "show\ all\ procs" Ns Oo Cm /a Oc Ns Oo Cm /n Oc Ns Oo Cm /w Oc Ns \
568Oo Cm /l Oc
569Display all process information.
570Valid modifiers:
571.Bl -tag -width 3n
572.It Cm /n
573show process information in a
574.Xr ps 1
575style format.
576Information printed includes: process ID, parent process ID,
577process group, UID, process status, process flags, number of LWPs,
578command name, and process wait channel message.
579.It Cm /a
580show each process ID, command name, kernel virtual addresses of
581each process' proc structure, u-area, and vmspace structure.
582The vmspace address is also the address of the process'
583vm_map structure, and can be used in the
584.Ic show map
585command.
586.It Cm /w
587show each LWP ID, process ID, command name, system call emulation,
588priority, wait channel message and wait channel address.
589LWPs currently running on a CPU are marked with the '\&>' sign.
590.It Cm /l
591show each LWP ID, process ID, process status, CPU ID the LWP runs on,
592process flags, kernel virtual address of LWP structure,
593LWP name and wait channel message.
594LWPs currently running on a CPU are marked with the '\&>' sign.
595This is the default.
596.El
597.It Ic show routes
598Dump the entire
599.Dv AF_INET
600routing table.
601This command is available only on systems which support inet.
602.It Ic show breaks
603Display all breakpoints.
604.It Ic show buf Ns Oo Cm /f Oc Ar address
605Print the struct buf at
606.Ar address .
607The
608.Cm /f
609does nothing at this time.
610.It Ic show event Ns Oo Cm /f Oc Ns Oo Cm /i Oc Ns Oo Cm /m Oc Ns \
611Oo Cm /t Oc
612Print all the non-zero
613.Xr evcnt 9
614event counters.
615Valid modifiers:
616.Bl -tag -width 3n
617.It Cm /f
618event counters with a count of zero are printed as well.
619.It Cm /i
620interrupted counters will be displayed.
621.It Cm /m
622misc counters will be displayed.
623.It Cm /t
624trap counters will be displayed.
625.El
626.Pp
627If none of
628.Cm /i ,
629.Cm /m
630or
631.Cm /t
632are specified, all are shown.
633You can combine any of these.
634For example, the modifier
635.Cm /itf
636will select both interrupt and trap events, including those that are non-zero.
637.It Ic show files Ar address
638Display information about the vnodes of the files that are currently
639open by the process associated with the proc structure at
640.Ar address .
641This address can be found using the
642.Ic show all procs /a
643command.
644If the kernel is compiled with
645.Cd options LOCKDEBUG
646then details about the locking of the underlying uvm object will also
647be displayed.
648.It Ic show lock Ar address
649Display information about a lock at
650.Ar address .
651This command is useful only if a kernel is compiled with
652.Cd options LOCKDEBUG .
653.It Ic show map Ns Oo Cm /f Oc Ar address
654Print the vm_map at
655.Ar address .
656If
657.Cm /f
658is specified, the complete map is printed.
659.It Ic show mount Ns Oo Cm /f Oc Ar address
660Print the mount structure at
661.Ar address .
662If
663.Cm /f
664is specified, the complete vnode list is printed.
665.It Ic show mbuf Ns Oo Cm /c Oc Ar address
666Print the mbuf structure at
667.Ar address .
668If
669.Cm /c
670is specified, the mbufs in the chain are followed.
671.It Ic show ncache Ar address
672Dump the namecache list associated with vnode at
673.Ar address .
674.It Ic show object Ns Oo Cm /f Oc Ar address
675Print the vm_object at
676.Ar address .
677If
678.Cm /f
679is specified, the complete object is printed.
680.It Ic show page Ns Oo Cm /f Oc Ar address
681Print the vm_page at
682.Ar address .
683If
684.Cm /f
685is specified, the complete page is printed.
686.It Ic show panic
687Print the current "panic" string.
688.It Ic show pool Ns Oo Cm /clp Oc Ar address
689Print the pool at
690.Ar address .
691Valid modifiers:
692.Bl -tag -width 4n -compact
693.It Cm /c
694Print the cachelist and its statistics for this pool.
695.It Cm /l
696Print the log entries for this pool.
697.It Cm /p
698Print the pagelist for this pool.
699.El
700.It Ic show proc Ns Oo Cm /ap Oc Ar address | pid
701Show information about a process and its LWPs.
702LWPs currently running on a CPU are marked with the '\&>' sign.
703.Bl -tag -width 4n -compact
704.It Cm /a
705The argument passed is the kernel virtual address
706of LWP structure.
707.It Cm /p
708The argument passed is a PID.
709Note that
710.Ar pid
711is interpreted using the current radix (see
712.Cm trace/t
713command for details).
714This is the default.
715.El
716.It Ic show registers Ns Op Cm /u
717Display the register set.
718If
719.Cm /u
720is specified, display user registers instead of kernel registers
721or the currently save one.
722.Pp
723Warning: support for
724.Cm /u
725is machine dependent.
726If not supported, incorrect information will be displayed.
727.It Ic show sched_qs
728Print the state of the scheduler's run queues.
729For each run queue that has an LWP, the run queue index and the list
730of LWPs will be shown.
731If the run queue has LWPs, but the sched_whichqs bit is not set for that
732queue, the queue index will be prefixed with a
733.Sq \&! .
734.It Ic show uvmexp
735Print a selection of UVM counters and statistics.
736.It Ic show kernhist Oo Ar addr Oc
737Dumps all the kernel histories if no address is specified, or the history
738at the address.
739This command is available only if a kernel is compiled with one or more
740of the kernel history options
741.Cd KERNHIST ,
742.Cd SYSCALL_DEBUG ,
743.Cd USB_DEBUG ,
744.Cd BIOHIST ,
745or
746.Cd UVMHIST .
747.It Ic show vnode Ns Oo Cm /f Oc Ar address
748Print the vnode at
749.Ar address .
750If
751.Cm /f
752is specified, the complete vnode is printed.
753.It Ic show vnode_lock Ns Oo Cm /f Oc Ar address
754Print the vnode which has its lock at
755.Ar address .
756If
757.Cm /f
758is specified, the complete vnode is printed.
759.It Ic show watches
760Display all watchpoints.
761.It Ic sifting Ns Oo Cm /F Oc Ar string
762Search the symbol tables for all symbols of which
763.Ar string
764is a substring, and display them.
765If
766.Cm /F
767is specified, a character is displayed immediately after each symbol
768name indicating the type of symbol.
769.Pp
770For
771.Xr a.out 5 Ns -format
772symbol tables,
773absolute symbols display
774.Sy @ ,
775text segment symbols display
776.Sy * ,
777data segment symbols display
778.Sy + ,
779BSS segment symbols display
780.Sy - ,
781and filename symbols display
782.Sy / .
783For ELF-format symbol tables,
784object symbols display
785.Sy + ,
786function symbols display
787.Sy * ,
788section symbols display
789.Sy & ,
790and file symbols display
791.Sy / .
792.Pp
793To sift for a string beginning with a number, escape the first
794character with a backslash as:
795.Bd -literal -offset indent
796sifting \\386
797.Ed
798.It Ic step Ns Oo Cm /p Oc Op Cm , Ns Ar count
799Single-step
800.Ar count
801times.
802If
803.Cm /p
804is specified, print each instruction at each step.
805Otherwise, only print the last instruction.
806.Pp
807Warning: depending on the machine type, it may not be possible
808to single-step through some low-level code paths or user-space
809code.
810On machines with software-emulated single-stepping (e.g., pmax),
811stepping through code executed by interrupt handlers will probably
812do the wrong thing.
813.It Ic sync
814Sync the disks, force a crash dump, and then reboot.
815.It Ic trace Ns Oo Cm /u Ns Oo Cm l Oc Oc Oo Ar frame-address Oc Ns \
816Oo Cm , Ns Ar count Oc
817Stack trace from
818.Ar frame-address .
819If
820.Cm /u
821is specified, trace user-space, otherwise trace kernel-space.
822.Ar count
823is the number of frames to be traced.
824If
825.Ar count
826is omitted, all frames are printed.
827If
828.Cm /l
829is specified, the trace is printed and also stored in the kernel
830message buffer.
831.Pp
832Warning: user-space stack trace is valid only if the machine dependent
833code supports it.
834.It Ic trace/t Ns Oo Cm l Oc Oo Ar pid Oc Ns Oo Cm , Ns Ar count Oc
835Stack trace by
836.Dq thread
837(process, on
838.Nx )
839rather than by stack frame address.
840Note that
841.Ar pid
842is interpreted using the current radix, whilst
843.Ic ps
844displays pids in decimal; prefix
845.Ar pid
846with
847.Sq 0t
848to force it to be interpreted as decimal (see
849.Sx VARIABLES
850section for radix).
851If
852.Cm /l
853is specified, the trace is printed and also stored in the kernel
854message buffer.
855.Pp
856Warning: trace by pid is valid only if the machine dependent code
857supports it.
858.It Ic trace/a Ns Oo Cm l Oc Oo Ar lwpaddr Oc Ns Oo Cm , Ns Ar count Oc
859Stack trace by light weight process (LWP) address
860rather than by stack frame address.
861If
862.Cm /l
863is specified, the trace is printed and also stored in the kernel
864message buffer.
865.Pp
866Warning: trace by LWP address is valid only if the machine dependent
867code supports it.
868.It Ic until Ns Op Cm /p
869Stop at the next call or return instruction.
870If
871.Cm /p
872is specified, print the call nesting depth and the
873cumulative instruction count at each call or return.
874Otherwise, only print when the matching return is hit.
875.It Ic watch Ar address Ns Oo Cm , Ns Ar size Oc
876Set a watchpoint for a region.
877Execution stops when an attempt to modify the region occurs.
878.Ar size
879defaults to 4.
880.Pp
881If you specify a wrong space address, the request is
882rejected with an error message.
883.Pp
884Warning: attempts to watch wired kernel memory may cause
885an unrecoverable error in some systems such as i386.
886Watchpoints on user addresses work the best.
887.It Ic whatis Ar address
888Describe what an address is.
889.It Ic write Ns Oo Cm /bhlBHL Oc Ar address Ar expression Oo Ar expression ... Oc
890Write the
891.Ar expression Ns s
892at succeeding locations.
893The unit size is specified with a modifier character, as per
894.Ic examine .
895Valid modifiers are:
896.Cm /b ,
897.Cm /h ,
898and
899.Cm /l .
900If no modifier is specified,
901.Cm /l
902is used.
903.Pp
904Specifying the modifiers in upper case,
905.Cm /B ,
906.Cm /H ,
907.Cm /L ,
908will prevent
909.Nm
910from reading the memory location first, which is useful for avoiding
911side effects when writing to I/O memory regions.
912.Pp
913Warning: since there is no delimiter between
914.Ar expression Ns s ,
915strange things may occur.
916It's best to enclose each
917.Ar expression
918in parentheses.
919.It Ic x Ns Oo Cm / Ns Ar modifier Oc Ar address Ns Op Cm , Ns Ar count
920A synonym for
921.Ic examine .
922.\" XXX - these commands aren't implemented; jhawk 19 May 2000
923.\" .It Ic xf
924.\" Examine forward.
925.\" .Ic xf
926.\" re-executes the most recent
927.\" .Ic execute
928.\" command with the same parameters except that
929.\" .Ar address
930.\" is set to
931.\" .Ar next .
932.\" .It Ic xb
933.\" Examine backward.
934.\" .Ic xb
935.\" re-executes the most recent
936.\" .Ic execute
937.\" command with the same parameters, except that
938.\" .Ar address
939.\" is set to the last start address minus its size.
940.El
941.Sh MACHINE-SPECIFIC COMMANDS
942The "glue" code that hooks
943.Nm
944into the
945.Nx
946kernel for any given port can also add machine specific commands
947to the
948.Nm
949command parser.
950All of these commands are preceded by the command word
951.Em machine
952to indicate that they are part of the machine-specific command
953set (e.g.
954.Ic machine reboot ) .
955Some of these commands are:
956.Ss ACORN26
957.Bl -tag -width "traptrace" -compact
958.It Ic bsw
959Writes one or two bytes to the IObus.
960Takes an address and a value.
961Use the
962.Dq b
963modifier to write a single byte and the
964.Dq h
965modifier to write two bytes.
966.It Ic frame
967Given a trap frame address, print out the trap frame.
968.It Ic irqstat
969Display the IRQ statistics
970.El
971.Ss ALPHA
972.Bl -tag -width "traptrace" -compact
973.It Ic cpu
974Switch to another cpu.
975.\" .It Ic halt
976.\" Call the PROM monitor to halt the CPU.
977.\" .It Ic reboot
978.\" Call the PROM monitor to reboot the CPU.
979.El
980.Ss AMD64
981.Bl -tag -width "traptrace" -compact
982.It Ic cpu
983Switch to another cpu.
984.El
985.Ss ARM32
986.Bl -tag -width "traptrace" -compact
987.It Ic frame
988Given a trap frame address, print out the trap frame.
989.El
990.Ss HPPA
991.Bl -tag -width "traptrace" -compact
992.It Ic frame
993Without an address the default trap frame is printed.
994Otherwise, the trap frame address can be given, or, when the
995.Dq l
996modifier is used, an LWP address.
997.El
998.Ss I386
999.Bl -tag -width "traptrace" -compact
1000.It Ic cpu
1001Switch to another cpu.
1002.El
1003.Ss IA64
1004.Bl -tag -width "traptrace" -compact
1005.It Ic vector
1006Without a vector, information about all 256 vectors is shown.
1007Otherwise, the given vector is shown.
1008.El
1009.Ss MIPS
1010.Bl -tag -width "traptrace" -compact
1011.It Ic cp0
1012Dump CP0 (coprocessor 0) register values.
1013.It Ic kvtop
1014Print the physical address for a given kernel virtual address.
1015.It Ic tlb
1016Print out the Translation Lookaside Buffer (TLB).
1017Only works in
1018.Nx
1019kernels compiled with
1020.Dv DEBUG
1021option.
1022.El
1023.Ss POWERPC 4xx
1024.Bl -tag -width "traptrace" -compact
1025.It Ic ctx
1026Print process MMU context information.
1027.It Ic pv
1028Print PA->VA mapping information.
1029.It Ic reset
1030Reset the system.
1031.It Ic tf
1032Display the contents of the trapframe.
1033.It Ic tlb
1034Display instruction translation storage buffer information.
1035.It Ic dcr
1036Set the DCR register.
1037Must be between 0x00 and 0x3ff.
1038.It Ic user
1039Display user memory.
1040Use the
1041.Dq i
1042modifier to get instruction decoding.
1043.El
1044.Ss POWERPC OEA
1045.Bl -tag -width "traptrace" -compact
1046.It Ic bat
1047Print BAT registers and translations.
1048.It Ic mmu
1049Print MMU registers.
1050.El
1051.Ss SH3
1052.Bl -tag -width "traptrace" -compact
1053.It Ic tlb
1054Print TLB entries.
1055.It Ic cache
1056Print cache entries.
1057.It Ic frame
1058Print switch frame and trap frames.
1059.It Ic stack
1060Print kernel stack usage.
1061Only works in
1062.Nx
1063kernels compiled with the
1064.Dv KSTACK_DEBUG
1065option.
1066.El
1067.Ss SPARC
1068.Bl -tag -width "traptrace" -compact
1069.It Ic cpu
1070Switch to another cpu.
1071.It Ic prom
1072Enter the Sun PROM monitor.
1073.It Ic proc
1074Display some information about the LWP pointed to, or curlwp.
1075.It Ic pcb
1076Display information about the
1077.Dq struct pcb
1078listed.
1079.It Ic page
1080Display the pointer to the
1081.Dq struct vm_page
1082for this physical address.
1083.El
1084.Ss SPARC64
1085.Bl -tag -width "traptrace" -compact
1086.It Ic ctx
1087Print process context information.
1088.It Ic cpu
1089Switch to another cpu.
1090.It Ic dtlb
1091Print data translation look-aside buffer context information.
1092.It Ic dtsb
1093Display data translation storage buffer information.
1094.It Ic kmap
1095Display information about the listed mapping in the kernel pmap.
1096Use the
1097.Dq f
1098modifier to get a full listing.
1099.It Ic extract
1100Extract the physical address for a given virtual address from the kernel pmap.
1101.It Ic fpstate
1102Dump the FPU state.
1103.It Ic itlb
1104Print instruction translation look-aside buffer context information.
1105.It Ic itsb
1106Display instruction translation storage buffer information.
1107.It Ic lwp
1108Display a struct lwp
1109.It Ic pcb
1110Display information about the
1111.Dq struct pcb
1112listed.
1113.It Ic pctx
1114Attempt to change process context.
1115.It Ic page
1116Display the pointer to the
1117.Dq struct vm_page
1118for this physical address.
1119.It Ic phys
1120Display physical memory.
1121.It Ic pmap
1122Display the pmap.
1123Use the
1124.Dq f
1125modifier to get a fuller listing.
1126.It Ic proc
1127Display some information about the process pointed to, or curproc.
1128.It Ic prom
1129Enter the OFW PROM.
1130.It Ic pv
1131Display the
1132.Dq struct pv_entry
1133pointed to.
1134.It Ic sir
1135Reset the machine and enter prom (do a Software Initiated Reset).
1136.It Ic stack
1137Dump the window stack.
1138Use the
1139.Dq u
1140modifier to get userland information.
1141.It Ic tf
1142Display full trap frame state.
1143This is most useful for inclusion with bug reports.
1144.It Ic ts
1145Display trap state.
1146.It Ic traptrace
1147Display or set trap trace information.
1148Use the
1149.Dq r
1150and
1151.Dq f
1152modifiers to get reversed and full information, respectively.
1153.It Ic watch
1154Set or clear a physical or virtual hardware watchpoint.
1155Pass the address to be watched, or
1156.Dq 0
1157(or omit the address) to clear the watchpoint.
1158Optional modifiers are
1159.Dq p
1160for physical address,
1161.Dq r
1162for trap on read access (default: trap on write access only),
1163.Dq b
1164for 8 bit width,
1165.Dq h
1166for 16 bit,
1167.Dq l
1168for 32 bit or
1169.Dq L
1170for 64 bit.
1171.It Ic window
1172Print register window information.
1173Argument is a stack frame number (0 is
1174top of stack, which is used when no index is given).
1175.El
1176.Ss SUN2, SUN3 and SUN3X
1177.Bl -tag -width "traptrace" -compact
1178.It Ic abort
1179Drop into monitor via abort (allows continue).
1180.It Ic halt
1181Exit to Sun PROM monitor as in
1182.Xr halt 8 .
1183.It Ic reboot
1184Reboot the machine as in
1185.Xr reboot 8 .
1186.It Ic pgmap
1187Given an address, print the address, segment map, page map, and
1188Page Table Entry (PTE).
1189.El
1190.Ss VAX
1191.Bl -tag -width "traptrace" -compact
1192.It Ic cpu
1193Switch to another cpu.
1194.El
1195.Sh VARIABLES
1196.Nm
1197accesses registers and variables as
1198.Cm $ Ns Ar name .
1199Register names are as per the
1200.Ic show registers
1201command.
1202Some variables are suffixed with numbers, and may have a modifier
1203following a colon immediately after the variable name.
1204For example, register variables may have a
1205.Sq u
1206modifier to indicate user register
1207(e.g.,
1208.Li "$eax:u" ) .
1209.Pp
1210Built-in variables currently supported are:
1211.Bl -tag -offset indent -width "maxwidth" -compact
1212.It Va lines
1213The number of lines.
1214This is used by the
1215.Ic more
1216feature.
1217When this variable is set to zero the
1218.Ic more
1219feature is disabled.
1220.It Va maxoff
1221Addresses are printed as
1222.Li 'symbol'+offset
1223unless
1224.Li offset
1225is greater than
1226.Va maxoff .
1227.It Va maxwidth
1228The width of the displayed line.
1229.Nm
1230wraps the current line by printing new line when
1231.Va maxwidth
1232column is reached.
1233When this variable is set to zero
1234.Nm
1235doesn't perform any wrapping.
1236.It Va onpanic
1237If greater than zero (the default is 1),
1238.Nm
1239will be invoked when the kernel panics.
1240If the kernel configuration option
1241.D1 Cd options DDB_ONPANIC=0
1242is used,
1243.Va onpanic
1244will be initialized to off, causing a stack trace to be printed and
1245the system to be rebooted instead of
1246.Nm
1247being entered.
1248Other useful settings are \-1, which suppresses the stack trace before
1249reboot, and 2, which causes a stack trace to be printed and
1250.Nm
1251to be entered.
1252.It Va fromconsole
1253If non-zero (the default),
1254the kernel allows to enter
1255.Nm
1256from the console (by break signal or special key sequence).
1257If the kernel configuration option
1258.D1 Cd options DDB_FROMCONSOLE=0
1259is used,
1260.Va fromconsole
1261will be initialized to off.
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