1.\" $NetBSD: ddb.4,v 1.164 2016/12/27 21:54:50 pgoyette Exp $ 2.\" 3.\" Copyright (c) 1997 - 2009 The NetBSD Foundation, Inc. 4.\" All rights reserved. 5.\" 6.\" This code is derived from software contributed to The NetBSD Foundation 7.\" by Luke Mewburn 8.\" 9.\" Redistribution and use in source and binary forms, with or without 10.\" modification, are permitted provided that the following conditions 11.\" are met: 12.\" 1. Redistributions of source code must retain the above copyright 13.\" notice, this list of conditions and the following disclaimer. 14.\" 2. Redistributions in binary form must reproduce the above copyright 15.\" notice, this list of conditions and the following disclaimer in the 16.\" documentation and/or other materials provided with the distribution. 17.\" 18.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 19.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28.\" POSSIBILITY OF SUCH DAMAGE. 29.\" 30.\" --- 31.\" This manual page was derived from a -man.old document which bore 32.\" the following copyright message: 33.\" --- 34.\" 35.\" Mach Operating System 36.\" Copyright (c) 1991,1990 Carnegie Mellon University 37.\" All Rights Reserved. 38.\" 39.\" Permission to use, copy, modify and distribute this software and its 40.\" documentation is hereby granted, provided that both the copyright 41.\" notice and this permission notice appear in all copies of the 42.\" software, derivative works or modified versions, and any portions 43.\" thereof, and that both notices appear in supporting documentation. 44.\" 45.\" CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 46.\" CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR 47.\" ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 48.\" 49.\" Carnegie Mellon requests users of this software to return to 50.\" 51.\" Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 52.\" School of Computer Science 53.\" Carnegie Mellon University 54.\" Pittsburgh PA 15213-3890 55.\" 56.\" any improvements or extensions that they make and grant Carnegie Mellon 57.\" the rights to redistribute these changes. 58.\" 59.Dd December 28, 2016 60.Dt DDB 4 61.Os 62.Sh NAME 63.Nm ddb 64.Nd in-kernel debugger 65.Sh SYNOPSIS 66.Cd options DDB 67.Pp 68To enable history editing: 69.Cd options DDB_HISTORY_SIZE=integer 70.Pp 71To disable entering 72.\" XXX: hack; .Nm automatically introduces newline in SYNOPSIS 73.Ic ddb 74upon kernel panic: 75.Cd options DDB_ONPANIC=0 76.Pp 77To enable teeing all 78.\" XXX: hack; .Nm automatically introduces newline in SYNOPSIS 79.Ic ddb 80output to the kernel msgbuf: 81.Cd options DDB_TEE_MSGBUF=1 82.Pp 83To specify commands which will be executed on each entry to 84.Ic ddb : 85.Cd options DDB_COMMANDONENTER="trace;show registers" 86In this case, "trace" and then "show registers" will be executed automatically. 87.Pp 88To enable extended online help: 89.Cd options DDB_VERBOSE_HELP . 90.Sh DESCRIPTION 91.Nm 92is the in-kernel debugger. 93It may be entered at any time via a special key sequence, and 94optionally may be invoked when the kernel panics. 95.Sh ENTERING THE DEBUGGER 96Unless 97.Dv DDB_ONPANIC 98is set to 0, 99.Nm 100will be activated whenever the kernel would otherwise panic. 101.Pp 102.Nm 103may also be activated from the console. 104In general, sending a break on a serial console will activate 105.Nm . 106There are also key sequences for each port that will activate 107.Nm 108from the keyboard: 109.Bl -tag -offset indent -width "xen domU" -compact 110.It alpha 111\*[Lt]Ctrl\*[Gt]-\*[Lt]Alt\*[Gt]-\*[Lt]Esc\*[Gt] on PC style keyboards. 112.It amd64 113\*[Lt]Ctrl\*[Gt]-\*[Lt]Alt\*[Gt]-\*[Lt]Esc\*[Gt] 114.It "" 115\*[Lt]Break\*[Gt] on serial console. 116.It amiga 117\*[Lt]LAlt\*[Gt]-\*[Lt]LAmiga\*[Gt]-\*[Lt]F10\*[Gt] 118.It atari 119\*[Lt]Alt\*[Gt]-\*[Lt]LeftShift\*[Gt]-\*[Lt]F9\*[Gt] 120.It hp300 121\*[Lt]Shift\*[Gt]-\*[Lt]Reset\*[Gt] 122.It hpcarm 123\*[Lt]Ctrl\*[Gt]-\*[Lt]Alt\*[Gt]-\*[Lt]Esc\*[Gt] 124.It hpcmips 125\*[Lt]Ctrl\*[Gt]-\*[Lt]Alt\*[Gt]-\*[Lt]Esc\*[Gt] 126.It hpcsh 127\*[Lt]Ctrl\*[Gt]-\*[Lt]Alt\*[Gt]-\*[Lt]Esc\*[Gt] 128.It hppa 129\*[Lt]Ctrl\*[Gt]-\*[Lt]Alt\*[Gt]-\*[Lt]Esc\*[Gt] on PC style keyboards. 130.It "" 131+++++ 132(five plus signs) on PDC console 133.It "" 134\*[Lt]Break\*[Gt] on serial console. 135.It i386 136\*[Lt]Ctrl\*[Gt]-\*[Lt]Alt\*[Gt]-\*[Lt]Esc\*[Gt] 137.It "" 138\*[Lt]Break\*[Gt] on serial console. 139.It mac68k 140\*[Lt]Command\*[Gt]-\*[Lt]Power\*[Gt], or the Interrupt switch. 141.It macppc 142Some models: 143\*[Lt]Command\*[Gt]-\*[Lt]Option\*[Gt]-\*[Lt]Power\*[Gt] 144.It mvme68k 145Abort switch on CPU card. 146.It pmax 147\*[Lt]Do\*[Gt] on 148.Tn LK-201 149rcons console. 150.It "" 151\*[Lt]Break\*[Gt] on serial console. 152.It sandpoint 153\*[Lt]Break\*[Gt] on serial console. 154.It sparc 155\*[Lt]L1\*[Gt]-A, or \*[Lt]Stop\*[Gt]-A on a 156.Tn Sun 157keyboard. 158.It "" 159\*[Lt]Break\*[Gt] on serial console. 160.It sparc64 161\*[Lt]L1\*[Gt]-A, or \*[Lt]Stop\*[Gt]-A on a 162.Tn Sun 163keyboard. 164.It "" 165\*[Lt]Break\*[Gt] on serial console. 166.It sun3 167\*[Lt]L1\*[Gt]-A, or \*[Lt]Stop\*[Gt]-A on a 168.Tn Sun 169keyboard. 170.It "" 171\*[Lt]Break\*[Gt] on serial console. 172.It vax 173\*[Lt]Esc\*[Gt]-\*[Lt]Shift\*[Gt]-D on serial console. 174.It x68k 175Interrupt switch on the body. 176.It xen dom0 177\*[Lt]Ctrl\*[Gt]-\*[Lt]Alt\*[Gt]-\*[Lt]Esc\*[Gt] on PC style keyboards. 178.It "" 179+++++ 180(five plus signs) on serial console. 181.It xen domU 182+++++ 183(five plus signs) on serial console. 184.It zaurus 185\*[Lt]Ctrl\*[Gt]-\*[Lt]Alt\*[Gt]-\*[Lt]Esc\*[Gt] 186.El 187.Pp 188The key sequence to activate 189.Nm 190can be changed by modifying 191.Dq hw.cnmagic 192with 193.Xr sysctl 8 . 194If the console is not dedicated to 195.Nm 196the sequence should not be easily typed by accident. 197In addition, 198.Nm 199may be explicitly activated by the debugging code in the kernel 200if 201.Cm DDB 202is configured. 203.Pp 204Commands can be automatically run when 205.Nm 206is entered by using 207.Cd options DDB_COMMANDONENTER 208or by setting 209.Ar ddb.commandonenter 210with 211.Xr sysctl 8 . 212Multiple commands can be separated by a semi-colon. 213.Sh COMMAND SYNTAX 214The general command syntax is: 215.Bd -ragged -offset indent 216.Ic command Ns Op Cm / Ns Ar modifier 217.Ar address 218.Op Cm , Ns Ar count 219.Ed 220.Pp 221The current memory location being edited is referred to as 222.Ar dot , 223and the next location is 224.Ar next . 225They are displayed as hexadecimal numbers. 226.Pp 227Commands that examine and/or modify memory update 228.Ar dot 229to the address of the last line examined or the last location 230modified, and set 231.Ar next 232to the next location to be examined or modified. 233Other commands don't change 234.Ar dot , 235and set 236.Ar next 237to be the same as 238.Ar dot . 239.Pp 240A blank line repeats the previous command from the address 241.Ar next 242with the previous 243.Cm count 244and no modifiers. 245Specifying 246.Cm address 247sets 248.Em dot 249to the address. 250If 251.Cm address 252is omitted, 253.Em dot 254is used. 255A missing 256.Cm count 257is taken to be 1 for printing commands, and infinity for stack traces. 258.Pp 259The syntax: 260.Bd -ragged -offset indent 261.Cm , Ns Ar count 262.Ed 263.Pp 264repeats the previous command, just as a blank line does, but with 265the specified 266.Cm count . 267.Pp 268.Nm 269has a 270.Xr more 1 Ns -like 271functionality; if a number of lines in a command's output exceeds the number 272defined in the 273.Va lines 274variable, then 275.Nm 276displays 277.Dq "--db more--" 278and waits for a response, which may be one of: 279.Bl -tag -offset indent -width "\*[Lt]return\*[Gt]" 280.It Aq return 281one more line. 282.It Aq space 283one more page. 284.It Ic q 285abort the current command, and return to the command input mode. 286.El 287.Pp 288You can set 289.Va lines 290variable to zero to disable this feature. 291.Pp 292If 293.Nm 294history editing is enabled (by defining the 295.D1 Cd options DDB_HISTORY_SIZE=num 296kernel option), then a history of the last 297.Cm num 298commands is kept. 299The history can be manipulated with the following key sequences: 300.Bl -tag -offset indent -width "\*[Lt]Ctrl\*[Gt]-P" 301.It \*[Lt]Ctrl\*[Gt]-P 302retrieve previous command in history (if any). 303.It \*[Lt]Ctrl\*[Gt]-N 304retrieve next command in history (if any). 305.El 306.Sh COMMANDS 307.Nm 308supports the following commands: 309.Bl -tag -width 5n 310.It Ic \&! Ns Ar address Ns Oo Cm ( Ar expression Ns Oo Ar ,... Oc Ns Cm ) Oc 311A synonym for 312.Ic call . 313.It Ic break Ns Oo Cm /u Oc Ar address Ns Op Cm , Ns Ar count 314Set a breakpoint at 315.Ar address . 316If 317.Ar count 318is supplied, continues 319.Pq Ar count Ns \-1 320times before stopping at the breakpoint. 321If the breakpoint is set, a breakpoint number is printed with 322.Sq \&# . 323This number can be used to 324.Ic delete 325the breakpoint, or to add 326conditions to it. 327.Pp 328If 329.Cm /u 330is specified, 331set a breakpoint at a user-space address. 332Without 333.Cm /u , 334.Ar address 335is considered to be in the kernel-space, and an address in the wrong 336space will be rejected, and an error message will be emitted. 337This modifier may only be used if it is supported by machine dependent 338routines. 339.Pp 340Warning: if a user text is shadowed by a normal user-space debugger, 341user-space breakpoints may not work correctly. 342Setting a breakpoint at the low-level code paths may also cause 343strange behavior. 344.It Ic bt Ns Oo Cm /ul Oc Oo Ar frame-address Oc Ns Oo Cm , Ns Ar count Oc 345A synonym for 346.Ic trace . 347.It Ic bt/t Ns Oo Cm /ul Oc Oo Ar pid Oc Ns Oo Cm , Ns Ar count Oc 348A synonym for 349.Ic trace/t . 350.It Ic bt/a Ns Oo Cm /ul Oc Oo Ar lwpaddr Oc Ns Oo Cm , Ns Ar count Oc 351A synonym for 352.Ic trace/a . 353.It Ic call Ar address Ns Oo Cm ( Ns Ar expression Ns Oo Ar ,... Oc Ns Cm ) Oc 354Call the function specified by 355.Ar address 356with the argument(s) listed in parentheses. 357Parentheses may be omitted if the function takes no arguments. 358The number of arguments is currently limited to 10. 359.It Ic continue Ns Op Cm /c 360Continue execution until a breakpoint or watchpoint. 361If 362.Cm /c 363is specified, count instructions while executing. 364Some machines (e.g., pmax) also count loads and stores. 365.Pp 366Warning: when counting, the debugger is really silently 367single-stepping. 368This means that single-stepping on low-level may cause strange 369behavior. 370.It Ic delete Ar "address" | Cm # Ns Ar number 371Delete a breakpoint. 372The target breakpoint may be specified by 373.Ar address , 374as per 375.Ic break , 376or by the breakpoint number returned by 377.Ic break 378if it's prefixed with 379.Sq Cm \&# . 380.It Ic dmesg Op Ar count 381Prints the contents of the kernel message buffer. 382The optional 383.Ar count 384argument will limit printing to at most the last 385.Ar count 386bytes of the message buffer. 387.It Ic dwatch Ar address 388Delete the watchpoint at 389.Ar address 390that was previously set with 391.Ic watch 392command. 393.It Ic examine Ns Oo Cm / Ns Ar modifier Oc Ar address Ns Op Cm , Ns Ar count 394Display the address locations according to the format in 395.Ar modifier . 396Multiple modifier formats display multiple locations. 397If 398.Ar modifier 399isn't specified, the modifier from the last use of 400.Ic examine 401is used. 402.Pp 403The valid format characters for 404.Ar modifier 405are: 406.Bl -tag -offset indent -width 2n -compact 407.It Cm b 408examine bytes (8 bits). 409.It Cm h 410examine half-words (16 bits). 411.It Cm l 412examine words (legacy 413.Dq long , 41432 bits). 415.It Cm L 416examine long words (implementation dependent) 417.It Cm a 418print the location being examined. 419.It Cm A 420print the location with a line number if possible. 421.It Cm x 422display in unsigned hex. 423.It Cm z 424display in signed hex. 425.It Cm o 426display in unsigned octal. 427.It Cm d 428display in signed decimal. 429.It Cm u 430display in unsigned decimal. 431.It Cm r 432display in current radix, signed. 433.It Cm c 434display low 8 bits as a character. 435Non-printing characters as displayed as an octal escape code 436(e.g., 437.Sq \e000 ) . 438.It Cm s 439display the NUL terminated string at the location. 440Non-printing characters are displayed as octal escapes. 441.It Cm m 442display in unsigned hex with a character dump at the end of each line. 443The location is displayed as hex at the beginning of each line. 444.It Cm i 445display as a machine instruction. 446.It Cm I 447display as a machine instruction, with possible alternative formats 448depending upon the machine: 449.Bl -tag -offset indent -width "sparc" -compact 450.It alpha 451print register operands 452.It m68k 453use Motorola syntax 454.It vax 455don't assume that each external label is a procedure entry mask 456.El 457.El 458.It Ic kill Ar pid Ns Op Cm , Ns Ar signal_number 459Send a signal to the process specified by the 460.Ar pid . 461Note that 462.Ar pid 463is interpreted using the current radix (see 464.Cm trace/t 465command for details). 466If 467.Ar signal_number 468isn't specified, the SIGTERM signal is sent. 469.It Ic match Ns Op Cm /p 470A synonym for 471.Ic next . 472.It Ic next Ns Op Cm /p 473Stop at the matching return instruction. 474If 475.Cm /p 476is specified, print the call nesting depth and the 477cumulative instruction count at each call or return. 478Otherwise, only print when the matching return is hit. 479.It Ic print Ns Oo Cm /axzodurc Oc Ar address Op Ar address ... 480Print addresses 481.Ar address 482according to the modifier character, as per 483.Ic examine . 484Valid modifiers are: 485.Cm /a , 486.Cm /x , 487.Cm /z , 488.Cm /o , 489.Cm /d , 490.Cm /u , 491.Cm /r , 492and 493.Cm /c 494(as per 495.Ic examine ) . 496If no modifier is specified, the most recent one specified is used. 497.Ar address 498may be a string, and is printed 499.Dq as-is . 500For example: 501.Bd -literal -offset indent 502print/x "eax = " $eax "\enecx = " $ecx "\en" 503.Ed 504.Pp 505will produce: 506.Bd -literal -offset indent 507eax = xxxxxx 508ecx = yyyyyy 509.Ed 510.It Ic ps Ns Oo Cm /a Oc Ns Oo Cm /n Oc Ns Oo Cm /w Oc Ns Oo Cm /l Oc 511A synonym for 512.Ic show all procs . 513.It Ic reboot Op Ar flags 514Reboot, using the optionally supplied boot 515.Ar flags , 516which is a bitmask supporting the same values as for 517.Xr reboot 2 . 518Some of the more useful flags: 519.Bl -column "Value" "RB_POWERDOWN" "Description" 520.It Sy "Value" Ta Sy "Name" Ta Sy "Description" 521.It 0x1 Ta RB_ASKNAME Ta Ask for file name to reboot from 522.It 0x2 Ta RB_SINGLE Ta Reboot to single user mode 523.It 0x4 Ta RB_NOSYNC Ta Don't sync before reboot 524.It 0x8 Ta RB_HALT Ta Halt instead of reboot 525.It 0x40 Ta RB_KDB Ta Boot into kernel debugger 526.It 0x100 Ta RB_DUMP Ta Dump unconditionally before reboot 527.It 0x808 Ta RB_POWERDOWN Ta Power off (or at least halt) 528.El 529.Pp 530Note: Limitations of the command line interface preclude 531specification of a boot string. 532.It Ic search Ns Oo Cm /bhl Oc Ar address Ar value \ 533Oo Ar mask Oc Oo Cm , Ns Ar count Oc 534Search memory from 535.Ar address 536for 537.Ar value . 538The unit size is specified with a modifier character, as per 539.Ic examine . 540Valid modifiers are: 541.Cm /b , 542.Cm /h , 543and 544.Cm /l . 545If no modifier is specified, 546.Cm /l 547is used. 548.Pp 549This command might fail in interesting ways if it doesn't find 550.Ar value . 551This is because 552.Nm 553doesn't always recover from touching bad memory. 554The optional 555.Ar count 556limits the search. 557.It Ic set Cm $ Ns Ar variable Oo Cm = Oc Ar expression 558Set the named variable or register to the value of 559.Ar expression . 560Valid variable names are described in 561.Sx VARIABLES . 562.It Ic show all callout 563Display information about callouts in the system. 564See 565.Xr callout 9 566for more information on callouts. 567.It Ic show all pages 568Display basic information about all physical pages managed by the VM system. 569For more detailed information about a single page, use 570.Ic show page . 571.It Ic show all pools Ns Op Cm /clp 572Display all pool information. 573Modifiers are the same as 574.Ic show pool . 575.It Ic "show\ all\ procs" Ns Oo Cm /a Oc Ns Oo Cm /n Oc Ns Oo Cm /w Oc Ns \ 576Oo Cm /l Oc 577Display all process information. 578Valid modifiers: 579.Bl -tag -width 3n 580.It Cm /n 581show process information in a 582.Xr ps 1 583style format. 584Information printed includes: process ID, parent process ID, 585process group, UID, process status, process flags, number of LWPs, 586command name, and process wait channel message. 587.It Cm /a 588show each process ID, command name, kernel virtual addresses of 589each process' proc structure, u-area, and vmspace structure. 590The vmspace address is also the address of the process' 591vm_map structure, and can be used in the 592.Ic show map 593command. 594.It Cm /w 595show each LWP ID, process ID, command name, system call emulation, 596priority, wait channel message and wait channel address. 597LWPs currently running on a CPU are marked with the '\&>' sign. 598.It Cm /l 599show each LWP ID, process ID, process status, CPU ID the LWP runs on, 600process flags, kernel virtual address of LWP structure, 601LWP name and wait channel message. 602LWPs currently running on a CPU are marked with the '\&>' sign. 603This is the default. 604.El 605.It Ic show routes 606Dump the entire 607.Dv AF_INET 608routing table. 609This command is available only on systems which support inet. 610.It Ic show breaks 611Display all breakpoints. 612.It Ic show buf Ns Oo Cm /f Oc Ar address 613Print the struct buf at 614.Ar address . 615The 616.Cm /f 617does nothing at this time. 618.It Ic show event Ns Oo Cm /f Oc Ns Oo Cm /i Oc Ns Oo Cm /m Oc Ns \ 619Oo Cm /t Oc 620Print all the non-zero 621.Xr evcnt 9 622event counters. 623Valid modifiers: 624.Bl -tag -width 3n 625.It Cm /f 626event counters with a count of zero are printed as well. 627.It Cm /i 628interrupted counters will be displayed. 629.It Cm /m 630misc counters will be displayed. 631.It Cm /t 632trap counters will be displayed. 633.El 634.Pp 635If none of 636.Cm /i , 637.Cm /m 638or 639.Cm /t 640are specified, all are shown. 641You can combine any of these. 642For example, the modifier 643.Cm /itf 644will select both interrupt and trap events, including those that are non-zero. 645.It Ic show files Ar address 646Display information about the vnodes of the files that are currently 647open by the process associated with the proc structure at 648.Ar address . 649This address can be found using the 650.Ic show all procs /a 651command. 652If the kernel is compiled with 653.Cd options LOCKDEBUG 654then details about the locking of the underlying uvm object will also 655be displayed. 656.It Ic show lock Ar address 657Display information about a lock at 658.Ar address . 659This command is useful only if a kernel is compiled with 660.Cd options LOCKDEBUG . 661.It Ic show map Ns Oo Cm /f Oc Ar address 662Print the vm_map at 663.Ar address . 664If 665.Cm /f 666is specified, the complete map is printed. 667.It Ic show mount Ns Oo Cm /f Oc Ar address 668Print the mount structure at 669.Ar address . 670If 671.Cm /f 672is specified, the complete vnode list is printed. 673.It Ic show mbuf Ns Oo Cm /c Oc Ar address 674Print the mbuf structure at 675.Ar address . 676If 677.Cm /c 678is specified, the mbufs in the chain are followed. 679.It Ic show ncache Ar address 680Dump the namecache list associated with vnode at 681.Ar address . 682.It Ic show object Ns Oo Cm /f Oc Ar address 683Print the vm_object at 684.Ar address . 685If 686.Cm /f 687is specified, the complete object is printed. 688.It Ic show page Ns Oo Cm /f Oc Ar address 689Print the vm_page at 690.Ar address . 691If 692.Cm /f 693is specified, the complete page is printed. 694.It Ic show panic 695Print the current "panic" string. 696.It Ic show pool Ns Oo Cm /clp Oc Ar address 697Print the pool at 698.Ar address . 699Valid modifiers: 700.Bl -tag -width 4n -compact 701.It Cm /c 702Print the cachelist and its statistics for this pool. 703.It Cm /l 704Print the log entries for this pool. 705.It Cm /p 706Print the pagelist for this pool. 707.El 708.It Ic show proc Ns Oo Cm /ap Oc Ar address | pid 709Show information about a process and its LWPs. 710LWPs currently running on a CPU are marked with the '\&>' sign. 711.Bl -tag -width 4n -compact 712.It Cm /a 713The argument passed is the kernel virtual address 714of LWP structure. 715.It Cm /p 716The argument passed is a PID. 717Note that 718.Ar pid 719is interpreted using the current radix (see 720.Cm trace/t 721command for details). 722This is the default. 723.El 724.It Ic show registers Ns Op Cm /u 725Display the register set. 726If 727.Cm /u 728is specified, display user registers instead of kernel registers 729or the currently save one. 730.Pp 731Warning: support for 732.Cm /u 733is machine dependent. 734If not supported, incorrect information will be displayed. 735.It Ic show sched_qs 736Print the state of the scheduler's run queues. 737For each run queue that has an LWP, the run queue index and the list 738of LWPs will be shown. 739If the run queue has LWPs, but the sched_whichqs bit is not set for that 740queue, the queue index will be prefixed with a 741.Sq \&! . 742.It Ic show uvmexp 743Print a selection of UVM counters and statistics. 744.It Ic show kernhist Oo Ar addr Oc 745Dumps all the kernel histories if no address is specified, or the history 746at the address. 747This command is available only if a kernel is compiled with one or more 748of the kernel history options 749.Cd KERNHIST , 750.Cd SYSCALL_DEBUG , 751.Cd USB_DEBUG , 752.Cd BIOHIST , 753or 754.Cd UVMHIST . 755.It Ic show vnode Ns Oo Cm /f Oc Ar address 756Print the vnode at 757.Ar address . 758If 759.Cm /f 760is specified, the complete vnode is printed. 761.It Ic show watches 762Display all watchpoints. 763.It Ic sifting Ns Oo Cm /F Oc Ar string 764Search the symbol tables for all symbols of which 765.Ar string 766is a substring, and display them. 767If 768.Cm /F 769is specified, a character is displayed immediately after each symbol 770name indicating the type of symbol. 771.Pp 772For 773.Xr a.out 5 Ns -format 774symbol tables, 775absolute symbols display 776.Sy @ , 777text segment symbols display 778.Sy * , 779data segment symbols display 780.Sy + , 781.Tn BSS 782segment symbols display 783.Sy - , 784and filename symbols display 785.Sy / . 786For 787.Tn ELF Ns -format 788symbol tables, 789object symbols display 790.Sy + , 791function symbols display 792.Sy * , 793section symbols display 794.Sy \*[Am] , 795and file symbols display 796.Sy / . 797.Pp 798To sift for a string beginning with a number, escape the first 799character with a backslash as: 800.Bd -literal -offset indent 801sifting \\386 802.Ed 803.It Ic step Ns Oo Cm /p Oc Op Cm , Ns Ar count 804Single-step 805.Ar count 806times. 807If 808.Cm /p 809is specified, print each instruction at each step. 810Otherwise, only print the last instruction. 811.Pp 812Warning: depending on the machine type, it may not be possible 813to single-step through some low-level code paths or user-space 814code. 815On machines with software-emulated single-stepping (e.g., pmax), 816stepping through code executed by interrupt handlers will probably 817do the wrong thing. 818.It Ic sync 819Sync the disks, force a crash dump, and then reboot. 820.It Ic trace Ns Oo Cm /u Ns Oo Cm l Oc Oc Oo Ar frame-address Oc Ns \ 821Oo Cm , Ns Ar count Oc 822Stack trace from 823.Ar frame-address . 824If 825.Cm /u 826is specified, trace user-space, otherwise trace kernel-space. 827.Ar count 828is the number of frames to be traced. 829If 830.Ar count 831is omitted, all frames are printed. 832If 833.Cm /l 834is specified, the trace is printed and also stored in the kernel 835message buffer. 836.Pp 837Warning: user-space stack trace is valid only if the machine dependent 838code supports it. 839.It Ic trace/t Ns Oo Cm l Oc Oo Ar pid Oc Ns Oo Cm , Ns Ar count Oc 840Stack trace by 841.Dq thread 842(process, on 843.Nx ) 844rather than by stack frame address. 845Note that 846.Ar pid 847is interpreted using the current radix, whilst 848.Ic ps 849displays pids in decimal; prefix 850.Ar pid 851with 852.Sq 0t 853to force it to be interpreted as decimal (see 854.Sx VARIABLES 855section for radix). 856If 857.Cm /l 858is specified, the trace is printed and also stored in the kernel 859message buffer. 860.Pp 861Warning: trace by pid is valid only if the machine dependent code 862supports it. 863.It Ic trace/a Ns Oo Cm l Oc Oo Ar lwpaddr Oc Ns Oo Cm , Ns Ar count Oc 864Stack trace by light weight process (LWP) address 865rather than by stack frame address. 866If 867.Cm /l 868is specified, the trace is printed and also stored in the kernel 869message buffer. 870.Pp 871Warning: trace by LWP address is valid only if the machine dependent 872code supports it. 873.It Ic until Ns Op Cm /p 874Stop at the next call or return instruction. 875If 876.Cm /p 877is specified, print the call nesting depth and the 878cumulative instruction count at each call or return. 879Otherwise, only print when the matching return is hit. 880.It Ic watch Ar address Ns Oo Cm , Ns Ar size Oc 881Set a watchpoint for a region. 882Execution stops when an attempt to modify the region occurs. 883.Ar size 884defaults to 4. 885.Pp 886If you specify a wrong space address, the request is 887rejected with an error message. 888.Pp 889Warning: attempts to watch wired kernel memory may cause 890an unrecoverable error in some systems such as i386. 891Watchpoints on user addresses work the best. 892.It Ic whatis Ar address 893Describe what an address is. 894.It Ic write Ns Oo Cm /bhlBHL Oc Ar address Ar expression Oo Ar expression ... Oc 895Write the 896.Ar expression Ns s 897at succeeding locations. 898The unit size is specified with a modifier character, as per 899.Ic examine . 900Valid modifiers are: 901.Cm /b , 902.Cm /h , 903and 904.Cm /l . 905If no modifier is specified, 906.Cm /l 907is used. 908.Pp 909Specifying the modifiers in upper case, 910.Cm /B , 911.Cm /H , 912.Cm /L , 913will prevent 914.Nm 915from reading the memory location first, which is useful for avoiding 916side effects when writing to I/O memory regions. 917.Pp 918Warning: since there is no delimiter between 919.Ar expression Ns s , 920strange things may occur. 921It's best to enclose each 922.Ar expression 923in parentheses. 924.It Ic x Ns Oo Cm / Ns Ar modifier Oc Ar address Ns Op Cm , Ns Ar count 925A synonym for 926.Ic examine . 927.\" XXX - these commands aren't implemented; jhawk 19 May 2000 928.\" .It Ic xf 929.\" Examine forward. 930.\" .Ic xf 931.\" re-executes the most recent 932.\" .Ic execute 933.\" command with the same parameters except that 934.\" .Ar address 935.\" is set to 936.\" .Ar next . 937.\" .It Ic xb 938.\" Examine backward. 939.\" .Ic xb 940.\" re-executes the most recent 941.\" .Ic execute 942.\" command with the same parameters, except that 943.\" .Ar address 944.\" is set to the last start address minus its size. 945.El 946.Sh MACHINE-SPECIFIC COMMANDS 947The "glue" code that hooks 948.Nm 949into the 950.Nx 951kernel for any given port can also add machine specific commands 952to the 953.Nm 954command parser. 955All of these commands are preceded by the command word 956.Em machine 957to indicate that they are part of the machine-specific command 958set (e.g. 959.Ic machine reboot ) . 960Some of these commands are: 961.Ss ACORN26 962.Bl -tag -width "traptrace" -compact 963.It Ic bsw 964Writes one or two bytes to the IObus. 965Takes an address and a value. 966Use the 967.Dq b 968modifier to write a single byte and the 969.Dq h 970modifier to write two bytes. 971.It Ic frame 972Given a trap frame address, print out the trap frame. 973.It Ic irqstat 974Display the IRQ statistics 975.El 976.Ss ALPHA 977.Bl -tag -width "traptrace" -compact 978.It Ic cpu 979Switch to another cpu. 980.\" .It Ic halt 981.\" Call the PROM monitor to halt the CPU. 982.\" .It Ic reboot 983.\" Call the PROM monitor to reboot the CPU. 984.El 985.Ss AMD64 986.Bl -tag -width "traptrace" -compact 987.It Ic cpu 988Switch to another cpu. 989.El 990.Ss ARM32 991.Bl -tag -width "traptrace" -compact 992.It Ic frame 993Given a trap frame address, print out the trap frame. 994.El 995.Ss HPPA 996.Bl -tag -width "traptrace" -compact 997.It Ic frame 998Without an address the default trap frame is printed. 999Otherwise, the trap frame address can be given, or, when the 1000.Dq l 1001modifier is used, an LWP address. 1002.El 1003.Ss I386 1004.Bl -tag -width "traptrace" -compact 1005.It Ic cpu 1006Switch to another cpu. 1007.El 1008.Ss IA64 1009.Bl -tag -width "traptrace" -compact 1010.It Ic vector 1011Without a vector, information about all 256 vectors is shown. 1012Otherwise, the given vector is shown. 1013.El 1014.Ss MIPS 1015.Bl -tag -width "traptrace" -compact 1016.It Ic cp0 1017Dump CP0 (coprocessor 0) register values. 1018.It Ic kvtop 1019Print the physical address for a given kernel virtual address. 1020.It Ic tlb 1021Print out the Translation Lookaside Buffer (TLB). 1022Only works in 1023.Nx 1024kernels compiled with 1025.Dv DEBUG 1026option. 1027.El 1028.Ss POWERPC 4xx 1029.Bl -tag -width "traptrace" -compact 1030.It Ic ctx 1031Print process MMU context information. 1032.It Ic pv 1033Print PA-\*[Gt]VA mapping information. 1034.It Ic reset 1035Reset the system. 1036.It Ic tf 1037Display the contents of the trapframe. 1038.It Ic tlb 1039Display instruction translation storage buffer information. 1040.It Ic dcr 1041Set the DCR register. 1042Must be between 0x00 and 0x3ff. 1043.It Ic user 1044Display user memory. 1045Use the 1046.Dq i 1047modifier to get instruction decoding. 1048.El 1049.Ss POWERPC OEA 1050.Bl -tag -width "traptrace" -compact 1051.It Ic bat 1052Print BAT registers and translations. 1053.It Ic mmu 1054Print MMU registers. 1055.El 1056.Ss SH3 1057.Bl -tag -width "traptrace" -compact 1058.It Ic tlb 1059Print TLB entries. 1060.It Ic cache 1061Print cache entries. 1062.It Ic frame 1063Print switch frame and trap frames. 1064.It Ic stack 1065Print kernel stack usage. 1066Only works in 1067.Nx 1068kernels compiled with the 1069.Dv KSTACK_DEBUG 1070option. 1071.El 1072.Ss SPARC 1073.Bl -tag -width "traptrace" -compact 1074.It Ic cpu 1075Switch to another cpu. 1076.It Ic prom 1077Enter the Sun PROM monitor. 1078.It Ic proc 1079Display some information about the LWP pointed to, or curlwp. 1080.It Ic pcb 1081Display information about the 1082.Dq struct pcb 1083listed. 1084.It Ic page 1085Display the pointer to the 1086.Dq struct vm_page 1087for this physical address. 1088.El 1089.Ss SPARC64 1090.Bl -tag -width "traptrace" -compact 1091.It Ic ctx 1092Print process context information. 1093.It Ic cpu 1094Switch to another cpu. 1095.It Ic dtlb 1096Print data translation look-aside buffer context information. 1097.It Ic dtsb 1098Display data translation storage buffer information. 1099.It Ic kmap 1100Display information about the listed mapping in the kernel pmap. 1101Use the 1102.Dq f 1103modifier to get a full listing. 1104.It Ic extract 1105Extract the physical address for a given virtual address from the kernel pmap. 1106.It Ic fpstate 1107Dump the FPU state. 1108.It Ic itlb 1109Print instruction translation look-aside buffer context information. 1110.It Ic itsb 1111Display instruction translation storage buffer information. 1112.It Ic lwp 1113Display a struct lwp 1114.It Ic pcb 1115Display information about the 1116.Dq struct pcb 1117listed. 1118.It Ic pctx 1119Attempt to change process context. 1120.It Ic page 1121Display the pointer to the 1122.Dq struct vm_page 1123for this physical address. 1124.It Ic phys 1125Display physical memory. 1126.It Ic pmap 1127Display the pmap. 1128Use the 1129.Dq f 1130modifier to get a fuller listing. 1131.It Ic proc 1132Display some information about the process pointed to, or curproc. 1133.It Ic prom 1134Enter the OFW PROM. 1135.It Ic pv 1136Display the 1137.Dq struct pv_entry 1138pointed to. 1139.It Ic sir 1140Reset the machine and enter prom (do a Software Initiated Reset). 1141.It Ic stack 1142Dump the window stack. 1143Use the 1144.Dq u 1145modifier to get userland information. 1146.It Ic tf 1147Display full trap frame state. 1148This is most useful for inclusion with bug reports. 1149.It Ic ts 1150Display trap state. 1151.It Ic traptrace 1152Display or set trap trace information. 1153Use the 1154.Dq r 1155and 1156.Dq f 1157modifiers to get reversed and full information, respectively. 1158.It Ic watch 1159Set or clear a physical or virtual hardware watchpoint. 1160Pass the address to be watched, or 1161.Dq 0 1162(or omit the address) to clear the watchpoint. 1163Optional modifiers are 1164.Dq p 1165for physical address, 1166.Dq r 1167for trap on read access (default: trap on write access only), 1168.Dq b 1169for 8 bit width, 1170.Dq h 1171for 16 bit, 1172.Dq l 1173for 32 bit or 1174.Dq L 1175for 64 bit. 1176.It Ic window 1177Print register window information. 1178Argument is a stack frame number (0 is 1179top of stack, which is used when no index is given). 1180.El 1181.Ss SUN2, SUN3 and SUN3X 1182.Bl -tag -width "traptrace" -compact 1183.It Ic abort 1184Drop into monitor via abort (allows continue). 1185.It Ic halt 1186Exit to Sun PROM monitor as in 1187.Xr halt 8 . 1188.It Ic reboot 1189Reboot the machine as in 1190.Xr reboot 8 . 1191.It Ic pgmap 1192Given an address, print the address, segment map, page map, and 1193Page Table Entry (PTE). 1194.El 1195.Ss VAX 1196.Bl -tag -width "traptrace" -compact 1197.It Ic cpu 1198Switch to another cpu. 1199.El 1200.Sh VARIABLES 1201.Nm 1202accesses registers and variables as 1203.Cm $ Ns Ar name . 1204Register names are as per the 1205.Ic show registers 1206command. 1207Some variables are suffixed with numbers, and may have a modifier 1208following a colon immediately after the variable name. 1209For example, register variables may have a 1210.Sq u 1211modifier to indicate user register 1212(e.g., 1213.Li "$eax:u" ) . 1214.Pp 1215Built-in variables currently supported are: 1216.Bl -tag -offset indent -width "maxwidth" -compact 1217.It Va lines 1218The number of lines. 1219This is used by the 1220.Ic more 1221feature. 1222When this variable is set to zero the 1223.Ic more 1224feature is disabled. 1225.It Va maxoff 1226Addresses are printed as 1227.Li 'symbol'+offset 1228unless 1229.Li offset 1230is greater than 1231.Va maxoff . 1232.It Va maxwidth 1233The width of the displayed line. 1234.Nm 1235wraps the current line by printing new line when 1236.Va maxwidth 1237column is reached. 1238When this variable is set to zero 1239.Nm 1240doesn't perform any wrapping. 1241.It Va onpanic 1242If greater than zero (the default is 1), 1243.Nm 1244will be invoked when the kernel panics. 1245If the kernel configuration option 1246.D1 Cd options DDB_ONPANIC=0 1247is used, 1248.Va onpanic 1249will be initialized to off, causing a stack trace to be printed and 1250the system to be rebooted instead of 1251.Nm 1252being entered. 1253Other useful settings are \-1, which suppresses the stack trace before 1254reboot, and 2, which causes a stack trace to be printed and 1255.Nm 1256to be entered. 1257.It Va fromconsole 1258If non-zero (the default), 1259the kernel allows to enter 1260.Nm 1261from the console (by break signal or special key sequence). 1262If the kernel configuration option 1263.D1 Cd options DDB_FROMCONSOLE=0 1264is used, 1265.Va fromconsole 1266will be initialized to off. 1267.It Va radix 1268Input and output radix. 1269.It Va tabstops 1270Tab stop width. 1271.It Va tee_msgbuf 1272If explicitly set to non zero (zero is the default) all 1273.Nm 1274output will not only be displayed on screen but 1275also be fed to the msgbuf. 1276The default of the variable can be set using the kernel configuration option 1277.D1 Cd options DDB_TEE_MSGBUF=1 1278which will initialize 1279.Va tee_msgbuf 1280to be 1. 1281This option is especially handy for poor souls 1282who don't have a serial console but want to recall 1283.Nm 1284output from a crash investigation. 1285This option is more generic than the /l command modifier possible for 1286selected commands as discussed above to log the output. 1287Mixing both /l 1288and this setting can give double loggings. 1289.\" .It Va work Ns Sy xx 1290.\" Temporary work variable. 1291.\" .Sq Sy xx 1292.\" is between 0 and 31. 1293.El 1294.Pp 1295All built-in variables are accessible via 1296.Xr sysctl 3 . 1297.Sh EXPRESSIONS 1298Almost all expression operators in C are supported, except 1299.Sq \&~ , 1300.Sq \&^ , 1301and unary 1302.Sq \&\*[Am] . 1303Special rules in 1304.Nm 1305are: 1306.Bl -tag -offset indent -width "identifier" 1307.It Ar identifier 1308name of a symbol. 1309It is translated to the address (or value) of it. 1310.Sq \&. 1311and 1312.Sq \&: 1313can be used in the identifier. 1314If supported by an object format dependent routine, 1315.Sm off 1316.Xo 1317.Oo Ar filename : Oc 1318.Ar function 1319.Oo : Ar line\ number Oc , 1320.Xc 1321.Sm on 1322.Sm off 1323.Xo 1324.Oo Ar filename : Oc 1325.Ar variable , 1326.Xc 1327.Sm on 1328and 1329.Sm off 1330.Xo 1331.Ar filename 1332.Oo : Ar "line number" Oc , 1333.Xc 1334.Sm on 1335can be accepted as a symbol. 1336The symbol may be prefixed with 1337.Ar symbol_table_name\^ : : 1338(e.g., 1339.Li emulator::mach_msg_trap ) 1340to specify other than kernel symbols. 1341.It Ar number 1342number. 1343Radix is determined by the first two characters: 1344.Sq 0x 1345- hex, 1346.Sq 0o 1347- octal, 1348.Sq 0t 1349- decimal, 1350otherwise follow current radix. 1351.It Cm . 1352.Ar dot 1353.It Cm + 1354.Ar next 1355.It Cm .. 1356address of the start of the last line examined. 1357Unlike 1358.Ar dot 1359or 1360.Ar next , 1361this is only changed by the 1362.Ic examine 1363or 1364.Ic write 1365commands. 1366.It Cm \&" \"" XXX: emacs highlighting 1367last address explicitly specified. 1368.It Cm $ Ns Ar name 1369register name or variable. 1370It is translated to the value of it. 1371It may be followed by a 1372.Sq \&: 1373and modifiers as described above. 1374.It Cm # 1375a binary operator which rounds up the left hand side to the next 1376multiple of right hand side. 1377.It Cm * Ns Ar expr 1378expression indirection. 1379It may be followed by a 1380.Sq \&: 1381and modifiers as described above. 1382.El 1383.Sh SEE ALSO 1384.Xr reboot 2 , 1385.Xr options 4 , 1386.Xr crash 8 , 1387.Xr reboot 8 , 1388.Xr sysctl 8 , 1389.Xr cnmagic 9 1390.Sh HISTORY 1391The 1392.Nm 1393kernel debugger was written as part of the MACH project at 1394Carnegie-Mellon University. 1395