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