Use .Xr for manpage references.
[dragonfly.git] / share / man / man4 / ddb.4
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: src/share/man/man4/ddb.4,v 1.7.2.6 2001/08/17 13:08:37 ru Exp $
61 .\" $DragonFly: src/share/man/man4/ddb.4,v 1.3 2006/05/11 08:23:19 swildner Exp $
62 .Dd May 11, 2006
63 .Dt DDB 4
64 .Os
65 .Sh NAME
66 .Nm ddb
67 .Nd interactive kernel debugger
68 .Sh SYNOPSIS
69 .Cd options DDB
70 .Pp
71 .Cd options DDB_TRACE
72 .Cd options DDB_UNATTENDED
73 .Sh DESCRIPTION
74 The
75 .Nm
76 kernel debugger has most of the features of the old kdb,
77 but with a more rational syntax
78 inspired by
79 .Xr gdb 1 .
80 If linked into the running kernel,
81 it can be invoked locally with the
82 .Ql debug
83 .Xr keymap 5
84 action.
85 The debugger is also invoked on kernel
86 .Xr panic 9
87 if the
88 .Va debug.debugger_on_panic
89 .Xr sysctl 8
90 MIB variable is set non-zero,
91 which is the default
92 unless the
93 .Dv DDB_UNATTENDED
94 option is specified.
95 If set, the
96 .Va debug.trace_on_panic
97 .Xr sysctl 8
98 MIB variable will cause
99 .Nm
100 to print a stack trace on
101 .Xr panic 9 .
102 It is zero by default unless the
103 .Dv DDB_TRACE
104 option is specified.
105 .Pp
106 The current location is called `dot'.  The `dot' is displayed with
107 a hexadecimal format at a prompt.
108 Examine and write commands update `dot' to the address of the last line
109 examined or the last location modified, and set `next' to the address of
110 the next location to be examined or changed.
111 Other commands don't change `dot', and set `next' to be the same as `dot'.
112 .Pp
113 The general command syntax is:
114 .Cm command Ns Op Li \&/ Ns Ar modifier
115 .Ar address Ns Op Li , Ns Ar count
116 .Pp
117 A blank line repeats the previous command from the address `next' with
118 count 1 and no modifiers.  Specifying
119 .Ar address
120 sets `dot' to the
121 address.  Omitting
122 .Ar address
123 uses `dot'.  A missing
124 .Ar count
125 is taken
126 to be 1 for printing commands or infinity for stack traces.
127 .Pp
128 The
129 .Nm
130 debugger has a feature like the
131 .Xr more 1
132 command
133 for the output.  If an output line exceeds the number set in the
134 .Li \&$lines
135 variable, it displays
136 .Dq Em --db_more--
137 and waits for a response.
138 The valid responses for it are:
139 .Pp
140 .Bl -tag -compact -width SPC
141 .It Li SPC
142 one more page
143 .It Li RET
144 one more line
145 .It Li q
146 abort the current command, and return to the command input mode
147 .El
148 .Pp
149 Finally,
150 .Nm
151 provides a small (currently 10 items) command history, and offers
152 simple emacs-style command line editing capabilities.  In addition to
153 the emacs control keys, the usual ANSI arrow keys might be used to
154 browse through the history buffer, and move the cursor within the
155 current line.
156 .Sh COMMANDS
157 .Bl -ohang
158 .It Cm examine
159 .It Cm x
160 Display the addressed locations according to the formats in the modifier.
161 Multiple modifier formats display multiple locations.
162 If no format is specified, the last formats specified for this command
163 is used.
164 .Pp
165 The format characters are:
166 .Bl -tag -compact -width indent
167 .It Li b
168 look at by bytes (8 bits)
169 .It Li h
170 look at by half words (16 bits)
171 .It Li l
172 look at by long words (32 bits)
173 .It Li a
174 print the location being displayed
175 .It Li A
176 print the location with a line number if possible
177 .It Li x
178 display in unsigned hex
179 .It Li z
180 display in signed hex
181 .It Li o
182 display in unsigned octal
183 .It Li d
184 display in signed decimal
185 .It Li u
186 display in unsigned decimal
187 .It Li r
188 display in current radix, signed
189 .It Li c
190 display low 8 bits as a character.
191 Non-printing characters are displayed as an octal escape code (e.g., `\e000').
192 .It Li s
193 display the null-terminated string at the location.
194 Non-printing characters are displayed as octal escapes.
195 .It Li m
196 display in unsigned hex with character dump at the end of each line.
197 The location is also displayed in hex at the beginning of each line.
198 .It Li i
199 display as an instruction
200 .It Li I
201 display as an instruction with possible alternate formats depending on the
202 machine:
203 .Bl -tag -width MIPS -compact
204 .It Tn VAX
205 don't assume that each external label is a procedure entry mask
206 .It Tn i386
207 don't round to the next long word boundary
208 .It Tn MIPS
209 print register contents
210 .El
211 .El
212 .It Cm xf
213 Examine forward:
214 Execute an examine command with the last specified parameters to it
215 except that the next address displayed by it is used as the start address.
216 .It Cm xb
217 Examine backward:
218 Execute an examine command with the last specified parameters to it
219 except that the last start address subtracted by the size displayed by it
220 is used as the start address.
221 .It Cm print Ns Op Cm /acdoruxz
222 Print
223 .Ar addr Ns s
224 according to the modifier character (as described above for
225 .Li examine ) .
226 Valid formats are:
227 .Li a ,
228 .Li x ,
229 .Li z ,
230 .Li o ,
231 .Li d ,
232 .Li u ,
233 .Li r ,
234 and
235 .Li c .
236 If no modifier is specified, the last one specified to it is used.
237 .Ar addr
238 can be a string, in which case it is printed as it is.  For example:
239 .Bd -literal -offset indent
240 print/x \&"eax = \&" $eax \&"\enecx = \&" $ecx \&"\en\&"
241 .Ed
242 .Pp
243 will print like:
244 .Bd -literal -offset indent
245 eax = xxxxxx
246 ecx = yyyyyy
247 .Ed
248 .It Xo
249 .Cm write Ns Op Cm /bhl
250 .Ar addr Ar expr1 Op Ar "expr2 ..."
251 .Xc
252 Write the expressions specified after
253 .Ar addr
254 on the command line at succeeding locations starting with
255 .Ar addr
256 The write unit size can be specified in the modifier with a letter
257 .Li b
258 (byte),
259 .Li h
260 (half word) or
261 .Li l
262 (long word) respectively.  If omitted,
263 long word is assumed.
264 .Pp
265 .Sy Warning :
266 since there is no delimiter between expressions, strange
267 things may happen.
268 It's best to enclose each expression in parentheses.
269 .It Xo
270 .Cm set
271 .Li \&$ Ns Ar variable
272 .Op Li =
273 .Ar expr
274 .Xc
275 Set the named variable or register with the value of
276 .Ar expr .
277 Valid variable names are described below.
278 .It Cm break Ns Op Cm /u
279 Set a break point at
280 .Ar addr .
281 If
282 .Ar count
283 is supplied, continues
284 .Ar count
285 - 1 times before stopping at the
286 break point.  If the break point is set, a break point number is
287 printed with
288 .Sq Li \&# .
289 This number can be used in deleting the break point
290 or adding conditions to it.
291 .Pp
292 If the
293 .Li u
294 modifier is specified, this command sets a break point in user space
295 address.  Without the
296 .Li u
297 option, the address is considered in the kernel
298 space, and wrong space address is rejected with an error message.
299 This modifier can be used only if it is supported by machine dependent
300 routines.
301 .Pp
302 .Sy Warning :
303 If a user text is shadowed by a normal user space debugger,
304 user space break points may not work correctly.  Setting a break
305 point at the low-level code paths may also cause strange behavior.
306 .It Cm delete Ar addr
307 .It Cm delete Li \&# Ns Ar number
308 Delete the break point.  The target break point can be specified by a
309 break point number with
310 .Li # ,
311 or by using the same
312 .Ar addr
313 specified in the original
314 .Cm break
315 command.
316 .It Cm step Ns Op Cm /p
317 Single step
318 .Ar count
319 times (the comma is a mandatory part of the syntax).
320 If the
321 .Li p
322 modifier is specified, print each instruction at each step.
323 Otherwise, only print the last instruction.
324 .Pp
325 .Sy Warning :
326 depending on machine type, it may not be possible to
327 single-step through some low-level code paths or user space code.
328 On machines with software-emulated single-stepping (e.g., pmax),
329 stepping through code executed by interrupt handlers will probably
330 do the wrong thing.
331 .It Cm continue Ns Op Cm /c
332 Continue execution until a breakpoint or watchpoint.
333 If the
334 .Li c
335 modifier is specified, count instructions while executing.
336 Some machines (e.g., pmax) also count loads and stores.
337 .Pp
338 .Sy Warning :
339 when counting, the debugger is really silently single-stepping.
340 This means that single-stepping on low-level code may cause strange
341 behavior.
342 .It Cm until Ns Op Cm /p
343 Stop at the next call or return instruction.
344 If the
345 .Li p
346 modifier is specified, print the call nesting depth and the
347 cumulative instruction count at each call or return.  Otherwise,
348 only print when the matching return is hit.
349 .It Cm next Ns Op Cm /p
350 .It Cm match Ns Op Cm /p
351 Stop at the matching return instruction.
352 If the
353 .Li p
354 modifier is specified, print the call nesting depth and the
355 cumulative instruction count at each call or return.  Otherwise,
356 only print when the matching return is hit.
357 .It Xo
358 .Cm trace Ns Op Cm /u
359 .Op Ar frame
360 .Op , Ns Ar count
361 .Xc
362 Stack trace.  The
363 .Li u
364 option traces user space; if omitted,
365 .Cm trace
366 only traces
367 kernel space.
368 .Ar count
369 is the number of frames to be traced.
370 If
371 .Ar count
372 is omitted, all frames are printed.
373 .Pp
374 .Sy Warning :
375 User space stack trace is valid
376 only if the machine dependent code supports it.
377 .It Xo
378 .Cm search Ns Op Cm /bhl
379 .Ar addr
380 .Ar value
381 .Op Ar mask
382 .Op , Ns Ar count
383 .Xc
384 Search memory for
385 .Ar value .
386 This command might fail in interesting
387 ways if it doesn't find the searched-for value.  This is because
388 ddb doesn't always recover from touching bad memory.  The optional
389 .Ar count
390 argument limits the search.
391 .It Cm show all procs Ns Op Cm /m
392 .It Cm ps Ns Op Cm /m
393 Display all process information.
394 The process information may not be shown if it is not
395 supported in the machine, or the bottom of the stack of the
396 target process is not in the main memory at that time.
397 The
398 .Li m
399 modifier will alter the display to show VM map
400 addresses for the process and not show other info.
401 .It Cm show registers Ns Op Cm /u
402 Display the register set.
403 If the
404 .Li u
405 option is specified, it displays user registers instead of
406 kernel or currently saved one.
407 .Pp
408 .Sy Warning :
409 The support of the
410 .Li u
411 modifier depends on the machine.  If
412 not supported, incorrect information will be displayed.
413 .It Xo
414 .Cm show map Ns Op Cm /f
415 .Ar addr
416 .Xc
417 Prints the VM map at
418 .Ar addr .
419 If the
420 .Li f
421 modifier is specified the
422 complete map is printed.
423 .It Xo
424 .Cm show object Ns Op Cm /f
425 .Ar addr
426 .Xc
427 Prints the VM object at
428 .Ar addr .
429 If the
430 .Li f
431 option is specified the
432 complete object is printed.
433 .It Cm "show watches"
434 Displays all watchpoints.
435 .It Xo
436 .Cm watch
437 .Ar addr Ns Li \&, Ns Ar size
438 .Xc
439 Set a watchpoint for a region.  Execution stops
440 when an attempt to modify the region occurs.
441 The
442 .Ar size
443 argument defaults to 4.
444 If you specify a wrong space address, the request is rejected
445 with an error message.
446 .Pp
447 .Sy Warning :
448 Attempts to watch wired kernel memory
449 may cause unrecoverable error in some systems such as i386.
450 Watchpoints on user addresses work best.
451 .It Cm gdb
452 Toggles between remote GDB and DDB mode.  In remote GDB mode, another
453 machine is required that runs
454 .Xr gdb 1
455 using the remote debug feature, with a connection to the serial
456 console port on the target machine.  Currently only available on the
457 .Em i386
458 architecture.
459 .It Cm help
460 Print a short summary of the available commands and command
461 abbreviations.
462 .El
463 .Sh VARIABLES
464 The debugger accesses registers and variables as
465 .Li \&$ Ns Em name .
466 Register names are as in the
467 .Dq Cm show registers
468 command.
469 Some variables are suffixed with numbers, and may have some modifier
470 following a colon immediately after the variable name.
471 For example, register variables can have a
472 .Li u
473 modifier to indicate user register (e.g.,
474 .Li $eax:u ) .
475 .Pp
476 Built-in variables currently supported are:
477 .Bl -tag -width tabstops -compact
478 .It Li radix
479 Input and output radix
480 .It Li maxoff
481 Addresses are printed as 'symbol'+offset unless offset is greater than maxoff.
482 .It Li maxwidth
483 The width of the displayed line.
484 .It Li lines
485 The number of lines.  It is used by "more" feature.
486 .It Li tabstops
487 Tab stop width.
488 .It Li work Ns Ar xx
489 Work variable.
490 .Ar xx
491 can be 0 to 31.
492 .El
493 .Sh EXPRESSIONS
494 Almost all expression operators in C are supported except
495 .Sq Li \&~ ,
496 .Sq Li \&^ ,
497 and unary
498 .Sq Li \&& .
499 Special rules in
500 .Nm
501 are:
502 .Bl -tag -width Identifiers
503 .It Em Identifiers
504 The name of a symbol is translated to the value of the symbol, which
505 is the address of the corresponding object.
506 .Sq Li \&.
507 and
508 .Sq Li \&:
509 can be used in the identifier.
510 If supported by an object format dependent routine,
511 .Sm off
512 .Oo Em filename : Oc Em func : lineno ,
513 .Sm on
514 .Oo Em filename : Oc Ns Em variable ,
515 and
516 .Oo Em filename : Oc Ns Em lineno
517 can be accepted as a symbol.
518 .It Em Numbers
519 Radix is determined by the first two letters:
520 .Li 0x :
521 hex,
522 .Li 0o :
523 octal,
524 .Li 0t :
525 decimal; otherwise, follow current radix.
526 .It Li \&.
527 `dot'
528 .It Li \&+
529 `next'
530 .It Li \&..
531 address of the start of the last line examined.
532 Unlike `dot' or `next', this is only changed by
533 .Dq Li examine
534 or
535 .Dq Li write
536 command.
537 .It Li \&'
538 last address explicitly specified.
539 .It Li \&$ Ns Em variable
540 Translated to the value of the specified variable.
541 It may be followed by a
542 .Li :
543 and modifiers as described above.
544 .It Em a Ns Li \&# Ns Em b
545 a binary operator which rounds up the left hand side to the next
546 multiple of right hand side.
547 .It Li \&* Ns Em expr
548 indirection.  It may be followed by a
549 .Sq Li :
550 and modifiers as described above.
551 .El
552 .Sh SEE ALSO
553 .Xr gdb 1
554 .Sh HISTORY
555 The
556 .Nm
557 debugger was developed for Mach, and ported to
558 .Bx 386 0.1 .
559 This manual page translated from
560 .Fl man
561 macros by Garrett Wollman.