1.\" 2.\" Mach Operating System 3.\" Copyright (c) 1991,1990 Carnegie Mellon University 4.\" Copyright (c) 2007 Robert N. M. Watson 5.\" All Rights Reserved. 6.\" 7.\" Permission to use, copy, modify and distribute this software and its 8.\" documentation is hereby granted, provided that both the copyright 9.\" notice and this permission notice appear in all copies of the 10.\" software, derivative works or modified versions, and any portions 11.\" thereof, and that both notices appear in supporting documentation. 12.\" 13.\" CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 14.\" CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR 15.\" ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 16.\" 17.\" Carnegie Mellon requests users of this software to return to 18.\" 19.\" Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 20.\" School of Computer Science 21.\" Carnegie Mellon University 22.\" Pittsburgh PA 15213-3890 23.\" 24.\" any improvements or extensions that they make and grant Carnegie Mellon 25.\" the rights to redistribute these changes. 26.\" 27.\" changed a \# to #, since groff choked on it. 28.\" 29.\" HISTORY 30.\" ddb.4,v 31.\" Revision 1.1 1993/07/15 18:41:02 brezak 32.\" Man page for DDB 33.\" 34.\" Revision 2.6 92/04/08 08:52:57 rpd 35.\" Changes from OSF. 36.\" [92/01/17 14:19:22 jsb] 37.\" Changes for OSF debugger modifications. 38.\" [91/12/12 tak] 39.\" 40.\" Revision 2.5 91/06/25 13:50:22 rpd 41.\" Added some watchpoint explanation. 42.\" [91/06/25 rpd] 43.\" 44.\" Revision 2.4 91/06/17 15:47:31 jsb 45.\" Added documentation for continue/c, match, search, and watchpoints. 46.\" I've not actually explained what a watchpoint is; maybe Rich can 47.\" do that (hint, hint). 48.\" [91/06/17 10:58:08 jsb] 49.\" 50.\" Revision 2.3 91/05/14 17:04:23 mrt 51.\" Correcting copyright 52.\" 53.\" Revision 2.2 91/02/14 14:10:06 mrt 54.\" Changed to new Mach copyright 55.\" [91/02/12 18:10:12 mrt] 56.\" 57.\" Revision 2.2 90/08/30 14:23:15 dbg 58.\" Created. 59.\" [90/08/30 dbg] 60.\" 61.\" $FreeBSD$ 62.\" 63.Dd October 18, 2008 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 has most of the features of the old 106.Nm kdb , 107but with a more rational syntax 108inspired by 109.Xr gdb 1 . 110If linked into the running kernel, 111it can be invoked locally with the 112.Ql debug 113.Xr keymap 5 114action. 115The debugger is also invoked on kernel 116.Xr panic 9 117if the 118.Va debug.debugger_on_panic 119.Xr sysctl 8 120MIB variable is set non-zero, 121which is the default 122unless the 123.Dv KDB_UNATTENDED 124option is specified. 125.Pp 126The current location is called 127.Va dot . 128The 129.Va dot 130is displayed with 131a hexadecimal format at a prompt. 132The commands 133.Ic examine 134and 135.Ic write 136update 137.Va dot 138to the address of the last line 139examined or the last location modified, and set 140.Va next 141to the address of 142the next location to be examined or changed. 143Other commands do not change 144.Va dot , 145and set 146.Va next 147to be the same as 148.Va dot . 149.Pp 150The general command syntax is: 151.Ar command Ns Op Li / Ns Ar modifier 152.Ar address Ns Op Li , Ns Ar count 153.Pp 154A blank line repeats the previous command from the address 155.Va next 156with 157count 1 and no modifiers. 158Specifying 159.Ar address 160sets 161.Va dot 162to the address. 163Omitting 164.Ar address 165uses 166.Va dot . 167A missing 168.Ar count 169is taken 170to be 1 for printing commands or infinity for stack traces. 171.Pp 172The 173.Nm 174debugger has a pager feature (like the 175.Xr more 1 176command) 177for the output. 178If an output line exceeds the number set in the 179.Va lines 180variable, it displays 181.Dq Li --More-- 182and waits for a response. 183The valid responses for it are: 184.Pp 185.Bl -tag -compact -width ".Li SPC" 186.It Li SPC 187one more page 188.It Li RET 189one more line 190.It Li q 191abort the current command, and return to the command input mode 192.El 193.Pp 194Finally, 195.Nm 196provides a small (currently 10 items) command history, and offers 197simple 198.Nm emacs Ns -style 199command line editing capabilities. 200In addition to 201the 202.Nm emacs 203control keys, the usual 204.Tn ANSI 205arrow keys might be used to 206browse through the history buffer, and move the cursor within the 207current line. 208.Sh COMMANDS 209.Bl -tag -width indent -compact 210.It Ic examine 211.It Ic x 212Display the addressed locations according to the formats in the modifier. 213Multiple modifier formats display multiple locations. 214If no format is specified, the last format specified for this command 215is used. 216.Pp 217The format characters are: 218.Bl -tag -compact -width indent 219.It Cm b 220look at by bytes (8 bits) 221.It Cm h 222look at by half words (16 bits) 223.It Cm l 224look at by long words (32 bits) 225.It Cm a 226print the location being displayed 227.It Cm A 228print the location with a line number if possible 229.It Cm x 230display in unsigned hex 231.It Cm z 232display in signed hex 233.It Cm o 234display in unsigned octal 235.It Cm d 236display in signed decimal 237.It Cm u 238display in unsigned decimal 239.It Cm r 240display in current radix, signed 241.It Cm c 242display low 8 bits as a character. 243Non-printing characters are displayed as an octal escape code (e.g., 244.Ql \e000 ) . 245.It Cm s 246display the null-terminated string at the location. 247Non-printing characters are displayed as octal escapes. 248.It Cm m 249display in unsigned hex with character dump at the end of each line. 250The location is also displayed in hex at the beginning of each line. 251.It Cm i 252display as an instruction 253.It Cm I 254display as an instruction with possible alternate formats depending on the 255machine: 256.Bl -tag -width ".Tn powerpc" -compact 257.It Tn alpha 258Show the registers of the instruction. 259.It Tn amd64 260No alternate format. 261.It Tn i386 262No alternate format. 263.It Tn ia64 264No alternate format. 265.It Tn powerpc 266No alternate format. 267.It Tn sparc64 268No alternate format. 269.El 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 Op Li / Ns Cm u 347.It Ic b Ns Op Li / Ns Cm u 348Set a break point at 349.Ar addr . 350If 351.Ar count 352is supplied, continues 353.Ar count 354\- 1 times before stopping at the 355break point. 356If the break point is set, a break point number is 357printed with 358.Ql # . 359This number can be used in deleting the break point 360or adding conditions to it. 361.Pp 362If the 363.Cm u 364modifier is specified, this command sets a break point in user 365address space. 366Without the 367.Cm u 368option, the address is considered to be in the kernel 369space, and a wrong space address is rejected with an error message. 370This modifier can be used only if it is supported by machine dependent 371routines. 372.Pp 373.Sy Warning : 374If a user text is shadowed by a normal user space debugger, 375user space break points may not work correctly. 376Setting a break 377point at the low-level code paths may also cause strange behavior. 378.Pp 379.It Ic delete Ar addr 380.It Ic d Ar addr 381.It Ic delete Li # Ns Ar number 382.It Ic d Li # Ns Ar number 383Delete the break point. 384The target break point can be specified by a 385break point number with 386.Ql # , 387or by using the same 388.Ar addr 389specified in the original 390.Ic break 391command. 392.Pp 393.It Ic watch Ar addr Ns Li , Ns Ar size 394Set a watchpoint for a region. 395Execution stops when an attempt to modify the region occurs. 396The 397.Ar size 398argument defaults to 4. 399If you specify a wrong space address, the request is rejected 400with an error message. 401.Pp 402.Sy Warning : 403Attempts to watch wired kernel memory 404may cause unrecoverable error in some systems such as i386. 405Watchpoints on user addresses work best. 406.Pp 407.It Ic hwatch Ar addr Ns Li , Ns Ar size 408Set a hardware watchpoint for a region if supported by the 409architecture. 410Execution stops when an attempt to modify the region occurs. 411The 412.Ar size 413argument defaults to 4. 414.Pp 415.Sy Warning : 416The hardware debug facilities do not have a concept of separate 417address spaces like the watch command does. 418Use 419.Ic hwatch 420for setting watchpoints on kernel address locations only, and avoid 421its use on user mode address spaces. 422.Pp 423.It Ic dhwatch Ar addr Ns Li , Ns Ar size 424Delete specified hardware watchpoint. 425.Pp 426.It Ic step Ns Op Li / Ns Cm p 427.It Ic s Ns Op Li / Ns Cm p 428Single step 429.Ar count 430times (the comma is a mandatory part of the syntax). 431If the 432.Cm p 433modifier is specified, print each instruction at each step. 434Otherwise, only print the last instruction. 435.Pp 436.Sy Warning : 437depending on machine type, it may not be possible to 438single-step through some low-level code paths or user space code. 439On machines with software-emulated single-stepping (e.g., pmax), 440stepping through code executed by interrupt handlers will probably 441do the wrong thing. 442.Pp 443.It Ic continue Ns Op Li / Ns Cm c 444.It Ic c Ns Op Li / Ns Cm c 445Continue execution until a breakpoint or watchpoint. 446If the 447.Cm c 448modifier is specified, count instructions while executing. 449Some machines (e.g., pmax) also count loads and stores. 450.Pp 451.Sy Warning : 452when counting, the debugger is really silently single-stepping. 453This means that single-stepping on low-level code may cause strange 454behavior. 455.Pp 456.It Ic until Ns Op Li / Ns Cm p 457Stop at the next call or return instruction. 458If the 459.Cm p 460modifier is specified, print the call nesting depth and the 461cumulative instruction count at each call or return. 462Otherwise, 463only print when the matching return is hit. 464.Pp 465.It Ic next Ns Op Li / Ns Cm p 466.It Ic match Ns Op Li / Ns Cm p 467Stop at the matching return instruction. 468If the 469.Cm p 470modifier is specified, print the call nesting depth and the 471cumulative instruction count at each call or return. 472Otherwise, only print when the matching return is hit. 473.Pp 474.It Xo 475.Ic trace Ns Op Li / Ns Cm u 476.Op Ar pid | tid 477.Op Li , Ns Ar count 478.Xc 479.It Xo 480.Ic t Ns Op Li / Ns Cm u 481.Op Ar pid | tid 482.Op Li , Ns Ar count 483.Xc 484.It Xo 485.Ic where Ns Op Li / Ns Cm u 486.Op Ar pid | tid 487.Op Li , Ns Ar count 488.Xc 489.It Xo 490.Ic bt Ns Op Li / Ns Cm u 491.Op Ar pid | tid 492.Op Li , Ns Ar count 493.Xc 494Stack trace. 495The 496.Cm u 497option traces user space; if omitted, 498.Ic trace 499only traces 500kernel space. 501The optional argument 502.Ar count 503is the number of frames to be traced. 504If 505.Ar count 506is omitted, all frames are printed. 507.Pp 508.Sy Warning : 509User space stack trace is valid 510only if the machine dependent code supports it. 511.Pp 512.It Xo 513.Ic search Ns Op Li / Ns Cm bhl 514.Ar addr 515.Ar value 516.Op Ar mask 517.Op Li , Ns Ar count 518.Xc 519Search memory for 520.Ar value . 521This command might fail in interesting 522ways if it does not find the searched-for value. 523This is because 524.Nm 525does not always recover from touching bad memory. 526The optional 527.Ar count 528argument limits the search. 529.\" 530.Pp 531.It Ic show Cm all procs Ns Op Li / Ns Cm m 532.It Ic ps Ns Op Li / Ns Cm m 533Display all process information. 534The process information may not be shown if it is not 535supported in the machine, or the bottom of the stack of the 536target process is not in the main memory at that time. 537The 538.Cm m 539modifier will alter the display to show VM map 540addresses for the process and not show other information. 541.\" 542.Pp 543.It Ic show Cm all ttys 544Show all TTY's within the system. 545Output is similar to 546.Xr pstat 8 , 547but also includes the address of the TTY structure. 548.\" 549.Pp 550.It Ic show Cm allchains 551Show the same information like "show lockchain" does, but 552for every thread in the system. 553.\" 554.Pp 555.It Ic show Cm alllocks 556Show all locks that are currently held. 557This command is only available if 558.Xr witness 4 559is included in the kernel. 560.\" 561.Pp 562.It Ic show Cm allpcpu 563The same as "show pcpu", but for every CPU present in the system. 564.\" 565.Pp 566.It Ic show Cm allrman 567Show information related with resource management, including 568interrupt request lines, DMA request lines, I/O ports and I/O memory 569addresses. 570.\" 571.Pp 572.It Ic show Cm apic 573Dump data about APIC IDT vector mappings. 574.\" 575.Pp 576.It Ic show Cm breaks 577Show breakpoints set with the "break" command. 578.\" 579.Pp 580.It Ic show Cm buffer 581Show buffer structure of 582.Vt struct buf 583type. 584Such a structure is used within the 585.Fx 586kernel for the I/O subsystem 587implementation. 588For an exact interpretation of the output, please see the 589.Pa sys/buf.h 590header file. 591.\" 592.Pp 593.It Ic show Cm cbstat 594Show brief information about the TTY subsystem. 595.\" 596.Pp 597.It Ic show Cm conifhk 598Lists hooks currently waiting for completion in 599run_interrupt_driven_config_hooks(). 600.\" 601.Pp 602.It Ic show Cm cpusets 603Print numbered root and assigned CPU affinity sets. 604See 605.Xr cpuset 2 606for more details. 607.\" 608.Pp 609.It Ic show Cm cyrixreg 610Show registers specific to the Cyrix processor. 611.\" 612.Pp 613.It Ic show Cm domain Ar addr 614Print protocol domain structure 615.Vt struct domain 616at address 617.Ar addr . 618See the 619.Pa sys/domain.h 620header file for more details on the exact meaning of the structure fields. 621.\" 622.Pp 623.It Ic show Cm ffs Op Ar addr 624Show brief information about ffs mount at the address 625.Ar addr , 626if argument is given. 627Otherwise, provides the summary about each ffs mount. 628.\" 629.Pp 630.It Ic show Cm file Ar addr 631Show information about the file structure 632.Vt struct file 633present at address 634.Ar addr . 635.\" 636.Pp 637.It Ic show Cm files 638Show information about every file structure in the system. 639.\" 640.Pp 641.It Ic show Cm freepages 642Show the number of physical pages in each of the free lists. 643.\" 644.Pp 645.It Ic show Cm geom Op Ar addr 646If the 647.Ar addr 648argument is not given, displays the entire GEOM topology. 649If 650.Ar addr 651is given, displays details about the given GEOM object (class, geom, 652provider or consumer). 653.\" 654.Pp 655.It Ic show Cm idt 656Show IDT layout. 657The first column specifies the IDT vector. 658The second one is the name of the interrupt/trap handler. 659Those functions are machine dependent. 660.\" 661.Pp 662.It Ic show Cm inodedeps Op Ar addr 663Show brief information about each inodedep structure. 664If 665.Ar addr 666is given, only inodedeps belonging to the fs located at the 667supplied address are shown. 668.\" 669.Pp 670.It Ic show Cm inpcb Ar addr 671Show information on IP Control Block 672.Vt struct in_pcb 673present at 674.Ar addr . 675.\" 676.Pp 677.It Ic show Cm intr 678Dump information about interrupt handlers. 679.\" 680.Pp 681.It Ic show Cm intrcnt 682Dump the interrupt statistics. 683.\" 684.Pp 685.It Ic show Cm irqs 686Show interrupt lines and their respective kernel threads. 687.\" 688.Pp 689.It Ic show Cm lapic 690Show information from the local APIC registers for this CPU. 691.\" 692.Pp 693.It Ic show Cm lock Ar addr 694Show lock structure. 695The output format is as follows: 696.Bl -tag -offset 0 -width "flags" 697.It Ic class: 698Class of the lock. 699Possible types include 700.Xr mutex 9 , 701.Xr rmlock 9 , 702.Xr rwlock 9 , 703.Xr sx 9 . 704.It Ic name: 705Name of the lock. 706.It Ic flags: 707Flags passed to the lock initialization function. 708For exact possibilities see manual pages of possible lock types. 709.It Ic state: 710Current state of a lock. 711As well as 712.Ic flags 713it's lock-specific. 714.It Ic owner: 715Lock owner. 716.El 717.\" 718.Pp 719.It Ic show Cm lockchain Ar addr 720Show all threads a particular thread at address 721.Ar addr 722is waiting on based on non-sleepable and non-spin locks. 723.\" 724.Pp 725.It Ic show Cm lockedbufs 726Show the same information as "show buf", but for every locked 727.Vt struct buf 728object. 729.\" 730.Pp 731.It Ic show Cm lockedvnods 732List all locked vnodes in the system. 733.\" 734.Pp 735.It Ic show Cm locks 736Prints all locks that are currently acquired. 737This command is only available if 738.Xr witness 4 739is included in the kernel. 740.\" 741.Pp 742.It Ic show Cm locktree 743.\" 744.Pp 745.It Ic show Cm malloc 746Prints 747.Xr malloc 9 748memory allocator statistics. 749The output format is as follows: 750.Pp 751.Bl -tag -compact -offset indent -width "Requests" 752.It Ic Type 753Specifies a type of memory. 754It is the same as a description string used while defining the 755given memory type with 756.Xr MALLOC_DECLARE 9 . 757.It Ic InUse 758Number of memory allocations of the given type, for which 759.Xr free 9 760has not been called yet. 761.It Ic MemUse 762Total memory consumed by the given allocation type. 763.It Ic Requests 764Number of memory allocation requests for the given 765memory type. 766.El 767.Pp 768The same information can be gathered in userspace with 769.Dq Nm vmstat Fl m . 770.\" 771.Pp 772.It Ic show Cm map Ns Oo Li / Ns Cm f Oc Ar addr 773Prints the VM map at 774.Ar addr . 775If the 776.Cm f 777modifier is specified the 778complete map is printed. 779.\" 780.Pp 781.It Ic show Cm msgbuf 782Print the system's message buffer. 783It is the same output as in the 784.Dq Nm dmesg 785case. 786It is useful if you got a kernel panic, attached a serial cable 787to the machine and want to get the boot messages from before the 788system hang. 789.\" 790.It Ic show Cm mount 791Displays short info about all currently mounted file systems. 792.Pp 793.It Ic show Cm mount Ar addr 794Displays details about the given mount point. 795.Pp 796.\" 797.Pp 798.It Ic show Cm object Ns Oo Li / Ns Cm f Oc Ar addr 799Prints the VM object at 800.Ar addr . 801If the 802.Cm f 803option is specified the 804complete object is printed. 805.\" 806.Pp 807.It Ic show Cm page 808Show statistics on VM pages. 809.\" 810.Pp 811.It Ic show Cm pageq 812Show statistics on VM page queues. 813.\" 814.Pp 815.It Ic show Cm pciregs 816Print PCI bus registers. 817The same information can be gathered in userspace by running 818.Dq Nm pciconf Fl lv . 819.\" 820.Pp 821.It Ic show Cm pcpu 822Print current processor state. 823The output format is as follows: 824.Pp 825.Bl -tag -compact -offset indent -width "spin locks held:" 826.It Ic cpuid 827Processor identifier. 828.It Ic curthread 829Thread pointer, process identifier and the name of the process. 830.It Ic curpcb 831Control block pointer. 832.It Ic fpcurthread 833FPU thread pointer. 834.It Ic idlethread 835Idle thread pointer. 836.It Ic APIC ID 837CPU identifier coming from APIC. 838.It Ic currentldt 839LDT pointer. 840.It Ic spin locks held 841Names of spin locks held. 842.El 843.\" 844.Pp 845.It Ic show Cm pgrpdump 846Dump process groups present within the system. 847.\" 848.Pp 849.It Ic show Cm proc Op Ar addr 850If no 851.Op Ar addr 852is specified, print information about the current process. 853Otherwise, show information about the process at address 854.Ar addr . 855.\" 856.Pp 857.It Ic show Cm procvm 858Show process virtual memory layout. 859.\" 860.Pp 861.It Ic show Cm protosw Ar addr 862Print protocol switch structure 863.Vt struct protosw 864at address 865.Ar addr . 866.\" 867.Pp 868.It Ic show Cm registers Ns Op Li / Ns Cm u 869Display the register set. 870If the 871.Cm u 872modifier is specified, it displays user registers instead of 873kernel registers or the currently saved one. 874.Pp 875.Sy Warning : 876The support of the 877.Cm u 878modifier depends on the machine. 879If not supported, incorrect information will be displayed. 880.\" 881.Pp 882.It Ic show Cm rman Ar addr 883Show resource manager object 884.Vt struct rman 885at address 886.Ar addr . 887Addresses of particular pointers can be gathered with "show allrman" 888command. 889.\" 890.Pp 891.It Ic show Cm rtc 892Show real time clock value. 893Useful for long debugging sessions. 894.\" 895.Pp 896.It Ic show Cm sleepchain 897Show all the threads a particular thread is waiting on based on 898sleepable locks. 899.\" 900.Pp 901.It Ic show Cm sleepq 902.It Ic show Cm sleepqueue 903Both commands provide the same functionality. 904They show sleepqueue 905.Vt struct sleepqueue 906structure. 907Sleepqueues are used within the 908.Fx 909kernel to implement sleepable 910synchronization primitives (thread holding a lock might sleep or 911be context switched), which at the time of writing are: 912.Xr condvar 9 , 913.Xr sx 9 914and standard 915.Xr msleep 9 916interface. 917.\" 918.Pp 919.It Ic show Cm sockbuf Ar addr 920.It Ic show Cm socket Ar addr 921Those commands print 922.Vt struct sockbuf 923and 924.Vt struct socket 925objects placed at 926.Ar addr . 927Output consists of all values present in structures mentioned. 928For exact interpretation and more details, visit 929.Pa sys/socket.h 930header file. 931.\" 932.Pp 933.It Ic show Cm sysregs 934Show system registers (e.g., 935.Li cr0-4 936on i386.) 937Not present on some platforms. 938.\" 939.Pp 940.It Ic show Cm tcpcb Ar addr 941Print TCP control block 942.Vt struct tcpcb 943lying at address 944.Ar addr . 945For exact interpretation of output, visit 946.Pa netinet/tcp.h 947header file. 948.\" 949.Pp 950.It Ic show Cm thread Op Ar addr 951If no 952.Ar addr 953is specified, show detailed information about current thread. 954Otherwise, information about thread at 955.Ar addr 956is printed. 957.\" 958.Pp 959.It Ic show Cm threads 960Show all threads within the system. 961Output format is as follows: 962.Pp 963.Bl -tag -width "PPID" -compact -offset indent -width "Second column" 964.It Ic First column 965Thread identifier (TID) 966.It Ic Second column 967Thread structure address 968.It Ic Third column 969Backtrace. 970.El 971.\" 972.Pp 973.It Ic show Cm tty Ar addr 974Display the contents of a TTY structure in a readable form. 975.\" 976.Pp 977.It Ic show Cm turnstile Ar addr 978Show turnstile 979.Vt struct turnstile 980structure at address 981.Ar addr . 982Turnstiles are structures used within the 983.Fx 984kernel to implement 985synchronization primitives which, while holding a specific type of lock, cannot 986sleep or context switch to another thread. 987Currently, those are: 988.Xr mutex 9 , 989.Xr rwlock 9 , 990.Xr rmlock 9 . 991.\" 992.Pp 993.It Ic show Cm uma 994Show UMA allocator statistics. 995Output consists five columns: 996.Pp 997.Bl -tag -compact -offset indent -width "Requests" 998.It Cm "Zone" 999Name of the UMA zone. 1000The same string that was passed to 1001.Xr uma_zcreate 9 1002as a first argument. 1003.It Cm "Size" 1004Size of a given memory object (slab). 1005.It Cm "Used" 1006Number of slabs being currently used. 1007.It Cm "Free" 1008Number of free slabs within the UMA zone. 1009.It Cm "Requests" 1010Number of allocations requests to the given zone. 1011.El 1012.Pp 1013The very same information might be gathered in the userspace 1014with the help of 1015.Dq Nm vmstat Fl z 1016.\" 1017.Pp 1018.It Ic show Cm unpcb Ar addr 1019Shows UNIX domain socket private control block 1020.Vt struct unpcb 1021present at the address 1022.Ar addr 1023.\" 1024.Pp 1025.It Ic show Cm vmochk 1026Prints, whether the internal VM objects are in a map somewhere 1027and none have zero ref counts. 1028.\" 1029.Pp 1030.It Ic show Cm vmopag 1031This is supposed to show physical addresses consumed by a 1032VM object. 1033Currently, it is not possible to use this command when 1034.Xr witness 4 1035is compiled in the kernel. 1036.\" 1037.Pp 1038.It Ic show Cm vnode Op Ar addr 1039Prints vnode 1040.Vt struct vnode 1041structure lying at 1042.Op Ar addr . 1043For the exact interpretation of the output, look at the 1044.Pa sys/vnode.h 1045header file. 1046.\" 1047.Pp 1048.It Ic show Cm vnodebufs Ar addr 1049Shows clean/dirty buffer lists of the vnode located at 1050.Ar addr . 1051.\" 1052.Pp 1053.It Ic show Cm watches 1054Displays all watchpoints. 1055Shows watchpoints set with "watch" command. 1056.\" 1057.Pp 1058.It Ic show Cm witness 1059Shows information about lock acquisition coming from the 1060.Xr witness 4 1061subsystem. 1062.\" 1063.Pp 1064.It Ic gdb 1065Toggles between remote GDB and DDB mode. 1066In remote GDB mode, another machine is required that runs 1067.Xr gdb 1 1068using the remote debug feature, with a connection to the serial 1069console port on the target machine. 1070Currently only available on the 1071i386 1072architecture. 1073.Pp 1074.It Ic halt 1075Halt the system. 1076.Pp 1077.It Ic kill Ar sig pid 1078Send signal 1079.Ar sig 1080to process 1081.Ar pid . 1082The signal is acted on upon returning from the debugger. 1083This command can be used to kill a process causing resource contention 1084in the case of a hung system. 1085See 1086.Xr signal 3 1087for a list of signals. 1088Note that the arguments are reversed relative to 1089.Xr kill 2 . 1090.Pp 1091.It Ic reboot 1092.It Ic reset 1093Hard reset the system. 1094.Pp 1095.It Ic help 1096Print a short summary of the available commands and command 1097abbreviations. 1098.Pp 1099.It Ic capture on 1100.It Ic capture off 1101.It Ic capture reset 1102.It Ic capture status 1103.Nm 1104supports a basic output capture facility, which can be used to retrieve the 1105results of debugging commands from userpsace using 1106.Xr sysctl 2 . 1107.Ic capture on 1108enables output capture; 1109.Ic capture off 1110disables capture. 1111.Ic capture reset 1112will clear the capture buffer and disable capture. 1113.Ic capture status 1114will report current buffer use, buffer size, and disposition of output 1115capture. 1116.Pp 1117Userspace processes may inspect and manage 1118.Nm 1119capture state using 1120.Xr sysctl 8 : 1121.Pp 1122.Dv debug.ddb.capture.bufsize 1123may be used to query or set the current capture buffer size. 1124.Pp 1125.Dv debug.ddb.capture.maxbufsize 1126may be used to query the compile-time limit on the capture buffer size. 1127.Pp 1128.Dv debug.ddb.capture.bytes 1129may be used to query the number of bytes of output currently in the capture 1130buffer. 1131.Pp 1132.Dv debug.ddb.capture.data 1133returns the contents of the buffer as a string to an appropriately privileged 1134process. 1135.Pp 1136This facility is particularly useful in concert with the scripting and 1137.Xr textdump 4 1138facilities, allowing scripted debugging output to be captured and 1139committed to disk as part of a textdump for later analysis. 1140The contents of the capture buffer may also be inspected in a kernel core dump 1141using 1142.Xr kgdb 1 . 1143.Pp 1144.It Ic run 1145.It Ic script 1146.It Ic scripts 1147.It Ic unscript 1148Run, define, list, and delete scripts. 1149See the 1150.Sx SCRIPTING 1151section for more information on the scripting facility. 1152.Pp 1153.It Ic textdump set 1154.It Ic textdump status 1155.It Ic textdump unset 1156The 1157.Ic textdump set 1158command may be used to force the next kernel core dump to be a textdump 1159rather than a traditional memory dump or minidump. 1160.Ic textdump status 1161reports whether a textdump has been scheduled. 1162.Ic textdump unset 1163cancels a request to perform a textdump as the next kernel core dump. 1164More information may be found in 1165.Xr textdump 4 . 1166.El 1167.Sh VARIABLES 1168The debugger accesses registers and variables as 1169.Li $ Ns Ar name . 1170Register names are as in the 1171.Dq Ic show Cm registers 1172command. 1173Some variables are suffixed with numbers, and may have some modifier 1174following a colon immediately after the variable name. 1175For example, register variables can have a 1176.Cm u 1177modifier to indicate user register (e.g., 1178.Dq Li $eax:u ) . 1179.Pp 1180Built-in variables currently supported are: 1181.Pp 1182.Bl -tag -width ".Va tabstops" -compact 1183.It Va radix 1184Input and output radix. 1185.It Va maxoff 1186Addresses are printed as 1187.Dq Ar symbol Ns Li + Ns Ar offset 1188unless 1189.Ar offset 1190is greater than 1191.Va maxoff . 1192.It Va maxwidth 1193The width of the displayed line. 1194.It Va lines 1195The number of lines. 1196It is used by the built-in pager. 1197.It Va tabstops 1198Tab stop width. 1199.It Va work Ns Ar xx 1200Work variable; 1201.Ar xx 1202can take values from 0 to 31. 1203.El 1204.Sh EXPRESSIONS 1205Most expression operators in C are supported except 1206.Ql ~ , 1207.Ql ^ , 1208and unary 1209.Ql & . 1210Special rules in 1211.Nm 1212are: 1213.Bl -tag -width ".No Identifiers" 1214.It Identifiers 1215The name of a symbol is translated to the value of the symbol, which 1216is the address of the corresponding object. 1217.Ql \&. 1218and 1219.Ql \&: 1220can be used in the identifier. 1221If supported by an object format dependent routine, 1222.Sm off 1223.Oo Ar filename : Oc Ar func : lineno , 1224.Sm on 1225.Oo Ar filename : Oc Ns Ar variable , 1226and 1227.Oo Ar filename : Oc Ns Ar lineno 1228can be accepted as a symbol. 1229.It Numbers 1230Radix is determined by the first two letters: 1231.Ql 0x : 1232hex, 1233.Ql 0o : 1234octal, 1235.Ql 0t : 1236decimal; otherwise, follow current radix. 1237.It Li \&. 1238.Va dot 1239.It Li + 1240.Va next 1241.It Li .. 1242address of the start of the last line examined. 1243Unlike 1244.Va dot 1245or 1246.Va next , 1247this is only changed by 1248.Ic examine 1249or 1250.Ic write 1251command. 1252.It Li ' 1253last address explicitly specified. 1254.It Li $ Ns Ar variable 1255Translated to the value of the specified variable. 1256It may be followed by a 1257.Ql \&: 1258and modifiers as described above. 1259.It Ar a Ns Li # Ns Ar b 1260A binary operator which rounds up the left hand side to the next 1261multiple of right hand side. 1262.It Li * Ns Ar expr 1263Indirection. 1264It may be followed by a 1265.Ql \&: 1266and modifiers as described above. 1267.El 1268.Sh SCRIPTING 1269.Nm 1270supports a basic scripting facility to allow automating tasks or responses to 1271specific events. 1272Each script consists of a list of DDB commands to be executed sequentially, 1273and is assigned a unique name. 1274Certain script names have special meaning, and will be automatically run on 1275various 1276.Nm 1277events if scripts by those names have been defined. 1278.Pp 1279The 1280.Ic script 1281command may be used to define a script by name. 1282Scripts consist of a series of 1283.Nm 1284commands separated with the 1285.Ic ; 1286character. 1287For example: 1288.Bd -literal -offset indent 1289script kdb.enter.panic=bt; show pcpu 1290script lockinfo=show alllocks; show lockedvnods 1291.Ed 1292.Pp 1293The 1294.Ic scripts 1295command lists currently defined scripts. 1296.Pp 1297The 1298.Ic run 1299command execute a script by name. 1300For example: 1301.Bd -literal -offset indent 1302run lockinfo 1303.Ed 1304.Pp 1305The 1306.Ic unscript 1307command may be used to delete a script by name. 1308For example: 1309.Bd -literal -offset indent 1310unscript kdb.enter.panic 1311.Ed 1312.Pp 1313These functions may also be performed from userspace using the 1314.Xr ddb 8 1315command. 1316.Pp 1317Certain scripts are run automatically, if defined, for specific 1318.Nm 1319events. 1320The follow scripts are run when various events occur: 1321.Bl -tag -width kdb.enter.powerfail 1322.It Dv kdb.enter.acpi 1323The kernel debugger was entered as a result of an 1324.Xr acpi 4 1325event. 1326.It Dv kdb.enter.bootflags 1327The kernel debugger was entered at boot as a result of the debugger boot 1328flag being set. 1329.It Dv kdb.enter.break 1330The kernel debugger was entered as a result of a serial or console break. 1331.It Dv kdb.enter.cam 1332The kernel debugger was entered as a result of a 1333.Xr CAM 4 1334event. 1335.It Dv kdb.enter.mac 1336The kernel debugger was entered as a result of an assertion failure in the 1337.Xr mac_test 4 1338module of the 1339TrustedBSD MAC Framework. 1340.It Dv kdb.enter.ndis 1341The kernel debugger was entered as a result of an 1342.Xr ndis 4 1343breakpoint event. 1344.It Dv kdb.enter.netgraph 1345The kernel debugger was entered as a result of a 1346.Xr netgraph 4 1347event. 1348.It Dv kdb.enter.panic 1349.Xr panic 9 1350was called. 1351.It Dv kdb.enter.powerfail 1352The kernel debugger was entered as a result of a powerfail NMI on the sparc64 1353platform. 1354.It Dv kdb.enter.powerpc 1355The kernel debugger was entered as a result of an unimplemented interrupt 1356type on the powerpc platform. 1357.It Dv kdb.enter.sysctl 1358The kernel debugger was entered as a result of the 1359.Dv debug.kdb.enter 1360sysctl being set. 1361.It Dv kdb.enter.trapsig 1362The kernel debugger was entered as a result of a trapsig event on the sparc64 1363or sun4v platform. 1364.It Dv kdb.enter.unionfs 1365The kernel debugger was entered as a result of an assertion failure in the 1366union file system. 1367.It Dv kdb.enter.unknown 1368The kernel debugger was entered, but no reason has been set. 1369.It Dv kdb.enter.vfslock 1370The kernel debugger was entered as a result of a VFS lock violation. 1371.It Dv kdb.enter.watchdog 1372The kernel debugger was entered as a result of a watchdog firing. 1373.It Dv kdb.enter.witness 1374The kernel debugger was entered as a result of a 1375.Xr witness 4 1376violation. 1377.El 1378.Pp 1379In the event that none of these scripts is found, 1380.Nm 1381will attempt to execute a default script: 1382.Bl -tag -width kdb.enter.powerfail 1383.It Dv kdb.enter.default 1384The kernel debugger was entered, but a script exactly matching the reason for 1385entering was not defined. 1386This can be used as a catch-all to handle cases not specifically of interest; 1387for example, 1388.Dv kdb.enter.witness 1389might be defined to have special handling, and 1390.Dv kdb.enter.default 1391might be defined to simply panic and reboot. 1392.El 1393.Sh HINTS 1394On machines with an ISA expansion bus, a simple NMI generation card can be 1395constructed by connecting a push button between the A01 and B01 (CHCHK# and 1396GND) card fingers. 1397Momentarily shorting these two fingers together may cause the bridge chipset to 1398generate an NMI, which causes the kernel to pass control to 1399.Nm . 1400Some bridge chipsets do not generate a NMI on CHCHK#, so your mileage may vary. 1401The NMI allows one to break into the debugger on a wedged machine to 1402diagnose problems. 1403Other bus' bridge chipsets may be able to generate NMI using bus specific 1404methods. 1405.Sh FILES 1406Header files mention in this manual page can be found below 1407.Pa /usr/include 1408directory. 1409.Pp 1410.Bl -dash -compact 1411.It 1412.Pa sys/buf.h 1413.It 1414.Pa sys/domain.h 1415.It 1416.Pa netinet/in_pcb.h 1417.It 1418.Pa sys/socket.h 1419.It 1420.Pa sys/vnode.h 1421.El 1422.Sh SEE ALSO 1423.Xr gdb 1 , 1424.Xr kgdb 1 , 1425.Xr acpi 4 , 1426.Xr CAM 4 , 1427.Xr mac_test 4 , 1428.Xr ndis 4 , 1429.Xr netgraph 4 , 1430.Xr textdump 4 , 1431.Xr witness 4 , 1432.Xr ddb 8 , 1433.Xr sysctl 8 , 1434.Xr panic 9 1435.Sh HISTORY 1436The 1437.Nm 1438debugger was developed for Mach, and ported to 1439.Bx 386 0.1 . 1440This manual page translated from 1441.Xr man 7 1442macros by 1443.An Garrett Wollman . 1444.Pp 1445.An Robert N. M. Watson 1446added support for 1447.Nm 1448output capture, 1449.Xr textdump 4 1450and scripting in 1451.Fx 7.1 . 1452