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