xref: /netbsd-src/share/man/man4/ddb.4 (revision 63aea4bd5b445e491ff0389fe27ec78b3099dba3)
1.\"	$NetBSD: ddb.4,v 1.158 2015/11/13 09:51:16 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 November 13, 2015
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 hpcarm
123\*[Lt]Ctrl\*[Gt]-\*[Lt]Alt\*[Gt]-\*[Lt]Esc\*[Gt]
124.It hpcmips
125\*[Lt]Ctrl\*[Gt]-\*[Lt]Alt\*[Gt]-\*[Lt]Esc\*[Gt]
126.It hpcsh
127\*[Lt]Ctrl\*[Gt]-\*[Lt]Alt\*[Gt]-\*[Lt]Esc\*[Gt]
128.It hppa
129\*[Lt]Ctrl\*[Gt]-\*[Lt]Alt\*[Gt]-\*[Lt]Esc\*[Gt] on PC style keyboards.
130.It ""
131+++++
132(five plus signs) on PDC console
133.It ""
134\*[Lt]Break\*[Gt] on serial console.
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 sandpoint
153\*[Lt]Break\*[Gt] on serial console.
154.It sparc
155\*[Lt]L1\*[Gt]-A, or \*[Lt]Stop\*[Gt]-A on a
156.Tn Sun
157keyboard.
158.It ""
159\*[Lt]Break\*[Gt] on serial console.
160.It sparc64
161\*[Lt]L1\*[Gt]-A, or \*[Lt]Stop\*[Gt]-A on a
162.Tn Sun
163keyboard.
164.It ""
165\*[Lt]Break\*[Gt] on serial console.
166.It sun3
167\*[Lt]L1\*[Gt]-A, or \*[Lt]Stop\*[Gt]-A on a
168.Tn Sun
169keyboard.
170.It ""
171\*[Lt]Break\*[Gt] on serial console.
172.It vax
173\*[Lt]Esc\*[Gt]-\*[Lt]Shift\*[Gt]-D on serial console.
174.It x68k
175Interrupt switch on the body.
176.It xen dom0
177\*[Lt]Ctrl\*[Gt]-\*[Lt]Alt\*[Gt]-\*[Lt]Esc\*[Gt] on PC style keyboards.
178.It ""
179+++++
180(five plus signs) on serial console.
181.It xen domU
182+++++
183(five plus signs) on serial console.
184.It zaurus
185\*[Lt]Ctrl\*[Gt]-\*[Lt]Alt\*[Gt]-\*[Lt]Esc\*[Gt]
186.El
187.Pp
188The key sequence to activate
189.Nm
190can be changed by modifying
191.Dq hw.cnmagic
192with
193.Xr sysctl 8 .
194If the console is not dedicated to
195.Nm
196the sequence should not be easily typed by accident.
197In addition,
198.Nm
199may be explicitly activated by the debugging code in the kernel
200if
201.Cm DDB
202is configured.
203.Pp
204Commands can be automatically run when
205.Nm
206is entered by using
207.Cd options DDB_COMMANDONENTER
208or by setting
209.Ar ddb.commandonenter
210with
211.Xr sysctl 8 .
212Multiple commands can be separated by a semi-colon.
213.Sh COMMAND SYNTAX
214The general command syntax is:
215.Bd -ragged -offset indent
216.Ic command Ns Op Cm / Ns Ar modifier
217.Ar address
218.Op Cm , Ns Ar count
219.Ed
220.Pp
221The current memory location being edited is referred to as
222.Ar dot ,
223and the next location is
224.Ar next .
225They are displayed as hexadecimal numbers.
226.Pp
227Commands that examine and/or modify memory update
228.Ar dot
229to the address of the last line examined or the last location
230modified, and set
231.Ar next
232to the next location to be examined or modified.
233Other commands don't change
234.Ar dot ,
235and set
236.Ar next
237to be the same as
238.Ar dot .
239.Pp
240A blank line repeats the previous command from the address
241.Ar next
242with the previous
243.Cm count
244and no modifiers.
245Specifying
246.Cm address
247sets
248.Em dot
249to the address.
250If
251.Cm address
252is omitted,
253.Em dot
254is used.
255A missing
256.Cm count
257is taken to be 1 for printing commands, and infinity for stack traces.
258.Pp
259The syntax:
260.Bd -ragged -offset indent
261.Cm , Ns Ar count
262.Ed
263.Pp
264repeats the previous command, just as a blank line does, but with
265the specified
266.Cm count .
267.Pp
268.Nm
269has a
270.Xr more 1 Ns -like
271functionality; if a number of lines in a command's output exceeds the number
272defined in the
273.Va lines
274variable, then
275.Nm
276displays
277.Dq "--db more--"
278and waits for a response, which may be one of:
279.Bl -tag -offset indent -width "\*[Lt]return\*[Gt]"
280.It Aq return
281one more line.
282.It Aq space
283one more page.
284.It Ic q
285abort the current command, and return to the command input mode.
286.El
287.Pp
288You can set
289.Va lines
290variable to zero to disable this feature.
291.Pp
292If
293.Nm
294history editing is enabled (by defining the
295.D1 Cd options DDB_HISTORY_SIZE=num
296kernel option), then a history of the last
297.Cm num
298commands is kept.
299The history can be manipulated with the following key sequences:
300.Bl -tag -offset indent -width "\*[Lt]Ctrl\*[Gt]-P"
301.It \*[Lt]Ctrl\*[Gt]-P
302retrieve previous command in history (if any).
303.It \*[Lt]Ctrl\*[Gt]-N
304retrieve next command in history (if any).
305.El
306.Sh COMMANDS
307.Nm
308supports the following commands:
309.Bl -tag -width 5n
310.It Ic \&! Ns Ar address Ns Oo Cm ( Ar expression Ns Oo Ar ,... Oc Ns Cm ) Oc
311A synonym for
312.Ic call .
313.It Ic break Ns Oo Cm /u Oc Ar address Ns Op Cm , Ns Ar count
314Set a breakpoint at
315.Ar address .
316If
317.Ar count
318is supplied, continues
319.Pq Ar count Ns \-1
320times before stopping at the breakpoint.
321If the breakpoint is set, a breakpoint number is printed with
322.Sq \&# .
323This number can be used to
324.Ic delete
325the breakpoint, or to add
326conditions to it.
327.Pp
328If
329.Cm /u
330is specified,
331set a breakpoint at a user-space address.
332Without
333.Cm /u ,
334.Ar address
335is considered to be in the kernel-space, and an address in the wrong
336space will be rejected, and an error message will be emitted.
337This modifier may only be used if it is supported by machine dependent
338routines.
339.Pp
340Warning: if a user text is shadowed by a normal user-space debugger,
341user-space breakpoints may not work correctly.
342Setting a breakpoint at the low-level code paths may also cause
343strange behavior.
344.It Ic bt Ns Oo Cm /ul Oc Oo Ar frame-address Oc Ns Oo Cm , Ns Ar count Oc
345A synonym for
346.Ic trace .
347.It Ic bt/t Ns Oo Cm /ul Oc Oo Ar pid Oc Ns Oo Cm , Ns Ar count Oc
348A synonym for
349.Ic trace/t .
350.It Ic bt/a Ns Oo Cm /ul Oc Oo Ar lwpaddr Oc Ns Oo Cm , Ns Ar count Oc
351A synonym for
352.Ic trace/a .
353.It Ic call Ar address Ns Oo Cm ( Ns Ar expression Ns Oo Ar ,... Oc Ns Cm ) Oc
354Call the function specified by
355.Ar address
356with the argument(s) listed in parentheses.
357Parentheses may be omitted if the function takes no arguments.
358The number of arguments is currently limited to 10.
359.It Ic continue Ns Op Cm /c
360Continue execution until a breakpoint or watchpoint.
361If
362.Cm /c
363is specified, count instructions while executing.
364Some machines (e.g., pmax) also count loads and stores.
365.Pp
366Warning: when counting, the debugger is really silently
367single-stepping.
368This means that single-stepping on low-level may cause strange
369behavior.
370.It Ic delete Ar "address" | Cm # Ns Ar number
371Delete a breakpoint.
372The target breakpoint may be specified by
373.Ar address ,
374as per
375.Ic break ,
376or by the breakpoint number returned by
377.Ic break
378if it's prefixed with
379.Sq Cm \&# .
380.It Ic dmesg Op Ar count
381Prints the contents of the kernel message buffer.
382The optional
383.Ar count
384argument will limit printing to at most the last
385.Ar count
386bytes of the message buffer.
387.It Ic dwatch Ar address
388Delete the watchpoint at
389.Ar address
390that was previously set with
391.Ic watch
392command.
393.It Ic examine Ns Oo Cm / Ns Ar modifier Oc Ar address Ns Op Cm , Ns Ar count
394Display the address locations according to the format in
395.Ar modifier .
396Multiple modifier formats display multiple locations.
397If
398.Ar modifier
399isn't specified, the modifier from the last use of
400.Ic examine
401is used.
402.Pp
403The valid format characters for
404.Ar modifier
405are:
406.Bl -tag -offset indent -width 2n -compact
407.It Cm b
408examine bytes (8 bits).
409.It Cm h
410examine half-words (16 bits).
411.It Cm l
412examine words (legacy
413.Dq long ,
41432 bits).
415.It Cm L
416examine long words (implementation dependent)
417.It Cm a
418print the location being examined.
419.It Cm A
420print the location with a line number if possible.
421.It Cm x
422display in unsigned hex.
423.It Cm z
424display in signed hex.
425.It Cm o
426display in unsigned octal.
427.It Cm d
428display in signed decimal.
429.It Cm u
430display in unsigned decimal.
431.It Cm r
432display in current radix, signed.
433.It Cm c
434display low 8 bits as a character.
435Non-printing characters as displayed as an octal escape code
436(e.g.,
437.Sq \e000 ) .
438.It Cm s
439display the NUL terminated string at the location.
440Non-printing characters are displayed as octal escapes.
441.It Cm m
442display in unsigned hex with a character dump at the end of each line.
443The location is displayed as hex at the beginning of each line.
444.It Cm i
445display as a machine instruction.
446.It Cm I
447display as a machine instruction, with possible alternative formats
448depending upon the machine:
449.Bl -tag -offset indent -width "sparc" -compact
450.It alpha
451print register operands
452.It m68k
453use Motorola syntax
454.It vax
455don't assume that each external label is a procedure entry mask
456.El
457.El
458.It Ic kill Ar pid Ns Op Cm , Ns Ar signal_number
459Send a signal to the process specified by the
460.Ar pid .
461Note that
462.Ar pid
463is interpreted using the current radix (see
464.Cm trace/t
465command for details).
466If
467.Ar signal_number
468isn't specified, the SIGTERM signal is sent.
469.It Ic match Ns Op Cm /p
470A synonym for
471.Ic next .
472.It Ic next Ns Op Cm /p
473Stop at the matching return instruction.
474If
475.Cm /p
476is specified, print the call nesting depth and the
477cumulative instruction count at each call or return.
478Otherwise, only print when the matching return is hit.
479.It Ic print Ns Oo Cm /axzodurc Oc Ar address Op Ar address ...
480Print addresses
481.Ar address
482according to the modifier character, as per
483.Ic examine .
484Valid modifiers are:
485.Cm /a ,
486.Cm /x ,
487.Cm /z ,
488.Cm /o ,
489.Cm /d ,
490.Cm /u ,
491.Cm /r ,
492and
493.Cm /c
494(as per
495.Ic examine ) .
496If no modifier is specified, the most recent one specified is used.
497.Ar address
498may be a string, and is printed
499.Dq as-is .
500For example:
501.Bd -literal -offset indent
502print/x "eax = " $eax "\enecx = " $ecx "\en"
503.Ed
504.Pp
505will produce:
506.Bd -literal -offset indent
507eax = xxxxxx
508ecx = yyyyyy
509.Ed
510.It Ic ps Ns Oo Cm /a Oc Ns Oo Cm /n Oc Ns Oo Cm /w Oc Ns Oo Cm /l Oc
511A synonym for
512.Ic show all procs .
513.It Ic reboot Op Ar flags
514Reboot, using the optionally supplied boot
515.Ar flags ,
516which is a bitmask supporting the same values as for
517.Xr reboot 2 .
518Some of the more useful flags:
519.Bl -column "Value" "RB_POWERDOWN" "Description"
520.It Sy "Value" Ta Sy "Name" Ta Sy "Description"
521.It 0x1 Ta RB_ASKNAME Ta Ask for file name to reboot from
522.It 0x2 Ta RB_SINGLE Ta Reboot to single user mode
523.It 0x4 Ta RB_NOSYNC Ta Don't sync before reboot
524.It 0x8 Ta RB_HALT Ta Halt instead of reboot
525.It 0x40 Ta RB_KDB Ta Boot into kernel debugger
526.It 0x100 Ta RB_DUMP Ta Dump unconditionally before reboot
527.It 0x808 Ta RB_POWERDOWN Ta Power off (or at least halt)
528.El
529.Pp
530Note: Limitations of the command line interface preclude
531specification of a boot string.
532.It Ic search Ns Oo Cm /bhl Oc Ar address Ar value \
533Oo Ar mask Oc Oo Cm , Ns Ar count Oc
534Search memory from
535.Ar address
536for
537.Ar value .
538The unit size is specified with a modifier character, as per
539.Ic examine .
540Valid modifiers are:
541.Cm /b ,
542.Cm /h ,
543and
544.Cm /l .
545If no modifier is specified,
546.Cm /l
547is used.
548.Pp
549This command might fail in interesting ways if it doesn't find
550.Ar value .
551This is because
552.Nm
553doesn't always recover from touching bad memory.
554The optional
555.Ar count
556limits the search.
557.It Ic set Cm $ Ns Ar variable Oo Cm = Oc Ar expression
558Set the named variable or register to the value of
559.Ar expression .
560Valid variable names are described in
561.Sx VARIABLES .
562.It Ic show all callout
563Display information about callouts in the system.
564See
565.Xr callout 9
566for more information on callouts.
567.It Ic show all pages
568Display basic information about all physical pages managed by the VM system.
569For more detailed information about a single page, use
570.Ic show page .
571.It Ic show all pools Ns Op Cm /clp
572Display all pool information.
573Modifiers are the same as
574.Ic show pool .
575.It Ic "show\ all\ procs" Ns Oo Cm /a Oc Ns Oo Cm /n Oc Ns Oo Cm /w Oc Ns \
576Oo Cm /l Oc
577Display all process information.
578Valid modifiers:
579.Bl -tag -width 3n
580.It Cm /n
581show process information in a
582.Xr ps 1
583style format.
584Information printed includes: process ID, parent process ID,
585process group, UID, process status, process flags, number of LWPs,
586command name, and process wait channel message.
587.It Cm /a
588show each process ID, command name, kernel virtual addresses of
589each process' proc structure, u-area, and vmspace structure.
590The vmspace address is also the address of the process'
591vm_map structure, and can be used in the
592.Ic show map
593command.
594.It Cm /w
595show each LWP ID, process ID, command name, system call emulation,
596priority, wait channel message and wait channel address.
597LWPs currently running on a CPU are marked with the '\&>' sign.
598.It Cm /l
599show each LWP ID, process ID, process status, CPU ID the LWP runs on,
600process flags, kernel virtual address of LWP structure,
601LWP name and wait channel message.
602LWPs currently running on a CPU are marked with the '\&>' sign.
603This is the default.
604.El
605.It Ic show arptab
606Dump the entire
607.Dv AF_INET
608routing table.
609This command is available only on systems which support inet and ARP.
610.It Ic show breaks
611Display all breakpoints.
612.It Ic show buf Ns Oo Cm /f Oc Ar address
613Print the struct buf at
614.Ar address .
615The
616.Cm /f
617does nothing at this time.
618.It Ic show event Ns Oo Cm /f Oc Ns Oo Cm /i Oc Ns Oo Cm /m Oc Ns \
619Oo Cm /t Oc
620Print all the non-zero
621.Xr evcnt 9
622event counters.
623Valid modifiers:
624.Bl -tag -width 3n
625.It Cm /f
626event counters with a count of zero are printed as well.
627.It Cm /i
628interrupted counters will be displayed.
629.It Cm /m
630misc counters will be displayed.
631.It Cm /t
632trap counters will be displayed.
633.El
634.Pp
635If none of
636.Cm /i ,
637.Cm /m
638or
639.Cm /t
640are specified, all are shown.
641You can combine any of these.
642For example, the modifier
643.Cm /itf
644will select both interrupt and trap events, including those that are non-zero.
645.It Ic show files Ar address
646Display information about the vnodes of the files that are currently
647open by the process associated with the proc structure at
648.Ar address .
649This address can be found using the
650.Ic show all procs /a
651command.
652If the kernel is compiled with
653.Cd options LOCKDEBUG
654then details about the locking of the underlying uvm object will also
655be displayed.
656.It Ic show lock Ar address
657Display information about a lock at
658.Ar address .
659This command is useful only if a kernel is compiled with
660.Cd options LOCKDEBUG .
661.It Ic show map Ns Oo Cm /f Oc Ar address
662Print the vm_map at
663.Ar address .
664If
665.Cm /f
666is specified, the complete map is printed.
667.It Ic show mount Ns Oo Cm /f Oc Ar address
668Print the mount structure at
669.Ar address .
670If
671.Cm /f
672is specified, the complete vnode list is printed.
673.It Ic show mbuf Ns Oo Cm /c Oc Ar address
674Print the mbuf structure at
675.Ar address .
676If
677.Cm /c
678is specified, the mbufs in the chain are followed.
679.It Ic show ncache Ar address
680Dump the namecache list associated with vnode at
681.Ar address .
682.It Ic show object Ns Oo Cm /f Oc Ar address
683Print the vm_object at
684.Ar address .
685If
686.Cm /f
687is specified, the complete object is printed.
688.It Ic show page Ns Oo Cm /f Oc Ar address
689Print the vm_page at
690.Ar address .
691If
692.Cm /f
693is specified, the complete page is printed.
694.It Ic show panic
695Print the current "panic" string.
696.It Ic show pool Ns Oo Cm /clp Oc Ar address
697Print the pool at
698.Ar address .
699Valid modifiers:
700.Bl -tag -width 4n -compact
701.It Cm /c
702Print the cachelist and its statistics for this pool.
703.It Cm /l
704Print the log entries for this pool.
705.It Cm /p
706Print the pagelist for this pool.
707.El
708.It Ic show proc Ns Oo Cm /ap Oc Ar address | pid
709Show information about a process and its LWPs.
710LWPs currently running on a CPU are marked with the '\&>' sign.
711.Bl -tag -width 4n -compact
712.It Cm /a
713The argument passed is the kernel virtual address
714of LWP structure.
715.It Cm /p
716The argument passed is a PID.
717Note that
718.Ar pid
719is interpreted using the current radix (see
720.Cm trace/t
721command for details).
722This is the default.
723.El
724.It Ic show registers Ns Op Cm /u
725Display the register set.
726If
727.Cm /u
728is specified, display user registers instead of kernel registers
729or the currently save one.
730.Pp
731Warning: support for
732.Cm /u
733is machine dependent.
734If not supported, incorrect information will be displayed.
735.It Ic show sched_qs
736Print the state of the scheduler's run queues.
737For each run queue that has an LWP, the run queue index and the list
738of LWPs will be shown.
739If the run queue has LWPs, but the sched_whichqs bit is not set for that
740queue, the queue index will be prefixed with a
741.Sq \&! .
742.It Ic show uvmexp
743Print a selection of UVM counters and statistics.
744.It Ic show kernhist
745Dumps the kernel histories.
746This command is available only if a kernel is compiled with
747.Cd options KERNHIST
748or
749.Cd options UVMHIST .
750.It Ic show vnode Ns Oo Cm /f Oc Ar address
751Print the vnode at
752.Ar address .
753If
754.Cm /f
755is specified, the complete vnode is printed.
756.It Ic show watches
757Display all watchpoints.
758.It Ic sifting Ns Oo Cm /F Oc Ar string
759Search the symbol tables for all symbols of which
760.Ar string
761is a substring, and display them.
762If
763.Cm /F
764is specified, a character is displayed immediately after each symbol
765name indicating the type of symbol.
766.Pp
767For
768.Xr a.out 5 Ns -format
769symbol tables,
770absolute symbols display
771.Sy @ ,
772text segment symbols display
773.Sy * ,
774data segment symbols display
775.Sy + ,
776.Tn BSS
777segment symbols display
778.Sy - ,
779and filename symbols display
780.Sy / .
781For
782.Tn ELF Ns -format
783symbol tables,
784object symbols display
785.Sy + ,
786function symbols display
787.Sy * ,
788section symbols display
789.Sy \*[Am] ,
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-\*[Gt]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 work Ns Sy xx
1285.\" Temporary work variable.
1286.\" .Sq Sy xx
1287.\" is between 0 and 31.
1288.El
1289.Pp
1290All built-in variables are accessible via
1291.Xr sysctl 3 .
1292.Sh EXPRESSIONS
1293Almost all expression operators in C are supported, except
1294.Sq \&~ ,
1295.Sq \&^ ,
1296and unary
1297.Sq \&\*[Am] .
1298Special rules in
1299.Nm
1300are:
1301.Bl -tag -offset indent -width "identifier"
1302.It Ar identifier
1303name of a symbol.
1304It is translated to the address (or value) of it.
1305.Sq \&.
1306and
1307.Sq \&:
1308can be used in the identifier.
1309If supported by an object format dependent routine,
1310.Sm off
1311.Xo
1312.Oo Ar filename : Oc
1313.Ar function
1314.Oo : Ar line\ number Oc ,
1315.Xc
1316.Sm on
1317.Sm off
1318.Xo
1319.Oo Ar filename : Oc
1320.Ar variable ,
1321.Xc
1322.Sm on
1323and
1324.Sm off
1325.Xo
1326.Ar filename
1327.Oo : Ar "line number" Oc ,
1328.Xc
1329.Sm on
1330can be accepted as a symbol.
1331The symbol may be prefixed with
1332.Ar symbol_table_name\^ : :
1333(e.g.,
1334.Li emulator::mach_msg_trap )
1335to specify other than kernel symbols.
1336.It Ar number
1337number.
1338Radix is determined by the first two characters:
1339.Sq 0x
1340- hex,
1341.Sq 0o
1342- octal,
1343.Sq 0t
1344- decimal,
1345otherwise follow current radix.
1346.It Cm .
1347.Ar dot
1348.It Cm +
1349.Ar next
1350.It Cm ..
1351address of the start of the last line examined.
1352Unlike
1353.Ar dot
1354or
1355.Ar next ,
1356this is only changed by the
1357.Ic examine
1358or
1359.Ic write
1360commands.
1361.It Cm \&" \"" XXX: emacs highlighting
1362last address explicitly specified.
1363.It Cm $ Ns Ar name
1364register name or variable.
1365It is translated to the value of it.
1366It may be followed by a
1367.Sq \&:
1368and modifiers as described above.
1369.It Cm #
1370a binary operator which rounds up the left hand side to the next
1371multiple of right hand side.
1372.It Cm * Ns Ar expr
1373expression indirection.
1374It may be followed by a
1375.Sq \&:
1376and modifiers as described above.
1377.El
1378.Sh SEE ALSO
1379.Xr reboot 2 ,
1380.Xr options 4 ,
1381.Xr crash 8 ,
1382.Xr reboot 8 ,
1383.Xr sysctl 8 ,
1384.Xr cnmagic 9
1385.Sh HISTORY
1386The
1387.Nm
1388kernel debugger was written as part of the MACH project at
1389Carnegie-Mellon University.
1390