DDB(4)
๐ ddb(4) โ interactive kernel debugger ๐
โจ NAME โจ
okay bestie, ddb is the interactive kernel debugger โ yes, the actual โtalk to the kernel while itโs freaking outโ girlie ๐
.
๐ธ SYNOPSIS ๐ธ
To enable kernel debugging facilities, include:
options KDB
options DDB
To prevent activation of the debugger on kernel panic(9):
options KDB_UNATTENDED
To print a stack trace of the current thread on the console for a panic:
options KDB_TRACE
To print the numerical value of symbols in addition to the symbolic representation, define:
options DDB_NUMSYM
To enable the gdb(4) backend, so that remote debugging with kgdb(1) (ports/devel/gdb) is possible, include:
options GDB
๐ฆ DESCRIPTION ๐ฆ
The ddb kernel debugger is an interactive debugger with syntax inspired by gdb(1) (ports/devel/gdb). If itโs linked into the running kernel, you can invoke it locally with the debug keymap(5) action, usually mapped to Ctrl+Alt+Esc, or by setting the debug.kdb.enter sysctl to 1. 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. Similarly, if debug.debugger_on_recursive_panic is set to 1, then the debugger will be invoked on a recursive kernel panic. This variable has a default value of 0, and has no effect if debug.debugger_on_panic is already set non-zero.
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:
SPCโ one more pageRETโ one more lineqโ abort the current command, and return to the command input mode
Finally, 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.
๐ฅ COMMANDS ๐ฅ
๐ฌ COMMON DEBUGGER COMMANDS ๐ฌ
helpโ print a short summary of the available commands and command abbreviations.examine[/AISabcdghilmorsuxz ...] [addr][,count]/x[/AISabcdghilmorsuxz ...] [addr][,count]โ display the addressed locations according to the formats in the modifier. Multiple modifier formats display multiple locations. If no format is specified, the last format specified for this command is used.
The format characters are:
bโ look at by bytes (8bits)hโ look at by half words (16bits)lโ look at by long words (32bits)gโ look at by quad words (64bits)aโ print the location being displayedAโ print the location with a line number if possiblexโ display in unsigned hexzโ display in signed hexoโ display in unsigned octaldโ display in signed decimaluโ display in unsigned decimalrโ display in current radix, signedcโ display low8bits 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 a disassembled instructionIโ display as a disassembled instruction with possible alternate formats depending on the machine. Oni386, this selects the alternate format for the instruction decoding (16bits in a32-bit code segment and vice versa).Sโ display a symbol name for the pointer stored at the address
xfโ Examine forward: execute anexaminecommand with the last specified parameters to it except that the next address displayed by it is used as the start address.xbโ Examine backward: execute anexaminecommand 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]โ printaddrsaccording to the modifier character (as described above forexamine). Valid formats are:a,x,z,o,d,u,r, andc. If no modifier is specified, the last one specified to it is used. The argumentaddrcan 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
pprint[/d depth] [name]โ pretty-print symbol specified bynameusing CTF debugging data. Works for all symbols exported by the kernel and loaded kernel modules.
If the d modifier has been specified, contents of structs nested up to depth levels deep will also be included in the output.
pprint struct[/d depth ] [name][addr]โ print memory ataddras structname. Works for all structs defined by the kernel and loaded kernel modules.
If the d modifier has been specified, contents of structs nested up to depth levels deep will also be included in the output.
write[/bhl] addr expr1 [expr2 ...]/w[/bhl] addr expr1 [expr2 ...]โ write the expressions specified afteraddron the command line at succeeding locations starting withaddr. The write unit size can be specified in the modifier with a letterb(byte),h(half word) orl(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 [=] exprโ set the named variable or register with the value ofexpr. Valid variable names are described below.break[/u] [addr][,count]/b[/u] [addr][,count]โ set a break point ataddr. Ifcountis supplied, thecontinuecommand will not stop at this break point on the firstcount - 1times 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 #number/d #numberโ delete the specified break point. The break point can be specified by a break point number with#, or by using the sameaddrspecified in the originalbreakcommand, or by omittingaddrto get the default address of dot.haltโ halt the system.watch [addr][,size]โ set a watchpoint for a region. Execution stops when an attempt to modify the region occurs. Thesizeargument defaults to4. If you specify a wrong space address, the request is rejected with an error message.
โ ๏ธ 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]โ set a hardware watchpoint for a region if supported by the architecture. Execution stops when an attempt to modify the region occurs. Thesizeargument defaults to4.
โ ๏ธ Warning: The hardware debug facilities do not have a concept of separate address spaces like thewatchcommand does. Usehwatchfor setting watchpoints on kernel address locations only, and avoid its use on user mode address spaces.
dhwatch [addr][,size]โ delete specified hardware watchpoint.kill sig pidโ send signalsigto processpid. The signal is acted on upon returning from the debugger. This command can be used to kill a process causing resource contention in the case of a hung system. Seesignal(3)for a list of signals. Note that the arguments are reversed relative tokill(2).step[/p][,count]/s[/p][,count]โ single stepcounttimes. If thepmodifier 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]โ continue execution until a breakpoint or watchpoint. If thecmodifier 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]โ keeps going until it hits the nextcallorreturninstruction, then stops. Add thepmodifier and it'll spill the call nesting depth + the cumulative instruction count at every call or return. Without/p, it only prints when the matching return is hit. ngl thepversion is way more noise but lowkey more informative ๐next[/p]โ same energy asuntilbut the actual name for it. Stops at the matching return instruction. With thepmodifier you get the call nesting depth and the cumulative instruction count printed at each call or return; without it, it only prints when the matching return is hit. โจmatch[/p]โ literally the same thing asnext[/p]bestie, and yes it also stops at the matching return instruction, and yes thepmodifier also prints the call nesting depth and the cumulative instruction count at each call or return, and withoutpit also only prints 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]โ stack trace, the icon of debugging ๐ฅ. Theuoption traces user space; if you leave it off,traceonly traces kernel space. That optional count argument is how many frames get traced โ omit count and literally all frames get printed (yes, all of them, buckle up).
โ ๏ธ Warning bestie: user space stack traces are only valid if the machine dependent code supports it. no cap, check first.
search[/bhl] addr value [mask][,count]โ searches memory for value. That optional count argument caps how far the search goes. ๐ต๏ธโโ๏ธreboot[/s] [seconds],reset[/s] [seconds]โ hard reset the system, bye ๐. If you pass the optional seconds argument, the debugger waits that long โ at most a week โ before rebooting. And when thesmodifier is given, the command straight up skips running any registered shutdown handlers and attempts the most basic reset. It's giving "no thoughts, just vibes" but for rebooting ๐thread addr | tidโ switches the debugger over to the thread with ID tid if the argument is a decimal number, or to address addr otherwise. โจwatchdog [exp]โ programs thewatchdog(4)timer to fire in2^expseconds. No argument at all? The watchdog timer just gets disabled. ๐
๐ SPECIALIZED HELPER COMMANDS ๐
findstack addrโ prints the address of the thread whose kernel-mode stack contains addr, if any such thread exists. ๐show active trace,acttraceโ shows a stack trace for every thread running on a CPU. ๐show all procs[/a],ps[/a]โ displays all process info. Heads up: it might just not show anything if the machine doesn't support it, or if the bottom of the target process's stack isn't in main memory at that moment ๐ญ. Theamodifier prints command line arguments for each process. ๐งพshow all tcpcbs[/bil]โ same output as"show tcpcb", but for all the TCP control blocks in the system. Thebmodifier requests that BBLog entries get printed. Pass theimodifier and the corresponding IP control block shows up too. And thelmodifier limits output to only those TCP control blocks which are locked. ๐show all trace,alltraceโ a stack trace for every single thread in the system. All of them. ๐show all ttysโ shows every TTY in the system. The output is similar topstat(8), except it also includes the address of the TTY structure. ๐ฅ๏ธshow all vnetsโ same output as"show vnet", but it lists all the virtualized network stacks within the system. ๐show allchainsโ the same info as"show lockchain", but for every thread in the system. ๐show alllocksโ shows all locks that are currently held. Only available ifwitness(4)is included in the kernel. ๐show allpcpuโ same as"show pcpu", but for every CPU present in the system. ๐show allrmanโ shows resource management info, including interrupt request lines, DMA request lines, I/O ports, I/O memory addresses, and Resource IDs. ๐๏ธshow apicโ dumps data about APIC IDT vector mappings. ๐show badstacksโ walks thewitness(4)graph and prints any lock-order violations it finds. Only available ifwitness(4)is included in the kernel. ๐show breaksโ shows the breakpoints you set with the"break"command. ๐show bio addrโ shows info about the bio structurestruct biopresent at addr. Peep thesys/bio.hheader file andg_bio(9)for more details on the exact meaning of the structure fields. ๐งฌshow buffer addrโ shows info about the buf structurestruct bufpresent at addr. See thesys/buf.hheader file for more details on the exact meaning of the structure fields. ๐ฆshow callout addrโ shows info about the callout structurestruct calloutpresent at addr. โฐshow cdev [addr]โ shows the internal devfs state of the cdev structure located at addr. No argument? Then it shows the list of all created cdevs instead, consisting of the devfs node name and thestruct cdevaddress. ๐๏ธshow conifhkโ lists the hooks currently waiting for completion inrun_interrupt_driven_config_hooks(). ๐ชshow cpusetsโ prints numbered root and assigned CPU affinity sets. Seecpuset(2)for more details. ๐งshow cyrixregโ shows registers specific to the Cyrix processor. (vintage!! ๐บ)show devmapโ prints the contents of the static device mapping table. Currently only available on the ARM architecture. ๐ฆพshow domain addrโ prints the protocol domain structurestruct domainat address addr. See thesys/domain.hheader file for more details on the exact meaning of the structure fields. ๐show ffs [addr]โ shows brief info about the ffs mount at the address addr, if the argument is given. Otherwise it gives you the summary about each ffs mount. ๐show file addrโ shows info about the file structurestruct filepresent at address addr. ๐show filesโ shows info about every file structure in the system. Every. Single. One. ๐ฎโ๐จshow freepagesโ shows the number of physical pages in each of the free lists. ๐งฎshow geom [addr]โ no addr argument? It displays the entire GEOM topology. Give it addr and it displays details about that given GEOM object (class, geom, provider or consumer). ๐งฑshow idtโ shows the IDT layout. First column = the IDT vector. Second column = the name of the interrupt/trap handler. Those functions are machine dependent, iykyk. ๐show igi_list addrโ shows info about the IGMP structurestruct igmp_ifsoftcpresent at addr. ๐กshow iosched addrโ shows info about the I/O schedulerstruct cam_iosched_softclocated at addr. ๐ฝshow inodedeps [addr]โ shows brief info about each inodedep structure. If addr is given, only the inodedeps belonging to the fs located at the supplied address are shown. ๐๏ธshow inpcb addrโ shows info on the IP Control Blockstruct in_pcbpresent at addr. ๐งทshow intrโ dumps info about interrupt handlers. โกshow intrcntโ dumps the interrupt statistics. ๐ขshow irqsโ shows interrupt lines and their respective kernel threads. ๐งตshow ktr[/avV]โ prints the contents of thektr(4)trace buffer. Thevmodifier asks for fully verbose output, which makes the file, line number, and timestamp get printed for each trace entry. TheVmodifier asks for only the timestamps to be printed. And theamodifier requests that the output be unpaginated. ๐๏ธshow lapicโ shows info from the local APIC registers for this CPU. ๐show lock addrโ shows the lock structure. The output format is literally this:- class: โ the class of the lock. Possible types include
mutex(9),rmlock(9),rwlock(9),sx(9). ๐ท๏ธ - name: โ the name of the lock. โ๏ธ
- flags: โ the flags passed to the lock initialization function.
flagsvalues are lock class specific. ๐ฉ - state: โ the current state of a lock.
statevalues are lock class specific. ๐ - owner: โ the lock owner. ๐ค
- class: โ the class of the lock. Possible types include
show lockchain addrโ shows all the threads that the particular thread at address addr is waiting on, based on non-spin locks. โ๏ธshow lockedbufsโ same info as"show buf", but for every lockedstruct bufobject. ๐show lockedvnodsโ lists all the locked vnodes in the system. ๐ณshow locksโ prints all locks that are currently acquired. Only available ifwitness(4)is included in the kernel. ๐show locktreeโ (that's it, that's the whole helper ๐)show malloc[/i]โ printsmalloc(9)memory allocator statistics. If theimodifier is specified, it formats the output as machine-parseable comma-separated values ("CSV"). The output columns are as follows:- Type โ specifies a type of memory. It's the same as a description string used while defining the given memory type with
MALLOC_DECLARE(9). - InUse โ number of memory allocations of the given type, for which
free(9)has not been called yet. - MemUse โ total memory consumed by the given allocation type.
- Requests โ number of memory allocation requests for the given memory type.
- Type โ specifies a type of memory. It's the same as a description string used while defining the given memory type with
The same information can be gathered in userspace with โvmstat -mโ. ๐
show map[/f] addrโ prints the VM map at addr. If thefmodifier is specified, the complete map gets printed. ๐บ๏ธshow msgbufโ prints the system's message buffer. It's the same output as in the โdmesgโ case. Super 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 mount [addr]โ displays details about the mount point located at addr. No addr specified? It displays short info about all currently mounted file systems. ๐show object[/f] addrโ prints the VM object at addr. If thefoption is specified, the complete object gets printed. ๐งshow panicโ prints the panic message, if one is set. ๐จshow pageโ shows statistics on VM pages. ๐show pageqโ shows statistics on VM page queues. ๐ถโโ๏ธshow pciregsโ prints PCI bus registers. The same info can be gathered in userspace by running โpciconf -lvโ. ๐งฉshow pcpuโ prints the current processor state. The output format is as follows: ๐cpuidโ the processor identifier ๐curthreadโ the thread pointer, the process identifier, and the name of the process, all in one little bundle ๐งตcurpcbโ the control block pointerfpcurthreadโ the FPU thread pointeridlethreadโ the idle thread pointer ๐ดAPIC IDโ the CPU identifier, coming straight from APICcurrentldtโ the LDT pointerspin locks heldโ the names of the spin locks currently held ๐
show pgrpdumpโ dumps all the process groups hanging out in the system ๐show prison [addr]โ shows the prison structure sitting at addr. No addr? Then it spills all the tea on every prison in the system ๐ฐshow proc [addr]โ info about the process structure at address addr, or about the current process if you don't pass one ๐ซถshow procvm [addr]โ the process virtual memory layout for the process at addr, or for the current process if you're feeling lazy and pass nothing ๐งshow protosw addrโ prints the protocol switch structurestruct protoswat address addr ๐กshow registers[/u]โ displays the register set. Add theumodifier and instead you get the register contents of the thread's previous trapframe โ which usually means the saved state from userspace โจshow rman addrโ shows the resource manager objectstruct rmanat address addr. Wanna collect addresses of particular pointers? Hit up the"show allrman"command ๐บ๏ธshow route addrโ shows the route table result for destination addr. As of right now,INETandINET6formatted addresses are the ones supported ๐ฃ๏ธshow routetable [af]โ shows the full route table (or tables). Pass af and you only get routes for that numeric address family. Pass nothing and it dumps the route table for all address families, no cap ๐show rtcโ shows the real time clock value. Genuinely useful for those long debugging sessions where you lose all sense of time ๐ญโฐshow sleepchainโ deprecated, bestie. It's now just an alias forshow lockchain๐show sleepq addrshow sleepqueue addrโ both show thesleepqueue(9)structure located at addr ๐ดshow sockbuf addrโ shows the socket bufferstruct sockbuflocated at addr ๐งฆshow socket addrโ shows the socket objectstruct socketlocated at addr ๐show sysregsโ shows system registers (thinkcr0-4on i386). Heads up: it's not present on some platforms ๐show tcpcb[/bi] addrโ prints the TCP control blockstruct tcpcblying at address addr. For the exact interpretation of the output, go visit thenetinet/tcp.hheader file. Thebmodifier requests that BBLog entries get printed. And if you provide theimodifier, the corresponding IP control block gets shown too ๐ฆshow thread [addr | tid]โ no addr or tid? Then you get detailed info about the current thread. Otherwise it prints info about the thread with ID tid or kernel address addr. (Pro tip: if the argument is a decimal number, it's assumed to be a tid.) ๐งตshow threadsโ shows every thread in the system. The output format goes like this:- First column โ thread identifier (TID)
- Second column โ thread structure address
- Third column โ backtrace
๐
show tty addrโ displays the contents of a TTY structure in a readable form ๐ฅ๏ธshow turnstile addrโ shows the turnstilestruct turnstilestructure at address addr. Turnstiles are the structures used inside the FreeBSD kernel to implement synchronization primitives which, while holding a specific type of lock, cannot sleep or context switch to another thread. Currently the cool kids in that club are:mutex(9),rwlock(9),rmlock(9)๐ชshow uma[/i]โ shows UMA allocator stats. Pass theimodifier and the output gets formatted as machine-parseable comma-separated values ("CSV") ๐ค. The output has these columns:Zoneโ name of the UMA zone. Same string that was passed touma_zcreate(9)as a first argument.Sizeโ size of a given memory object (slab).Usedโ number of slabs currently being used.Freeโ number of free slabs within the UMA zone.Requestsโ number of allocation requests to the given zone.Total Memโ total memory in use (either allocated or free) by a zone, in bytes.XFreeโ number of free slabs within the UMA zone that were freed on a different NUMA domain than allocated. (The count in theFreecolumn is inclusive ofXFree.)
Fun fact: you can gather the same info in userspace with the help of "vmstat -z" ๐
show unpcb addrโ shows the UNIX domain socket private control blockstruct unpcbpresent at the address addr ๐งฆshow vmochkโ prints whether the internal VM objects are in a map somewhere, and whether none of them have zero ref counts โshow vmopagโ walks the list of VM objects in the system, printing the indices and physical addresses of the VM pages belonging to each object ๐ถโโ๏ธshow vnet addrโ prints the virtualized network stackstruct vnetstructure present at the address addr ๐show vnode addrโ prints the vnodestruct vnodestructure lying at addr. For the exact interpretation of the output, go look at thesys/vnode.hheader file ๐show vnodebufs addrโ shows the clean/dirty buffer lists of the vnode located at addr ๐งบshow vpath addrโ walks the namecache to look up the pathname of the vnode located at addr ๐ค๏ธshow watchesโ displays all watchpoints. Specifically, the ones you set with the"watch"command ๐show witnessโ shows info about lock acquisition coming from thewitness(4)subsystem ๐
๐ OFFLINE DEBUGGING COMMANDS ๐
dumpโ initiates a kernel core dump to the device(s) configured bydumpon(8)๐พgdbโ switches to remote GDB mode. Heads up: in remote GDB mode you need another machine runninggdb(1)(ports/devel/gdb) using the remote debug feature, connected to the serial console port on the target machine ๐netdump -s server [-g gateway -c client -i iface]โ configuresnetdump(4)with the parameters you gave it, and immediately performs a netdump.
There are some known limitations, ngl. Principally, netdump(4) only supports IPv4 at this time. The address arguments to the netdump command must be dotted decimal IPv4 addresses. (Hostnames are not supported.) At present, the command only works if the machine is in a panic state. And finally, the ddb netdump command does not provide any way to configure compression or encryption ๐
netgdb -s server [-g gateway -c client -i iface]โ initiates anetgdb(4)session with the provided parameters.netgdbhas identical limitations tonetdump๐capture oncapture offcapture resetcapture statusโddbsupports a basic output capture facility, which you can use to retrieve the results of debugging commands from userspace usingsysctl(3).capture onenables output capture;capture offdisables it.capture resetclears the capture buffer and disables capture.capture statusreports the current buffer use, the buffer size, and the disposition of output capture ๐ธ
Userspace processes may inspect and manage ddb capture state using sysctl(8):
debug.ddb.capture.bufsizemay be used to query or set the current capture buffer size.debug.ddb.capture.maxbufsizemay be used to query the compile-time limit on the capture buffer size.debug.ddb.capture.bytesmay be used to query the number of bytes of output currently in the capture buffer.debug.ddb.capture.datareturns 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 โ it lets scripted debugging output 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) (ports/devel/gdb) ๐ซถ
runscriptscriptsunscriptโ run, define, list, and delete scripts. See the"SCRIPTING"section for more on the scripting facility ๐textdump dumptextdump settextdump statustextdump unsetโ use thetextdump dumpcommand to immediately perform a textdump. More info lives intextdump(4). Thetextdump setcommand may be used to force the next kernel core dump to be a textdump rather than a traditional memory dump or minidump.textdump statusreports whether a textdump has been scheduled.textdump unsetcancels a request to perform a textdump as the next kernel core dump ๐
๐ VARIABLES ๐
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:
radixโ input and output radix ๐ขmaxoffโ addresses are printed as"symbol+offset"unless offset is greater thanmaxoffmaxwidthโ the width of the displayed line ๐linesโ the number of lines. It's used by the built-in pager. Setting it to0disables paging ๐tabstopsโ tab stop width โฉworkxxโ work variable; xx can take values from0to31๐ ๏ธ
โจ EXPRESSIONS โจ
okay so ddb does math ๐งฎ and honestly it's lowkey C-coded โ most C expression operators work here, except for ~, ^, and the unary &. those three? not invited to the party ๐
โโ๏ธ. and there are some special ddb rules you gotta know:
- Identifiers โ the name of a symbol gets translated into the value of the symbol, which is the address of the corresponding object. you can use
.and:inside the identifier too ๐ . and if it's supported by an object format dependent routine, then[filename:]func:lineno,[filename:]variable, and[filename:]linenocan all be accepted as a symbol. fancy! - Numbers โ the radix is decided by the first two letters:
0xmeans hex,0omeans octal,0tmeans decimal. otherwise, it just follows whatever the current radix is. iykyk ๐ .โ dot ๐ซถ+โ next..โ the address of the start of the last line examined. and here's the thing: unlike dot or next, this one only changes when you use an examine or write command. icon behavior honestly โจ'โ the last address explicitly specified$variableโ translated to the value of the specified variable. it may be followed by a:and modifiers as described above ๐a#bโ a binary operator that rounds up the left hand side to the next multiple of the right hand side. math slay ๐ฅ*exprโ Indirection. it may be followed by a:and modifiers as described above ๐ซ
๐ฆ SCRIPTING ๐ฆ
so ddb has a basic scripting facility and it's genuinely so good โ it lets you automate tasks or responses to specific events ๐ธ. each script is just a list of DDB commands executed sequentially, and it gets assigned a unique name. and bestie, some script names are special โ those get automatically run on various ddb events if scripts by those names have been defined ๐
the script command defines a script by name. scripts are 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 executes a script by name. for example:
run lockinfo
the unscript command deletes a script by name ๐
. for example:
unscript kdb.enter.panic
and psst โ these functions can also be performed from userspace using the ddb(8) command ๐.
some scripts run automatically, if defined, for specific ddb events. here are the scripts that run when various events occur:
kdb.enter.acpiโ the kernel debugger was entered as a result of anacpi(4)event.kdb.enter.bootflagsโ the kernel debugger was entered at boot as a result of the debugger boot flag being set.kdb.enter.breakโ the kernel debugger was entered as a result of a serial or console break.kdb.enter.camโ the kernel debugger was entered as a result of aCAM(4)event.kdb.enter.macโ the kernel debugger was entered as a result of an assertion failure in themac_test(4)module of the TrustedBSD MAC Framework.kdb.enter.netgraphโ the kernel debugger was entered as a result of anetgraph(4)event.kdb.enter.panicโpanic(9)was called. ๐ญkdb.enter.powerpcโ the kernel debugger was entered as a result of an unimplemented interrupt type on the powerpc platform.kdb.enter.sysctlโ the kernel debugger was entered as a result of thedebug.kdb.entersysctl being set.kdb.enter.unionfsโ the kernel debugger was entered as a result of an assertion failure in the union file system.kdb.enter.unknownโ the kernel debugger was entered, but no reason has been set. ๐kdb.enter.vfslockโ the kernel debugger was entered as a result of a VFS lock violation.kdb.enter.watchdogโ the kernel debugger was entered as a result of a watchdog firing.kdb.enter.witnessโ the kernel debugger was entered as a result of awitness(4)violation.
and in the event that none of these scripts is found, ddb will attempt to execute a default script:
kdb.enter.defaultโ the kernel debugger was entered, but a script exactly matching the reason for entering was not defined. this can be used as a catch-all to handle cases not specifically of interest ๐ฏ โ for example,kdb.enter.witnessmight be defined to have special handling, andkdb.enter.defaultmight be defined to simply panic and reboot. main character fallback energy fr fr ๐
๐ HINTS ๐
on machines with an ISA expansion bus, you can construct a simple NMI generation card 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 an NMI on CHCHK#, so your mileage may vary bestie ๐ฌ. the NMI lets you 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 ๐.
serial consoles can break to the debugger by sending a BREAK condition on the serial line. this requires a kernel built with options BREAK_TO_DEBUGGER specified in the kernel ๐ง. most terminal emulation programs can send a break sequence with a special key sequence or menu selection. sending the break can be difficult, or even happen spuriously in some setups ๐. an alternative method is to build a kernel with options ALT_BREAK_TO_DEBUGGER โ then the sequence of CR TILDE CTRL-B enters the debugger; CR TILDE CTRL-P causes a panic; and CR TILDE CTRL-R causes an immediate reboot ๐ฅ. in all these sequences, CR represents Carriage Return and is usually sent by pressing the Enter or Return key. TILDE is the ASCII tilde character (~). CTRL-x is Control x, sent by pressing the Control key, then x, then releasing both ๐
.
the break-to-debugger behavior can be enabled by setting sysctl(8) debug.kdb.break_to_debugger to 1. the alt-break-to-debugger behavior can be enabled by setting sysctl(8) debug.kdb.alt_break_to_debugger to 1. and the debugger can be entered by setting sysctl(8) debug.kdb.enter to 1 โจ.
output can be interrupted, paused, and resumed with the control characters CTRL-C, CTRL-S, and CTRL-Q ๐ซถ. and because these control characters are received as in-band data from the console, there is an input buffer โ and once that buffer fills, ddb must either stop responding to control characters or drop additional input while continuing to search for control characters. this behavior is controlled by the tunable sysctl(8) debug.ddb.prioritize_control_input, which defaults to 1. the input buffer size is 512 bytes ๐ฆ.
๐ FILES ๐
header files mentioned in this manual page can be found below the /usr/include directory ๐:
sys/buf.hsys/domain.hnetinet/in_pcb.hsys/socket.hsys/vnode.h
๐ SEE ALSO ๐
gdb(1) (ports/devel/gdb), kgdb(1) (ports/devel/gdb), acpi(4), CAM(4), gdb(4), mac_ddb(4), mac_test(4), netgraph(4), textdump(4), witness(4), ddb(8), sysctl(8), panic(9) ๐ซ
โญ HISTORY โญ
the ddb debugger was developed for Mach, and ported to 386BSD 0.1 ๐ฐ๏ธ. this manual page was 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 ๐
and that's the whole page bestie, you ate that ๐ซถ๐ โจ โ this one's from Debian, dated October 31, 2025, and it's page DDB(4). go forth and debug, icon ๐๐ฆ
๐ฆ where this page comes from
- freebsd 15.1: base 15.1
- Copyright (c) 1991,1990 Carnegie Mellon University
- Copyright (c) 2007 Robert N. M. Watson
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms