ddb4
Kernel debugger
Overview
The ddb debugger provides a means for debugging the kernel, and analysing the kernel after a system crash ("panic"), with a gdb(1)-like syntax.
ddb is invoked upon a kernel panic when the sysctl(8) ddb.panic is set to 1. It may be invoked from the console when the sysctl ddb.console is set to 1, using any of the following methods:
-
Using the key sequence Ctrl-Alt-Esc.
-
Sending a BREAK when using a serial console.
-
Writing to the sysctl ddb.trigger.
-
For i386 and amd64 architectures, using the key sequence Ctrl-Alt-Delete when the sysctl machdep.kbdreset is set to 2.
ddb prompts for commands on the console with:
ddb>
The general syntax of a ddb command is:
command [/modifiers] [address] [,count]
To save typing, ddb makes use of a context inferred from previous commands. In this context, the current location is called dot. The examine, search, show struct, and write commands update dot to be that of the last address examined or the last location modified, and have intuitive effects on next and prev. All the other commands do not change dot, and set next to be the same. (See VARIABLES.)
An expression can be used in place of address (see EXPRESSIONS). Omitting address in a command uses the last value of dot. A missing count is taken to be 1 for printing commands or for stack traces. Entering a blank line causes the last command to be repeated using next in place of address, a count of 1, and no modifiers.
ddb has a feature like more(1) for the output. If the number of lines output in response to one command exceeds the number set in the $lines variable, it displays the message ‘--db_more--’ and waits for a response.
The valid responses are:
- ⟨
space⟩ -
One more page.
- ⟨
return⟩ -
One more line.
q-
Abort the current command, and return to the command input mode.
The following command line editing keys are provided:
^b-
back one character
^f-
forward one character
^a-
beginning of line
^e-
end of line
^w-
erase word back
^h| ⟨del⟩-
erase previous character
^d-
erase next character
^k-
delete to end of line
^u-
delete line
^p-
previous in command history
^n-
next in command history
^r-
redraw line
^t-
exchange the two characters to the left of the cursor
Commands
The following commands may be typed at the ‘ddb>’ prompt. Some commands consist of more than one word, and if only the first word or words are entered, the possible alternatives to complete the command are displayed and no other action is performed.
help-
List the available commands.
-
[
e]x[amine] [/bhlqaAxzodurcsmiI][addr] [,count] Display the contents at address addr according to the formats in the modifier. If no format is specified, the last formats specified for this command are used.The format characters are:
/b-
look at by bytes (8 bits)
/h-
look at by half words (16 bits)
/l-
look at by long words (32 bits) (default)
/q-
look at by long longs (64 bits) (only available on 64-bit platforms)
/a-
print the location being displayed
/A-
print the location with a line number if possible
/x-
display in unsigned hex
/z-
display in signed hex
/o-
display in unsigned octal
/d-
display in signed decimal
/u-
display in unsigned decimal
/r-
display in current radix, signed
/c-
display low 8 bits as a character. Non-printing characters are displayed as an octal escape code (e.g., '\000').
/s-
display the null-terminated string at the location. Non-printing characters are displayed as octal escapes.
/m-
display in unsigned hex with character dump at the end of each line. The location is also displayed in hex at the beginning of each line.
/i-
display as an instruction
/I-
display as an alternate format instruction depending on the machine:
- alpha
-
Print affected register contents for every instruction.
- amd64,
- i386
-
Do not skip padding to the next long word boundary for unconditional jumps.
- m88k
-
Decode instructions for the opposite CPU model (e.g. m88110 when running on an m88100 processor).
The value of next is set to the addr plus the size of the data examined.
-
p[rint] [/axzodurc] [addr] Print addr according to the modifier character. The valid modifiers are a subset of those from theexaminecommand, and act as described there. If no modifier is specified, the last one specified in a previous use ofprintis used.For example,
print/x $eax
will print something like this:
xxxxxx
-
pp[rint] [addr] Pretty-print addr using CTF debug symbols included in the kernel binary image. The CTF section is normally added by running ctfstrip(1) as part of building a new kernel. -
w[rite] [/bhl] [addr] expr [expr ...] Write the value of each expr expression at succeeding locations start at addr. The write unit size can be specified using one of the modifiers:/b-
byte (8 bits)
/h-
half word (16 bits)
/l-
long word (32 bits) (default)
The value of next is set to addr plus the size of values written.
Warning: since there is no delimiter between expressions, the command may not parse as you expect. It is best to enclose each expression in parentheses.
set-
$name [=] expr Set the named variable or register with the value of expr. For valid variable names, see VARIABLES.
boothow-
Reboot the machine depending on how:
bootsync-
Sync disks and reboot.
bootcrash-
Dump core and reboot.
bootdump-
Sync disks, dump core and reboot.
boothalt-
Just halt.
bootreboot-
Just reboot.
bootpoweroff-
Power down the machine whenever possible; if it fails, just halt.
-
break[addr] [,count] Set a break point at addr. If count is supplied,ddballows the breakpoint to be silently hit (count - 1) times before stopping at the break point. -
d[elete] [addr] Delete the break point set with thebreakcommand. -
s[tep] [/p] [,count] Single step count times. If the/pmodifier is specified, print each instruction at each step. Otherwise, only print the last instruction.Warning: depending on machine type, it may not be possible to single-step through some low-level code paths. On machines with software-emulated single-stepping (e.g., alpha), stepping through code executed by interrupt handlers will probably do the wrong thing. callname-
(expr [, expr ...] ) Call the function named by name with the argument(s) listed in parentheses. Parentheses may be omitted if the function takes no arguments. The number of arguments is currently limited to 10.
-
c[ontinue] [/c] Continue execution until a breakpoint or watchpoint. If the/cmodifier is given, instructions are counted while executing.Warning: when counting with/c,ddbis really silently single-stepping. This means that single-stepping on low-level code may cause strange behavior. -
watchaddr [,size] Set a watchpoint for the region starting at addr. Execution stops and control returns toddbwhen an attempt is made to modify a watched region. The size argument defaults to 4.If you specify a wrong space address, the request is rejected with an error message.
Warning: attempts to watch wired kernel memory may cause an unrecoverable error on some systems (e.g., i386). dwatchaddr-
Delete the watchpoint at address addr that was previously set with a
watchcommand. -
hangman[/s[0-9]] This is a tiny and handy tool for random kernel hangs analysis, of which its depth is controlled by the optional argument of the default value of five. It uses some sophisticated heuristics to spot the global symbol that caused the hang. Since the discovering algorithm is a probabilistic one, you may spend substantial time to figure the exact symbol name. This smart thing requires a little of your attention, the input it accepts is mostly of the same format as that of the famous hangman(6) game, to which it, apparently, is obliged by the name. Hint: the nm(1) utility might help. until[/p]-
Stop at the next "call" or "return" instruction. If the
/pmodifier is specified,ddbprints the call nesting depth and the cumulative instruction count at each call or return. Otherwise, it stays silent until the matching return is hit. match[/p]-
Stop at the next matching return instruction. If the
/pmodifier is specified,ddbprints the call nesting depth and the cumulative instruction count at each call or return. Otherwise, it remains mostly quiet. next[/p]-
The
nextcommand is a synonym formatch. killpid-
Send an uncatchable SIGABRT signal to the process specified by the pid argument.
stoppid-
Send a SIGSTOP signal to the process specified by the pid argument.
-
trace[/tu][frameaddr] [,count] Show the stack trace. The/tmodifier interprets the frameaddr argument as the TID of a process and shows the stack trace of that process. frameaddr is subject to the radix; use the 0t prefix to enter a decimal TID. The/tmodifier is not supported on all platforms. The/umodifier shows the stack trace of user space; if omitted, the kernel stack is traced instead. The count argument is the limit on the number of frames to be followed. If count is omitted, all frames are printed.Warning: user space stack trace is valid only if the machine dependent code supports it. -
search[/bhl] [addr] value [mask] [,count] Search memory for a value beginning at addr. This command might fail in interesting ways if it doesn't find the searched-for value. This is becauseddbdoesn't always recover from touching bad memory. The optional count argument limits the search. The modifiers are the same as those of thewritecommand.The next address is set to the address where value is found, or just after where the search area finishes.
reboot-
Shortcut for
bootreboot showwhat-
Displays various things, depending on what:
showbcstats-
Prints the buffer cache statistics.
showbreaks-
Prints a list of all breakpoints that have been set with the
breakcommand. showbufaddr-
Prints the struct buf at addr.
showextents-
Prints a detailed list of all extents.
showlocks[addr]-
Prints the list of locks held by a thread. If an optional address is not specified, curproc is assumed. The
optionWITNESS is required for this command to be available. showmalloc[addr]-
Prints malloc debugging information if available. If an optional address is specified, only information about that address is printed.
-
showmap[/f] addr Prints the vm_map at addr. If the/fmodifier is specified, the complete map is printed. -
showmbuf[/cp] addr Prints the struct mbuf header at addr. Depending on the mbuf flags struct pkthdr and struct m_ext are printed as well. If the/cmodifier is specified, print the mbuf chain linked with the m_next pointer./pdoes the same using m_nextpkt. Both can be combined. -
showmount[/f] addr Prints the struct mount at addr. If the/fmodifier is specified, prints out all vnodes (see alsoshowvnode) and also all bufs (see alsoshowbuf) on all those vnodes. -
shownfsnode[/f] addr Prints the struct nfsnode at addr. If the/fmodifier is specified, prints out additional information as well. -
shownfsreq[/f] addr Prints the struct nfsreq at addr. If the/fmodifier is specified, prints out additional information as well. -
showobject[/f] addr Prints the vm_object at addr. If the/fmodifier is specified, the complete object is printed. -
showpage[/f] addr Prints the vm_page at addr. If the/fmodifier is specified, the complete page is printed. showpanic-
Prints the panic string.
-
showpool[/p] addr Prints the pool at addr. Valid modifiers:/p-
Print the pagelist for this pool.
-
showproc[/t] [addr] Prints the struct proc at addr. If an optional address is not specified, curproc is assumed. The/tmodifier interprets the addr argument as the TID of a proc. showregisters[/u]-
Display the register set. If the
/umodifier is specified, it displays user registers (or the currently saved registers) instead of the kernel's. Note: The/umodifier is not supported on every machine, in which case incorrect information may be displayed. showrouteaddr-
Prints the struct rtentry at addr.
showsocketaddr-
Prints the struct socket at addr. If the socket is spliced, the struct sosplice associated with the socket is printed as well.
-
showstructname [addr] Prints the content of the memory at addr as a struct name. Nested structures and bit fields are not printed. Character arrays are printed as bytes. showswap-
Prints a detailed list of all swaps.
-
showtdb[/f] addr Prints the struct tdb at addr. If the/fmodifier is specified, prints out all fields of this IPsec SA. showuvmexp-
Displays a selection of uvm counters and statistics.
-
showvnode[/f] addr Prints the struct vnode at addr. If the/fmodifier is specified, prints out all bufs (see alsoshowbuf) currently attached to this vnode. showwatches-
Displays all watchpoints set with the
watchcommand. showwitness[/b]-
Prints the current order list. If the
/bmodifier is specified, the list of found lock order violations is printed instead. TheoptionWITNESS is required for this command to be available. showallprocs[/anow]-
Display information on all processes.
/n-
(Default) Show process information in a ps(1)-like format. Information printed includes process ID, thread ID, parent process ID, UID, process status, process flags, process wait channel message and process command name.
/a-
Shows the kernel virtual addresses of each process' proc structure, u-area, and vmspace structure. The vmspace address is also the address of the process' vm_map structure and can be used in the
showmapcommand. /o-
Shows non-idle threads that were on CPU when ddb was entered. Information printed includes thread ID, process ID, UID, process flags, thread flags, current CPU, and command name.
/w-
Shows each thread's ID, command, process group, wait channel address, and wait channel message.
showallbufs[/f]-
Display information about all buffers in the system.
/f-
For each buffer, print a more detailed output. See the
showbufcommand for more information.
showallcallout-
Display the contents of the callout table.
showallpools[/a]-
Display information about all system pools in a format similar to vmstat(8).
/a-
Displays “interesting” address information.
showalllocks-
Prints the list of locks held by all threads in the system. The
optionWITNESS is required for this command to be available. showallmounts[/f]-
Display information on all mounted filesystems.
/f-
For each filesystem, list all its struct vnode addresses. These addresses can be used in the
showvnodecommand.
showallnfsnodes[/f]-
Display information about all nfsnodes in the system.
/f-
For each nfsnode, print a more detailed output. See the
shownfsnodecommand for more information.
showallnfsreqs[/f]-
Display information for all outstanding NFS requests.
/f-
For each NFS requests, print a more detailed output. See the
shownfsreqcommand for more information.
-
showallroutes[/iI] [rtableid] [,count] Show internet routing tables. Default for rtableid is 0 and count is 1./i-
Restrict to AF_INET.
/I-
Restrict to AF_INET6.
showalltdbs[/f]-
Display information about all IPsec SAs in the system.
/f-
For each tdb, print a more detailed output. See the
showtdbcommand for more information.
showallvnodes[/f]-
Display information about all vnodes in the system.
/f-
For each vnode, print a more detailed output. See the
showvnodecommand for more information.
callout-
A synonym for the
showallcalloutcommand. ps[/anow]-
A synonym for
showallprocs. -
mac[hine] subcommand [arg ...] Perform a platform-specific command.The following commands are supported by multiprocessor kernels on these platforms: amd64, i386, macppc, mips64, and sparc64.
cpuinfo-
Display the state of each CPU.
ddbcpuN-
Stop the current CPU and start handling
ddbon the selected CPU. startcpu[N]-
Resume normal processing on the selected CPU, or all CPUs if none is specified.
stopcpu[N]-
Stop normal processing on the selected CPU, or all CPUs (except the one handling
ddb) if none is specified.Other platform-specific commands:
arm:
frameaddr-
Display the trapframe at addr.
i386:
sysregs-
Display the contents of the privileged registers: IDTR, GDTR, LDTR, TR, CR0, CR2, CR3, and CR4.
m88k:
ddbcpuN-
Stop the current CPU and start handling
ddbon the selected CPU. frameaddr-
Display the trapframe at addr.
regs-
Display the registers from when
ddbwas entered. searchframe[addr]-
Search for and display stack exception frames, starting from addr if given, else the address in register r31, and stopping at the next 8k boundary.
where-
Display where the current CPU was stopped.
mips64:
-
tlb[/pasid] [/c] [tlb] trap??-
sh:
cache[addr]-
Display the cache, starting from addr, defaulting to 0.
frame-
Display the switch and trap frames.
tlb-
Display the TLB.
sparc64:
ctx-
Display the context addresses for all threads.
-
Variables
ddb denotes registers and variables by $name. Register names can be found with the show registers command.
Built-in debugger variables currently supported are:
- $radix
-
Input and output radix.
- $maxoff
-
Addresses are printed as symbol+offset unless offset is greater than $maxoff.
- $maxwidth
-
The width of the displayed lines.
- $lines
-
The number of lines to page. This is used by the “more” feature.
- $tabstops
-
Tab stop width.
- $log
-
Controls whether the output of
ddbwill also appear in the system message buffer.
These variables can also be controlled outside ddb via the ‘ddb’ sysctl(8) hierarchy.
Expressions
Almost all expression operators in C are supported except for ‘~’, ‘^’, and unary ‘&’. Special rules for expressions in ddb are:
- identifier
-
The name of a symbol. It is translated to the address (or value) of the symbol. ‘.’ and ‘:’ can be used in the identifier. The following can be accepted as an identifier, if supported by an object format dependent routine:
-
[filename:]func [:linenumber]
-
[filename:] variable
-
filename [:linenumber]
The symbol may be prefixed with ‘symboltablename::’ (e.g., ‘emulator::mach_msg_trap’) to specify other than kernel symbols.
-
- number
-
The radix is determined by the first two letters: ‘0x’: hex, ‘0o’: octal, ‘0t’: decimal, otherwise, the value of $radix is used.
- .
-
dot: the current address.
- +
-
next: the next address.
- ..
-
The address of the start of the last line examined. Unlike dot or next, this is only changed by the
examineorwritecommand. - '
-
The last address explicitly specified.
- $variable
-
The value of a register or variable.
- expr # expr
-
A binary operator which rounds up the left hand side to the next multiple of right hand side.
- *expr
-
Indirection. It may be followed by a ':' as described above with identifier.
Releases
61 releases since OpenBSD 2.1; the text changed 47 times.