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