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