GBD
"GBD" is a misspelling of GDB: the encyclopedia entry traces to a 99 Bottles of Beer program written in the GNU Debugger's own command language, the define/if/while/printf scripting dialect Richard Stallman built into GDB in 1986.
Created by Richard Stallman (GDB), with the if/while and argument extensions added in GDB 4.14 under release manager Stan Shebs
GBD is a typo. The name in the encyclopedia list comes from a program on the 99 Bottles of Beer website whose header reads # GBD command version of 99 bottles of beer. The very next lines tell you to run it with gdb --batch -nw --command=THIS_FILE. The “language” is therefore the command language of GDB, the GNU Debugger: the lines you type at the (gdb) prompt, extended with define, if, while, printf and convenience variables into a small procedural scripting language. It lives in .gdbinit files and command scripts wherever GDB is used.
The master list gives this entry 1975, Database and Historical. None of these fits. No database language called GBD from 1975 could be found, and the program the entry is based on is unambiguously a GDB script. GDB dates from 1986, it has nothing to do with databases, and it is still in active development. This page uses 1986.
History & Origins
Stallman’s debugger, 1986
Richard Stallman wrote GDB after GNU Emacs, as the next major piece of the GNU system. He described it in a lecture at the Royal Institute of Technology (KTH) in Stockholm on 30 October 1986, calling it “a symbolic debugger for C code, which recently entered distribution”. He said it was “to a large extent in the spirit of DBX, which is a debugger that comes with Berkeley Unix”.
Even in that first description the scripting features were already there:
- Debugger variables. “You say dollar-sign followed by a name, and that is a variable,” assignable to any C datatype. Stallman showed
SET $foo=0followed byPRINT X[$foo++]to walk an array, and$foo--==0as a breakpoint condition to stop on the Nth hit. - User-defined commands. “You can say Define Mumble, and then you give some lines of commands and then you say end.”
- Command files. These could live “in each directory” and be “loaded automatically when you start the debugger with that as your working directory.” This is the ancestor of
.gdbinit. - Documentation for user commands, so that they “get handled by the help features just like the built-in commands.”
The GDB manual says that “changes much prior to version 2.0 are lost in the mists of time”. It credits Stallman with releases through 2.8, followed by a succession of maintainers including Randy Smith, Jim Kingdon, John Gilmore, Fred Fish and Stan Shebs.
Becoming a real scripting language: GDB 4.14 (1995)
For its first decade the command language could define macros but could not make decisions. The release notes for GDB 4.14 describe two changes that turned it into a programming language. The 4.14 README is dated 2 March 1995 and signed by Stan Shebs.
Arguments to user-defined commands. User commands may accept up to 10 arguments separated by whitespace. Arguments are accessed within the user command via $arg0..$arg9.
New
if' andwhile’ commands. This makes it possible to write more sophisticated user-defined commands.
Every version since has added to the language without replacing it.
Design Philosophy
GDB’s command language was never designed as a language. It grew out of the debugger’s interactive command line, and its shape follows from that:
- One command per line. A script is simply what you would have typed at the prompt. Any GDB command, whether
break,run,print,xorbt, is a statement. - Expressions belong to the program being debugged. GDB evaluates
ifandwhileconditions andset $var = …in the current source language, usually C. Its own syntax is therefore mostly keywords andend. - Text substitution, not values. The manual warns that
$argNarguments “are text substitutions”. As a result, “there is no way for the user to pass an argument containing a space”. It recommends Python for “more complicated and robust commands”. - Quiet by default. In a command file or user-defined command, the manual says “normal GDB output is suppressed” and only what the commands explicitly print appears.
echo,outputandprintfexist to give a script exact control over what the user sees.
Key Features
| Feature | Commands | Notes |
|---|---|---|
| Variables | set $name = expr | “Convenience variables” with no fixed type |
| User commands | define … end | Arguments $arg0… and $argc; unlimited since GDB 8.0 |
| Help text | document … end | Shows up in help yourcommand |
| Prefix commands | define-prefix | Groups user commands, as in mycmds foo (GDB 9) |
| Conditionals | if / else / end | Since GDB 4.14 |
| Loops | while / loop_break / loop_continue / end | while since GDB 4.14 |
| Output | echo, output, printf | printf takes C-style format strings |
| Indirection | eval "template", args… | Builds a command line, then runs it (GDB 7.2) |
| Hooks | define hook-stop, hookpost-… | Run automatically around other commands |
| Script files | source file, -x file, .gdbinit | Also auto-loaded per objfile as *-gdb.gdb |
A user-defined command
This is the GDB manual’s adder example, with a document block added:
define adder
print $arg0 + $arg1 + $arg2
end
document adder
Print the sum of three arguments.
end
After that, adder 1 2 3 prints $1 = 6, and help adder shows the documentation line.
The 99 Bottles program
Laurent Vogel’s program is the one behind this encyclopedia entry. It does not use while at all. It builds the 97 middle verses from nested macros: loop3 calls loop2 four times, loop2 calls loop four times, and loop3 is invoked six times. That makes 96 verses, plus one more direct call to loop:
# GBD command version of 99 bottles of beer
# Laurent Vogel, http://lvogel.free.fr
#
# run as: gdb --batch -nw --command=THIS_FILE
printf "99 bottles of beer on the wall,\n"
printf "99 bottles of beer.\n"
set $i = 99
define loop
set $i = $i-1
printf "Take one down, pass it around,\n"
printf "%d bottles of beer on the wall.\n\n", $i
printf "%d bottles of beer on the wall,\n", $i
printf "%d bottles of beer.\n", $i
end
define loop2
loop
loop
loop
loop
end
define loop3
loop2
loop2
loop2
loop2
end
loop3
loop3
loop3
loop3
loop3
loop3
loop
The original then hard-codes the last two verses with plain printf lines. The same count can be written with the while loop that GDB has supported since 1995:
set $i = 99
while $i > 0
printf "%d bottles of beer on the wall, %d bottles of beer.\n", $i, $i
set $i = $i - 1
printf "Take one down, pass it around, %d bottles of beer on the wall.\n\n", $i
end
Neither script needs a program loaded. Convenience variables and printf work in a bare gdb --batch session.
Evolution
GDB’s history added more languages around the command language rather than replacing it:
- 1986:
define, debugger variables, command files and user-command documentation. - 1995 (GDB 4.14):
if,elseandwhile, and$arg0–$arg9. - 2005 (GDB 6.4):
$argc. - 2009 (GDB 7.0): Python scripting. New commands, and later pretty-printers, can be written in Python. Most large modern GDB extensions take this route.
- 2010 (GDB 7.2):
eval. - 2012 (GDB 7.5):
dprintfdynamic printf breakpoints. Also the auto-load settings, includingset auto-load safe-path, which restricts which directories GDB will auto-load scripts and.gdbinitfiles from. - 2014 (GDB 7.8): GNU Guile as a second extension language.
- 2017 (GDB 8.0): unlimited arguments to user commands, and
evalexpansion of$argN. - GDB 9:
define-prefixfor user-defined prefix commands.
The per-directory command file Stallman described in 1986 still exists as the local .gdbinit. Since GDB 7.5 it is subject to the auto-load safety checks, so GDB declines to load a .gdbinit from a directory outside the configured safe path and prints a warning instead.
Current Relevance
GDB is actively maintained by the GNU Project, and the most recent release is GDB 18.1 (25 September 2026). The command language is fully documented in the current manual in the “Canned Sequences of Commands” section of the “Extending GDB” chapter. It remains the quickest way to write a breakpoint action, a hook-stop, a crash-dump helper or a batch script. Python is the recommended choice once a task needs real data structures, string handling or robust argument parsing. In practice the two are used side by side, often in the same .gdbinit.
GDB itself is not in the Docker Hub official images list, so no official image is given above. It is packaged by the major Linux distributions.
Why It Matters
The GDB command language is a clear case of a language that nobody set out to design. It began as a convenience in an interactive tool: a way to name a sequence of commands. It grew conditionals and loops in 1995 because users wanted their macros to make decisions. Forty years on, define … end in a .gdbinit is still how developers in projects from the Linux kernel to CPython have packaged knowledge of their own data structures for the debugger. That is exactly the use Stallman described in 1986: “for each program you can define a set of user defined commands to access the data structures of that program in a useful way.”
Sources
- Richard Stallman, lecture at KTH, Stockholm, 30 October 1986 (gnu.org/philosophy/stallman-kth.html). Source for GDB’s origin, the dbx comparison, and the 1986
define/command-file/variable features. - GDB
NEWSfile (binutils-gdb git, HEAD). Source for the feature dates per release: 4.14 (arguments,if/while), 6.4 ($argc), 7.0 (Python), 7.2 (eval), 7.5 (auto-load,dprintf), 7.8 (Guile), 8.0 (unlimited arguments), 9 (define-prefix). - GDB manual,
gdb.texinfo(HEAD). Source for the contributors and release-manager list, convenience-variable typing, the user-command and flow-control sections, and theadderexample. README for gdb-4.14 release, “Updated 2-Mar-95 by Stan Shebs” (Slackware 3.0 copy).- ftp.gnu.org/gnu/gdb listing and binutils-gdb release tags. Sources for release dates: 6.4 tagged 2 December 2005, 7.0 tagged 6 October 2009, 7.2 tagged 2 September 2010, 7.5 on 17 August 2012, 7.8 on 29 July 2014, 8.0 on 4 June 2017, 18.1 on 25 September 2026.
- 99-bottles-of-beer.net “Language GBD” (entry 278), via the Wayback Machine. Source for the program, Laurent Vogel’s authorship and the 04/20/05 date. The live site no longer resolves.
- Linux
Documentation/admin-guide/kdump/gdbmacros.txt, CPythonMisc/gdbinit(2.7 and 3.11 branches), and github.com/gdbinit/Gdbinit (revision 9.01).
Timeline
Notable Uses & Legacy
Linux kernel (kdump)
The kernel source tree ships Documentation/admin-guide/kdump/gdbmacros.txt, a set of GDB user-defined commands (btt, btpid, trapinfo, dump_record and others) for pulling stack traces and trap information out of a kernel crash dump. It is meant to be copied into .gdbinit
CPython
Python's source tree carried Misc/gdbinit, a file of GDB commands such as pyo, pylocals and pystack for inspecting Python objects and interpreter frames from inside gdb. It is present on the 2.7 and 3.11 branches and gone from 3.12
Gdbinit (reverse engineering)
A widely shared ~/.gdbinit for x86, x86-64 and ARM, crediting mammon_, fG! and others, that adds about 126 user-defined commands for register, stack and disassembly context displays. The current file is revision 9.01, dated 31 March 2024
Batch debugging and automation
gdb --batch with -x or --command runs a file of these commands non-interactively. The 99 Bottles of Beer program behind this entry was meant to be run exactly that way