| DDB(4) | Device Drivers Manual | DDB(4) |
ddb — interactive
kernel debugger
In order to enable kernel debugging facilities include:
options KDB
options DDBTo prevent activation of the debugger on kernel panic(9):
options
KDB_UNATTENDEDIn order to print a stack trace of the current thread on the console for a panic:
options KDB_TRACETo print the numerical value of symbols in addition to the symbolic representation, define:
options DDB_NUMSYMTo enable the gdb(1) backend, so that remote debugging with kgdb(1) is possible, include:
options GDBThe ddb kernel debugger is an interactive
debugger with a syntax inspired by gdb(1). If linked into
the running kernel, it can be invoked locally with the
‘debug’ keymap(5)
action. The debugger is also invoked on kernel panic(9) if
the debug.debugger_on_panic
sysctl(8) MIB variable is set non-zero, which is the
default unless the KDB_UNATTENDED option is
specified.
The current location is called dot. The
dot is displayed with a hexadecimal format at a
prompt. The commands examine and
write update dot to the
address of the last line examined or the last location modified, and set
next to the address of the next location to be
examined or changed. Other commands do not change dot,
and set next to be the same as
dot.
The general command syntax is:
command[/modifier]
[addr][,count]
A blank line repeats the previous command from the address next with count 1 and no modifiers. Specifying addr sets dot to the address. Omitting addr uses dot. A missing count is taken to be 1 for printing commands or infinity for stack traces. A count of -1 is equivalent to a missing count. Options that are supplied but not supported by the given command are usually ignored.
The ddb debugger has a pager feature (like
the more(1) command) for the output. If an output line
exceeds the number set in the lines variable, it
displays “--More--” and waits for a
response. The valid responses for it are:
SPCRETqFinally, ddb provides a small (currently
10 items) command history, and offers simple
emacs-style command line editing capabilities. In
addition to the emacs control keys, the usual ANSI
arrow keys may be used to browse through the history buffer, and move the
cursor within the current line.
examine[/AISabcdghilmorsuxz
...] [addr][,count]x[/AISabcdghilmorsuxz
...] [addr][,count]The format characters are:
bhlgaAxzodurc\000’).smiISxfexamine command with
the last specified parameters to it except that the next address displayed
by it is used as the start address.
xbexamine command with
the last specified parameters to it except that the last start address
subtracted by the size displayed by it is used as the start address.
print[/acdoruxz]p[/acdoruxz]examine). Valid formats are:
a, x,
z, o,
d, u,
r, and c. If no modifier
is specified, the last one specified to it is used. The argument
addr can be a string, in which case it is printed as
it is. For example:
print/x "eax = " $eax "\necx = " $ecx "\n"
will print like:
eax = xxxxxx ecx = yyyyyy
write[/bhl]
addr expr1 [expr2 ...]w[/bhl]
addr expr1 [expr2 ...]b (byte),
h (half word) or l (long
word) respectively. If omitted, long word is assumed.
Warning: since there is no delimiter between expressions, strange things may happen. It is best to enclose each expression in parentheses.
set
$variable
[=] exprbreak[/u]
[addr][,count]b[/u]
[addr][,count]continue command will not stop at this break point
on the first count - 1 times that it is hit. If the
break point is set, a break point number is printed with
‘#’. This number can be used in
deleting the break point or adding conditions to it.
If the u modifier is specified, this
command sets a break point in user address space. Without the
u option, the address is considered to be in the
kernel space, and a wrong space address is rejected with an error
message. This modifier can be used only if it is supported by machine
dependent routines.
Warning: If a user text is shadowed by a normal user space debugger, user space break points may not work correctly. Setting a break point at the low-level code paths may also cause strange behavior.
delete
[addr]d
[addr]delete
#numberd
#number#’, or by
using the same addr specified in the original
break command, or by omitting
addr to get the default address of
dot.
watch
[addr][,size]Warning: Attempts to watch wired kernel memory may cause unrecoverable error in some systems such as i386. Watchpoints on user addresses work best.
hwatch
[addr][,size]Warning: The hardware debug facilities do
not have a concept of separate address spaces like the watch command
does. Use hwatch for setting watchpoints on
kernel address locations only, and avoid its use on user mode address
spaces.
dhwatch
[addr][,size]step[/p][,count]s[/p][,count]p modifier 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 or user space code. On machines with software-emulated single-stepping (e.g., pmax), stepping through code executed by interrupt handlers will probably do the wrong thing.
continue[/c]c[/c]c modifier is specified, count instructions while
executing. Some machines (e.g., pmax) also count loads and stores.
Warning: when counting, the debugger is really silently single-stepping. This means that single-stepping on low-level code may cause strange behavior.
until[/p]p modifier is specified, print the call nesting
depth and the cumulative instruction count at each call or return.
Otherwise, only print when the matching return is hit.
next[/p]match[/p]p
modifier is specified, print the call nesting depth and the cumulative
instruction count at each call or return. Otherwise, only print when the
matching return is hit.
trace[/u]
[pid |
tid][,count]t[/u]
[pid |
tid][,count]where[/u]
[pid |
tid][,count]bt[/u]
[pid |
tid][,count]u option traces user space; if
omitted, trace only traces kernel space. The
optional argument count is the number of frames to
be traced. 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]findstack
addrshow
all
procs[/a]ps[/a]a modifier will print command line arguments for
each process.
show
all tracealltraceshow
all ttysshow
all vnetsshow
allchainsshow
alllocksshow
allpcpushow
allrmanshow
apicshow
breaksshow
bio addrshow
buffer addrshow
callout addrshow
cbstatshow
cdevshow
conifhkshow
cpusetsshow
cyrixregshow
devmapshow
domain addrshow
ffs [addr]show
file addrshow
filesshow
freepagesshow
geom [addr]show
idtshow
igi_list addrshow
inodedeps [addr]show
inpcb addrshow
intrshow
intrcntshow
irqsshow
jailsshow
lapicshow
lock addrshow
lockchain addrshow
lockedbufsshow
lockedvnodsshow
locksshow
locktreeshow
mallocTypeInUseMemUseRequestsThe same information can be gathered in userspace with
“vmstat
-m”.
show
map[/f]
addrf modifier is specified the complete map is
printed.
show
msgbufdmesg” case. It is useful if you
got a kernel panic, attached a serial cable to the machine and want to get
the boot messages from before the system hang.show
mountshow
mount addrshow
object[/f]
addrf option is specified the complete object is
printed.
show
panicshow
pageshow
pageqshow
pciregspciconf
-lv”.
show
pcpucpuidcurthreadcurpcbfpcurthreadidlethreadAPIC
IDcurrentldtspin
locks heldshow
pgrpdumpshow
proc [addr]show
procvmshow
protosw addrshow
registers[/u]u modifier is
specified, it displays user registers instead of kernel registers or the
currently saved one.
Warning: The support of the
u modifier depends on the machine. If not
supported, incorrect information will be displayed.
show
rman addrshow
rtcshow
sleepchainshow
lockchain.
show
sleepqshow
sleepqueueshow
sockbuf addrshow
socket addrshow
sysregscr0-4 on i386.) Not
present on some platforms.
show
tcpcb addrshow
thread [addr]show
threadsFirst
columnSecond
columnThird
columnshow
tty addrshow
turnstile addrshow
umaThe very same information might be gathered in the userspace
with the help of “vmstat
-z”.
show
unpcb addrshow
vmochkshow
vmopagshow
vnet addrshow
vnode [addr]show
vnodebufs addrshow
vpath addrshow
watchesshow
witnessgdbhaltkill
sig pidreboot
[seconds]reset
[seconds]helpcapture
oncapture
offcapture
resetcapture
statusddb supports a basic output capture facility,
which can be used to retrieve the results of debugging commands from
userspace using sysctl(3). capture
on enables output capture; capture off
disables capture. capture reset will clear the
capture buffer and disable capture. capture status
will report current buffer use, buffer size, and disposition of output
capture.
Userspace processes may inspect and manage
ddb capture state using
sysctl(8):
debug.ddb.capture.bufsize may be used
to query or set the current capture buffer size.
debug.ddb.capture.maxbufsize may be
used to query the compile-time limit on the capture buffer size.
debug.ddb.capture.bytes may be used to
query the number of bytes of output currently in the capture buffer.
debug.ddb.capture.data returns the
contents of the buffer as a string to an appropriately privileged
process.
This facility is particularly useful in concert with the scripting and textdump(4) facilities, allowing scripted debugging output to be captured and committed to disk as part of a textdump for later analysis. The contents of the capture buffer may also be inspected in a kernel core dump using kgdb(1).
runscriptscriptsunscripttextdump
dumptextdump
settextdump
statustextdump
unsettextdump dump command to immediately
perform a textdump. More information may be found in
textdump(4). The textdump set
command may be used to force the next kernel core dump to be a textdump
rather than a traditional memory dump or minidump.
textdump status reports whether a textdump has
been scheduled. textdump unset cancels a request
to perform a textdump as the next kernel core dump.The debugger accesses registers and variables as
$name. Register names are as
in the “show
registers” command. Some variables are
suffixed with numbers, and may have some modifier following a colon
immediately after the variable name. For example, register variables can
have a u modifier to indicate user register (e.g.,
“$eax:u”).
Built-in variables currently supported are:
+offset”
unless offset is greater than
maxoff.Most expression operators in C are supported except
‘~’,
‘^’, and unary
‘&’. Special rules in
ddb are:
.’ and
‘:’ can be used in the identifier.
If supported by an object format dependent routine,
[filename:]func:lineno,
[filename:]variable, and
[filename:]lineno can be
accepted as a symbol.0x’: hex,
‘0o’: octal,
‘0t’: decimal; otherwise, follow
current radix..+..examine or
write command.'$variable:’ and modifiers as described
above.#b*expr:’ and modifiers as described
above.ddb supports a basic scripting facility to
allow automating tasks or responses to specific events. Each script consists
of a list of DDB commands to be executed sequentially, and is assigned a
unique name. Certain script names have special meaning, and will be
automatically run on various ddb events if scripts
by those names have been defined.
The script command may be used to define a
script by name. Scripts consist of a series of ddb
commands separated with the ‘;’
character. For example:
script kdb.enter.panic=bt; show pcpu script lockinfo=show alllocks; show lockedvnods
The scripts command lists currently
defined scripts.
The run command execute a script by name.
For example:
run lockinfo
The unscript command may be used to delete
a script by name. For example:
unscript kdb.enter.panic
These functions may also be performed from userspace using the ddb(8) command.
Certain scripts are run automatically, if defined, for specific
ddb events. The follow scripts are run when various
events occur:
kdb.enter.acpikdb.enter.bootflagskdb.enter.breakkdb.enter.camkdb.enter.mackdb.enter.ndiskdb.enter.netgraphkdb.enter.panickdb.enter.powerfailkdb.enter.powerpckdb.enter.sysctldebug.kdb.enter sysctl being set.kdb.enter.trapsigkdb.enter.unionfskdb.enter.unknownkdb.enter.vfslockkdb.enter.watchdogkdb.enter.witnessIn the event that none of these scripts is found,
ddb will attempt to execute a default script:
kdb.enter.defaultkdb.enter.witness might be defined to have special
handling, and kdb.enter.default might be defined
to simply panic and reboot.On machines with an ISA expansion bus, a simple NMI generation
card can be constructed by connecting a push button between the A01 and B01
(CHCHK# and GND) card fingers. Momentarily shorting these two fingers
together may cause the bridge chipset to generate an NMI, which causes the
kernel to pass control to ddb. Some bridge chipsets
do not generate a NMI on CHCHK#, so your mileage may vary. The NMI allows
one to break into the debugger on a wedged machine to diagnose problems.
Other bus' bridge chipsets may be able to generate NMI using bus specific
methods. There are many PCI and PCIe add-in cards which can generate NMI for
debugging. Modern server systems typically use IPMI to generate signals to
enter the debugger. The devel/ipmitool port can be
used to send the chassis power diag command which
delivers an NMI to the processor. Embedded systems often use JTAG for
debugging, but rarely use it in combination with
ddb.
For serial consoles, you can enter the debugger by sending a BREAK
condition on the serial line if options
BREAK_TO_DEBUGGER is specified in the kernel. Most terminal emulation
programs can send a break sequence with a special key sequence or via a menu
item. However, in some setups, sending the break can be difficult to arrange
or happens spuriously, so if the kernel contains options
ALT_BREAK_TO_DEBUGGER then the sequence of CR TILDE CTRL-B enters the
debugger; CR TILDE CTRL-P causes a panic instead of entering the debugger;
and CR TILDE CTRL-R causes an immediate reboot. In all the above sequences,
CR is a Carriage Return and is usually sent by hitting the Enter or Return
key. TILDE is the ASCII tilde character (~). CTRL-x is Control x created by
hitting the control key and then x and then releasing both.
The break to enter the debugger behavior may be enabled at
run-time by setting the sysctl(8)
debug.kdb.break_to_debugger to 1. The alternate
sequence to enter the debugger behavior may be enabled at run-time by
setting the sysctl(8)
debug.kdb.alt_break_to_debugger to 1. The debugger
may be entered by setting the sysctl(8)
debug.kdb.enter to 1.
Header files mentioned in this manual page can be found below /usr/include directory.
gdb(1), kgdb(1), acpi(4), CAM(4), mac_test(4), ndis(4), netgraph(4), textdump(4), witness(4), ddb(8), sysctl(8), panic(9)
The ddb debugger was developed for Mach,
and ported to 386BSD-0.1. This manual page
translated from man(7) macros by Garrett
Wollman.
Robert N. M. Watson added support for
ddb output capture, textdump(4)
and scripting in FreeBSD 7.1.
| September 7, 2018 | Debian |