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