1.\" 2.\" Mach Operating System 3.\" Copyright (c) 1991,1990 Carnegie Mellon University 4.\" All Rights Reserved. 5.\" 6.\" Permission to use, copy, modify and distribute this software and its 7.\" documentation is hereby granted, provided that both the copyright 8.\" notice and this permission notice appear in all copies of the 9.\" software, derivative works or modified versions, and any portions 10.\" thereof, and that both notices appear in supporting documentation. 11.\" 12.\" CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 13.\" CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR 14.\" ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 15.\" 16.\" Carnegie Mellon requests users of this software to return to 17.\" 18.\" Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 19.\" School of Computer Science 20.\" Carnegie Mellon University 21.\" Pittsburgh PA 15213-3890 22.\" 23.\" any improvements or extensions that they make and grant Carnegie Mellon 24.\" the rights to redistribute these changes. 25.\" 26.\" changed a \# to #, since groff choked on it. 27.\" 28.\" HISTORY 29.\" ddb.4,v 30.\" Revision 1.1 1993/07/15 18:41:02 brezak 31.\" Man page for DDB 32.\" 33.\" Revision 2.6 92/04/08 08:52:57 rpd 34.\" Changes from OSF. 35.\" [92/01/17 14:19:22 jsb] 36.\" Changes for OSF debugger modifications. 37.\" [91/12/12 tak] 38.\" 39.\" Revision 2.5 91/06/25 13:50:22 rpd 40.\" Added some watchpoint explanation. 41.\" [91/06/25 rpd] 42.\" 43.\" Revision 2.4 91/06/17 15:47:31 jsb 44.\" Added documentation for continue/c, match, search, and watchpoints. 45.\" I've not actually explained what a watchpoint is; maybe Rich can 46.\" do that (hint, hint). 47.\" [91/06/17 10:58:08 jsb] 48.\" 49.\" Revision 2.3 91/05/14 17:04:23 mrt 50.\" Correcting copyright 51.\" 52.\" Revision 2.2 91/02/14 14:10:06 mrt 53.\" Changed to new Mach copyright 54.\" [91/02/12 18:10:12 mrt] 55.\" 56.\" Revision 2.2 90/08/30 14:23:15 dbg 57.\" Created. 58.\" [90/08/30 dbg] 59.\" 60.\" $FreeBSD$ 61.Dd January 16, 1996 62.Dt DDB 4 63.Os 64.Sh NAME 65.Nm ddb 66.Nd interactive kernel debugger 67.Sh SYNOPSIS 68.Cd options DDB 69.Pp 70To prevent activation of the debugger on kernel 71.Xr panic 9 : 72.Cd options DDB_UNATTENDED 73.Sh DESCRIPTION 74The 75.Nm 76kernel debugger has most of the features of the old kdb, 77but with a more rational syntax 78inspired by 79.Xr gdb 1 . 80If linked into the running kernel, 81it can be invoked locally with the 82.Ql debug 83.Xr keymap 5 84action. 85The debugger is also invoked on kernel 86.Xr panic 9 87if the 88.Va debug.debugger_on_panic 89.Xr sysctl 8 90MIB variable is set non-zero, 91which is the default 92unless the 93.Dv DDB_UNATTENDED 94option is specified. 95.Pp 96The current location is called `dot'. 97The `dot' is displayed with 98a hexadecimal format at a prompt. 99Examine and write commands update `dot' to the address of the last line 100examined or the last location modified, and set `next' to the address of 101the next location to be examined or changed. 102Other commands don't change `dot', and set `next' to be the same as `dot'. 103.Pp 104The general command syntax is: 105.Cm command Ns Op Li \&/ Ns Ar modifier 106.Ar address Ns Op Li , Ns Ar count 107.Pp 108A blank line repeats the previous command from the address `next' with 109count 1 and no modifiers. 110Specifying 111.Ar address 112sets `dot' to the 113address. 114Omitting 115.Ar address 116uses `dot'. 117A missing 118.Ar count 119is taken 120to be 1 for printing commands or infinity for stack traces. 121.Pp 122The 123.Nm 124debugger has a feature like the 125.Xr more 1 126command 127for the output. 128If an output line exceeds the number set in the 129.Li \&$lines 130variable, it displays 131.Dq Em --db_more-- 132and waits for a response. 133The valid responses for it are: 134.Pp 135.Bl -tag -compact -width SPC 136.It Li SPC 137one more page 138.It Li RET 139one more line 140.It Li q 141abort the current command, and return to the command input mode 142.El 143.Pp 144Finally, 145.Nm 146provides a small (currently 10 items) command history, and offers 147simple emacs-style command line editing capabilities. 148In addition to 149the emacs control keys, the usual ANSI arrow keys might be used to 150browse through the history buffer, and move the cursor within the 151current line. 152.Sh COMMANDS 153.Bl -ohang 154.It Cm examine 155.It Cm x 156Display the addressed locations according to the formats in the modifier. 157Multiple modifier formats display multiple locations. 158If no format is specified, the last formats specified for this command 159is used. 160.Pp 161The format characters are: 162.Bl -tag -compact -width indent 163.It Li b 164look at by bytes (8 bits) 165.It Li h 166look at by half words (16 bits) 167.It Li l 168look at by long words (32 bits) 169.It Li a 170print the location being displayed 171.It Li A 172print the location with a line number if possible 173.It Li x 174display in unsigned hex 175.It Li z 176display in signed hex 177.It Li o 178display in unsigned octal 179.It Li d 180display in signed decimal 181.It Li u 182display in unsigned decimal 183.It Li r 184display in current radix, signed 185.It Li c 186display low 8 bits as a character. 187Non-printing characters are displayed as an octal escape code (e.g., `\e000'). 188.It Li s 189display the null-terminated string at the location. 190Non-printing characters are displayed as octal escapes. 191.It Li m 192display in unsigned hex with character dump at the end of each line. 193The location is also displayed in hex at the beginning of each line. 194.It Li i 195display as an instruction 196.It Li I 197display as an instruction with possible alternate formats depending on the 198machine: 199.Bl -tag -width MIPS -compact 200.It Tn VAX 201don't assume that each external label is a procedure entry mask 202.It Tn i386 203don't round to the next long word boundary 204.It Tn MIPS 205print register contents 206.El 207.El 208.It Cm xf 209Examine forward: 210Execute an examine command with the last specified parameters to it 211except that the next address displayed by it is used as the start address. 212.It Cm xb 213Examine backward: 214Execute an examine command with the last specified parameters to it 215except that the last start address subtracted by the size displayed by it 216is used as the start address. 217.It Cm print Ns Op Cm /acdoruxz 218Print 219.Ar addr Ns s 220according to the modifier character (as described above for 221.Li examine ) . 222Valid formats are: 223.Li a , 224.Li x , 225.Li z , 226.Li o , 227.Li d , 228.Li u , 229.Li r , 230and 231.Li c . 232If no modifier is specified, the last one specified to it is used. 233.Ar addr 234can be a string, in which case it is printed as it is. 235For example: 236.Bd -literal -offset indent 237print/x \&"eax = \&" $eax \&"\enecx = \&" $ecx \&"\en\&" 238.Ed 239.Pp 240will print like: 241.Bd -literal -offset indent 242eax = xxxxxx 243ecx = yyyyyy 244.Ed 245.It Xo 246.Cm write Ns Op Cm /bhl 247.Ar addr Ar expr1 Op Ar "expr2 ..." 248.Xc 249Write the expressions specified after 250.Ar addr 251on the command line at succeeding locations starting with 252.Ar addr 253The write unit size can be specified in the modifier with a letter 254.Li b 255(byte), 256.Li h 257(half word) or 258.Li l 259(long word) respectively. 260If omitted, 261long word is assumed. 262.Pp 263.Sy Warning : 264since there is no delimiter between expressions, strange 265things may happen. 266It's best to enclose each expression in parentheses. 267.It Xo 268.Cm set 269.Li \&$ Ns Ar variable 270.Op Li = 271.Ar expr 272.Xc 273Set the named variable or register with the value of 274.Ar expr . 275Valid variable names are described below. 276.It Cm break Ns Op Cm /u 277Set a break point at 278.Ar addr . 279If 280.Ar count 281is supplied, continues 282.Ar count 283- 1 times before stopping at the 284break point. 285If the break point is set, a break point number is 286printed with 287.Sq Li \&# . 288This number can be used in deleting the break point 289or adding conditions to it. 290.Pp 291If the 292.Li u 293modifier is specified, this command sets a break point in user space 294address. 295Without the 296.Li u 297option, the address is considered in the kernel 298space, and wrong space address is rejected with an error message. 299This modifier can be used only if it is supported by machine dependent 300routines. 301.Pp 302.Sy Warning : 303If a user text is shadowed by a normal user space debugger, 304user space break points may not work correctly. 305Setting a break 306point at the low-level code paths may also cause strange behavior. 307.It Cm delete Ar addr 308.It Cm delete Li \&# Ns Ar number 309Delete the break point. The target break point can be specified by a 310break point number with 311.Li # , 312or by using the same 313.Ar addr 314specified in the original 315.Cm break 316command. 317.It Cm step Ns Op Cm /p 318Single step 319.Ar count 320times (the comma is a mandatory part of the syntax). 321If the 322.Li p 323modifier is specified, print each instruction at each step. 324Otherwise, only print the last instruction. 325.Pp 326.Sy Warning : 327depending on machine type, it may not be possible to 328single-step through some low-level code paths or user space code. 329On machines with software-emulated single-stepping (e.g., pmax), 330stepping through code executed by interrupt handlers will probably 331do the wrong thing. 332.It Cm continue Ns Op Cm /c 333Continue execution until a breakpoint or watchpoint. 334If the 335.Li c 336modifier is specified, count instructions while executing. 337Some machines (e.g., pmax) also count loads and stores. 338.Pp 339.Sy Warning : 340when counting, the debugger is really silently single-stepping. 341This means that single-stepping on low-level code may cause strange 342behavior. 343.It Cm until Ns Op Cm /p 344Stop at the next call or return instruction. 345If the 346.Li p 347modifier is specified, print the call nesting depth and the 348cumulative instruction count at each call or return. 349Otherwise, 350only print when the matching return is hit. 351.It Cm next Ns Op Cm /p 352.It Cm match Ns Op Cm /p 353Stop at the matching return instruction. 354If the 355.Li p 356modifier is specified, print the call nesting depth and the 357cumulative instruction count at each call or return. 358Otherwise, only print when the matching return is hit. 359.It Xo 360.Cm trace Ns Op Cm /u 361.Op Ar frame 362.Op , Ns Ar count 363.Xc 364Stack trace. 365The 366.Li u 367option traces user space; if omitted, 368.Cm trace 369only traces 370kernel space. 371.Ar count 372is the number of frames to be traced. 373If 374.Ar count 375is omitted, all frames are printed. 376.Pp 377.Sy Warning : 378User space stack trace is valid 379only if the machine dependent code supports it. 380.It Xo 381.Cm search Ns Op Cm /bhl 382.Ar addr 383.Ar value 384.Op Ar mask 385.Op , Ns Ar count 386.Xc 387Search memory for 388.Ar value . 389This command might fail in interesting 390ways if it doesn't find the searched-for value. 391This is because ddb doesn't always recover from touching bad memory. 392The optional 393.Ar count 394argument limits the search. 395.It Cm show all procs Ns Op Cm /m 396.It Cm ps Ns Op Cm /m 397Display all process information. 398The process information may not be shown if it is not 399supported in the machine, or the bottom of the stack of the 400target process is not in the main memory at that time. 401The 402.Li m 403modifier will alter the display to show VM map 404addresses for the process and not show other info. 405.It Cm show registers Ns Op Cm /u 406Display the register set. 407If the 408.Li u 409option is specified, it displays user registers instead of 410kernel or currently saved one. 411.Pp 412.Sy Warning : 413The support of the 414.Li u 415modifier depends on the machine. 416If not supported, incorrect information will be displayed. 417.It Xo 418.Cm show map Ns Op Cm /f 419.Ar addr 420.Xc 421Prints the VM map at 422.Ar addr . 423If the 424.Li f 425modifier is specified the 426complete map is printed. 427.It Xo 428.Cm show object Ns Op Cm /f 429.Ar addr 430.Xc 431Prints the VM object at 432.Ar addr . 433If the 434.Li f 435option is specified the 436complete object is printed. 437.It Cm "show watches" 438Displays all watchpoints. 439.It Cm reset 440Hard reset the system. 441.It Xo 442.Cm watch 443.Ar addr Ns Li \&, Ns Ar size 444.Xc 445Set a watchpoint for a region. 446Execution stops when an attempt to modify the region occurs. 447The 448.Ar size 449argument defaults to 4. 450If you specify a wrong space address, the request is rejected 451with an error message. 452.Pp 453.Sy Warning : 454Attempts to watch wired kernel memory 455may cause unrecoverable error in some systems such as i386. 456Watchpoints on user addresses work best. 457.It Xo 458.Cm hwatch 459.Ar addr Ns Li \&, Ns Ar size 460.Xc 461Set a hardware watchpoint for a region if supported by the 462architecture. 463Execution stops when an attempt to modify the region occurs. 464The 465.Ar size 466argument defaults to 4. 467.Pp 468.Sy Warning : 469The hardware debug facilities do not have a concept of separate 470address spaces like the watch command does. 471Use 472.Cm hwatch 473for setting watchpoints on kernel address locations only, and avoid 474its use on user mode address spaces. 475.It Xo 476.Cm dhwatch 477.Ar addr Ns Li \&, Ns Ar size 478.Xc 479Delete specified hardware watchpoint. 480.It Cm gdb 481Toggles between remote GDB and DDB mode. 482In remote GDB mode, another machine is required that runs 483.Xr gdb 1 484using the remote debug feature, with a connection to the serial 485console port on the target machine. 486Currently only available on the 487.Em i386 488and 489.Em Alpha 490architectures. 491.It Cm help 492Print a short summary of the available commands and command 493abbreviations. 494.El 495.Sh VARIABLES 496The debugger accesses registers and variables as 497.Li \&$ Ns Em name . 498Register names are as in the 499.Dq Cm show registers 500command. 501Some variables are suffixed with numbers, and may have some modifier 502following a colon immediately after the variable name. 503For example, register variables can have a 504.Li u 505modifier to indicate user register (e.g., 506.Li $eax:u ) . 507.Pp 508Built-in variables currently supported are: 509.Bl -tag -width tabstops -compact 510.It Li radix 511Input and output radix 512.It Li maxoff 513Addresses are printed as 'symbol'+offset unless offset is greater than maxoff. 514.It Li maxwidth 515The width of the displayed line. 516.It Li lines 517The number of lines. It is used by "more" feature. 518.It Li tabstops 519Tab stop width. 520.It Li work Ns Ar xx 521Work variable. 522.Ar xx 523can be 0 to 31. 524.El 525.Sh EXPRESSIONS 526Almost all expression operators in C are supported except 527.Sq Li \&~ , 528.Sq Li \&^ , 529and unary 530.Sq Li \&& . 531Special rules in 532.Nm 533are: 534.Bl -tag -width Identifiers 535.It Em Identifiers 536The name of a symbol is translated to the value of the symbol, which 537is the address of the corresponding object. 538.Sq Li \&. 539and 540.Sq Li \&: 541can be used in the identifier. 542If supported by an object format dependent routine, 543.Sm off 544.Oo Em filename : Oc Em func : lineno , 545.Sm on 546.Oo Em filename : Oc Ns Em variable , 547and 548.Oo Em filename : Oc Ns Em lineno 549can be accepted as a symbol. 550.It Em Numbers 551Radix is determined by the first two letters: 552.Li 0x : 553hex, 554.Li 0o : 555octal, 556.Li 0t : 557decimal; otherwise, follow current radix. 558.It Li \&. 559`dot' 560.It Li \&+ 561`next' 562.It Li \&.. 563address of the start of the last line examined. 564Unlike `dot' or `next', this is only changed by 565.Dq Li examine 566or 567.Dq Li write 568command. 569.It Li \&' 570last address explicitly specified. 571.It Li \&$ Ns Em variable 572Translated to the value of the specified variable. 573It may be followed by a 574.Li : 575and modifiers as described above. 576.It Em a Ns Li \&# Ns Em b 577a binary operator which rounds up the left hand side to the next 578multiple of right hand side. 579.It Li \&* Ns Em expr 580indirection. It may be followed by a 581.Sq Li : 582and modifiers as described above. 583.El 584.Sh HINTS 585On machines with an ISA expansion bus, a simple NMI generation card can be 586constructed by connecting a push button between the A01 and B01 (CHCHK# and 587GND) card fingers. 588Momentarily shorting these two fingers together may cause the bridge chipset to 589generate an NMI, which causes the kernel to pass control to 590.Nm . 591Some bridge chipsets do not generate a NMI on CHCHK#, so your mileage may vary. 592The NMI allows one to break into the debugger on a wedged machine to 593diagnose problems. 594Other bus' bridge chipsets may be able to generate NMI using bus specific 595methods. 596.Sh SEE ALSO 597.Xr gdb 1 598.Sh HISTORY 599The 600.Nm 601debugger was developed for Mach, and ported to 602.Bx 386 0.1 . 603This manual page translated from 604.Fl man 605macros by Garrett Wollman. 606