xref: /netbsd-src/share/man/man4/ddb.4 (revision 2d8e86c2f207da6fbbd50f11b6f33765ebdfa0e9)
1.\"	$NetBSD: ddb.4,v 1.185 2019/07/21 15:51:58 rin 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 July 21, 2019
60.Dt DDB 4
61.Os
62.Sh NAME
63.Nm ddb
64.Nd in-kernel debugger
65.Sh SYNOPSIS
66.Cd options DDB
67.Pp
68To enable history editing:
69.Cd options DDB_HISTORY_SIZE=integer
70.Pp
71To disable entering
72.\" XXX: hack; .Nm automatically introduces newline in SYNOPSIS
73.Ic ddb
74upon kernel panic:
75.Cd options DDB_ONPANIC=0
76.Pp
77To enable teeing all
78.\" XXX: hack; .Nm automatically introduces newline in SYNOPSIS
79.Ic ddb
80output to the kernel msgbuf:
81.Cd options DDB_TEE_MSGBUF=1
82.Pp
83To specify commands which will be executed on each entry to
84.Ic ddb :
85.Cd options DDB_COMMANDONENTER="trace;show registers"
86In this case, "trace" and then "show registers" will be executed automatically.
87.Pp
88To enable extended online help:
89.Cd options DDB_VERBOSE_HELP .
90.Sh DESCRIPTION
91.Nm
92is the in-kernel debugger.
93It may be entered at any time via a special key sequence, and
94optionally may be invoked when the kernel panics.
95.Sh ENTERING THE DEBUGGER
96Unless
97.Dv DDB_ONPANIC
98is set to 0,
99.Nm
100will be activated whenever the kernel would otherwise panic.
101.Pp
102.Nm
103may also be activated from the console.
104In general, sending a break on a serial console will activate
105.Nm .
106There are also key sequences for each port that will activate
107.Nm
108from the keyboard:
109.Bl -tag -offset indent -width "xen domU" -compact
110.It alpha
111<Ctrl>-<Alt>-<Esc> on PC style keyboards.
112.It amd64
113<Ctrl>-<Alt>-<Esc>
114.It ""
115<Break> on serial console.
116.It amiga
117<LAlt>-<LAmiga>-<F10>
118.It atari
119<Alt>-<LeftShift>-<F9>
120.It evbarm
121<Ctrl>-<Alt>-<Esc> on PC style keyboards.
122.It ""
123<Break> on serial console.
124.It ""
125Some models:
126+++++
127(five plus signs) on serial console.
128.It hp300
129<Shift>-<Reset>
130.It hpcarm
131<Ctrl>-<Alt>-<Esc>
132.It hpcmips
133<Ctrl>-<Alt>-<Esc>
134.It hpcsh
135<Ctrl>-<Alt>-<Esc>
136.It hppa
137<Ctrl>-<Alt>-<Esc> on PC style keyboards.
138.It ""
139+++++
140(five plus signs) on PDC console
141.It ""
142<Break> on serial console.
143.It i386
144<Ctrl>-<Alt>-<Esc>
145.It ""
146<Break> on serial console.
147.It mac68k
148<Command>-<Power>, or the Interrupt switch.
149.It macppc
150Some models:
151<Command>-<Option>-<Power>
152.It mvme68k
153Abort switch on CPU card.
154.It pmax
155<Do> on LK-201 rcons console.
156.It ""
157<Break> on serial console.
158.It sandpoint
159<Break> on serial console.
160.It sparc
161<L1>-A, or <Stop>-A on a Sun keyboard.
162.It ""
163<Break> on serial console.
164.It sparc64
165<L1>-A, or <Stop>-A on a Sun keyboard.
166.It ""
167<Break> on serial console.
168.It sun3
169<L1>-A, or <Stop>-A on a Sun keyboard.
170.It ""
171<Break> on serial console.
172.It vax
173<Esc>-<Shift>-D on serial console.
174.It x68k
175Interrupt switch on the body.
176.It xen dom0
177<Ctrl>-<Alt>-<Esc> 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<Ctrl>-<Alt>-<Esc>
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 / Ns Ar modifier
217.Ar address
218.Op , 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 "<return>"
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 "<Ctrl>-P"
301.It <Ctrl>-P
302retrieve previous command in history (if any).
303.It <Ctrl>-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 ( Ar expression Ns Oo Ar ,... Oc ) Oc
311A synonym for
312.Ic call .
313.It Ic break Ns Oo Cm /u Oc Ar address Ns Op , 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 , 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 , 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 , Ns Ar count Oc
351A synonym for
352.Ic trace/a .
353.It Ic call Ar address Ns Oo ( Ns Ar expression Ns Oo Ar ,... Oc ) 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 , 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 , 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 , 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 locks Ns Op Cm /t
568Display details information about all active locks.
569If
570.Cm /t
571is specified, stack traces of LWPs holding locks are also printed.
572This command is only useful if a kernel is compiled with
573.Cd options LOCKDEBUG .
574.It Ic show all pages
575Display basic information about all physical pages managed by the VM system.
576For more detailed information about a single page, use
577.Ic show page .
578.It Ic show all pools Ns Op Cm /clp
579Display all pool information.
580Modifiers are the same as
581.Ic show pool .
582.It Ic "show\ all\ procs" Ns Oo Cm /a Oc Ns Oo Cm /n Oc Ns Oo Cm /w Oc Ns \
583Oo Cm /l Oc
584Display all process information.
585Valid modifiers:
586.Bl -tag -width 3n
587.It Cm /n
588show process information in a
589.Xr ps 1
590style format.
591Information printed includes: process ID, parent process ID,
592process group, UID, process status, process flags, number of LWPs,
593command name, and process wait channel message.
594.It Cm /a
595show each process ID, command name, kernel virtual addresses of
596each process' proc structure, u-area, and vmspace structure.
597The vmspace address is also the address of the process'
598vm_map structure, and can be used in the
599.Ic show map
600command.
601.It Cm /w
602show each LWP ID, process ID, command name, system call emulation,
603priority, wait channel message and wait channel address.
604LWPs currently running on a CPU are marked with the '\&>' sign.
605.It Cm /l
606show each LWP ID, process ID, process status, CPU ID the LWP runs on,
607process flags, kernel virtual address of LWP structure,
608LWP name and wait channel message.
609LWPs currently running on a CPU are marked with the '\&>' sign.
610This is the default.
611.El
612.It Ic show routes
613Dump the entire
614.Dv AF_INET
615routing table.
616This command is available only on systems which support inet.
617.It Ic show breaks
618Display all breakpoints.
619.It Ic show buf Ns Oo Cm /f Oc Ar address
620Print the struct buf at
621.Ar address .
622The
623.Cm /f
624does nothing at this time.
625.It Ic show event Ns Oo Cm /f Oc Ns Oo Cm /i Oc Ns Oo Cm /m Oc Ns \
626Oo Cm /t Oc
627Print all the non-zero
628.Xr evcnt 9
629event counters.
630Valid modifiers:
631.Bl -tag -width 3n
632.It Cm /f
633event counters with a count of zero are printed as well.
634.It Cm /i
635interrupted counters will be displayed.
636.It Cm /m
637misc counters will be displayed.
638.It Cm /t
639trap counters will be displayed.
640.El
641.Pp
642If none of
643.Cm /i ,
644.Cm /m ,
645or
646.Cm /t
647are specified, all are shown.
648You can combine any of these.
649For example, the modifier
650.Cm /itf
651will select both interrupt and trap events, including those that are non-zero.
652.It Ic show files Ar address
653Display information about the vnodes of the files that are currently
654open by the process associated with the proc structure at
655.Ar address .
656This address can be found using the
657.Ic show all procs /a
658command.
659If the kernel is compiled with
660.Cd options LOCKDEBUG
661then details about the locking of the underlying uvm object will also
662be displayed.
663.It Ic show lock Ar address
664Display information about a lock at
665.Ar address .
666This command is only useful if a kernel is compiled with
667.Cd options LOCKDEBUG .
668.It Ic show lockstats
669Display information about lock statistics.
670This command is only useful if a kernel is compiled with
671.Cd options LOCKDEBUG .
672.It Ic show map Ns Oo Cm /f Oc Ar address
673Print the vm_map at
674.Ar address .
675If
676.Cm /f
677is specified, the complete map is printed.
678.It Ic show mount Ns Oo Cm /f Oc Ar address
679Print the mount structure at
680.Ar address .
681If
682.Cm /f
683is specified, the complete vnode list is printed.
684.It Ic show mbuf Ns Oo Cm /cdv Oc Ar address
685Print the mbuf structure at
686.Ar address .
687Valid modifiers:
688.Bl -tag -width 4n -compact
689.It Cm /c
690The mbufs in the chain are NOT followed.
691.It Cm /d
692The data is dumped.
693.It Cm /v
694Decode the mbuf chain as a packet.
695It currently supports Ethernet, PPP, PPPoE, ARP, IPv4, ICMP, IPv6, ICMP6, TCP
696and UDP.
697.El
698.It Ic show ncache Ar address
699Dump the namecache list associated with vnode at
700.Ar address .
701.It Ic show object Ns Oo Cm /f Oc Ar address
702Print the vm_object at
703.Ar address .
704If
705.Cm /f
706is specified, the complete object is printed.
707.It Ic show page Ns Oo Cm /f Oc Ar address
708Print the vm_page at
709.Ar address .
710If
711.Cm /f
712is specified, the complete page is printed.
713.It Ic show panic
714Print the current "panic" string.
715.It Ic show pool Ns Oo Cm /clp Oc Ar address
716Print the pool at
717.Ar address .
718Valid modifiers:
719.Bl -tag -width 4n -compact
720.It Cm /c
721Print the cachelist and its statistics for this pool.
722.It Cm /l
723Print the log entries for this pool.
724.It Cm /p
725Print the pagelist for this pool.
726.El
727.It Ic show proc Ns Oo Cm /ap Oc Ar address | pid
728Show information about a process and its LWPs.
729LWPs currently running on a CPU are marked with the '\&>' sign.
730.Bl -tag -width 4n -compact
731.It Cm /a
732The argument passed is the kernel virtual address
733of LWP structure.
734.It Cm /p
735The argument passed is a PID.
736Note that
737.Ar pid
738is interpreted using the current radix (see
739.Cm trace/t
740command for details).
741This is the default.
742.El
743.It Ic show registers Ns Op Cm /u
744Display the register set.
745If
746.Cm /u
747is specified, display user registers instead of kernel registers
748or the currently save one.
749.Pp
750Warning: support for
751.Cm /u
752is machine dependent.
753If not supported, incorrect information will be displayed.
754.It Ic show sched_qs
755Print the state of the scheduler's run queues.
756For each run queue that has an LWP, the run queue index and the list
757of LWPs will be shown.
758If the run queue has LWPs, but the sched_whichqs bit is not set for that
759queue, the queue index will be prefixed with a
760.Sq \&! .
761.It Ic show socket Ns Oo Cm /ampv Oc
762Print usage of system's socket buffers.
763By default, empty sockets aren't printed.
764.Bl -tag -width 4n -compact
765.It Cm /a
766Print all processes which use the socket.
767.It Cm /m
768Print mbuf chain in the socket buffer.
769.It Cm /p
770By default, a process which uses the socket is printed (only one socket).
771If
772.Cm /p
773is specified, the process isn't printed.
774.It Cm /v
775Verbose mode.
776If
777.Cm /v
778is specified, all sockets are printed.
779.El
780.It Ic show uvmexp
781Print a selection of UVM counters and statistics.
782.It Ic show kernhist Ns Oo Cm /i Oc Oo Ar addr Ns Oo , Ns Ar count Oc Oc
783Dumps all the kernel histories if no address is specified, or the history
784at the address.
785If
786.Cm /i
787is specified, display information about the named history or all histories,
788instead of history entries.
789If
790.Ar count
791is specified, only the last
792.Ar count
793entries will be displayed.
794Currently the
795.Ar count
796handling is only performed if a single history is requested.
797This command is available only if a kernel is compiled with one or more
798of the kernel history options
799.Cd KERNHIST ,
800.Cd SYSCALL_DEBUG ,
801.Cd USB_DEBUG ,
802.Cd BIOHIST ,
803or
804.Cd UVMHIST .
805.It Ic show vnode Ns Oo Cm /f Oc Ar address
806Print the vnode at
807.Ar address .
808If
809.Cm /f
810is specified, the complete vnode is printed.
811.It Ic show vnode_lock Ns Oo Cm /f Oc Ar address
812Print the vnode which has its lock at
813.Ar address .
814If
815.Cm /f
816is specified, the complete vnode is printed.
817.It Ic show watches
818Display all watchpoints.
819.It Ic sifting Ns Oo Cm /F Oc Ar string
820Search the symbol tables for all symbols of which
821.Ar string
822is a substring, and display them.
823If
824.Cm /F
825is specified, a character is displayed immediately after each symbol
826name indicating the type of symbol.
827.Pp
828For
829.Xr a.out 5 Ns -format
830symbol tables,
831absolute symbols display
832.Sy @ ,
833text segment symbols display
834.Sy * ,
835data segment symbols display
836.Sy + ,
837BSS segment symbols display
838.Sy - ,
839and filename symbols display
840.Sy / .
841For ELF-format symbol tables,
842object symbols display
843.Sy + ,
844function symbols display
845.Sy * ,
846section symbols display
847.Sy & ,
848and file symbols display
849.Sy / .
850.Pp
851To sift for a string beginning with a number, escape the first
852character with a backslash as:
853.Bd -literal -offset indent
854sifting \\386
855.Ed
856.It Ic step Ns Oo Cm /p Oc Op , Ns Ar count
857Single-step
858.Ar count
859times.
860If
861.Cm /p
862is specified, print each instruction at each step.
863Otherwise, only print the last instruction.
864.Pp
865Warning: depending on the machine type, it may not be possible
866to single-step through some low-level code paths or user-space
867code.
868On machines with software-emulated single-stepping (e.g., pmax),
869stepping through code executed by interrupt handlers will probably
870do the wrong thing.
871.It Ic sync
872Sync the disks, force a crash dump, and then reboot.
873.It Ic trace Ns Oo Cm /u Ns Oo Cm l Oc Oc Oo Ar frame-address Oc Ns \
874Oo , Ns Ar count Oc
875Stack trace from
876.Ar frame-address .
877If
878.Cm /u
879is specified, trace user-space, otherwise trace kernel-space.
880.Ar count
881is the number of frames to be traced.
882If
883.Ar count
884is omitted, all frames are printed.
885If
886.Cm /l
887is specified, the trace is printed and also stored in the kernel
888message buffer.
889.Pp
890Warning: user-space stack trace is valid only if the machine dependent
891code supports it.
892.It Ic trace/t Ns Oo Cm l Oc Oo Ar pid Oc Ns Oo , Ns Ar count Oc
893Stack trace by
894.Dq thread
895(process, on
896.Nx )
897rather than by stack frame address.
898Note that
899.Ar pid
900is interpreted using the current radix, whilst
901.Ic ps
902displays pids in decimal; prefix
903.Ar pid
904with
905.Sq 0t
906to force it to be interpreted as decimal (see
907.Sx VARIABLES
908section for radix).
909If
910.Cm /l
911is specified, the trace is printed and also stored in the kernel
912message buffer.
913.Pp
914Warning: trace by pid is valid only if the machine dependent code
915supports it.
916.It Ic trace/a Ns Oo Cm l Oc Oo Ar lwpaddr Oc Ns Oo , Ns Ar count Oc
917Stack trace by light weight process (LWP) address
918rather than by stack frame address.
919If
920.Cm /l
921is specified, the trace is printed and also stored in the kernel
922message buffer.
923.Pp
924Warning: trace by LWP address is valid only if the machine dependent
925code supports it.
926.It Ic until Ns Op Cm /p
927Stop at the next call or return instruction.
928If
929.Cm /p
930is specified, print the call nesting depth and the
931cumulative instruction count at each call or return.
932Otherwise, only print when the matching return is hit.
933.It Ic watch Ar address Ns Oo , Ns Ar size Oc
934Set a watchpoint for a region.
935Execution stops when an attempt to modify the region occurs.
936.Ar size
937defaults to 4.
938.Pp
939If you specify a wrong space address, the request is
940rejected with an error message.
941.Pp
942Warning: attempts to watch wired kernel memory may cause
943an unrecoverable error in some systems such as i386.
944Watchpoints on user addresses work the best.
945.It Ic whatis Ar address
946Describe what an address is.
947.It Ic write Ns Oo Cm /bhlBHL Oc Ar address Ar expression Oo Ar expression ... Oc
948Write the
949.Ar expression Ns s
950at succeeding locations.
951The unit size is specified with a modifier character, as per
952.Ic examine .
953Valid modifiers are:
954.Cm /b ,
955.Cm /h ,
956and
957.Cm /l .
958If no modifier is specified,
959.Cm /l
960is used.
961.Pp
962Specifying the modifiers in upper case,
963.Cm /B ,
964.Cm /H ,
965.Cm /L ,
966will prevent
967.Nm
968from reading the memory location first, which is useful for avoiding
969side effects when writing to I/O memory regions.
970.Pp
971Warning: since there is no delimiter between
972.Ar expression Ns s ,
973strange things may occur.
974It's best to enclose each
975.Ar expression
976in parentheses.
977.It Ic x Ns Oo Cm / Ns Ar modifier Oc Ar address Ns Op , Ns Ar count
978A synonym for
979.Ic examine .
980.\" XXX - these commands aren't implemented; jhawk 19 May 2000
981.\" .It Ic xf
982.\" Examine forward.
983.\" .Ic xf
984.\" re-executes the most recent
985.\" .Ic execute
986.\" command with the same parameters except that
987.\" .Ar address
988.\" is set to
989.\" .Ar next .
990.\" .It Ic xb
991.\" Examine backward.
992.\" .Ic xb
993.\" re-executes the most recent
994.\" .Ic execute
995.\" command with the same parameters, except that
996.\" .Ar address
997.\" is set to the last start address minus its size.
998.El
999.Sh MACHINE-SPECIFIC COMMANDS
1000The "glue" code that hooks
1001.Nm
1002into the
1003.Nx
1004kernel for any given port can also add machine specific commands
1005to the
1006.Nm
1007command parser.
1008All of these commands are preceded by the command word
1009.Em machine
1010to indicate that they are part of the machine-specific command
1011set (e.g.
1012.Ic machine reboot ) .
1013Some of these commands are:
1014.Ss AARCH64
1015.Bl -tag -width "traptrace" -compact
1016.It Ic cpu
1017Switch to another cpu.
1018.It Ic cpuinfo
1019Print cpu information about the ``struct cpuinfo''.
1020.It Ic frame
1021Given a trap frame address, print out the trap frame.
1022.It Ic lwp
1023Print lwp information about the ``struct lwp''.
1024.It Ic pte
1025Print PTE information.
1026.It Ic sysreg
1027Print system registers.
1028.It Ic watch
1029Set or clear a hardware watchpoint.
1030Pass the address to be watched, or watchpoint number to clear the watchpoint.
1031Optional modifiers are
1032.Dq l
1033for load access,
1034.Dq s
1035for store access,
1036.Dq 1
1037for 8 bit width,
1038.Dq 2
1039for 16 bit,
1040.Dq 3
1041for 24 bit,
1042.Dq 4
1043for 32 bit,
1044.Dq 5
1045for 40 bit,
1046.Dq 6
1047for 48 bit,
1048.Dq 7
1049for 56 bit,
1050.Dq 8
1051for 64 bit.
1052.El
1053.Ss ALPHA
1054.Bl -tag -width "traptrace" -compact
1055.It Ic cpu
1056Switch to another cpu.
1057.\" .It Ic halt
1058.\" Call the PROM monitor to halt the CPU.
1059.\" .It Ic reboot
1060.\" Call the PROM monitor to reboot the CPU.
1061.El
1062.Ss AMD64
1063.Bl -tag -width "traptrace" -compact
1064.It Ic cpu
1065Switch to another cpu.
1066.El
1067.Ss ARM32
1068.Bl -tag -width "traptrace" -compact
1069.It Ic frame
1070Given a trap frame address, print out the trap frame.
1071.El
1072.Ss HPPA
1073.Bl -tag -width "traptrace" -compact
1074.It Ic frame
1075Without an address the default trap frame is printed.
1076Otherwise, the trap frame address can be given, or, when the
1077.Dq l
1078modifier is used, an LWP address.
1079.El
1080.Ss I386
1081.Bl -tag -width "traptrace" -compact
1082.It Ic cpu
1083Switch to another cpu.
1084.El
1085.Ss IA64
1086.Bl -tag -width "traptrace" -compact
1087.It Ic vector
1088Without a vector, information about all 256 vectors is shown.
1089Otherwise, the given vector is shown.
1090.El
1091.Ss MIPS
1092.Bl -tag -width "traptrace" -compact
1093.It Ic cp0
1094Dump CP0 (coprocessor 0) register values.
1095.It Ic kvtop
1096Print the physical address for a given kernel virtual address.
1097.It Ic tlb
1098Print out the Translation Lookaside Buffer (TLB).
1099Only works in
1100.Nx
1101kernels compiled with
1102.Dv DEBUG
1103option.
1104.El
1105.Ss POWERPC 4xx
1106.Bl -tag -width "traptrace" -compact
1107.It Ic ctx
1108Print process MMU context information.
1109.It Ic pv
1110Print PA->VA mapping information.
1111.It Ic reset
1112Reset the system.
1113.It Ic tf
1114Display the contents of the trapframe.
1115.It Ic tlb
1116Display instruction translation storage buffer information.
1117.It Ic dcr
1118Set the DCR register.
1119Must be between 0x00 and 0x3ff.
1120.It Ic user
1121Display user memory.
1122Use the
1123.Dq i
1124modifier to get instruction decoding.
1125.El
1126.Ss POWERPC OEA
1127.Bl -tag -width "traptrace" -compact
1128.It Ic bat
1129Print BAT registers and translations.
1130.It Ic mmu
1131Print MMU registers.
1132.El
1133.Ss SH3
1134.Bl -tag -width "traptrace" -compact
1135.It Ic tlb
1136Print TLB entries.
1137.It Ic cache
1138Print cache entries.
1139.It Ic frame
1140Print switch frame and trap frames.
1141.It Ic stack
1142Print kernel stack usage.
1143Only works in
1144.Nx
1145kernels compiled with the
1146.Dv KSTACK_DEBUG
1147option.
1148.El
1149.Ss SPARC
1150.Bl -tag -width "traptrace" -compact
1151.It Ic cpu
1152Switch to another cpu.
1153.It Ic prom
1154Enter the Sun PROM monitor.
1155.It Ic proc
1156Display some information about the LWP pointed to, or curlwp.
1157.It Ic pcb
1158Display information about the
1159.Dq struct pcb
1160listed.
1161.It Ic page
1162Display the pointer to the
1163.Dq struct vm_page
1164for this physical address.
1165.El
1166.Ss SPARC64
1167.Bl -tag -width "traptrace" -compact
1168.It Ic ctx
1169Print process context information.
1170.It Ic cpu
1171Switch to another cpu.
1172.It Ic dtlb
1173Print data translation look-aside buffer context information.
1174.It Ic dtsb
1175Display data translation storage buffer information.
1176.It Ic kmap
1177Display information about the listed mapping in the kernel pmap.
1178Use the
1179.Dq f
1180modifier to get a full listing.
1181.It Ic extract
1182Extract the physical address for a given virtual address from the kernel pmap.
1183.It Ic fpstate
1184Dump the FPU state.
1185.It Ic itlb
1186Print instruction translation look-aside buffer context information.
1187.It Ic itsb
1188Display instruction translation storage buffer information.
1189.It Ic lwp
1190Display a struct lwp
1191.It Ic pcb
1192Display information about the
1193.Dq struct pcb
1194listed.
1195.It Ic pctx
1196Attempt to change process context.
1197.It Ic page
1198Display the pointer to the
1199.Dq struct vm_page
1200for this physical address.
1201.It Ic phys
1202Display physical memory.
1203.It Ic pmap
1204Display the pmap.
1205Use the
1206.Dq f
1207modifier to get a fuller listing.
1208.It Ic proc
1209Display some information about the process pointed to, or curproc.
1210.It Ic prom
1211Enter the OFW PROM.
1212.It Ic pv
1213Display the
1214.Dq struct pv_entry
1215pointed to.
1216.It Ic sir
1217Reset the machine and enter prom (do a Software Initiated Reset).
1218.It Ic stack
1219Dump the window stack.
1220Use the
1221.Dq u
1222modifier to get userland information.
1223.It Ic tf
1224Display full trap frame state.
1225This is most useful for inclusion with bug reports.
1226.It Ic ts
1227Display trap state.
1228.It Ic traptrace
1229Display or set trap trace information.
1230Use the
1231.Dq r
1232and
1233.Dq f
1234modifiers to get reversed and full information, respectively.
1235.It Ic watch
1236Set or clear a physical or virtual hardware watchpoint.
1237Pass the address to be watched, or
1238.Dq 0
1239(or omit the address) to clear the watchpoint.
1240Optional modifiers are
1241.Dq p
1242for physical address,
1243.Dq r
1244for trap on read access (default: trap on write access only),
1245.Dq b
1246for 8 bit width,
1247.Dq h
1248for 16 bit,
1249.Dq l
1250for 32 bit or
1251.Dq L
1252for 64 bit.
1253.It Ic window
1254Print register window information.
1255Argument is a stack frame number (0 is
1256top of stack, which is used when no index is given).
1257.El
1258.Ss SUN2, SUN3 and SUN3X
1259.Bl -tag -width "traptrace" -compact
1260.It Ic abort
1261Drop into monitor via abort (allows continue).
1262.It Ic halt
1263Exit to Sun PROM monitor as in
1264.Xr halt 8 .
1265.It Ic reboot
1266Reboot the machine as in
1267.Xr reboot 8 .
1268.It Ic pgmap
1269Given an address, print the address, segment map, page map, and
1270Page Table Entry (PTE).
1271.El
1272.Ss VAX
1273.Bl -tag -width "traptrace" -compact
1274.It Ic cpu
1275Switch to another cpu.
1276.El
1277.Sh VARIABLES
1278.Nm
1279accesses registers and variables as
1280.Cm $ Ns Ar name .
1281Register names are as per the
1282.Ic show registers
1283command.
1284Some variables are suffixed with numbers, and may have a modifier
1285following a colon immediately after the variable name.
1286For example, register variables may have a
1287.Sq u
1288modifier to indicate user register
1289(e.g.,
1290.Li "$eax:u" ) .
1291.Pp
1292Built-in variables currently supported are:
1293.Bl -tag -offset indent -width "maxwidth" -compact
1294.It Va dumpstack
1295If non-zero (the default),
1296causes a stack trace to be printed when
1297.Nm
1298is entered on panic.
1299.It Va fromconsole
1300If non-zero (the default),
1301the kernel allows to enter
1302.Nm
1303from the console (by break signal or special key sequence).
1304If the kernel configuration option
1305.D1 Cd options DDB_FROMCONSOLE=0
1306is used,
1307.Va fromconsole
1308will be initialized to off.
1309.It Va lines
1310The number of lines.
1311This is used by the
1312.Ic more
1313feature.
1314When this variable is set to zero the
1315.Ic more
1316feature is disabled.
1317.It Va maxoff
1318Addresses are printed as
1319.Li 'symbol'+offset
1320unless
1321.Li offset
1322is greater than
1323.Va maxoff .
1324.It Va maxwidth
1325The width of the displayed line.
1326.Nm
1327wraps the current line by printing new line when
1328.Va maxwidth
1329column is reached.
1330When this variable is set to zero
1331.Nm
1332doesn't perform any wrapping.
1333.It Va onpanic
1334If greater than zero (the default is 1),
1335.Nm
1336will be invoked when the kernel panics.
1337If the kernel configuration option
1338.D1 Cd options DDB_ONPANIC=0
1339is used,
1340.Va onpanic
1341will be initialized to off, causing a stack trace to be printed and
1342the system to be rebooted instead of
1343.Nm
1344being entered.
1345Setting
1346.Va onpanic
1347to \-1 suppresses the stack trace before reboot.
1348.It Va radix
1349Input and output radix.
1350.It Va tabstops
1351Tab stop width.
1352.It Va tee_msgbuf
1353If explicitly set to non zero (zero is the default) all
1354.Nm
1355output will not only be displayed on screen but
1356also be fed to the msgbuf.
1357The default of the variable can be set using the kernel configuration option
1358.D1 Cd options DDB_TEE_MSGBUF=1
1359which will initialize
1360.Va tee_msgbuf
1361to be 1.
1362This option is especially handy for poor souls
1363who don't have a serial console but want to recall
1364.Nm
1365output from a crash investigation.
1366This option is more generic than the /l command modifier possible for
1367selected commands as discussed above to log the output.
1368Mixing both /l
1369and this setting can give double loggings.
1370.It Va panicstackframes
1371Number of stack frames to display on panic.
1372Useful to avoid scrolling away the interesting frames on a glass tty.
1373Default value is
1374.Dv 65535
1375(all frames), useful value around
1376.Dv 10 .
1377.\" .It Va work Ns Sy xx
1378.\" Temporary work variable.
1379.\" .Sq Sy xx
1380.\" is between 0 and 31.
1381.El
1382.Pp
1383All built-in variables are accessible via
1384.Xr sysctl 3 .
1385.Sh EXPRESSIONS
1386Almost all expression operators in C are supported, except
1387.Sq \&~ ,
1388.Sq \&^ ,
1389and unary
1390.Sq \&& .
1391Special rules in
1392.Nm
1393are:
1394.Bl -tag -offset indent -width "identifier"
1395.It Ar identifier
1396name of a symbol.
1397It is translated to the address (or value) of it.
1398.Sq \&.
1399and
1400.Sq \&:
1401can be used in the identifier.
1402If supported by an object format dependent routine,
1403.Sm off
1404.Xo
1405.Oo Ar filename : Oc
1406.Ar function
1407.Oo : Ar line\ number Oc ,
1408.Xc
1409.Sm on
1410.Sm off
1411.Xo
1412.Oo Ar filename : Oc
1413.Ar variable ,
1414.Xc
1415.Sm on
1416and
1417.Sm off
1418.Xo
1419.Ar filename
1420.Oo : Ar "line number" Oc ,
1421.Xc
1422.Sm on
1423can be accepted as a symbol.
1424The symbol may be prefixed with
1425.Ar symbol_table_name\^ : :
1426(e.g.,
1427.Li emulator::mach_msg_trap )
1428to specify other than kernel symbols.
1429.It Ar number
1430number.
1431Radix is determined by the first two characters:
1432.Sq 0x
1433- hex,
1434.Sq 0o
1435- octal,
1436.Sq 0t
1437- decimal,
1438otherwise follow current radix.
1439.It Cm \&.
1440.Ar dot
1441.It Cm +
1442.Ar next
1443.It Cm ..
1444address of the start of the last line examined.
1445Unlike
1446.Ar dot
1447or
1448.Ar next ,
1449this is only changed by the
1450.Ic examine
1451or
1452.Ic write
1453commands.
1454.It Cm \&" \"" XXX: emacs highlighting
1455last address explicitly specified.
1456.It Cm $ Ns Ar name
1457register name or variable.
1458It is translated to the value of it.
1459It may be followed by a
1460.Sq \&:
1461and modifiers as described above.
1462.It Cm #
1463a binary operator which rounds up the left hand side to the next
1464multiple of right hand side.
1465.It Cm * Ns Ar expr
1466expression indirection.
1467It may be followed by a
1468.Sq \&:
1469and modifiers as described above.
1470.El
1471.Sh SEE ALSO
1472.Xr reboot 2 ,
1473.Xr options 4 ,
1474.Xr crash 8 ,
1475.Xr reboot 8 ,
1476.Xr sysctl 8 ,
1477.Xr cnmagic 9
1478.Sh HISTORY
1479The
1480.Nm
1481kernel debugger was written as part of the MACH project at
1482Carnegie-Mellon University.
1483