xref: /freebsd/share/man/man4/ddb.4 (revision 6829dae12bb055451fa467da4589c43bd03b1e64)
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 November 30, 2018
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
810Prints
811.Xr malloc 9
812memory allocator statistics.
813The output format is as follows:
814.Pp
815.Bl -tag -compact -offset indent -width "Requests"
816.It Ic Type
817Specifies a type of memory.
818It is the same as a description string used while defining the
819given memory type with
820.Xr MALLOC_DECLARE 9 .
821.It Ic InUse
822Number of memory allocations of the given type, for which
823.Xr free 9
824has not been called yet.
825.It Ic MemUse
826Total memory consumed by the given allocation type.
827.It Ic Requests
828Number of memory allocation requests for the given
829memory type.
830.El
831.Pp
832The same information can be gathered in userspace with
833.Dq Nm vmstat Fl m .
834.\"
835.Pp
836.It Ic show Cm map Ns Oo Li / Ns Cm f Oc Ar addr
837Prints the VM map at
838.Ar addr .
839If the
840.Cm f
841modifier is specified the
842complete map is printed.
843.\"
844.Pp
845.It Ic show Cm msgbuf
846Print the system's message buffer.
847It is the same output as in the
848.Dq Nm dmesg
849case.
850It is useful if you got a kernel panic, attached a serial cable
851to the machine and want to get the boot messages from before the
852system hang.
853.\"
854.It Ic show Cm mount
855Displays short info about all currently mounted file systems.
856.Pp
857.It Ic show Cm mount Ar addr
858Displays details about the given mount point.
859.\"
860.Pp
861.It Ic show Cm object Ns Oo Li / Ns Cm f Oc Ar addr
862Prints the VM object at
863.Ar addr .
864If the
865.Cm f
866option is specified the
867complete object is printed.
868.\"
869.Pp
870.It Ic show Cm panic
871Print the panic message if set.
872.\"
873.Pp
874.It Ic show Cm page
875Show statistics on VM pages.
876.\"
877.Pp
878.It Ic show Cm pageq
879Show statistics on VM page queues.
880.\"
881.Pp
882.It Ic show Cm pciregs
883Print PCI bus registers.
884The same information can be gathered in userspace by running
885.Dq Nm pciconf Fl lv .
886.\"
887.Pp
888.It Ic show Cm pcpu
889Print current processor state.
890The output format is as follows:
891.Pp
892.Bl -tag -compact -offset indent -width "spin locks held:"
893.It Ic cpuid
894Processor identifier.
895.It Ic curthread
896Thread pointer, process identifier and the name of the process.
897.It Ic curpcb
898Control block pointer.
899.It Ic fpcurthread
900FPU thread pointer.
901.It Ic idlethread
902Idle thread pointer.
903.It Ic APIC ID
904CPU identifier coming from APIC.
905.It Ic currentldt
906LDT pointer.
907.It Ic spin locks held
908Names of spin locks held.
909.El
910.\"
911.Pp
912.It Ic show Cm pgrpdump
913Dump process groups present within the system.
914.\"
915.Pp
916.It Ic show Cm proc Op Ar addr
917If no
918.Op Ar addr
919is specified, print information about the current process.
920Otherwise, show information about the process at address
921.Ar addr .
922.\"
923.Pp
924.It Ic show Cm procvm
925Show process virtual memory layout.
926.\"
927.Pp
928.It Ic show Cm protosw Ar addr
929Print protocol switch structure
930.Vt struct protosw
931at address
932.Ar addr .
933.\"
934.Pp
935.It Ic show Cm registers Ns Op Li / Ns Cm u
936Display the register set.
937If the
938.Cm u
939modifier is specified, it displays user registers instead of
940kernel registers or the currently saved one.
941.Pp
942.Sy Warning :
943The support of the
944.Cm u
945modifier depends on the machine.
946If not supported, incorrect information will be displayed.
947.\"
948.Pp
949.It Ic show Cm rman Ar addr
950Show resource manager object
951.Vt struct rman
952at address
953.Ar addr .
954Addresses of particular pointers can be gathered with "show allrman"
955command.
956.\"
957.Pp
958.It Ic show Cm rtc
959Show real time clock value.
960Useful for long debugging sessions.
961.\"
962.Pp
963.It Ic show Cm sleepchain
964Deprecated.
965Now an alias for
966.Ic show Cm lockchain .
967.\"
968.Pp
969.It Ic show Cm sleepq
970.It Ic show Cm sleepqueue
971Both commands provide the same functionality.
972They show sleepqueue
973.Vt struct sleepqueue
974structure.
975Sleepqueues are used within the
976.Fx
977kernel to implement sleepable
978synchronization primitives (thread holding a lock might sleep or
979be context switched), which at the time of writing are:
980.Xr condvar 9 ,
981.Xr sx 9
982and standard
983.Xr msleep 9
984interface.
985.\"
986.Pp
987.It Ic show Cm sockbuf Ar addr
988.It Ic show Cm socket Ar addr
989Those commands print
990.Vt struct sockbuf
991and
992.Vt struct socket
993objects placed at
994.Ar addr .
995Output consists of all values present in structures mentioned.
996For exact interpretation and more details, visit
997.Pa sys/socket.h
998header file.
999.\"
1000.Pp
1001.It Ic show Cm sysregs
1002Show system registers (e.g.,
1003.Li cr0-4
1004on i386.)
1005Not present on some platforms.
1006.\"
1007.Pp
1008.It Ic show Cm tcpcb Ar addr
1009Print TCP control block
1010.Vt struct tcpcb
1011lying at address
1012.Ar addr .
1013For exact interpretation of output, visit
1014.Pa netinet/tcp.h
1015header file.
1016.\"
1017.Pp
1018.It Ic show Cm thread Op Ar addr | tid
1019If no
1020.Ar addr
1021or
1022.Ar tid
1023is specified, show detailed information about current thread.
1024Otherwise, print information about the thread with ID
1025.Ar tid
1026or kernel address
1027.Ar addr .
1028(If the argument is a decimal number, it is assumed to be a tid.)
1029.\"
1030.Pp
1031.It Ic show Cm threads
1032Show all threads within the system.
1033Output format is as follows:
1034.Pp
1035.Bl -tag -compact -offset indent -width "Second column"
1036.It Ic First column
1037Thread identifier (TID)
1038.It Ic Second column
1039Thread structure address
1040.It Ic Third column
1041Backtrace.
1042.El
1043.\"
1044.Pp
1045.It Ic show Cm tty Ar addr
1046Display the contents of a TTY structure in a readable form.
1047.\"
1048.Pp
1049.It Ic show Cm turnstile Ar addr
1050Show turnstile
1051.Vt struct turnstile
1052structure at address
1053.Ar addr .
1054Turnstiles are structures used within the
1055.Fx
1056kernel to implement
1057synchronization primitives which, while holding a specific type of lock, cannot
1058sleep or context switch to another thread.
1059Currently, those are:
1060.Xr mutex 9 ,
1061.Xr rwlock 9 ,
1062.Xr rmlock 9 .
1063.\"
1064.Pp
1065.It Ic show Cm uma
1066Show UMA allocator statistics.
1067Output consists five columns:
1068.Pp
1069.Bl -tag -compact -offset indent -width "Requests"
1070.It Cm "Zone"
1071Name of the UMA zone.
1072The same string that was passed to
1073.Xr uma_zcreate 9
1074as a first argument.
1075.It Cm "Size"
1076Size of a given memory object (slab).
1077.It Cm "Used"
1078Number of slabs being currently used.
1079.It Cm "Free"
1080Number of free slabs within the UMA zone.
1081.It Cm "Requests"
1082Number of allocations requests to the given zone.
1083.El
1084.Pp
1085The very same information might be gathered in the userspace
1086with the help of
1087.Dq Nm vmstat Fl z .
1088.\"
1089.Pp
1090.It Ic show Cm unpcb Ar addr
1091Shows UNIX domain socket private control block
1092.Vt struct unpcb
1093present at the address
1094.Ar addr .
1095.\"
1096.Pp
1097.It Ic show Cm vmochk
1098Prints, whether the internal VM objects are in a map somewhere
1099and none have zero ref counts.
1100.\"
1101.Pp
1102.It Ic show Cm vmopag
1103This is supposed to show physical addresses consumed by a
1104VM object.
1105Currently, it is not possible to use this command when
1106.Xr witness 4
1107is compiled in the kernel.
1108.\"
1109.Pp
1110.It Ic show Cm vnet Ar addr
1111Prints virtualized network stack
1112.Vt struct vnet
1113structure present at the address
1114.Ar addr .
1115.\"
1116.Pp
1117.It Ic show Cm vnode Op Ar addr
1118Prints vnode
1119.Vt struct vnode
1120structure lying at
1121.Op Ar addr .
1122For the exact interpretation of the output, look at the
1123.Pa sys/vnode.h
1124header file.
1125.\"
1126.Pp
1127.It Ic show Cm vnodebufs Ar addr
1128Shows clean/dirty buffer lists of the vnode located at
1129.Ar addr .
1130.\"
1131.Pp
1132.It Ic show Cm vpath Ar addr
1133Walk the namecache to lookup the pathname of the vnode located at
1134.Ar addr .
1135.\"
1136.Pp
1137.It Ic show Cm watches
1138Displays all watchpoints.
1139Shows watchpoints set with "watch" command.
1140.\"
1141.Pp
1142.It Ic show Cm witness
1143Shows information about lock acquisition coming from the
1144.Xr witness 4
1145subsystem.
1146.\"
1147.Pp
1148.It Ic gdb
1149Toggles between remote GDB and DDB mode.
1150In remote GDB mode, another machine is required that runs
1151.Xr gdb 1
1152using the remote debug feature, with a connection to the serial
1153console port on the target machine.
1154Currently only available on the
1155i386
1156architecture.
1157.Pp
1158.It Ic halt
1159Halt the system.
1160.Pp
1161.It Ic kill Ar sig pid
1162Send signal
1163.Ar sig
1164to process
1165.Ar pid .
1166The signal is acted on upon returning from the debugger.
1167This command can be used to kill a process causing resource contention
1168in the case of a hung system.
1169See
1170.Xr signal 3
1171for a list of signals.
1172Note that the arguments are reversed relative to
1173.Xr kill 2 .
1174.Pp
1175.It Ic reboot Op Ar seconds
1176.It Ic reset Op Ar seconds
1177Hard reset the system.
1178If the optional argument
1179.Ar seconds
1180is given, the debugger will wait for this long, at most a week,
1181before rebooting.
1182.Pp
1183.It Ic help
1184Print a short summary of the available commands and command
1185abbreviations.
1186.Pp
1187.It Ic capture on
1188.It Ic capture off
1189.It Ic capture reset
1190.It Ic capture status
1191.Nm
1192supports a basic output capture facility, which can be used to retrieve the
1193results of debugging commands from userspace using
1194.Xr sysctl 3 .
1195.Ic capture on
1196enables output capture;
1197.Ic capture off
1198disables capture.
1199.Ic capture reset
1200will clear the capture buffer and disable capture.
1201.Ic capture status
1202will report current buffer use, buffer size, and disposition of output
1203capture.
1204.Pp
1205Userspace processes may inspect and manage
1206.Nm
1207capture state using
1208.Xr sysctl 8 :
1209.Pp
1210.Va debug.ddb.capture.bufsize
1211may be used to query or set the current capture buffer size.
1212.Pp
1213.Va debug.ddb.capture.maxbufsize
1214may be used to query the compile-time limit on the capture buffer size.
1215.Pp
1216.Va debug.ddb.capture.bytes
1217may be used to query the number of bytes of output currently in the capture
1218buffer.
1219.Pp
1220.Va debug.ddb.capture.data
1221returns the contents of the buffer as a string to an appropriately privileged
1222process.
1223.Pp
1224This facility is particularly useful in concert with the scripting and
1225.Xr textdump 4
1226facilities, allowing scripted debugging output to be captured and
1227committed to disk as part of a textdump for later analysis.
1228The contents of the capture buffer may also be inspected in a kernel core dump
1229using
1230.Xr kgdb 1 .
1231.Pp
1232.It Ic run
1233.It Ic script
1234.It Ic scripts
1235.It Ic unscript
1236Run, define, list, and delete scripts.
1237See the
1238.Sx SCRIPTING
1239section for more information on the scripting facility.
1240.Pp
1241.It Ic textdump dump
1242.It Ic textdump set
1243.It Ic textdump status
1244.It Ic textdump unset
1245Use the
1246.Ic textdump dump
1247command to immediately perform a textdump.
1248More information may be found in
1249.Xr textdump 4 .
1250The
1251.Ic textdump set
1252command may be used to force the next kernel core dump to be a textdump
1253rather than a traditional memory dump or minidump.
1254.Ic textdump status
1255reports whether a textdump has been scheduled.
1256.Ic textdump unset
1257cancels a request to perform a textdump as the next kernel core dump.
1258.Pp
1259.It Ic thread Ar addr | tid
1260Switch the debugger to the thread with ID
1261.Ar tid ,
1262if the argument is a decimal number, or address
1263.Ar addr ,
1264otherwise.
1265.El
1266.Sh VARIABLES
1267The debugger accesses registers and variables as
1268.Li $ Ns Ar name .
1269Register names are as in the
1270.Dq Ic show Cm registers
1271command.
1272Some variables are suffixed with numbers, and may have some modifier
1273following a colon immediately after the variable name.
1274For example, register variables can have a
1275.Cm u
1276modifier to indicate user register (e.g.,
1277.Dq Li $eax:u ) .
1278.Pp
1279Built-in variables currently supported are:
1280.Pp
1281.Bl -tag -width ".Va tabstops" -compact
1282.It Va radix
1283Input and output radix.
1284.It Va maxoff
1285Addresses are printed as
1286.Dq Ar symbol Ns Li + Ns Ar offset
1287unless
1288.Ar offset
1289is greater than
1290.Va maxoff .
1291.It Va maxwidth
1292The width of the displayed line.
1293.It Va lines
1294The number of lines.
1295It is used by the built-in pager.
1296Setting it to 0 disables paging.
1297.It Va tabstops
1298Tab stop width.
1299.It Va work Ns Ar xx
1300Work variable;
1301.Ar xx
1302can take values from 0 to 31.
1303.El
1304.Sh EXPRESSIONS
1305Most expression operators in C are supported except
1306.Ql ~ ,
1307.Ql ^ ,
1308and unary
1309.Ql & .
1310Special rules in
1311.Nm
1312are:
1313.Bl -tag -width ".No Identifiers"
1314.It Identifiers
1315The name of a symbol is translated to the value of the symbol, which
1316is the address of the corresponding object.
1317.Ql \&.
1318and
1319.Ql \&:
1320can be used in the identifier.
1321If supported by an object format dependent routine,
1322.Sm off
1323.Oo Ar filename : Oc Ar func : lineno ,
1324.Sm on
1325.Oo Ar filename : Oc Ns Ar variable ,
1326and
1327.Oo Ar filename : Oc Ns Ar lineno
1328can be accepted as a symbol.
1329.It Numbers
1330Radix is determined by the first two letters:
1331.Ql 0x :
1332hex,
1333.Ql 0o :
1334octal,
1335.Ql 0t :
1336decimal; otherwise, follow current radix.
1337.It Li \&.
1338.Va dot
1339.It Li +
1340.Va next
1341.It Li ..
1342address of the start of the last line examined.
1343Unlike
1344.Va dot
1345or
1346.Va next ,
1347this is only changed by
1348.Ic examine
1349or
1350.Ic write
1351command.
1352.It Li '
1353last address explicitly specified.
1354.It Li $ Ns Ar variable
1355Translated to the value of the specified variable.
1356It may be followed by a
1357.Ql \&:
1358and modifiers as described above.
1359.It Ar a Ns Li # Ns Ar b
1360A binary operator which rounds up the left hand side to the next
1361multiple of right hand side.
1362.It Li * Ns Ar expr
1363Indirection.
1364It may be followed by a
1365.Ql \&:
1366and modifiers as described above.
1367.El
1368.Sh SCRIPTING
1369.Nm
1370supports a basic scripting facility to allow automating tasks or responses to
1371specific events.
1372Each script consists of a list of DDB commands to be executed sequentially,
1373and is assigned a unique name.
1374Certain script names have special meaning, and will be automatically run on
1375various
1376.Nm
1377events if scripts by those names have been defined.
1378.Pp
1379The
1380.Ic script
1381command may be used to define a script by name.
1382Scripts consist of a series of
1383.Nm
1384commands separated with the
1385.Ql \&;
1386character.
1387For example:
1388.Bd -literal -offset indent
1389script kdb.enter.panic=bt; show pcpu
1390script lockinfo=show alllocks; show lockedvnods
1391.Ed
1392.Pp
1393The
1394.Ic scripts
1395command lists currently defined scripts.
1396.Pp
1397The
1398.Ic run
1399command execute a script by name.
1400For example:
1401.Bd -literal -offset indent
1402run lockinfo
1403.Ed
1404.Pp
1405The
1406.Ic unscript
1407command may be used to delete a script by name.
1408For example:
1409.Bd -literal -offset indent
1410unscript kdb.enter.panic
1411.Ed
1412.Pp
1413These functions may also be performed from userspace using the
1414.Xr ddb 8
1415command.
1416.Pp
1417Certain scripts are run automatically, if defined, for specific
1418.Nm
1419events.
1420The follow scripts are run when various events occur:
1421.Bl -tag -width kdb.enter.powerfail
1422.It Va kdb.enter.acpi
1423The kernel debugger was entered as a result of an
1424.Xr acpi 4
1425event.
1426.It Va kdb.enter.bootflags
1427The kernel debugger was entered at boot as a result of the debugger boot
1428flag being set.
1429.It Va kdb.enter.break
1430The kernel debugger was entered as a result of a serial or console break.
1431.It Va kdb.enter.cam
1432The kernel debugger was entered as a result of a
1433.Xr CAM 4
1434event.
1435.It Va kdb.enter.mac
1436The kernel debugger was entered as a result of an assertion failure in the
1437.Xr mac_test 4
1438module of the
1439TrustedBSD MAC Framework.
1440.It Va kdb.enter.ndis
1441The kernel debugger was entered as a result of an
1442.Xr ndis 4
1443breakpoint event.
1444.It Va kdb.enter.netgraph
1445The kernel debugger was entered as a result of a
1446.Xr netgraph 4
1447event.
1448.It Va kdb.enter.panic
1449.Xr panic 9
1450was called.
1451.It Va kdb.enter.powerfail
1452The kernel debugger was entered as a result of a powerfail NMI on the sparc64
1453platform.
1454.It Va kdb.enter.powerpc
1455The kernel debugger was entered as a result of an unimplemented interrupt
1456type on the powerpc platform.
1457.It Va kdb.enter.sysctl
1458The kernel debugger was entered as a result of the
1459.Va debug.kdb.enter
1460sysctl being set.
1461.It Va kdb.enter.trapsig
1462The kernel debugger was entered as a result of a trapsig event on the sparc64
1463platform.
1464.It Va kdb.enter.unionfs
1465The kernel debugger was entered as a result of an assertion failure in the
1466union file system.
1467.It Va kdb.enter.unknown
1468The kernel debugger was entered, but no reason has been set.
1469.It Va kdb.enter.vfslock
1470The kernel debugger was entered as a result of a VFS lock violation.
1471.It Va kdb.enter.watchdog
1472The kernel debugger was entered as a result of a watchdog firing.
1473.It Va kdb.enter.witness
1474The kernel debugger was entered as a result of a
1475.Xr witness 4
1476violation.
1477.El
1478.Pp
1479In the event that none of these scripts is found,
1480.Nm
1481will attempt to execute a default script:
1482.Bl -tag -width kdb.enter.powerfail
1483.It Va kdb.enter.default
1484The kernel debugger was entered, but a script exactly matching the reason for
1485entering was not defined.
1486This can be used as a catch-all to handle cases not specifically of interest;
1487for example,
1488.Va kdb.enter.witness
1489might be defined to have special handling, and
1490.Va kdb.enter.default
1491might be defined to simply panic and reboot.
1492.El
1493.Sh HINTS
1494On machines with an ISA expansion bus, a simple NMI generation card can be
1495constructed by connecting a push button between the A01 and B01 (CHCHK# and
1496GND) card fingers.
1497Momentarily shorting these two fingers together may cause the bridge chipset to
1498generate an NMI, which causes the kernel to pass control to
1499.Nm .
1500Some bridge chipsets do not generate a NMI on CHCHK#, so your mileage may vary.
1501The NMI allows one to break into the debugger on a wedged machine to
1502diagnose problems.
1503Other bus' bridge chipsets may be able to generate NMI using bus specific
1504methods.
1505There are many PCI and PCIe add-in cards which can generate NMI for
1506debugging.
1507Modern server systems typically use IPMI to generate signals to enter the
1508debugger.
1509The
1510.Va devel/ipmitool
1511port can be used to send the
1512.Cd chassis power diag
1513command which delivers an NMI to the processor.
1514Embedded systems often use JTAG for debugging, but rarely use it in
1515combination with
1516.Nm .
1517.Pp
1518For serial consoles, you can enter the debugger by sending a BREAK
1519condition on the serial line if
1520.Cd options BREAK_TO_DEBUGGER
1521is specified in the kernel.
1522Most terminal emulation programs can send a break sequence with a
1523special key sequence or via a menu item.
1524However, in some setups, sending the break can be difficult to arrange
1525or happens spuriously, so if the kernel contains
1526.Cd options ALT_BREAK_TO_DEBUGGER
1527then the sequence of CR TILDE CTRL-B enters the debugger;
1528CR TILDE CTRL-P causes a panic instead of entering the
1529debugger; and
1530CR TILDE CTRL-R causes an immediate reboot.
1531In all the above sequences, CR is a Carriage Return and is usually
1532sent by hitting the Enter or Return key.
1533TILDE is the ASCII tilde character (~).
1534CTRL-x is Control x created by hitting the control key and then x
1535and then releasing both.
1536.Pp
1537The break to enter the debugger behavior may be enabled at run-time
1538by setting the
1539.Xr sysctl 8
1540.Va debug.kdb.break_to_debugger
1541to 1.
1542The alternate sequence to enter the debugger behavior may be enabled
1543at run-time by setting the
1544.Xr sysctl 8
1545.Va debug.kdb.alt_break_to_debugger
1546to 1.
1547The debugger may be entered by setting the
1548.Xr sysctl 8
1549.Va debug.kdb.enter
1550to 1.
1551.Sh FILES
1552Header files mentioned in this manual page can be found below
1553.Pa /usr/include
1554directory.
1555.Pp
1556.Bl -dash -compact
1557.It
1558.Pa sys/buf.h
1559.It
1560.Pa sys/domain.h
1561.It
1562.Pa netinet/in_pcb.h
1563.It
1564.Pa sys/socket.h
1565.It
1566.Pa sys/vnode.h
1567.El
1568.Sh SEE ALSO
1569.Xr gdb 1 ,
1570.Xr kgdb 1 ,
1571.Xr acpi 4 ,
1572.Xr CAM 4 ,
1573.Xr mac_test 4 ,
1574.Xr ndis 4 ,
1575.Xr netgraph 4 ,
1576.Xr textdump 4 ,
1577.Xr witness 4 ,
1578.Xr ddb 8 ,
1579.Xr sysctl 8 ,
1580.Xr panic 9
1581.Sh HISTORY
1582The
1583.Nm
1584debugger was developed for Mach, and ported to
1585.Bx 386 0.1 .
1586This manual page translated from
1587.Xr man 7
1588macros by
1589.An Garrett Wollman .
1590.Pp
1591.An Robert N. M. Watson
1592added support for
1593.Nm
1594output capture,
1595.Xr textdump 4
1596and scripting in
1597.Fx 7.1 .
1598