xref: /freebsd/share/man/man4/ddb.4 (revision 1d386b48)
1.\"
2.\" Mach Operating System
3.\" Copyright (c) 1991,1990 Carnegie Mellon University
4.\" Copyright (c) 2007 Robert N. M. Watson
5.\" All Rights Reserved.
6.\"
7.\" Permission to use, copy, modify and distribute this software and its
8.\" documentation is hereby granted, provided that both the copyright
9.\" notice and this permission notice appear in all copies of the
10.\" software, derivative works or modified versions, and any portions
11.\" thereof, and that both notices appear in supporting documentation.
12.\"
13.\" CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
14.\" CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
15.\" ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
16.\"
17.\" Carnegie Mellon requests users of this software to return to
18.\"
19.\"  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
20.\"  School of Computer Science
21.\"  Carnegie Mellon University
22.\"  Pittsburgh PA 15213-3890
23.\"
24.\" any improvements or extensions that they make and grant Carnegie Mellon
25.\" the rights to redistribute these changes.
26.\"
27.\" $FreeBSD$
28.\"
29.Dd November 10, 2022
30.Dt DDB 4
31.Os
32.Sh NAME
33.Nm ddb
34.Nd interactive kernel debugger
35.Sh SYNOPSIS
36In order to enable kernel debugging facilities include:
37.Bd -ragged -offset indent
38.Cd options KDB
39.Cd options DDB
40.Ed
41.Pp
42To prevent activation of the debugger on kernel
43.Xr panic 9 :
44.Bd -ragged -offset indent
45.Cd options KDB_UNATTENDED
46.Ed
47.Pp
48In order to print a stack trace of the current thread on the console
49for a panic:
50.Bd -ragged -offset indent
51.Cd options KDB_TRACE
52.Ed
53.Pp
54To print the numerical value of symbols in addition to the symbolic
55representation, define:
56.Bd -ragged -offset indent
57.Cd options DDB_NUMSYM
58.Ed
59.Pp
60To enable the
61.Xr gdb 4
62backend, so that remote debugging with
63.Xr kgdb 1 Pq Pa ports/devel/gdb
64is possible, include:
65.Bd -ragged -offset indent
66.Cd options GDB
67.Ed
68.Sh DESCRIPTION
69The
70.Nm
71kernel debugger is an interactive debugger with a syntax inspired by
72.Xr gdb 1 Pq Pa ports/devel/gdb .
73If linked into the running kernel,
74it can be invoked locally with the
75.Ql debug
76.Xr keymap 5
77action, usually mapped to Ctrl+Alt+Esc, or by setting the
78.Va debug.kdb.enter
79sysctl to 1.
80The debugger is also invoked on kernel
81.Xr panic 9
82if the
83.Va debug.debugger_on_panic
84.Xr sysctl 8
85MIB variable is set non-zero,
86which is the default
87unless the
88.Dv KDB_UNATTENDED
89option is specified.
90Similarly, if the
91.Va debug.debugger_on_recursive_panic
92variable is set to
93.Dv 1 ,
94then the debugger will be invoked on a recursive kernel panic.
95This variable has a default value of
96.Dv 0 ,
97and has no effect if
98.Va debug.debugger_on_panic
99is already set non-zero.
100.Pp
101The current location is called
102.Va dot .
103The
104.Va dot
105is displayed with
106a hexadecimal format at a prompt.
107The commands
108.Ic examine
109and
110.Ic write
111update
112.Va dot
113to the address of the last line
114examined or the last location modified, and set
115.Va next
116to the address of
117the next location to be examined or changed.
118Other commands do not change
119.Va dot ,
120and set
121.Va next
122to be the same as
123.Va dot .
124.Pp
125The general command syntax is:
126.Ar command Ns Op Li / Ns Ar modifier
127.Oo Ar addr Oc Ns Op , Ns Ar count
128.Pp
129A blank line repeats the previous command from the address
130.Va next
131with
132count 1 and no modifiers.
133Specifying
134.Ar addr
135sets
136.Va dot
137to the address.
138Omitting
139.Ar addr
140uses
141.Va dot .
142A missing
143.Ar count
144is taken
145to be 1 for printing commands or infinity for stack traces.
146A
147.Ar count
148of -1 is equivalent to a missing
149.Ar count .
150Options that are supplied but not supported by the given
151.Ar command
152are usually ignored.
153.Pp
154The
155.Nm
156debugger has a pager feature (like the
157.Xr more 1
158command)
159for the output.
160If an output line exceeds the number set in the
161.Va lines
162variable, it displays
163.Dq Li --More--
164and waits for a response.
165The valid responses for it are:
166.Pp
167.Bl -tag -compact -width ".Li SPC"
168.It Li SPC
169one more page
170.It Li RET
171one more line
172.It Li q
173abort the current command, and return to the command input mode
174.El
175.Pp
176Finally,
177.Nm
178provides a small (currently 10 items) command history, and offers
179simple
180.Nm emacs Ns -style
181command line editing capabilities.
182In addition to
183the
184.Nm emacs
185control keys, the usual ANSI arrow keys may be used to browse through the
186history buffer, and move the cursor within the current line.
187.Sh COMMANDS
188.Ss COMMON DEBUGGER COMMANDS
189.Bl -tag -width indent -compact
190.It Ic help
191Print a short summary of the available commands and command
192abbreviations.
193.Pp
194.It Xo
195.Ic examine Ns Op Li / Ns Cm AISabcdghilmorsuxz ...
196.Oo Ar addr Oc Ns Op , Ns Ar count
197.Xc
198.It Xo
199.Ic x       Ns Op Li / Ns Cm AISabcdghilmorsuxz ...
200.Oo Ar addr Oc Ns Op , Ns Ar count
201.Xc
202Display the addressed locations according to the formats in the modifier.
203Multiple modifier formats display multiple locations.
204If no format is specified, the last format specified for this command
205is used.
206.Pp
207The format characters are:
208.Bl -tag -compact -width indent
209.It Cm b
210look at by bytes (8 bits)
211.It Cm h
212look at by half words (16 bits)
213.It Cm l
214look at by long words (32 bits)
215.It Cm g
216look at by quad words (64 bits)
217.It Cm a
218print the location being displayed
219.It Cm A
220print the location with a line number if possible
221.It Cm x
222display in unsigned hex
223.It Cm z
224display in signed hex
225.It Cm o
226display in unsigned octal
227.It Cm d
228display in signed decimal
229.It Cm u
230display in unsigned decimal
231.It Cm r
232display in current radix, signed
233.It Cm c
234display low 8 bits as a character.
235Non-printing characters are displayed as an octal escape code (e.g.,
236.Ql \e000 ) .
237.It Cm s
238display the null-terminated string at the location.
239Non-printing characters are displayed as octal escapes.
240.It Cm m
241display in unsigned hex with character dump at the end of each line.
242The location is also displayed in hex at the beginning of each line.
243.It Cm i
244display as a disassembled instruction
245.It Cm I
246display as a disassembled instruction with possible alternate formats
247depending on the machine.
248On i386, this selects the alternate format for the instruction decoding
249(16 bits in a 32-bit code segment and vice versa).
250.It Cm S
251display a symbol name for the pointer stored at the address
252.El
253.Pp
254.It Ic xf
255Examine forward:
256execute an
257.Ic examine
258command with the last specified parameters to it
259except that the next address displayed by it is used as the start address.
260.Pp
261.It Ic xb
262Examine backward:
263execute an
264.Ic examine
265command with the last specified parameters to it
266except that the last start address subtracted by the size displayed by it
267is used as the start address.
268.Pp
269.It Ic print Ns Op Li / Ns Cm acdoruxz
270.It Ic p Ns Op Li / Ns Cm acdoruxz
271Print
272.Ar addr Ns s
273according to the modifier character (as described above for
274.Cm examine ) .
275Valid formats are:
276.Cm a , x , z , o , d , u , r ,
277and
278.Cm c .
279If no modifier is specified, the last one specified to it is used.
280The argument
281.Ar addr
282can be a string, in which case it is printed as it is.
283For example:
284.Bd -literal -offset indent
285print/x "eax = " $eax "\enecx = " $ecx "\en"
286.Ed
287.Pp
288will print like:
289.Bd -literal -offset indent
290eax = xxxxxx
291ecx = yyyyyy
292.Ed
293.Pp
294.It Xo
295.Ic write Ns Op Li / Ns Cm bhl
296.Ar addr expr1 Op Ar expr2 ...
297.Xc
298.It Xo
299.Ic w Ns Op Li / Ns Cm bhl
300.Ar addr expr1 Op Ar expr2 ...
301.Xc
302Write the expressions specified after
303.Ar addr
304on the command line at succeeding locations starting with
305.Ar addr .
306The write unit size can be specified in the modifier with a letter
307.Cm b
308(byte),
309.Cm h
310(half word) or
311.Cm l
312(long word) respectively.
313If omitted,
314long word is assumed.
315.Pp
316.Sy Warning :
317since there is no delimiter between expressions, strange
318things may happen.
319It is best to enclose each expression in parentheses.
320.Pp
321.It Ic set Li $ Ns Ar variable Oo Li = Oc Ar expr
322Set the named variable or register with the value of
323.Ar expr .
324Valid variable names are described below.
325.Pp
326.It Ic break Ns Oo Li / Ns Cm u Oc Oo Ar addr Oc Ns Op , Ns Ar count
327.It Ic b     Ns Oo Li / Ns Cm u Oc Oo Ar addr Oc Ns Op , Ns Ar count
328Set a break point at
329.Ar addr .
330If
331.Ar count
332is supplied, the
333.Ic continue
334command will not stop at this break point on the first
335.Ar count
336\- 1 times that it is hit.
337If the break point is set, a break point number is
338printed with
339.Ql # .
340This number can be used in deleting the break point
341or adding conditions to it.
342.Pp
343If the
344.Cm u
345modifier is specified, this command sets a break point in user
346address space.
347Without the
348.Cm u
349option, the address is considered to be in the kernel
350space, and a wrong space address is rejected with an error message.
351This modifier can be used only if it is supported by machine dependent
352routines.
353.Pp
354.Sy Warning :
355If a user text is shadowed by a normal user space debugger,
356user space break points may not work correctly.
357Setting a break
358point at the low-level code paths may also cause strange behavior.
359.Pp
360.It Ic delete Op Ar addr
361.It Ic d      Op Ar addr
362.It Ic delete Li # Ns Ar number
363.It Ic d      Li # Ns Ar number
364Delete the specified break point.
365The break point can be specified by a
366break point number with
367.Ql # ,
368or by using the same
369.Ar addr
370specified in the original
371.Ic break
372command, or by omitting
373.Ar addr
374to get the default address of
375.Va dot .
376.Pp
377.It Ic halt
378Halt the system.
379.Pp
380.It Ic watch Oo Ar addr Oc Ns Op , Ns Ar size
381Set a watchpoint for a region.
382Execution stops when an attempt to modify the region occurs.
383The
384.Ar size
385argument defaults to 4.
386If you specify a wrong space address, the request is rejected
387with an error message.
388.Pp
389.Sy Warning :
390Attempts to watch wired kernel memory
391may cause unrecoverable error in some systems such as i386.
392Watchpoints on user addresses work best.
393.Pp
394.It Ic hwatch Oo Ar addr Oc Ns Op , Ns Ar size
395Set a hardware watchpoint for a region if supported by the
396architecture.
397Execution stops when an attempt to modify the region occurs.
398The
399.Ar size
400argument defaults to 4.
401.Pp
402.Sy Warning :
403The hardware debug facilities do not have a concept of separate
404address spaces like the watch command does.
405Use
406.Ic hwatch
407for setting watchpoints on kernel address locations only, and avoid
408its use on user mode address spaces.
409.Pp
410.It Ic dhwatch Oo Ar addr Oc Ns Op , Ns Ar size
411Delete specified hardware watchpoint.
412.Pp
413.It Ic kill Ar sig pid
414Send signal
415.Ar sig
416to process
417.Ar pid .
418The signal is acted on upon returning from the debugger.
419This command can be used to kill a process causing resource contention
420in the case of a hung system.
421See
422.Xr signal 3
423for a list of signals.
424Note that the arguments are reversed relative to
425.Xr kill 2 .
426.Pp
427.It Ic step Ns Oo Li / Ns Cm p Oc Ns Op , Ns Ar count
428.It Ic s    Ns Oo Li / Ns Cm p Oc Ns Op , Ns Ar count
429Single step
430.Ar count
431times.
432If the
433.Cm p
434modifier is specified, print each instruction at each step.
435Otherwise, only print the last instruction.
436.Pp
437.Sy Warning :
438depending on machine type, it may not be possible to
439single-step through some low-level code paths or user space code.
440On machines with software-emulated single-stepping (e.g., pmax),
441stepping through code executed by interrupt handlers will probably
442do the wrong thing.
443.Pp
444.It Ic continue Ns Op Li / Ns Cm c
445.It Ic c Ns Op Li / Ns Cm c
446Continue execution until a breakpoint or watchpoint.
447If the
448.Cm c
449modifier is specified, count instructions while executing.
450Some machines (e.g., pmax) also count loads and stores.
451.Pp
452.Sy Warning :
453when counting, the debugger is really silently single-stepping.
454This means that single-stepping on low-level code may cause strange
455behavior.
456.Pp
457.It Ic until Ns Op Li / Ns Cm p
458Stop at the next call or return instruction.
459If the
460.Cm p
461modifier is specified, print the call nesting depth and the
462cumulative instruction count at each call or return.
463Otherwise,
464only print when the matching return is hit.
465.Pp
466.It Ic next Ns Op Li / Ns Cm p
467.It Ic match Ns Op Li / Ns Cm p
468Stop at the matching return instruction.
469If the
470.Cm p
471modifier is specified, print the call nesting depth and the
472cumulative instruction count at each call or return.
473Otherwise, only print when the matching return is hit.
474.Pp
475.It Xo
476.Ic trace Ns Op Li / Ns Cm u
477.Op Ar pid | tid Ns
478.Op , Ns Ar count
479.Xc
480.It Xo
481.Ic t Ns Op Li / Ns Cm u
482.Op Ar pid | tid Ns
483.Op , Ns Ar count
484.Xc
485.It Xo
486.Ic where Ns Op Li / Ns Cm u
487.Op Ar pid | tid Ns
488.Op , Ns Ar count
489.Xc
490.It Xo
491.Ic bt Ns Op Li / Ns Cm u
492.Op Ar pid | tid Ns
493.Op , Ns Ar count
494.Xc
495Stack trace.
496The
497.Cm u
498option traces user space; if omitted,
499.Ic trace
500only traces
501kernel space.
502The optional argument
503.Ar count
504is the number of frames to be traced.
505If
506.Ar count
507is omitted, all frames are printed.
508.Pp
509.Sy Warning :
510User space stack trace is valid
511only if the machine dependent code supports it.
512.Pp
513.It Xo
514.Ic search Ns Op Li / Ns Cm bhl
515.Ar addr
516.Ar value
517.Op Ar mask Ns
518.Op , Ns Ar count
519.Xc
520Search memory for
521.Ar value .
522The optional
523.Ar count
524argument limits the search.
525.\"
526.Pp
527.It Xo
528.Ic Ic reboot Ns Op Li / Ns Cm s
529.Op Ar seconds
530.Xc
531.It Xo
532.Ic Ic reset Ns Op Li / Ns Cm s
533.Op Ar seconds
534.Xc
535Hard reset the system.
536If the optional argument
537.Ar seconds
538is given, the debugger will wait for this long, at most a week,
539before rebooting.
540When the
541.Cm s
542modifier is given, the command will skip running any registered shutdown
543handlers and attempt the most basic reset.
544.Pp
545.It Ic thread Ar addr | tid
546Switch the debugger to the thread with ID
547.Ar tid ,
548if the argument is a decimal number, or address
549.Ar addr ,
550otherwise.
551.Pp
552.It Ic watchdog Op Ar exp
553Program the
554.Xr watchdog 4
555timer to fire in
556.Pf 2^ Ar exp
557seconds.
558If no argument is provided, the watchdog timer is disabled.
559.El
560.Ss SPECIALIZED HELPER COMMANDS
561.Bl -tag -width indent -compact
562.It Xo
563.Ic findstack
564.Ar addr
565.Xc
566Prints the address of the thread whose kernel-mode stack contains
567.Ar addr ,
568if any.
569.Pp
570.It Ic show Cm active trace
571.It acttrace
572Show a stack trace for every thread running on a CPU.
573.Pp
574.It Ic show Cm all procs Ns Op Li / Ns Cm a
575.It Ic ps Ns Op Li / Ns Cm a
576Display all process information.
577The process information may not be shown if it is not
578supported in the machine, or the bottom of the stack of the
579target process is not in the main memory at that time.
580The
581.Cm a
582modifier will print command line arguments for each process.
583.\"
584.Pp
585.It Ic show Cm all trace
586.It Ic alltrace
587Show a stack trace for every thread in the system.
588.Pp
589.It Ic show Cm all ttys
590Show all TTY's within the system.
591Output is similar to
592.Xr pstat 8 ,
593but also includes the address of the TTY structure.
594.\"
595.Pp
596.It Ic show Cm all vnets
597Show the same output as "show vnet" does, but lists all
598virtualized network stacks within the system.
599.\"
600.Pp
601.It Ic show Cm allchains
602Show the same information like "show lockchain" does, but
603for every thread in the system.
604.\"
605.Pp
606.It Ic show Cm alllocks
607Show all locks that are currently held.
608This command is only available if
609.Xr witness 4
610is included in the kernel.
611.\"
612.Pp
613.It Ic show Cm allpcpu
614The same as "show pcpu", but for every CPU present in the system.
615.\"
616.Pp
617.It Ic show Cm allrman
618Show information related with resource management, including
619interrupt request lines, DMA request lines, I/O ports, I/O memory
620addresses, and Resource IDs.
621.\"
622.Pp
623.It Ic show Cm apic
624Dump data about APIC IDT vector mappings.
625.\"
626.Pp
627.It Ic show Cm badstacks
628Walk the
629.Xr witness 4
630graph and print any lock-order violations.
631This command is only available if
632.Xr witness 4
633is included in the kernel.
634.\"
635.Pp
636.It Ic show Cm breaks
637Show breakpoints set with the "break" command.
638.\"
639.Pp
640.It Ic show Cm bio Ar addr
641Show information about the bio structure
642.Vt struct bio
643present at
644.Ar addr .
645See the
646.Pa sys/bio.h
647header file and
648.Xr g_bio 9
649for more details on the exact meaning of the structure fields.
650.\"
651.Pp
652.It Ic show Cm buffer Ar addr
653Show information about the buf structure
654.Vt struct buf
655present at
656.Ar addr .
657See the
658.Pa sys/buf.h
659header file for more details on the exact meaning of the structure fields.
660.\"
661.Pp
662.It Ic show Cm callout Ar addr
663Show information about the callout structure
664.Vt struct callout
665present at
666.Ar addr .
667.\"
668.Pp
669.It Ic show Cm cdev Op Ar addr
670Show the internal devfs state of the cdev structure located at
671.Ar addr .
672If no argument is provided, show the list of all created cdevs, consisting of
673the devfs node name and the
674.Vt struct cdev
675address.
676.\"
677.Pp
678.It Ic show Cm conifhk
679Lists hooks currently waiting for completion in
680.Fn run_interrupt_driven_config_hooks .
681.\"
682.Pp
683.It Ic show Cm cpusets
684Print numbered root and assigned CPU affinity sets.
685See
686.Xr cpuset 2
687for more details.
688.\"
689.Pp
690.It Ic show Cm cyrixreg
691Show registers specific to the Cyrix processor.
692.\"
693.Pp
694.It Ic show Cm devmap
695Prints the contents of the static device mapping table.
696Currently only available on the
697ARM
698architecture.
699.\"
700.Pp
701.It Ic show Cm domain Ar addr
702Print protocol domain structure
703.Vt struct domain
704at address
705.Ar addr .
706See the
707.Pa sys/domain.h
708header file for more details on the exact meaning of the structure fields.
709.\"
710.Pp
711.It Ic show Cm ffs Op Ar addr
712Show brief information about ffs mount at the address
713.Ar addr ,
714if argument is given.
715Otherwise, provides the summary about each ffs mount.
716.\"
717.Pp
718.It Ic show Cm file Ar addr
719Show information about the file structure
720.Vt struct file
721present at address
722.Ar addr .
723.\"
724.Pp
725.It Ic show Cm files
726Show information about every file structure in the system.
727.\"
728.Pp
729.It Ic show Cm freepages
730Show the number of physical pages in each of the free lists.
731.\"
732.Pp
733.It Ic show Cm geom Op Ar addr
734If the
735.Ar addr
736argument is not given, displays the entire GEOM topology.
737If
738.Ar addr
739is given, displays details about the given GEOM object (class, geom,
740provider or consumer).
741.\"
742.Pp
743.It Ic show Cm idt
744Show IDT layout.
745The first column specifies the IDT vector.
746The second one is the name of the interrupt/trap handler.
747Those functions are machine dependent.
748.\"
749.Pp
750.It Ic show Cm igi_list Ar addr
751Show information about the IGMP structure
752.Vt struct igmp_ifsoftc
753present at
754.Ar addr .
755.\"
756.Pp
757.It Ic show Cm iosched Ar addr
758Show information about the I/O scheduler
759.Vt struct cam_iosched_softc
760located at
761.Ar addr .
762.\"
763.Pp
764.It Ic show Cm inodedeps Op Ar addr
765Show brief information about each inodedep structure.
766If
767.Ar addr
768is given, only inodedeps belonging to the fs located at the
769supplied address are shown.
770.\"
771.Pp
772.It Ic show Cm inpcb Ar addr
773Show information on IP Control Block
774.Vt struct in_pcb
775present at
776.Ar addr .
777.\"
778.Pp
779.It Ic show Cm intr
780Dump information about interrupt handlers.
781.\"
782.Pp
783.It Ic show Cm intrcnt
784Dump the interrupt statistics.
785.\"
786.Pp
787.It Ic show Cm irqs
788Show interrupt lines and their respective kernel threads.
789.\"
790.Pp
791.It Ic show Cm ktr Ns Op Li / Ns Cm a Ns Cm v Ns Cm V
792Print the contents of the
793.Xr ktr 4
794trace buffer.
795The
796.Cm v
797modifier will request fully verbose output, causing the file, line number, and
798timestamp to be printed for each trace entry.
799The
800.Cm V
801modifier will request only the timestamps to be printed.
802The
803.Cm a
804modifier will request that the output be unpaginated.
805.\"
806.Pp
807.It Ic show Cm lapic
808Show information from the local APIC registers for this CPU.
809.\"
810.Pp
811.It Ic show Cm lock Ar addr
812Show lock structure.
813The output format is as follows:
814.Bl -tag -width "flags"
815.It Ic class :
816Class of the lock.
817Possible types include
818.Xr mutex 9 ,
819.Xr rmlock 9 ,
820.Xr rwlock 9 ,
821.Xr sx 9 .
822.It Ic name :
823Name of the lock.
824.It Ic flags :
825Flags passed to the lock initialization function.
826.Em flags
827values are lock class specific.
828.It Ic state :
829Current state of a lock.
830.Em state
831values are lock class specific.
832.It Ic owner :
833Lock owner.
834.El
835.\"
836.Pp
837.It Ic show Cm lockchain Ar addr
838Show all threads a particular thread at address
839.Ar addr
840is waiting on based on non-spin locks.
841.\"
842.Pp
843.It Ic show Cm lockedbufs
844Show the same information as "show buf", but for every locked
845.Vt struct buf
846object.
847.\"
848.Pp
849.It Ic show Cm lockedvnods
850List all locked vnodes in the system.
851.\"
852.Pp
853.It Ic show Cm locks
854Prints all locks that are currently acquired.
855This command is only available if
856.Xr witness 4
857is included in the kernel.
858.\"
859.Pp
860.It Ic show Cm locktree
861.\"
862.Pp
863.It Ic show Cm malloc Ns Op Li / Ns Cm i
864Prints
865.Xr malloc 9
866memory allocator statistics.
867If the
868.Cm i
869modifier is specified, format output as machine-parseable comma-separated
870values ("CSV").
871The output columns are as follows:
872.Pp
873.Bl -tag -compact -offset indent -width "Requests"
874.It Ic Type
875Specifies a type of memory.
876It is the same as a description string used while defining the
877given memory type with
878.Xr MALLOC_DECLARE 9 .
879.It Ic InUse
880Number of memory allocations of the given type, for which
881.Xr free 9
882has not been called yet.
883.It Ic MemUse
884Total memory consumed by the given allocation type.
885.It Ic Requests
886Number of memory allocation requests for the given
887memory type.
888.El
889.Pp
890The same information can be gathered in userspace with
891.Dq Nm vmstat Fl m .
892.\"
893.Pp
894.It Ic show Cm map Ns Oo Li / Ns Cm f Oc Ar addr
895Prints the VM map at
896.Ar addr .
897If the
898.Cm f
899modifier is specified the
900complete map is printed.
901.\"
902.Pp
903.It Ic show Cm msgbuf
904Print the system's message buffer.
905It is the same output as in the
906.Dq Nm dmesg
907case.
908It is useful if you got a kernel panic, attached a serial cable
909to the machine and want to get the boot messages from before the
910system hang.
911.\"
912.Pp
913.It Ic show Cm mount Op Ar addr
914Displays details about the mount point located at
915.Ar addr .
916If no
917.Ar addr
918is specified,
919displays short info about all currently mounted file systems.
920.\"
921.Pp
922.It Ic show Cm object Ns Oo Li / Ns Cm f Oc Ar addr
923Prints the VM object at
924.Ar addr .
925If the
926.Cm f
927option is specified the
928complete object is printed.
929.\"
930.Pp
931.It Ic show Cm panic
932Print the panic message if set.
933.\"
934.Pp
935.It Ic show Cm page
936Show statistics on VM pages.
937.\"
938.Pp
939.It Ic show Cm pageq
940Show statistics on VM page queues.
941.\"
942.Pp
943.It Ic show Cm pciregs
944Print PCI bus registers.
945The same information can be gathered in userspace by running
946.Dq Nm pciconf Fl lv .
947.\"
948.Pp
949.It Ic show Cm pcpu
950Print current processor state.
951The output format is as follows:
952.Pp
953.Bl -tag -compact -offset indent -width "spin locks held:"
954.It Ic cpuid
955Processor identifier.
956.It Ic curthread
957Thread pointer, process identifier and the name of the process.
958.It Ic curpcb
959Control block pointer.
960.It Ic fpcurthread
961FPU thread pointer.
962.It Ic idlethread
963Idle thread pointer.
964.It Ic APIC ID
965CPU identifier coming from APIC.
966.It Ic currentldt
967LDT pointer.
968.It Ic spin locks held
969Names of spin locks held.
970.El
971.\"
972.Pp
973.It Ic show Cm pgrpdump
974Dump process groups present within the system.
975.\"
976.Pp
977.It Ic show Cm prison Op Ar addr
978Show the prison structure located at
979.Ar addr .
980If no
981.Ar addr
982argument is specified, show information about all prisons in the system.
983.\"
984.Pp
985.It Ic show Cm proc Op Ar addr
986Show information about the process structure located at address
987.Ar addr ,
988or the current process if no argument is specified.
989.\"
990.Pp
991.It Ic show Cm procvm Op Ar addr
992Show process virtual memory layout for the process located at
993.Ar addr ,
994or the current process if no argument is specified.
995.\"
996.Pp
997.It Ic show Cm protosw Ar addr
998Print protocol switch structure
999.Vt struct protosw
1000at address
1001.Ar addr .
1002.\"
1003.Pp
1004.It Ic show Cm registers Ns Op Li / Ns Cm u
1005Display the register set.
1006If the
1007.Cm u
1008modifier is specified, the register contents of the thread's previous
1009trapframe are displayed instead.
1010Usually, this corresponds to the saved state from userspace.
1011.\"
1012.Pp
1013.It Ic show Cm rman Ar addr
1014Show resource manager object
1015.Vt struct rman
1016at address
1017.Ar addr .
1018Addresses of particular pointers can be gathered with "show allrman"
1019command.
1020.\"
1021.Pp
1022.It Ic show Cm route Ar addr
1023Show route table result for destination
1024.Ar addr .
1025At this time, INET and INET6 formatted addresses are supported.
1026.\"
1027.Pp
1028.It Ic show Cm routetable Oo Ar af Oc
1029Show full route table or tables.
1030If
1031.Ar af
1032is specified, show only routes for the given numeric address family.
1033If no argument is specified, dump the route table for all address families.
1034.\"
1035.Pp
1036.It Ic show Cm rtc
1037Show real time clock value.
1038Useful for long debugging sessions.
1039.\"
1040.Pp
1041.It Ic show Cm sleepchain
1042Deprecated.
1043Now an alias for
1044.Ic show Cm lockchain .
1045.\"
1046.Pp
1047.It Ic show Cm sleepq Ar addr
1048.It Ic show Cm sleepqueue Ar addr
1049Show the
1050.Xr sleepqueue 9
1051structure located at
1052.Ar addr .
1053.\"
1054.Pp
1055.It Ic show Cm sockbuf Ar addr
1056Show the socket buffer
1057.Va struct sockbuf
1058located at
1059.Ar addr .
1060.\"
1061.Pp
1062.It Ic show Cm socket Ar addr
1063Show the socket object
1064.Vt struct socket
1065located at
1066.Ar addr .
1067.\"
1068.Pp
1069.It Ic show Cm sysregs
1070Show system registers (e.g.,
1071.Li cr0-4
1072on i386.)
1073Not present on some platforms.
1074.\"
1075.Pp
1076.It Ic show Cm tcpcb Ar addr
1077Print TCP control block
1078.Vt struct tcpcb
1079lying at address
1080.Ar addr .
1081For exact interpretation of output, visit
1082.Pa netinet/tcp.h
1083header file.
1084.\"
1085.Pp
1086.It Ic show Cm thread Op Ar addr | tid
1087If no
1088.Ar addr
1089or
1090.Ar tid
1091is specified, show detailed information about current thread.
1092Otherwise, print information about the thread with ID
1093.Ar tid
1094or kernel address
1095.Ar addr .
1096(If the argument is a decimal number, it is assumed to be a tid.)
1097.\"
1098.Pp
1099.It Ic show Cm threads
1100Show all threads within the system.
1101Output format is as follows:
1102.Pp
1103.Bl -tag -compact -offset indent -width "Second column"
1104.It Ic First column
1105Thread identifier (TID)
1106.It Ic Second column
1107Thread structure address
1108.It Ic Third column
1109Backtrace.
1110.El
1111.\"
1112.Pp
1113.It Ic show Cm tty Ar addr
1114Display the contents of a TTY structure in a readable form.
1115.\"
1116.Pp
1117.It Ic show Cm turnstile Ar addr
1118Show turnstile
1119.Vt struct turnstile
1120structure at address
1121.Ar addr .
1122Turnstiles are structures used within the
1123.Fx
1124kernel to implement
1125synchronization primitives which, while holding a specific type of lock, cannot
1126sleep or context switch to another thread.
1127Currently, those are:
1128.Xr mutex 9 ,
1129.Xr rwlock 9 ,
1130.Xr rmlock 9 .
1131.\"
1132.Pp
1133.It Ic show Cm uma Ns Op Li / Ns Cm i
1134Show UMA allocator statistics.
1135If the
1136.Cm i
1137modifier is specified, format output as machine-parseable comma-separated
1138values ("CSV").
1139The output contains the following columns:
1140.Pp
1141.Bl -tag -compact -offset indent -width "Total Mem"
1142.It Cm "Zone"
1143Name of the UMA zone.
1144The same string that was passed to
1145.Xr uma_zcreate 9
1146as a first argument.
1147.It Cm "Size"
1148Size of a given memory object (slab).
1149.It Cm "Used"
1150Number of slabs being currently used.
1151.It Cm "Free"
1152Number of free slabs within the UMA zone.
1153.It Cm "Requests"
1154Number of allocations requests to the given zone.
1155.It Cm "Total Mem"
1156Total memory in use (either allocated or free) by a zone, in bytes.
1157.It Cm "XFree"
1158Number of free slabs within the UMA zone that were freed on a different NUMA
1159domain than allocated.
1160(The count in the
1161.Cm "Free"
1162column is inclusive of
1163.Cm "XFree" . )
1164.El
1165.Pp
1166The same information might be gathered in the userspace
1167with the help of
1168.Dq Nm vmstat Fl z .
1169.\"
1170.Pp
1171.It Ic show Cm unpcb Ar addr
1172Shows UNIX domain socket private control block
1173.Vt struct unpcb
1174present at the address
1175.Ar addr .
1176.\"
1177.Pp
1178.It Ic show Cm vmochk
1179Prints, whether the internal VM objects are in a map somewhere
1180and none have zero ref counts.
1181.\"
1182.Pp
1183.It Ic show Cm vmopag
1184Walk the list of VM objects in the system, printing the indices and physical
1185addresses of the VM pages belonging to each object.
1186.\"
1187.Pp
1188.It Ic show Cm vnet Ar addr
1189Prints virtualized network stack
1190.Vt struct vnet
1191structure present at the address
1192.Ar addr .
1193.\"
1194.Pp
1195.It Ic show Cm vnode Ar addr
1196Prints vnode
1197.Vt struct vnode
1198structure lying at
1199.Ar addr .
1200For the exact interpretation of the output, look at the
1201.Pa sys/vnode.h
1202header file.
1203.\"
1204.Pp
1205.It Ic show Cm vnodebufs Ar addr
1206Shows clean/dirty buffer lists of the vnode located at
1207.Ar addr .
1208.\"
1209.Pp
1210.It Ic show Cm vpath Ar addr
1211Walk the namecache to lookup the pathname of the vnode located at
1212.Ar addr .
1213.\"
1214.Pp
1215.It Ic show Cm watches
1216Displays all watchpoints.
1217Shows watchpoints set with "watch" command.
1218.\"
1219.Pp
1220.It Ic show Cm witness
1221Shows information about lock acquisition coming from the
1222.Xr witness 4
1223subsystem.
1224.El
1225.Ss OFFLINE DEBUGGING COMMANDS
1226.Bl -tag -width indent -compact
1227.It Ic dump
1228Initiate a kernel core dump to the device(s) configured by
1229.Xr dumpon 8 .
1230.Pp
1231.It Ic gdb
1232Switches to remote GDB mode.
1233In remote GDB mode, another machine is required that runs
1234.Xr gdb 1 Pq Pa ports/devel/gdb
1235using the remote debug feature, with a connection to the serial
1236console port on the target machine.
1237.Pp
1238.It Ic netdump Fl s Ar server Oo Fl g Ar gateway Fl c Ar client Fl i Ar iface Oc
1239Configure
1240.Xr netdump 4
1241with the provided parameters, and immediately perform a netdump.
1242.Pp
1243There are some known limitations.
1244Principally,
1245.Xr netdump 4
1246only supports IPv4 at this time.
1247The address arguments to the
1248.Ic netdump
1249command must be dotted decimal IPv4 addresses.
1250(Hostnames are not supported.)
1251At present, the command only works if the machine is in a panic state.
1252Finally, the
1253.Nm
1254.Ic netdump
1255command does not provide any way to configure compression or encryption.
1256.Pp
1257.It Ic netgdb Fl s Ar server Oo Fl g Ar gateway Fl c Ar client Fl i Ar iface Oc
1258Initiate a
1259.Xr netgdb 4
1260session with the provided parameters.
1261.Pp
1262.Ic netgdb
1263has identical limitations to
1264.Ic netdump .
1265.Pp
1266.It Ic capture on
1267.It Ic capture off
1268.It Ic capture reset
1269.It Ic capture status
1270.Nm
1271supports a basic output capture facility, which can be used to retrieve the
1272results of debugging commands from userspace using
1273.Xr sysctl 3 .
1274.Ic capture on
1275enables output capture;
1276.Ic capture off
1277disables capture.
1278.Ic capture reset
1279will clear the capture buffer and disable capture.
1280.Ic capture status
1281will report current buffer use, buffer size, and disposition of output
1282capture.
1283.Pp
1284Userspace processes may inspect and manage
1285.Nm
1286capture state using
1287.Xr sysctl 8 :
1288.Pp
1289.Va debug.ddb.capture.bufsize
1290may be used to query or set the current capture buffer size.
1291.Pp
1292.Va debug.ddb.capture.maxbufsize
1293may be used to query the compile-time limit on the capture buffer size.
1294.Pp
1295.Va debug.ddb.capture.bytes
1296may be used to query the number of bytes of output currently in the capture
1297buffer.
1298.Pp
1299.Va debug.ddb.capture.data
1300returns the contents of the buffer as a string to an appropriately privileged
1301process.
1302.Pp
1303This facility is particularly useful in concert with the scripting and
1304.Xr textdump 4
1305facilities, allowing scripted debugging output to be captured and
1306committed to disk as part of a textdump for later analysis.
1307The contents of the capture buffer may also be inspected in a kernel core dump
1308using
1309.Xr kgdb 1 Pq Pa ports/devel/gdb .
1310.Pp
1311.It Ic run
1312.It Ic script
1313.It Ic scripts
1314.It Ic unscript
1315Run, define, list, and delete scripts.
1316See the
1317.Sx SCRIPTING
1318section for more information on the scripting facility.
1319.Pp
1320.It Ic textdump dump
1321.It Ic textdump set
1322.It Ic textdump status
1323.It Ic textdump unset
1324Use the
1325.Ic textdump dump
1326command to immediately perform a textdump.
1327More information may be found in
1328.Xr textdump 4 .
1329The
1330.Ic textdump set
1331command may be used to force the next kernel core dump to be a textdump
1332rather than a traditional memory dump or minidump.
1333.Ic textdump status
1334reports whether a textdump has been scheduled.
1335.Ic textdump unset
1336cancels a request to perform a textdump as the next kernel core dump.
1337.El
1338.Sh VARIABLES
1339The debugger accesses registers and variables as
1340.Li $ Ns Ar name .
1341Register names are as in the
1342.Dq Ic show Cm registers
1343command.
1344Some variables are suffixed with numbers, and may have some modifier
1345following a colon immediately after the variable name.
1346For example, register variables can have a
1347.Cm u
1348modifier to indicate user register (e.g.,
1349.Dq Li $eax:u ) .
1350.Pp
1351Built-in variables currently supported are:
1352.Pp
1353.Bl -tag -width ".Va tabstops" -compact
1354.It Va radix
1355Input and output radix.
1356.It Va maxoff
1357Addresses are printed as
1358.Dq Ar symbol Ns Li + Ns Ar offset
1359unless
1360.Ar offset
1361is greater than
1362.Va maxoff .
1363.It Va maxwidth
1364The width of the displayed line.
1365.It Va lines
1366The number of lines.
1367It is used by the built-in pager.
1368Setting it to 0 disables paging.
1369.It Va tabstops
1370Tab stop width.
1371.It Va work Ns Ar xx
1372Work variable;
1373.Ar xx
1374can take values from 0 to 31.
1375.El
1376.Sh EXPRESSIONS
1377Most expression operators in C are supported except
1378.Ql ~ ,
1379.Ql ^ ,
1380and unary
1381.Ql & .
1382Special rules in
1383.Nm
1384are:
1385.Bl -tag -width ".No Identifiers"
1386.It Identifiers
1387The name of a symbol is translated to the value of the symbol, which
1388is the address of the corresponding object.
1389.Ql \&.
1390and
1391.Ql \&:
1392can be used in the identifier.
1393If supported by an object format dependent routine,
1394.Sm off
1395.Oo Ar filename : Oc Ar func : lineno ,
1396.Sm on
1397.Oo Ar filename : Oc Ns Ar variable ,
1398and
1399.Oo Ar filename : Oc Ns Ar lineno
1400can be accepted as a symbol.
1401.It Numbers
1402Radix is determined by the first two letters:
1403.Ql 0x :
1404hex,
1405.Ql 0o :
1406octal,
1407.Ql 0t :
1408decimal; otherwise, follow current radix.
1409.It Li \&.
1410.Va dot
1411.It Li +
1412.Va next
1413.It Li ..
1414address of the start of the last line examined.
1415Unlike
1416.Va dot
1417or
1418.Va next ,
1419this is only changed by
1420.Ic examine
1421or
1422.Ic write
1423command.
1424.It Li '
1425last address explicitly specified.
1426.It Li $ Ns Ar variable
1427Translated to the value of the specified variable.
1428It may be followed by a
1429.Ql \&:
1430and modifiers as described above.
1431.It Ar a Ns Li # Ns Ar b
1432A binary operator which rounds up the left hand side to the next
1433multiple of right hand side.
1434.It Li * Ns Ar expr
1435Indirection.
1436It may be followed by a
1437.Ql \&:
1438and modifiers as described above.
1439.El
1440.Sh SCRIPTING
1441.Nm
1442supports a basic scripting facility to allow automating tasks or responses to
1443specific events.
1444Each script consists of a list of DDB commands to be executed sequentially,
1445and is assigned a unique name.
1446Certain script names have special meaning, and will be automatically run on
1447various
1448.Nm
1449events if scripts by those names have been defined.
1450.Pp
1451The
1452.Ic script
1453command may be used to define a script by name.
1454Scripts consist of a series of
1455.Nm
1456commands separated with the
1457.Ql \&;
1458character.
1459For example:
1460.Bd -literal -offset indent
1461script kdb.enter.panic=bt; show pcpu
1462script lockinfo=show alllocks; show lockedvnods
1463.Ed
1464.Pp
1465The
1466.Ic scripts
1467command lists currently defined scripts.
1468.Pp
1469The
1470.Ic run
1471command execute a script by name.
1472For example:
1473.Bd -literal -offset indent
1474run lockinfo
1475.Ed
1476.Pp
1477The
1478.Ic unscript
1479command may be used to delete a script by name.
1480For example:
1481.Bd -literal -offset indent
1482unscript kdb.enter.panic
1483.Ed
1484.Pp
1485These functions may also be performed from userspace using the
1486.Xr ddb 8
1487command.
1488.Pp
1489Certain scripts are run automatically, if defined, for specific
1490.Nm
1491events.
1492The follow scripts are run when various events occur:
1493.Bl -tag -width kdb.enter.powerfail
1494.It Va kdb.enter.acpi
1495The kernel debugger was entered as a result of an
1496.Xr acpi 4
1497event.
1498.It Va kdb.enter.bootflags
1499The kernel debugger was entered at boot as a result of the debugger boot
1500flag being set.
1501.It Va kdb.enter.break
1502The kernel debugger was entered as a result of a serial or console break.
1503.It Va kdb.enter.cam
1504The kernel debugger was entered as a result of a
1505.Xr CAM 4
1506event.
1507.It Va kdb.enter.mac
1508The kernel debugger was entered as a result of an assertion failure in the
1509.Xr mac_test 4
1510module of the
1511TrustedBSD MAC Framework.
1512.It Va kdb.enter.netgraph
1513The kernel debugger was entered as a result of a
1514.Xr netgraph 4
1515event.
1516.It Va kdb.enter.panic
1517.Xr panic 9
1518was called.
1519.It Va kdb.enter.powerpc
1520The kernel debugger was entered as a result of an unimplemented interrupt
1521type on the powerpc platform.
1522.It Va kdb.enter.sysctl
1523The kernel debugger was entered as a result of the
1524.Va debug.kdb.enter
1525sysctl being set.
1526.It Va kdb.enter.unionfs
1527The kernel debugger was entered as a result of an assertion failure in the
1528union file system.
1529.It Va kdb.enter.unknown
1530The kernel debugger was entered, but no reason has been set.
1531.It Va kdb.enter.vfslock
1532The kernel debugger was entered as a result of a VFS lock violation.
1533.It Va kdb.enter.watchdog
1534The kernel debugger was entered as a result of a watchdog firing.
1535.It Va kdb.enter.witness
1536The kernel debugger was entered as a result of a
1537.Xr witness 4
1538violation.
1539.El
1540.Pp
1541In the event that none of these scripts is found,
1542.Nm
1543will attempt to execute a default script:
1544.Bl -tag -width kdb.enter.powerfail
1545.It Va kdb.enter.default
1546The kernel debugger was entered, but a script exactly matching the reason for
1547entering was not defined.
1548This can be used as a catch-all to handle cases not specifically of interest;
1549for example,
1550.Va kdb.enter.witness
1551might be defined to have special handling, and
1552.Va kdb.enter.default
1553might be defined to simply panic and reboot.
1554.El
1555.Sh HINTS
1556On machines with an ISA expansion bus, a simple NMI generation card can be
1557constructed by connecting a push button between the A01 and B01 (CHCHK# and
1558GND) card fingers.
1559Momentarily shorting these two fingers together may cause the bridge chipset to
1560generate an NMI, which causes the kernel to pass control to
1561.Nm .
1562Some bridge chipsets do not generate a NMI on CHCHK#, so your mileage may vary.
1563The NMI allows one to break into the debugger on a wedged machine to
1564diagnose problems.
1565Other bus' bridge chipsets may be able to generate NMI using bus specific
1566methods.
1567There are many PCI and PCIe add-in cards which can generate NMI for
1568debugging.
1569Modern server systems typically use IPMI to generate signals to enter the
1570debugger.
1571The
1572.Va devel/ipmitool
1573port can be used to send the
1574.Cd chassis power diag
1575command which delivers an NMI to the processor.
1576Embedded systems often use JTAG for debugging, but rarely use it in
1577combination with
1578.Nm .
1579.Pp
1580Serial consoles can break to the debugger by sending a BREAK
1581condition on the serial line.
1582This requires a kernel built with
1583.Cd options BREAK_TO_DEBUGGER
1584is specified in the kernel.
1585Most terminal emulation programs can send a break sequence with a
1586special key sequence or menu selection.
1587Sending the break can be difficult or even happen spuriously in some setups.
1588An alternative method is to build a kernel with
1589.Cd options ALT_BREAK_TO_DEBUGGER
1590then the sequence of CR TILDE CTRL-B enters the debugger;
1591CR TILDE CTRL-P causes a panic; and
1592CR TILDE CTRL-R causes an immediate reboot.
1593In all these sequences, CR represents Carriage Return and is usually
1594sent by pressing the Enter or Return key.
1595TILDE is the ASCII tilde character (~).
1596CTRL-x is Control x, sent by pressing the Control key, then x, then releasing
1597both.
1598.Pp
1599The break-to-debugger behavior can be enabled by setting
1600.Xr sysctl 8
1601.Va debug.kdb.break_to_debugger
1602to 1.
1603The alt-break-to-debugger behavior can be enabled by setting
1604.Xr sysctl 8
1605.Va debug.kdb.alt_break_to_debugger
1606to 1.
1607The debugger can be entered by setting
1608.Xr sysctl 8
1609.Va debug.kdb.enter
1610to 1.
1611.Pp
1612Output can be interrupted, paused, and resumed with the control
1613characters CTRL-C, CTRL-S, and CTRL-Q.
1614Because these control characters are received as in-band data from the
1615console, there is an input buffer, and once that buffer fills
1616.Nm
1617must either stop responding to control characters or drop additional
1618input while continuing to search for control characters.
1619This behavior is controlled by the tunable
1620.Xr sysctl 8
1621.Va debug.ddb.prioritize_control_input ,
1622which defaults to 1.
1623The input buffer size is 512 bytes.
1624.Sh FILES
1625Header files mentioned in this manual page can be found below
1626.Pa /usr/include
1627directory.
1628.Pp
1629.Bl -dash -compact
1630.It
1631.Pa sys/buf.h
1632.It
1633.Pa sys/domain.h
1634.It
1635.Pa netinet/in_pcb.h
1636.It
1637.Pa sys/socket.h
1638.It
1639.Pa sys/vnode.h
1640.El
1641.Sh SEE ALSO
1642.Xr gdb 1 Pq Pa ports/devel/gdb ,
1643.Xr kgdb 1 Pq Pa ports/devel/gdb ,
1644.Xr acpi 4 ,
1645.Xr CAM 4 ,
1646.Xr gdb 4 ,
1647.Xr mac_ddb 4 ,
1648.Xr mac_test 4 ,
1649.Xr netgraph 4 ,
1650.Xr textdump 4 ,
1651.Xr witness 4 ,
1652.Xr ddb 8 ,
1653.Xr sysctl 8 ,
1654.Xr panic 9
1655.Sh HISTORY
1656The
1657.Nm
1658debugger was developed for Mach, and ported to
1659.Bx 386 0.1 .
1660This manual page translated from
1661.Xr man 7
1662macros by
1663.An Garrett Wollman .
1664.Pp
1665.An Robert N. M. Watson
1666added support for
1667.Nm
1668output capture,
1669.Xr textdump 4
1670and scripting in
1671.Fx 7.1 .
1672