DB(1)
okay bestie, welcome to DB(1) from the General Commands Manual β the db, stack debugger page. it's giving old-school Unix but make it cute π
πΈ NAME πΈ
db, stack β debugger. that's it, short and iconic β¨
β SYNOPSIS β
db [ option ... ] [ pid | corefile ] [ textfile ]
stack [ pid | corefile | name ] [ textfile ]
π DESCRIPTION π
db is a general purpose debugging program, no cap. It may be used to examine files and to provide a controlled environment for the execution of programs. main character debugger energy π
A textfile is a file containing the text and initialized data of an executable program. A pid or corefile specifies the memory image of a process. A pid gives the id of an executing process to be accessed via ptrace(2). A corefile specifies the name of a core dump (see core(5) on your system of choice) containing the memory image of a terminated process. This manual refers to the memory image specified by pid or corefile as a memfile. okay so that's the vocabulary, bestie, we're locked in π«Ά
A map associated with each textfile or memfile supports accesses to instructions and data in the file; see Addresses.
An argument consisting entirely of digits is assumed to be a process id; otherwise, it is the name of a textfile or corefile. When a textfile is given, the textfile map is associated with it. If only a memfile is given, the textfile map is derived from the corresponding textfile, if it can be determined (this varies from system to system). When a memfile is given, the memfile map is associated with it; otherwise the map is undefined and accesses to it are not permitted.
stack takes the same arguments as db. It prints a stack trace (see the $c command below) and then exits. If the first argument is a process name, then stack prints the stack trace of every running process with the given name that is owned by the current user. very "show me the receipts" of it all π
Commands to db are read from the standard input and responses are to the standard output. The options are
-qβ quiet mode: suppress informational prints at startup. lowkey bliss π-wβ open textfile and memfile for writing as well as reading. be careful, bestie π-Ipathβ directory in which to look for relative path names in$<and$<<commands.-mmachineβ assume instructions are for the given CPU type (possible names include386andpowerpc; adding the suffix-coas in386-coandpowerpc-coselects disassembly in the manufacturer's syntax, if available, rather than the default Plan 9 syntax).
Most db commands have the following form:
[address] [, count] [command]
If address is present then the current position, called dot, is set to address. Initially dot is set to 0. Most commands are repeated count times with dot advancing between repetitions. The default count is 1. Address and count are expressions. Multiple commands on one line must be separated by ;.
π§ Expressions π§
Expressions are evaluated as long ints.
.β the value ofdot.+β the value ofdotincremented by the current increment.^β the value ofdotdecremented by the current increment."β the last address typed.integerβ a number, in decimal radix by default. The prefixes0and0o(zero oh) force interpretation in octal radix; the prefixes0dand0Dforce interpretation in decimal radix; the prefixes0xand0Xforce interpretation in hexadecimal radix. Thus0x10,0X10,020, and0d16all represent sixteen.integer.fractionβ a single-precision floating point number.Β΄cΒ΄β the 16-bit value of a character.\may be used to escape a character.<nameβ the value ofname, which is a register name. The register names are those printed by the$rcommand.symbolβ a symbol is a sequence of upper or lower case letters, underscores or digits, not starting with a digit.\may be used to escape other characters. The location of the symbol is calculated from the symbol table in textfile.routine.nameβ the address of the variablenamein the specified C routine. Bothroutineandnameare symbols. Ifnameis omitted the value is the address of the most recently activated stack frame corresponding toroutine; ifroutineis omitted, the active procedure is assumed.file:integerβ the address of the instruction corresponding to the source statement at the indicated line number of the file. If the source line contains no executable statement, the address of the instruction associated with the nearest executable source line is returned. Files begin at line 1. If multiple files of the same name are loaded, an expression of this form resolves to the first file encountered in the symbol table.(exp)β the value of the expressionexp.
β¨ Monadic operators β¨
*expβ the contents of the location addressed byexpin memfile.@expβ the contents of the location addressed byexpin textfile.-expβ integer negation.~expβ bitwise complement.%expβ when used as an address,expis an offset into the segment namedublock; seeAddresses.
π« Dyadic operators π«
Dyadic operators are left-associative and are less binding than monadic operators.
e1+e2β integer addition.e1-e2β integer subtraction.e1*e2β integer multiplication.e1%e2β integer division.e1&e2β bitwise conjunction.e1|e2β bitwise disjunction.e1#e2βE1rounded up to the next multiple ofe2.
π Commands π
Most commands have the following syntax:
?fβ locations starting at address in textfile are printed according to the formatf./fβ locations starting at address in memfile are printed according to the formatf.=fβ the value of address itself is printed according to the formatf.
A format consists of one or more characters that specify a style of printing. Each format character may be preceded by a decimal integer that is a repeat count for the format character. If no format is given then the last format is used.
Most format letters fetch some data, print it, and advance (a local copy of) dot by the number of bytes fetched. The total number of bytes in a format becomes the current increment.
oβ print two-byte integer in octal.Oβ print four-byte integer in octal.qβ print two-byte integer in signed octal.Qβ print four-byte integer in signed octal.dβ print two-byte integer in decimal.Dβ print four-byte integer in decimal.Vβ print eight-byte integer in decimal.Zβ print eight-byte integer in unsigned decimal.xβ print two-byte integer in hexadecimal.Xβ print four-byte integer in hexadecimal.Yβ print eight-byte integer in hexadecimal.uβ print two-byte integer in unsigned decimal.Uβ print four-byte integer in unsigned decimal.fβ print as a single-precision floating point number.Fβ print double-precision floating point.bβ print the addressed byte in hexadecimal.cβ print the addressed byte as an ASCII character.Cβ print the addressed byte as a character. Printable ASCII characters are represented normally; others are printed in the form\xnn.sβ print the addressed characters, as a UTF string, until a zero byte is reached. Advancedotby the length of the string, including the zero terminator.Sβ print a string using the escape convention (seeCabove).rβ print as UTF the addressed two-byte integer (rune).Rβ print as UTF the addressed two-byte integers as runes until a zero rune is reached. Advancedotby the length of the string, including the zero terminator.iβ print as machine instructions.dotis incremented by the size of the instruction.Iβ asiabove, but print the machine instructions in an alternate form if possible.Mβ print the addressed machine instruction in a machine-dependent hexadecimal form.aβ print the value ofdotin symbolic form.dotis unaffected.Aβ print the value ofdotin hexadecimal.dotis unaffected.zβ print the function name, source file, and line number corresponding todot(textfile only).dotis unaffected.pβ print the addressed value in symbolic form.dotis advanced by the size of a machine address.tβ when preceded by an integer, tabs to the next appropriate tab stop. For example,8tmoves to the next 8-space tab stop.dotis unaffected.nβ print a newline.dotis unaffected."..."β print the enclosed string.dotis unaffected.^βdotis decremented by the current increment. Nothing is printed.+βdotis incremented by1. Nothing is printed.-βdotis decremented by1. Nothing is printed.
π¦ Other commands include π¦
newlineβ updatedotby the current increment. Repeat the previous command with a count of1.[?/]l value maskβ words starting atdotare masked withmaskand compared withvalueuntil a match is found. Iflis used, the match is for a two-byte integer;Lmatches four bytes. If no match is found thendotis unchanged; otherwisedotis set to the matched location. Ifmaskis omitted then~0is used.[?/]w value ...β write the two-byte value into the addressed location. If the command isW, write four bytes.[?/]m s b e f [?]β new values for (b,e,f) in the segment namedsare recorded. Valid segment names aretext,data, orublock. If less than three address expressions are given, the remaining parameters are left unchanged. If the list is terminated by?or/, then the file (textfile or memfile respectively) is used for subsequent requests. For example, ending the list with?causes subsequent requests to refer to textfile.>nameβdotis assigned to the variable or register named.!β the rest of the line is passed torc(1)for execution.$modifierβ miscellaneous commands. The available modifiers are:<fβ read commands from the file f. If this command is executed in a file, further commands in the file are not seen, periodt. If f is omitted, the current input stream is terminated. If a count is given, and is zero, the command is ignored. π<<fβ basically<but the glow-up: similar to<except it can be used in a file of commands without causing the file to be closed. There is a (small) limit to the number of<<files that can be open at once, so don't go feral. π¦>fβ append output to the file f, which is created if it does not exist. If f is omitted, output is returned to the terminal. π?β print process id, the condition which caused stopping or termination, the registers and the instruction addressed bypc. This is the default if modifier is omitted. πrβ print the general registers and the instruction addressed bypc.Dotis set topc. β¨Rβ like$r, but include miscellaneous processor control registers and floating point registers. πfβ print floating-point register values as single-precision floating point numbers. πFβ print floating-point register values as double-precision floating point numbers. πΈbβ print all breakpoints and their associated counts and commands.B'produces the same results. πcβ stack backtrace. If address is given, it specifies the address of a pair of 32-bit values containing thespandpcof an active process. This allows selecting among various contexts of a multi-threaded process. IfCis used, the names and (long) values of all parameters, automatic and static variables are printed for each active function. If count is given, only the first count frames are printed. π§aβ attach to the running process whose pid is contained in address. π«Άeβ the names and values of all external variables are printed. πwβ set the page width for output to address (default80). πqβ exit fromdb. bye bestie πmβ print the address maps. πΊοΈkβ simulate kernel memory management. πMmachineβ set the machine type used for disassembling instructions. π₯
π
:modifier β subprocess management era
Manage a subprocess. Available modifiers are:
hβ halt an asynchronously running process to allow breakpointing. Unnecessary for processes created underdb, e.g. by:r. π«Άbcβ set breakpoint at address. The breakpoint is executedcount-1times before causing a stop. Also, if a command c is given it is executed at each breakpoint and if it setsdotto zero the breakpoint causes a stop. β¨dβ delete breakpoint at address. πrβ run textfile as a subprocess. If address is given the program is entered at that point; otherwise the standard entry point is used. Count specifies how many breakpoints are to be ignored before stopping. Arguments to the subprocess may be supplied on the same line as the command. An argument starting with<or>causes the standard input or output to be established for the command. πββοΈcsβ the subprocess is continued. If s is omitted or nonzero, the subprocess is sent the note that caused it to stop. If0is specified, no note is sent. (If the stop was due to a breakpoint or single-step, the corresponding note is elided before continuing.) Breakpoint skipping is the same as forr. πssβ as forcexcept that the subprocess is single stepped for count machine instructions. If a note is pending, it is received before the first instruction is executed. If there is no current subprocess then textfile is run as a subprocess as forr. In this case no note can be sent; the remainder of the line is treated as arguments to the subprocess. πSsβ identical tosexcept the subprocess is single stepped for count lines of C source. In optimized code, the correspondence between C source and the machine instructions is approximate at best. π¬xβ the current subprocess, if any, is released bydband allowed to continue executing normally. ποΈkβ the current subprocess, if any, is terminated. πncβ display the pending notes for the process. If c is specified, first delete c'th pending note. π
πΊοΈ Addresses
The location in a file or memory image associated with an address is calculated from a map associated with the file. Each map contains one or more quadruples (t, f, b, e, o), defining a segment named t (usually, text, data, or core) in file f mapping addresses in the range b through e to the part of the file beginning at offset o. If segments overlap, later segments obscure earlier ones. An address a is translated to a file address by finding the last segment in the list for which bβ€a<e; the location in the file is then address+f-b. π§
Usually, the text and initialized data of a program are mapped by segments called text, data, and bss. Since a program file does not contain stack data, this data is not mapped. The text segment is mapped similarly in a normal (i.e., non-kernel) memfile. However, one or more segments called data provide access to process memory. This region contains the program's static data, the bss, the heap and the stack. πΈ
Sometimes it is useful to define a map with a single segment mapping the region from 0 to 0xFFFFFFFF; a map of this type allows an entire file to be examined without address translation. π
The $m command dumps the currently active maps. The ?m and /m commands modify the segment parameters in the textfile and memfile maps, respectively. π₯
β¨ EXAMPLES β¨
To set a breakpoint at the beginning of write() in extant process 27:
% db 27
:h
write:b
:c
To set a breakpoint at the entry of function parse when the local variable argc in main is equal to 1:
parse:b *main.argc-1=X
This prints the value of argc-1 which as a side effect sets dot; when argc is one the breakpoint will fire. Beware that local variables may be stored in registers; see the BUGS section. π
π SEE ALSO π
acid(1), core(1) β go read those too bestie π
π SOURCE π
/src/cmd/db
π DIAGNOSTICS π
Exit status is 0, unless the last command failed or returned non-zero status. π¬
π BUGS π
Examining a local variable with routine.name returns the contents of the memory allocated for the variable, but with optimization, variables often reside in registers. Also, on some architectures, the first argument is always passed in a register. π
Variables and parameters that have been optimized away do not appear in the symbol table, returning the error bad local variable when accessed by db. π
Breakpoints should not be set on instructions scheduled in delay slots. When a program stops on such a breakpoint, it is usually impossible to continue its execution. π
That's the whole DB(1) page, bestie β source is /src/cmd/db, and the footer's version/date energy is doing its iconic little signature moment β¨π
π«Ά
π¦ where this page comes from
- alpine 3.24: plan9port-doc 0_git20260208-r0 Β· LPL-1.02
- arch rolling: plan9port 20261021-2 Β· custom
- nixos 26.05: plan9port 0-unstable-2025-11-10
- nixos 26.05: plan9port-wayland 0-unstable-2025-11-26
- nixpkgs unstable: plan9port 0-unstable-2025-11-10
- nixpkgs unstable: plan9port-wayland 0-unstable-2025-11-26
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms