xref: /freebsd/share/man/man4/ddb.4 (revision 036d2e814bf0f5d88ffb4b24c159320894541757)
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 September 9, 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
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 route Ar addr
959Show route table result for destination
960.Ar addr .
961At this time, INET and INET6 formatted addresses are supported.
962.\"
963.Pp
964.It Ic show Cm routetable Oo Ar af Oc
965Show full route table or tables.
966If
967.Ar af
968is specified, show only routes for the given numeric address family.
969If no argument is specified, dump the route table for all address families.
970.\"
971.Pp
972.It Ic show Cm rtc
973Show real time clock value.
974Useful for long debugging sessions.
975.\"
976.Pp
977.It Ic show Cm sleepchain
978Deprecated.
979Now an alias for
980.Ic show Cm lockchain .
981.\"
982.Pp
983.It Ic show Cm sleepq
984.It Ic show Cm sleepqueue
985Both commands provide the same functionality.
986They show sleepqueue
987.Vt struct sleepqueue
988structure.
989Sleepqueues are used within the
990.Fx
991kernel to implement sleepable
992synchronization primitives (thread holding a lock might sleep or
993be context switched), which at the time of writing are:
994.Xr condvar 9 ,
995.Xr sx 9
996and standard
997.Xr msleep 9
998interface.
999.\"
1000.Pp
1001.It Ic show Cm sockbuf Ar addr
1002.It Ic show Cm socket Ar addr
1003Those commands print
1004.Vt struct sockbuf
1005and
1006.Vt struct socket
1007objects placed at
1008.Ar addr .
1009Output consists of all values present in structures mentioned.
1010For exact interpretation and more details, visit
1011.Pa sys/socket.h
1012header file.
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
1080Show UMA allocator statistics.
1081Output consists five columns:
1082.Pp
1083.Bl -tag -compact -offset indent -width "Requests"
1084.It Cm "Zone"
1085Name of the UMA zone.
1086The same string that was passed to
1087.Xr uma_zcreate 9
1088as a first argument.
1089.It Cm "Size"
1090Size of a given memory object (slab).
1091.It Cm "Used"
1092Number of slabs being currently used.
1093.It Cm "Free"
1094Number of free slabs within the UMA zone.
1095.It Cm "Requests"
1096Number of allocations requests to the given zone.
1097.El
1098.Pp
1099The very same information might be gathered in the userspace
1100with the help of
1101.Dq Nm vmstat Fl z .
1102.\"
1103.Pp
1104.It Ic show Cm unpcb Ar addr
1105Shows UNIX domain socket private control block
1106.Vt struct unpcb
1107present at the address
1108.Ar addr .
1109.\"
1110.Pp
1111.It Ic show Cm vmochk
1112Prints, whether the internal VM objects are in a map somewhere
1113and none have zero ref counts.
1114.\"
1115.Pp
1116.It Ic show Cm vmopag
1117This is supposed to show physical addresses consumed by a
1118VM object.
1119Currently, it is not possible to use this command when
1120.Xr witness 4
1121is compiled in the kernel.
1122.\"
1123.Pp
1124.It Ic show Cm vnet Ar addr
1125Prints virtualized network stack
1126.Vt struct vnet
1127structure present at the address
1128.Ar addr .
1129.\"
1130.Pp
1131.It Ic show Cm vnode Op Ar addr
1132Prints vnode
1133.Vt struct vnode
1134structure lying at
1135.Op Ar addr .
1136For the exact interpretation of the output, look at the
1137.Pa sys/vnode.h
1138header file.
1139.\"
1140.Pp
1141.It Ic show Cm vnodebufs Ar addr
1142Shows clean/dirty buffer lists of the vnode located at
1143.Ar addr .
1144.\"
1145.Pp
1146.It Ic show Cm vpath Ar addr
1147Walk the namecache to lookup the pathname of the vnode located at
1148.Ar addr .
1149.\"
1150.Pp
1151.It Ic show Cm watches
1152Displays all watchpoints.
1153Shows watchpoints set with "watch" command.
1154.\"
1155.Pp
1156.It Ic show Cm witness
1157Shows information about lock acquisition coming from the
1158.Xr witness 4
1159subsystem.
1160.\"
1161.Pp
1162.It Ic gdb
1163Toggles between remote GDB and DDB mode.
1164In remote GDB mode, another machine is required that runs
1165.Xr gdb 1
1166using the remote debug feature, with a connection to the serial
1167console port on the target machine.
1168Currently only available on the
1169i386
1170architecture.
1171.Pp
1172.It Ic halt
1173Halt the system.
1174.Pp
1175.It Ic kill Ar sig pid
1176Send signal
1177.Ar sig
1178to process
1179.Ar pid .
1180The signal is acted on upon returning from the debugger.
1181This command can be used to kill a process causing resource contention
1182in the case of a hung system.
1183See
1184.Xr signal 3
1185for a list of signals.
1186Note that the arguments are reversed relative to
1187.Xr kill 2 .
1188.Pp
1189.It Ic reboot Op Ar seconds
1190.It Ic reset Op Ar seconds
1191Hard reset the system.
1192If the optional argument
1193.Ar seconds
1194is given, the debugger will wait for this long, at most a week,
1195before rebooting.
1196.Pp
1197.It Ic help
1198Print a short summary of the available commands and command
1199abbreviations.
1200.Pp
1201.It Ic capture on
1202.It Ic capture off
1203.It Ic capture reset
1204.It Ic capture status
1205.Nm
1206supports a basic output capture facility, which can be used to retrieve the
1207results of debugging commands from userspace using
1208.Xr sysctl 3 .
1209.Ic capture on
1210enables output capture;
1211.Ic capture off
1212disables capture.
1213.Ic capture reset
1214will clear the capture buffer and disable capture.
1215.Ic capture status
1216will report current buffer use, buffer size, and disposition of output
1217capture.
1218.Pp
1219Userspace processes may inspect and manage
1220.Nm
1221capture state using
1222.Xr sysctl 8 :
1223.Pp
1224.Va debug.ddb.capture.bufsize
1225may be used to query or set the current capture buffer size.
1226.Pp
1227.Va debug.ddb.capture.maxbufsize
1228may be used to query the compile-time limit on the capture buffer size.
1229.Pp
1230.Va debug.ddb.capture.bytes
1231may be used to query the number of bytes of output currently in the capture
1232buffer.
1233.Pp
1234.Va debug.ddb.capture.data
1235returns the contents of the buffer as a string to an appropriately privileged
1236process.
1237.Pp
1238This facility is particularly useful in concert with the scripting and
1239.Xr textdump 4
1240facilities, allowing scripted debugging output to be captured and
1241committed to disk as part of a textdump for later analysis.
1242The contents of the capture buffer may also be inspected in a kernel core dump
1243using
1244.Xr kgdb 1 .
1245.Pp
1246.It Ic run
1247.It Ic script
1248.It Ic scripts
1249.It Ic unscript
1250Run, define, list, and delete scripts.
1251See the
1252.Sx SCRIPTING
1253section for more information on the scripting facility.
1254.Pp
1255.It Ic textdump dump
1256.It Ic textdump set
1257.It Ic textdump status
1258.It Ic textdump unset
1259Use the
1260.Ic textdump dump
1261command to immediately perform a textdump.
1262More information may be found in
1263.Xr textdump 4 .
1264The
1265.Ic textdump set
1266command may be used to force the next kernel core dump to be a textdump
1267rather than a traditional memory dump or minidump.
1268.Ic textdump status
1269reports whether a textdump has been scheduled.
1270.Ic textdump unset
1271cancels a request to perform a textdump as the next kernel core dump.
1272.Pp
1273.It Ic thread Ar addr | tid
1274Switch the debugger to the thread with ID
1275.Ar tid ,
1276if the argument is a decimal number, or address
1277.Ar addr ,
1278otherwise.
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.ndis
1455The kernel debugger was entered as a result of an
1456.Xr ndis 4
1457breakpoint event.
1458.It Va kdb.enter.netgraph
1459The kernel debugger was entered as a result of a
1460.Xr netgraph 4
1461event.
1462.It Va kdb.enter.panic
1463.Xr panic 9
1464was called.
1465.It Va kdb.enter.powerfail
1466The kernel debugger was entered as a result of a powerfail NMI on the sparc64
1467platform.
1468.It Va kdb.enter.powerpc
1469The kernel debugger was entered as a result of an unimplemented interrupt
1470type on the powerpc platform.
1471.It Va kdb.enter.sysctl
1472The kernel debugger was entered as a result of the
1473.Va debug.kdb.enter
1474sysctl being set.
1475.It Va kdb.enter.trapsig
1476The kernel debugger was entered as a result of a trapsig event on the sparc64
1477platform.
1478.It Va kdb.enter.unionfs
1479The kernel debugger was entered as a result of an assertion failure in the
1480union file system.
1481.It Va kdb.enter.unknown
1482The kernel debugger was entered, but no reason has been set.
1483.It Va kdb.enter.vfslock
1484The kernel debugger was entered as a result of a VFS lock violation.
1485.It Va kdb.enter.watchdog
1486The kernel debugger was entered as a result of a watchdog firing.
1487.It Va kdb.enter.witness
1488The kernel debugger was entered as a result of a
1489.Xr witness 4
1490violation.
1491.El
1492.Pp
1493In the event that none of these scripts is found,
1494.Nm
1495will attempt to execute a default script:
1496.Bl -tag -width kdb.enter.powerfail
1497.It Va kdb.enter.default
1498The kernel debugger was entered, but a script exactly matching the reason for
1499entering was not defined.
1500This can be used as a catch-all to handle cases not specifically of interest;
1501for example,
1502.Va kdb.enter.witness
1503might be defined to have special handling, and
1504.Va kdb.enter.default
1505might be defined to simply panic and reboot.
1506.El
1507.Sh HINTS
1508On machines with an ISA expansion bus, a simple NMI generation card can be
1509constructed by connecting a push button between the A01 and B01 (CHCHK# and
1510GND) card fingers.
1511Momentarily shorting these two fingers together may cause the bridge chipset to
1512generate an NMI, which causes the kernel to pass control to
1513.Nm .
1514Some bridge chipsets do not generate a NMI on CHCHK#, so your mileage may vary.
1515The NMI allows one to break into the debugger on a wedged machine to
1516diagnose problems.
1517Other bus' bridge chipsets may be able to generate NMI using bus specific
1518methods.
1519There are many PCI and PCIe add-in cards which can generate NMI for
1520debugging.
1521Modern server systems typically use IPMI to generate signals to enter the
1522debugger.
1523The
1524.Va devel/ipmitool
1525port can be used to send the
1526.Cd chassis power diag
1527command which delivers an NMI to the processor.
1528Embedded systems often use JTAG for debugging, but rarely use it in
1529combination with
1530.Nm .
1531.Pp
1532For serial consoles, you can enter the debugger by sending a BREAK
1533condition on the serial line if
1534.Cd options BREAK_TO_DEBUGGER
1535is specified in the kernel.
1536Most terminal emulation programs can send a break sequence with a
1537special key sequence or via a menu item.
1538However, in some setups, sending the break can be difficult to arrange
1539or happens spuriously, so if the kernel contains
1540.Cd options ALT_BREAK_TO_DEBUGGER
1541then the sequence of CR TILDE CTRL-B enters the debugger;
1542CR TILDE CTRL-P causes a panic instead of entering the
1543debugger; and
1544CR TILDE CTRL-R causes an immediate reboot.
1545In all the above sequences, CR is a Carriage Return and is usually
1546sent by hitting the Enter or Return key.
1547TILDE is the ASCII tilde character (~).
1548CTRL-x is Control x created by hitting the control key and then x
1549and then releasing both.
1550.Pp
1551The break to enter the debugger behavior may be enabled at run-time
1552by setting the
1553.Xr sysctl 8
1554.Va debug.kdb.break_to_debugger
1555to 1.
1556The alternate sequence to enter the debugger behavior may be enabled
1557at run-time by setting the
1558.Xr sysctl 8
1559.Va debug.kdb.alt_break_to_debugger
1560to 1.
1561The debugger may be entered by setting the
1562.Xr sysctl 8
1563.Va debug.kdb.enter
1564to 1.
1565.Sh FILES
1566Header files mentioned in this manual page can be found below
1567.Pa /usr/include
1568directory.
1569.Pp
1570.Bl -dash -compact
1571.It
1572.Pa sys/buf.h
1573.It
1574.Pa sys/domain.h
1575.It
1576.Pa netinet/in_pcb.h
1577.It
1578.Pa sys/socket.h
1579.It
1580.Pa sys/vnode.h
1581.El
1582.Sh SEE ALSO
1583.Xr gdb 1 ,
1584.Xr kgdb 1 ,
1585.Xr acpi 4 ,
1586.Xr CAM 4 ,
1587.Xr mac_test 4 ,
1588.Xr ndis 4 ,
1589.Xr netgraph 4 ,
1590.Xr textdump 4 ,
1591.Xr witness 4 ,
1592.Xr ddb 8 ,
1593.Xr sysctl 8 ,
1594.Xr panic 9
1595.Sh HISTORY
1596The
1597.Nm
1598debugger was developed for Mach, and ported to
1599.Bx 386 0.1 .
1600This manual page translated from
1601.Xr man 7
1602macros by
1603.An Garrett Wollman .
1604.Pp
1605.An Robert N. M. Watson
1606added support for
1607.Nm
1608output capture,
1609.Xr textdump 4
1610and scripting in
1611.Fx 7.1 .
1612