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