xref: /freebsd/share/man/man4/ddb.4 (revision 94f6ee56e316be5648054e15f58dde9bd2c1c2c6)
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 Ic reboot Op Ar seconds
528.It Ic reset Op Ar seconds
529Hard reset the system.
530If the optional argument
531.Ar seconds
532is given, the debugger will wait for this long, at most a week,
533before rebooting.
534.Pp
535.It Ic thread Ar addr | tid
536Switch the debugger to the thread with ID
537.Ar tid ,
538if the argument is a decimal number, or address
539.Ar addr ,
540otherwise.
541.El
542.Ss SPECIALIZED HELPER COMMANDS
543.Bl -tag -width indent -compact
544.It Xo
545.Ic findstack
546.Ar addr
547.Xc
548Prints the address of the thread whose kernel-mode stack contains
549.Ar addr ,
550if any.
551.Pp
552.It Ic show Cm all procs Ns Op Li / Ns Cm a
553.It Ic ps Ns Op Li / Ns Cm a
554Display all process information.
555The process information may not be shown if it is not
556supported in the machine, or the bottom of the stack of the
557target process is not in the main memory at that time.
558The
559.Cm a
560modifier will print command line arguments for each process.
561.\"
562.Pp
563.It Ic show Cm all trace
564.It Ic alltrace
565Show a stack trace for every thread in the system.
566.Pp
567.It Ic show Cm all ttys
568Show all TTY's within the system.
569Output is similar to
570.Xr pstat 8 ,
571but also includes the address of the TTY structure.
572.\"
573.Pp
574.It Ic show Cm all vnets
575Show the same output as "show vnet" does, but lists all
576virtualized network stacks within the system.
577.\"
578.Pp
579.It Ic show Cm allchains
580Show the same information like "show lockchain" does, but
581for every thread in the system.
582.\"
583.Pp
584.It Ic show Cm alllocks
585Show all locks that are currently held.
586This command is only available if
587.Xr witness 4
588is included in the kernel.
589.\"
590.Pp
591.It Ic show Cm allpcpu
592The same as "show pcpu", but for every CPU present in the system.
593.\"
594.Pp
595.It Ic show Cm allrman
596Show information related with resource management, including
597interrupt request lines, DMA request lines, I/O ports, I/O memory
598addresses, and Resource IDs.
599.\"
600.Pp
601.It Ic show Cm apic
602Dump data about APIC IDT vector mappings.
603.\"
604.Pp
605.It Ic show Cm breaks
606Show breakpoints set with the "break" command.
607.\"
608.Pp
609.It Ic show Cm bio Ar addr
610Show information about the bio structure
611.Vt struct bio
612present at
613.Ar addr .
614See the
615.Pa sys/bio.h
616header file and
617.Xr g_bio 9
618for more details on the exact meaning of the structure fields.
619.\"
620.Pp
621.It Ic show Cm buffer Ar addr
622Show information about the buf structure
623.Vt struct buf
624present at
625.Ar addr .
626See the
627.Pa sys/buf.h
628header file for more details on the exact meaning of the structure fields.
629.\"
630.Pp
631.It Ic show Cm callout Ar addr
632Show information about the callout structure
633.Vt struct callout
634present at
635.Ar addr .
636.\"
637.Pp
638.It Ic show Cm cdev Op Ar addr
639Show the internal devfs state of the cdev structure located at
640.Ar addr .
641If no argument is provided, show the list of all created cdevs, consisting of
642the devfs node name and the
643.Vt struct cdev
644address.
645.\"
646.Pp
647.It Ic show Cm conifhk
648Lists hooks currently waiting for completion in
649.Fn run_interrupt_driven_config_hooks .
650.\"
651.Pp
652.It Ic show Cm cpusets
653Print numbered root and assigned CPU affinity sets.
654See
655.Xr cpuset 2
656for more details.
657.\"
658.Pp
659.It Ic show Cm cyrixreg
660Show registers specific to the Cyrix processor.
661.\"
662.Pp
663.It Ic show Cm devmap
664Prints the contents of the static device mapping table.
665Currently only available on the
666ARM
667architecture.
668.\"
669.Pp
670.It Ic show Cm domain Ar addr
671Print protocol domain structure
672.Vt struct domain
673at address
674.Ar addr .
675See the
676.Pa sys/domain.h
677header file for more details on the exact meaning of the structure fields.
678.\"
679.Pp
680.It Ic show Cm ffs Op Ar addr
681Show brief information about ffs mount at the address
682.Ar addr ,
683if argument is given.
684Otherwise, provides the summary about each ffs mount.
685.\"
686.Pp
687.It Ic show Cm file Ar addr
688Show information about the file structure
689.Vt struct file
690present at address
691.Ar addr .
692.\"
693.Pp
694.It Ic show Cm files
695Show information about every file structure in the system.
696.\"
697.Pp
698.It Ic show Cm freepages
699Show the number of physical pages in each of the free lists.
700.\"
701.Pp
702.It Ic show Cm geom Op Ar addr
703If the
704.Ar addr
705argument is not given, displays the entire GEOM topology.
706If
707.Ar addr
708is given, displays details about the given GEOM object (class, geom,
709provider or consumer).
710.\"
711.Pp
712.It Ic show Cm idt
713Show IDT layout.
714The first column specifies the IDT vector.
715The second one is the name of the interrupt/trap handler.
716Those functions are machine dependent.
717.\"
718.Pp
719.It Ic show Cm igi_list Ar addr
720Show information about the IGMP structure
721.Vt struct igmp_ifsoftc
722present at
723.Ar addr .
724.\"
725.Pp
726.It Ic show Cm inodedeps Op Ar addr
727Show brief information about each inodedep structure.
728If
729.Ar addr
730is given, only inodedeps belonging to the fs located at the
731supplied address are shown.
732.\"
733.Pp
734.It Ic show Cm inpcb Ar addr
735Show information on IP Control Block
736.Vt struct in_pcb
737present at
738.Ar addr .
739.\"
740.Pp
741.It Ic show Cm intr
742Dump information about interrupt handlers.
743.\"
744.Pp
745.It Ic show Cm intrcnt
746Dump the interrupt statistics.
747.\"
748.Pp
749.It Ic show Cm irqs
750Show interrupt lines and their respective kernel threads.
751.\"
752.Pp
753.It Ic show Cm lapic
754Show information from the local APIC registers for this CPU.
755.\"
756.Pp
757.It Ic show Cm lock Ar addr
758Show lock structure.
759The output format is as follows:
760.Bl -tag -width "flags"
761.It Ic class :
762Class of the lock.
763Possible types include
764.Xr mutex 9 ,
765.Xr rmlock 9 ,
766.Xr rwlock 9 ,
767.Xr sx 9 .
768.It Ic name :
769Name of the lock.
770.It Ic flags :
771Flags passed to the lock initialization function.
772.Em flags
773values are lock class specific.
774.It Ic state :
775Current state of a lock.
776.Em state
777values are lock class specific.
778.It Ic owner :
779Lock owner.
780.El
781.\"
782.Pp
783.It Ic show Cm lockchain Ar addr
784Show all threads a particular thread at address
785.Ar addr
786is waiting on based on non-spin locks.
787.\"
788.Pp
789.It Ic show Cm lockedbufs
790Show the same information as "show buf", but for every locked
791.Vt struct buf
792object.
793.\"
794.Pp
795.It Ic show Cm lockedvnods
796List all locked vnodes in the system.
797.\"
798.Pp
799.It Ic show Cm locks
800Prints all locks that are currently acquired.
801This command is only available if
802.Xr witness 4
803is included in the kernel.
804.\"
805.Pp
806.It Ic show Cm locktree
807.\"
808.Pp
809.It Ic show Cm malloc Ns Op Li / Ns Cm i
810Prints
811.Xr malloc 9
812memory allocator statistics.
813If the
814.Cm i
815modifier is specified, format output as machine-parseable comma-separated
816values ("CSV").
817The output columns are as follows:
818.Pp
819.Bl -tag -compact -offset indent -width "Requests"
820.It Ic Type
821Specifies a type of memory.
822It is the same as a description string used while defining the
823given memory type with
824.Xr MALLOC_DECLARE 9 .
825.It Ic InUse
826Number of memory allocations of the given type, for which
827.Xr free 9
828has not been called yet.
829.It Ic MemUse
830Total memory consumed by the given allocation type.
831.It Ic Requests
832Number of memory allocation requests for the given
833memory type.
834.El
835.Pp
836The same information can be gathered in userspace with
837.Dq Nm vmstat Fl m .
838.\"
839.Pp
840.It Ic show Cm map Ns Oo Li / Ns Cm f Oc Ar addr
841Prints the VM map at
842.Ar addr .
843If the
844.Cm f
845modifier is specified the
846complete map is printed.
847.\"
848.Pp
849.It Ic show Cm msgbuf
850Print the system's message buffer.
851It is the same output as in the
852.Dq Nm dmesg
853case.
854It is useful if you got a kernel panic, attached a serial cable
855to the machine and want to get the boot messages from before the
856system hang.
857.\"
858.Pp
859.It Ic show Cm mount Op Ar addr
860Displays details about the mount point located at
861.Ar addr .
862If no
863.Ar addr
864is specified,
865displays short info about all currently mounted file systems.
866.\"
867.Pp
868.It Ic show Cm object Ns Oo Li / Ns Cm f Oc Ar addr
869Prints the VM object at
870.Ar addr .
871If the
872.Cm f
873option is specified the
874complete object is printed.
875.\"
876.Pp
877.It Ic show Cm panic
878Print the panic message if set.
879.\"
880.Pp
881.It Ic show Cm page
882Show statistics on VM pages.
883.\"
884.Pp
885.It Ic show Cm pageq
886Show statistics on VM page queues.
887.\"
888.Pp
889.It Ic show Cm pciregs
890Print PCI bus registers.
891The same information can be gathered in userspace by running
892.Dq Nm pciconf Fl lv .
893.\"
894.Pp
895.It Ic show Cm pcpu
896Print current processor state.
897The output format is as follows:
898.Pp
899.Bl -tag -compact -offset indent -width "spin locks held:"
900.It Ic cpuid
901Processor identifier.
902.It Ic curthread
903Thread pointer, process identifier and the name of the process.
904.It Ic curpcb
905Control block pointer.
906.It Ic fpcurthread
907FPU thread pointer.
908.It Ic idlethread
909Idle thread pointer.
910.It Ic APIC ID
911CPU identifier coming from APIC.
912.It Ic currentldt
913LDT pointer.
914.It Ic spin locks held
915Names of spin locks held.
916.El
917.\"
918.Pp
919.It Ic show Cm pgrpdump
920Dump process groups present within the system.
921.\"
922.Pp
923.It Ic show Cm prison Op Ar addr
924Show the prison structure located at
925.Ar addr .
926If no
927.Ar addr
928argument is specified, show information about all prisons in the system.
929.\"
930.Pp
931.It Ic show Cm proc Op Ar addr
932Show information about the process structure located at address
933.Ar addr ,
934or the current process if no argument is specified.
935.\"
936.Pp
937.It Ic show Cm procvm Op Ar addr
938Show process virtual memory layout for the process located at
939.Ar addr ,
940or the current process if no argument is specified.
941.\"
942.Pp
943.It Ic show Cm protosw Ar addr
944Print protocol switch structure
945.Vt struct protosw
946at address
947.Ar addr .
948.\"
949.Pp
950.It Ic show Cm registers Ns Op Li / Ns Cm u
951Display the register set.
952If the
953.Cm u
954modifier is specified, the register contents of the thread's previous
955trapframe are displayed instead.
956Usually, this corresponds to the saved state from userspace.
957.\"
958.Pp
959.It Ic show Cm rman Ar addr
960Show resource manager object
961.Vt struct rman
962at address
963.Ar addr .
964Addresses of particular pointers can be gathered with "show allrman"
965command.
966.\"
967.Pp
968.It Ic show Cm route Ar addr
969Show route table result for destination
970.Ar addr .
971At this time, INET and INET6 formatted addresses are supported.
972.\"
973.Pp
974.It Ic show Cm routetable Oo Ar af Oc
975Show full route table or tables.
976If
977.Ar af
978is specified, show only routes for the given numeric address family.
979If no argument is specified, dump the route table for all address families.
980.\"
981.Pp
982.It Ic show Cm rtc
983Show real time clock value.
984Useful for long debugging sessions.
985.\"
986.Pp
987.It Ic show Cm sleepchain
988Deprecated.
989Now an alias for
990.Ic show Cm lockchain .
991.\"
992.Pp
993.It Ic show Cm sleepq Ar addr
994.It Ic show Cm sleepqueue Ar addr
995Show the
996.Xr sleepqueue 9
997structure located at
998.Ar addr .
999.\"
1000.Pp
1001.It Ic show Cm sockbuf Ar addr
1002Show the socket buffer
1003.Va struct sockbuf
1004located at
1005.Ar addr .
1006.\"
1007.Pp
1008.It Ic show Cm socket Ar addr
1009Show the socket object
1010.Vt struct socket
1011located at
1012.Ar addr .
1013.\"
1014.Pp
1015.It Ic show Cm sysregs
1016Show system registers (e.g.,
1017.Li cr0-4
1018on i386.)
1019Not present on some platforms.
1020.\"
1021.Pp
1022.It Ic show Cm tcpcb Ar addr
1023Print TCP control block
1024.Vt struct tcpcb
1025lying at address
1026.Ar addr .
1027For exact interpretation of output, visit
1028.Pa netinet/tcp.h
1029header file.
1030.\"
1031.Pp
1032.It Ic show Cm thread Op Ar addr | tid
1033If no
1034.Ar addr
1035or
1036.Ar tid
1037is specified, show detailed information about current thread.
1038Otherwise, print information about the thread with ID
1039.Ar tid
1040or kernel address
1041.Ar addr .
1042(If the argument is a decimal number, it is assumed to be a tid.)
1043.\"
1044.Pp
1045.It Ic show Cm threads
1046Show all threads within the system.
1047Output format is as follows:
1048.Pp
1049.Bl -tag -compact -offset indent -width "Second column"
1050.It Ic First column
1051Thread identifier (TID)
1052.It Ic Second column
1053Thread structure address
1054.It Ic Third column
1055Backtrace.
1056.El
1057.\"
1058.Pp
1059.It Ic show Cm tty Ar addr
1060Display the contents of a TTY structure in a readable form.
1061.\"
1062.Pp
1063.It Ic show Cm turnstile Ar addr
1064Show turnstile
1065.Vt struct turnstile
1066structure at address
1067.Ar addr .
1068Turnstiles are structures used within the
1069.Fx
1070kernel to implement
1071synchronization primitives which, while holding a specific type of lock, cannot
1072sleep or context switch to another thread.
1073Currently, those are:
1074.Xr mutex 9 ,
1075.Xr rwlock 9 ,
1076.Xr rmlock 9 .
1077.\"
1078.Pp
1079.It Ic show Cm uma Ns Op Li / Ns Cm i
1080Show UMA allocator statistics.
1081If the
1082.Cm i
1083modifier is specified, format output as machine-parseable comma-separated
1084values ("CSV").
1085The output contains the following columns:
1086.Pp
1087.Bl -tag -compact -offset indent -width "Total Mem"
1088.It Cm "Zone"
1089Name of the UMA zone.
1090The same string that was passed to
1091.Xr uma_zcreate 9
1092as a first argument.
1093.It Cm "Size"
1094Size of a given memory object (slab).
1095.It Cm "Used"
1096Number of slabs being currently used.
1097.It Cm "Free"
1098Number of free slabs within the UMA zone.
1099.It Cm "Requests"
1100Number of allocations requests to the given zone.
1101.It Cm "Total Mem"
1102Total memory in use (either allocated or free) by a zone, in bytes.
1103.It Cm "XFree"
1104Number of free slabs within the UMA zone that were freed on a different NUMA
1105domain than allocated.
1106(The count in the
1107.Cm "Free"
1108column is inclusive of
1109.Cm "XFree" . )
1110.El
1111.Pp
1112The same information might be gathered in the userspace
1113with the help of
1114.Dq Nm vmstat Fl z .
1115.\"
1116.Pp
1117.It Ic show Cm unpcb Ar addr
1118Shows UNIX domain socket private control block
1119.Vt struct unpcb
1120present at the address
1121.Ar addr .
1122.\"
1123.Pp
1124.It Ic show Cm vmochk
1125Prints, whether the internal VM objects are in a map somewhere
1126and none have zero ref counts.
1127.\"
1128.Pp
1129.It Ic show Cm vmopag
1130Walk the list of VM objects in the system, printing the indices and physical
1131addresses of the VM pages belonging to each object.
1132.\"
1133.Pp
1134.It Ic show Cm vnet Ar addr
1135Prints virtualized network stack
1136.Vt struct vnet
1137structure present at the address
1138.Ar addr .
1139.\"
1140.Pp
1141.It Ic show Cm vnode Ar addr
1142Prints vnode
1143.Vt struct vnode
1144structure lying at
1145.Ar addr .
1146For the exact interpretation of the output, look at the
1147.Pa sys/vnode.h
1148header file.
1149.\"
1150.Pp
1151.It Ic show Cm vnodebufs Ar addr
1152Shows clean/dirty buffer lists of the vnode located at
1153.Ar addr .
1154.\"
1155.Pp
1156.It Ic show Cm vpath Ar addr
1157Walk the namecache to lookup the pathname of the vnode located at
1158.Ar addr .
1159.\"
1160.Pp
1161.It Ic show Cm watches
1162Displays all watchpoints.
1163Shows watchpoints set with "watch" command.
1164.\"
1165.Pp
1166.It Ic show Cm witness
1167Shows information about lock acquisition coming from the
1168.Xr witness 4
1169subsystem.
1170.El
1171.Ss OFFLINE DEBUGGING COMMANDS
1172.Bl -tag -width indent -compact
1173.It Ic gdb
1174Switches to remote GDB mode.
1175In remote GDB mode, another machine is required that runs
1176.Xr gdb 1 Pq Pa ports/devel/gdb
1177using the remote debug feature, with a connection to the serial
1178console port on the target machine.
1179.Pp
1180.It Ic netdump Fl s Ar server Oo Fl g Ar gateway Fl c Ar client Fl i Ar iface Oc
1181Configure
1182.Xr netdump 4
1183with the provided parameters, and immediately perform a netdump.
1184.Pp
1185There are some known limitations.
1186Principally,
1187.Xr netdump 4
1188only supports IPv4 at this time.
1189The address arguments to the
1190.Ic netdump
1191command must be dotted decimal IPv4 addresses.
1192(Hostnames are not supported.)
1193At present, the command only works if the machine is in a panic state.
1194Finally, the
1195.Nm
1196.Ic netdump
1197command does not provide any way to configure compression or encryption.
1198.Pp
1199.It Ic netgdb Fl s Ar server Oo Fl g Ar gateway Fl c Ar client Fl i Ar iface Oc
1200Initiate a
1201.Xr netgdb 4
1202session with the provided parameters.
1203.Pp
1204.Ic netgdb
1205has identical limitations to
1206.Ic netdump .
1207.Pp
1208.It Ic capture on
1209.It Ic capture off
1210.It Ic capture reset
1211.It Ic capture status
1212.Nm
1213supports a basic output capture facility, which can be used to retrieve the
1214results of debugging commands from userspace using
1215.Xr sysctl 3 .
1216.Ic capture on
1217enables output capture;
1218.Ic capture off
1219disables capture.
1220.Ic capture reset
1221will clear the capture buffer and disable capture.
1222.Ic capture status
1223will report current buffer use, buffer size, and disposition of output
1224capture.
1225.Pp
1226Userspace processes may inspect and manage
1227.Nm
1228capture state using
1229.Xr sysctl 8 :
1230.Pp
1231.Va debug.ddb.capture.bufsize
1232may be used to query or set the current capture buffer size.
1233.Pp
1234.Va debug.ddb.capture.maxbufsize
1235may be used to query the compile-time limit on the capture buffer size.
1236.Pp
1237.Va debug.ddb.capture.bytes
1238may be used to query the number of bytes of output currently in the capture
1239buffer.
1240.Pp
1241.Va debug.ddb.capture.data
1242returns the contents of the buffer as a string to an appropriately privileged
1243process.
1244.Pp
1245This facility is particularly useful in concert with the scripting and
1246.Xr textdump 4
1247facilities, allowing scripted debugging output to be captured and
1248committed to disk as part of a textdump for later analysis.
1249The contents of the capture buffer may also be inspected in a kernel core dump
1250using
1251.Xr kgdb 1 Pq Pa ports/devel/gdb .
1252.Pp
1253.It Ic run
1254.It Ic script
1255.It Ic scripts
1256.It Ic unscript
1257Run, define, list, and delete scripts.
1258See the
1259.Sx SCRIPTING
1260section for more information on the scripting facility.
1261.Pp
1262.It Ic textdump dump
1263.It Ic textdump set
1264.It Ic textdump status
1265.It Ic textdump unset
1266Use the
1267.Ic textdump dump
1268command to immediately perform a textdump.
1269More information may be found in
1270.Xr textdump 4 .
1271The
1272.Ic textdump set
1273command may be used to force the next kernel core dump to be a textdump
1274rather than a traditional memory dump or minidump.
1275.Ic textdump status
1276reports whether a textdump has been scheduled.
1277.Ic textdump unset
1278cancels a request to perform a textdump as the next kernel core dump.
1279.El
1280.Sh VARIABLES
1281The debugger accesses registers and variables as
1282.Li $ Ns Ar name .
1283Register names are as in the
1284.Dq Ic show Cm registers
1285command.
1286Some variables are suffixed with numbers, and may have some modifier
1287following a colon immediately after the variable name.
1288For example, register variables can have a
1289.Cm u
1290modifier to indicate user register (e.g.,
1291.Dq Li $eax:u ) .
1292.Pp
1293Built-in variables currently supported are:
1294.Pp
1295.Bl -tag -width ".Va tabstops" -compact
1296.It Va radix
1297Input and output radix.
1298.It Va maxoff
1299Addresses are printed as
1300.Dq Ar symbol Ns Li + Ns Ar offset
1301unless
1302.Ar offset
1303is greater than
1304.Va maxoff .
1305.It Va maxwidth
1306The width of the displayed line.
1307.It Va lines
1308The number of lines.
1309It is used by the built-in pager.
1310Setting it to 0 disables paging.
1311.It Va tabstops
1312Tab stop width.
1313.It Va work Ns Ar xx
1314Work variable;
1315.Ar xx
1316can take values from 0 to 31.
1317.El
1318.Sh EXPRESSIONS
1319Most expression operators in C are supported except
1320.Ql ~ ,
1321.Ql ^ ,
1322and unary
1323.Ql & .
1324Special rules in
1325.Nm
1326are:
1327.Bl -tag -width ".No Identifiers"
1328.It Identifiers
1329The name of a symbol is translated to the value of the symbol, which
1330is the address of the corresponding object.
1331.Ql \&.
1332and
1333.Ql \&:
1334can be used in the identifier.
1335If supported by an object format dependent routine,
1336.Sm off
1337.Oo Ar filename : Oc Ar func : lineno ,
1338.Sm on
1339.Oo Ar filename : Oc Ns Ar variable ,
1340and
1341.Oo Ar filename : Oc Ns Ar lineno
1342can be accepted as a symbol.
1343.It Numbers
1344Radix is determined by the first two letters:
1345.Ql 0x :
1346hex,
1347.Ql 0o :
1348octal,
1349.Ql 0t :
1350decimal; otherwise, follow current radix.
1351.It Li \&.
1352.Va dot
1353.It Li +
1354.Va next
1355.It Li ..
1356address of the start of the last line examined.
1357Unlike
1358.Va dot
1359or
1360.Va next ,
1361this is only changed by
1362.Ic examine
1363or
1364.Ic write
1365command.
1366.It Li '
1367last address explicitly specified.
1368.It Li $ Ns Ar variable
1369Translated to the value of the specified variable.
1370It may be followed by a
1371.Ql \&:
1372and modifiers as described above.
1373.It Ar a Ns Li # Ns Ar b
1374A binary operator which rounds up the left hand side to the next
1375multiple of right hand side.
1376.It Li * Ns Ar expr
1377Indirection.
1378It may be followed by a
1379.Ql \&:
1380and modifiers as described above.
1381.El
1382.Sh SCRIPTING
1383.Nm
1384supports a basic scripting facility to allow automating tasks or responses to
1385specific events.
1386Each script consists of a list of DDB commands to be executed sequentially,
1387and is assigned a unique name.
1388Certain script names have special meaning, and will be automatically run on
1389various
1390.Nm
1391events if scripts by those names have been defined.
1392.Pp
1393The
1394.Ic script
1395command may be used to define a script by name.
1396Scripts consist of a series of
1397.Nm
1398commands separated with the
1399.Ql \&;
1400character.
1401For example:
1402.Bd -literal -offset indent
1403script kdb.enter.panic=bt; show pcpu
1404script lockinfo=show alllocks; show lockedvnods
1405.Ed
1406.Pp
1407The
1408.Ic scripts
1409command lists currently defined scripts.
1410.Pp
1411The
1412.Ic run
1413command execute a script by name.
1414For example:
1415.Bd -literal -offset indent
1416run lockinfo
1417.Ed
1418.Pp
1419The
1420.Ic unscript
1421command may be used to delete a script by name.
1422For example:
1423.Bd -literal -offset indent
1424unscript kdb.enter.panic
1425.Ed
1426.Pp
1427These functions may also be performed from userspace using the
1428.Xr ddb 8
1429command.
1430.Pp
1431Certain scripts are run automatically, if defined, for specific
1432.Nm
1433events.
1434The follow scripts are run when various events occur:
1435.Bl -tag -width kdb.enter.powerfail
1436.It Va kdb.enter.acpi
1437The kernel debugger was entered as a result of an
1438.Xr acpi 4
1439event.
1440.It Va kdb.enter.bootflags
1441The kernel debugger was entered at boot as a result of the debugger boot
1442flag being set.
1443.It Va kdb.enter.break
1444The kernel debugger was entered as a result of a serial or console break.
1445.It Va kdb.enter.cam
1446The kernel debugger was entered as a result of a
1447.Xr CAM 4
1448event.
1449.It Va kdb.enter.mac
1450The kernel debugger was entered as a result of an assertion failure in the
1451.Xr mac_test 4
1452module of the
1453TrustedBSD MAC Framework.
1454.It Va kdb.enter.netgraph
1455The kernel debugger was entered as a result of a
1456.Xr netgraph 4
1457event.
1458.It Va kdb.enter.panic
1459.Xr panic 9
1460was called.
1461.It Va kdb.enter.powerpc
1462The kernel debugger was entered as a result of an unimplemented interrupt
1463type on the powerpc platform.
1464.It Va kdb.enter.sysctl
1465The kernel debugger was entered as a result of the
1466.Va debug.kdb.enter
1467sysctl being set.
1468.It Va kdb.enter.unionfs
1469The kernel debugger was entered as a result of an assertion failure in the
1470union file system.
1471.It Va kdb.enter.unknown
1472The kernel debugger was entered, but no reason has been set.
1473.It Va kdb.enter.vfslock
1474The kernel debugger was entered as a result of a VFS lock violation.
1475.It Va kdb.enter.watchdog
1476The kernel debugger was entered as a result of a watchdog firing.
1477.It Va kdb.enter.witness
1478The kernel debugger was entered as a result of a
1479.Xr witness 4
1480violation.
1481.El
1482.Pp
1483In the event that none of these scripts is found,
1484.Nm
1485will attempt to execute a default script:
1486.Bl -tag -width kdb.enter.powerfail
1487.It Va kdb.enter.default
1488The kernel debugger was entered, but a script exactly matching the reason for
1489entering was not defined.
1490This can be used as a catch-all to handle cases not specifically of interest;
1491for example,
1492.Va kdb.enter.witness
1493might be defined to have special handling, and
1494.Va kdb.enter.default
1495might be defined to simply panic and reboot.
1496.El
1497.Sh HINTS
1498On machines with an ISA expansion bus, a simple NMI generation card can be
1499constructed by connecting a push button between the A01 and B01 (CHCHK# and
1500GND) card fingers.
1501Momentarily shorting these two fingers together may cause the bridge chipset to
1502generate an NMI, which causes the kernel to pass control to
1503.Nm .
1504Some bridge chipsets do not generate a NMI on CHCHK#, so your mileage may vary.
1505The NMI allows one to break into the debugger on a wedged machine to
1506diagnose problems.
1507Other bus' bridge chipsets may be able to generate NMI using bus specific
1508methods.
1509There are many PCI and PCIe add-in cards which can generate NMI for
1510debugging.
1511Modern server systems typically use IPMI to generate signals to enter the
1512debugger.
1513The
1514.Va devel/ipmitool
1515port can be used to send the
1516.Cd chassis power diag
1517command which delivers an NMI to the processor.
1518Embedded systems often use JTAG for debugging, but rarely use it in
1519combination with
1520.Nm .
1521.Pp
1522Serial consoles can break to the debugger by sending a BREAK
1523condition on the serial line.
1524This requires a kernel built with
1525.Cd options BREAK_TO_DEBUGGER
1526is specified in the kernel.
1527Most terminal emulation programs can send a break sequence with a
1528special key sequence or menu selection.
1529Sending the break can be difficult or even happen spuriously in some setups.
1530An alternative method is to build a kernel with
1531.Cd options ALT_BREAK_TO_DEBUGGER
1532then the sequence of CR TILDE CTRL-B enters the debugger;
1533CR TILDE CTRL-P causes a panic; and
1534CR TILDE CTRL-R causes an immediate reboot.
1535In all these sequences, CR represents Carriage Return and is usually
1536sent by pressing the Enter or Return key.
1537TILDE is the ASCII tilde character (~).
1538CTRL-x is Control x, sent by pressing the Control key, then x, then releasing
1539both.
1540.Pp
1541The break-to-debugger behavior can be enabled by setting
1542.Xr sysctl 8
1543.Va debug.kdb.break_to_debugger
1544to 1.
1545The alt-break-to-debugger behavior can be enabled by setting
1546.Xr sysctl 8
1547.Va debug.kdb.alt_break_to_debugger
1548to 1.
1549The debugger can be entered by setting
1550.Xr sysctl 8
1551.Va debug.kdb.enter
1552to 1.
1553.Pp
1554Output can be interrupted, paused, and resumed with the control
1555characters CTRL-C, CTRL-S, and CTRL-Q.
1556Because these control characters are received as in-band data from the
1557console, there is an input buffer, and once that buffer fills
1558.Nm
1559must either stop responding to control characters or drop additional
1560input while continuing to search for control characters.
1561This behavior is controlled by the tunable
1562.Xr sysctl 8
1563.Va debug.ddb.prioritize_control_input ,
1564which defaults to 1.
1565The input buffer size is 512 bytes.
1566.Sh FILES
1567Header files mentioned in this manual page can be found below
1568.Pa /usr/include
1569directory.
1570.Pp
1571.Bl -dash -compact
1572.It
1573.Pa sys/buf.h
1574.It
1575.Pa sys/domain.h
1576.It
1577.Pa netinet/in_pcb.h
1578.It
1579.Pa sys/socket.h
1580.It
1581.Pa sys/vnode.h
1582.El
1583.Sh SEE ALSO
1584.Xr gdb 1 Pq Pa ports/devel/gdb ,
1585.Xr kgdb 1 Pq Pa ports/devel/gdb ,
1586.Xr acpi 4 ,
1587.Xr CAM 4 ,
1588.Xr gdb 4 ,
1589.Xr mac_ddb 4 ,
1590.Xr mac_test 4 ,
1591.Xr netgraph 4 ,
1592.Xr textdump 4 ,
1593.Xr witness 4 ,
1594.Xr ddb 8 ,
1595.Xr sysctl 8 ,
1596.Xr panic 9
1597.Sh HISTORY
1598The
1599.Nm
1600debugger was developed for Mach, and ported to
1601.Bx 386 0.1 .
1602This manual page translated from
1603.Xr man 7
1604macros by
1605.An Garrett Wollman .
1606.Pp
1607.An Robert N. M. Watson
1608added support for
1609.Nm
1610output capture,
1611.Xr textdump 4
1612and scripting in
1613.Fx 7.1 .
1614