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