GDB(1)

๐Ÿ“ฆ
version 7.2.4 ยท 2 versions
, in arch rolling

๐Ÿ’– GDB(1) โ€” GNU Development Tools ๐Ÿ’–

okay bestie, welcome to the GNU Development Tools corner of the manual, bestie. this one's a whole situation โ€” it's long, it's iconic, and it's literally the debugger manual. let's get into it ๐Ÿซถ

โœจ NAME โœจ

gdb โ€” The GNU Debugger. that's it. that's the name. ๐Ÿ‘‘

โœจ SYNOPSIS โœจ

gdb [OPTIONS] [prog|prog procID|prog core]

like, you can just run it with options, or you can point it at a program, or a program + a process ID, or a program + a core file. three flavors, all valid, all slay ๐Ÿ’…

๐ŸŒธ DESCRIPTION ๐ŸŒธ

so the whole point of a debugger like ROCGDB is to let you peek at what's going on "inside" another program while it's running โ€” or what that program was doing at the exact moment it crashed ๐Ÿ˜ญ it's giving microscope energy, fr fr.

ROCGDB can do four main kinds of things (plus a bunch of supporting stuff around them) to help you catch bugs in the act:

  • Start your program, specifying anything that might affect its behavior. ๐Ÿš€
  • Make your program stop on specified conditions. โœ‹
  • Examine what has happened, when your program has stopped. ๐Ÿ”
  • Change things in your program, so you can experiment with correcting the effects of one bug and go on to learn about another. ๐Ÿงช

you can use ROCGDB to debug programs written in C, C++, Fortran and Modula-2. multilingual icon behavior ๐ŸŒˆ

ROCGDB is invoked with the shell command gdb. once it's started, it reads commands from the terminal until you tell it to exit with the ROCGDB command quit or exit. and you can get online help from ROCGDB itself by using the command help โ€” she's self-aware, she's helpful, she's that girl ๐Ÿ’โ€โ™€๏ธ

you can run gdb with no arguments or options; but the most usual way to start ROCGDB is with one argument or two, specifying an executable program as the argument:

gdb program

you can also start with both an executable program and a core file specified:

gdb program core

you can, instead, specify a process ID as a second argument or use option -p, if you want to debug a running process:

gdb program 1234
gdb -p 1234

both of those would attach ROCGDB to process 1234. and with option -p you can omit the program filename entirely โ€” no program file, no problem ๐ŸŽ€

here are some of the most frequently needed ROCGDB commands, aka the starter pack, the greatest hits, the ones you'll actually type:

  • break [file:][function|line] โ€” Set a breakpoint at function or line (in file). ๐Ÿ›‘
  • run [arglist] โ€” Start your program (with arglist, if specified). ๐Ÿƒโ€โ™€๏ธ
  • bt โ€” Backtrace: display the program stack. ๐Ÿชœ
  • print expr โ€” Display the value of an expression. ๐Ÿ–จ๏ธ
  • c โ€” Continue running your program (after stopping, e.g. at a breakpoint). โ–ถ๏ธ
  • next โ€” Execute next program line (after stopping); step over any function calls in the line. โญ๏ธ
  • edit [file:]function โ€” look at the program line where it is presently stopped. ๐Ÿ“
  • list [file:]function โ€” type the text of the program in the vicinity of where it is presently stopped. ๐Ÿ“„
  • step โ€” Execute next program line (after stopping); step into any function calls in the line. ๐Ÿ‘ฃ
  • help [name] โ€” Show information about ROCGDB command name, or general information about using ROCGDB. โ“
  • quit / exit โ€” Exit from ROCGDB. ๐Ÿ‘‹

for full details on ROCGDB, see Using GDB: A Guide to the GNU Source-Level Debugger, by Richard M. Stallman and Roland H. Pesch. the same text is available online as the gdb entry in the info program. ๐Ÿ“š


โœจ OPTIONS โœจ

okay so, ground rules first, because the vibes here are specific ๐Ÿงš

any arguments other than options specify an executable file and core file (or process ID); that is, the first argument encountered with no associated option flag is equivalent to a --se option, and the second, if any, is equivalent to a -c option if it's the name of a file. many options have both long and abbreviated forms; both are shown here. the long forms are also recognized if you truncate them, so long as enough of the option is present to be unambiguous. so like, truncation slay, but only unambiguous truncation. bestie, do not test her. ๐Ÿ’€

the abbreviated forms are shown here with - and long forms are shown with -- to reflect how they are shown in --help. however, ROCGDB recognizes all of the following conventions for most options:

"--option=value"
"--option value"
"-option=value"
"-option value"
"--o=value"
"--o value"
"-o=value"
"-o value"

like, she's flexible. she's accommodating. she contains multitudes ๐Ÿ˜Œโœจ

important: all the options and command line arguments you give are processed in sequential order. the order makes a difference when the -x option is used. so don't come for her about ordering, the ordering is load-bearing ๐Ÿ”ฅ

  • --help, -h โ€” List all options, with brief explanations. the literal cheat sheet, we love her ๐ŸŽ€
  • --symbols=file, -s file โ€” Read symbol table from file. ๐Ÿ“–
  • --write โ€” Enable writing into executable and core files. yes, writing. into files. be normal about it, or don't ๐Ÿ’…
  • --exec=file, -e file โ€” Use file as the executable file to execute when appropriate, and for examining pure data in conjunction with a core dump. ๐Ÿ—๏ธ
  • --se=file โ€” Read symbol table from file and use it as the executable file. two jobs, one flag, main character energy ๐Ÿ‘‘
  • --core=file, -c file โ€” Use file as a core dump to examine. ๐Ÿ’พ
  • --command=file, -x file โ€” Execute ROCGDB commands from file. ๐Ÿ“œ
  • --eval-command=command, -ex command โ€” Execute given ROCGDB command. โšก
  • --init-eval-command=command, -iex โ€” Execute ROCGDB command before loading the inferior. before!! loading!! the inferior!! timing is everything โฐ
  • --directory=directory, -d directory โ€” Add directory to the path to search for source files. ๐Ÿ—‚๏ธ
  • --nh โ€” Do not execute commands from ~/.config/gdb/gdbinit, ~/.gdbinit, ~/.config/gdb/gdbearlyinit, or ~/.gdbearlyinit. she said not today to all four of those ๐Ÿ™…โ€โ™€๏ธ
  • --nx, -n โ€” Do not execute commands from any .gdbinit or .gdbearlyinit initialization files. all of them. every single one. no cap ๐Ÿšซ
  • --quiet, --silent, -q โ€” "Quiet". Do not print the introductory and copyright messages. these messages are also suppressed in batch mode. she's being demure, she's being mindful ๐Ÿคซ
  • --batch โ€” Run in batch mode. Exit with status 0 after processing all the command files specified with -x (and .gdbinit, if not inhibited). Exit with nonzero status if an error occurs in executing the ROCGDB commands in the command files. ๐Ÿ“ฆ

batch mode may be useful for running ROCGDB as a filter, for example to download and run a program on another computer; in order to make this more useful, the message

Program exited normally.

(which is ordinarily issued whenever a program running under ROCGDB control terminates) is not issued when running in batch mode. she's quiet in batch mode, it's her era ๐Ÿ˜Œ

  • --batch-silent โ€” Run in batch mode, just like --batch, but totally silent. All ROCGDB output is suppressed (stderr is unaffected). this is much quieter than --silent and would be useless for an interactive session. like babe, do not try to have a conversation with this mode, it is not conversing with you ๐Ÿ’€

this is particularly useful when using targets that give Loading section messages, for example. ๐Ÿšš

note that targets that give their output via ROCGDB, as opposed to writing directly to stdout, will also be made silent. ๐ŸŒซ๏ธ

  • --args prog [arglist] โ€” Change interpretation of command line so that arguments following this option are passed as arguments to the inferior. so like, everything after --args belongs to the program, not to you. boundaries!! โœ‹

as an example, take the following command:

gdb ./a.out -q

it would start ROCGDB with -q, not printing the introductory message. on the other hand, using:

gdb --args ./a.out -q

starts ROCGDB with the introductory message, and passes the option to the inferior. same flags, completely different vibes, iykyk ๐Ÿฆ‹

  • --pid=pid โ€” Attach ROCGDB to an already running program, with the PID pid. ๐ŸŽฏ
  • --tui โ€” Open the terminal user interface. pretty UI hours ๐ŸŒธ
  • --readnow โ€” Read all symbols from the given symfile on the first access. gimme all of it, immediately, no waiting ๐Ÿ“
  • --readnever โ€” Do not read symbol files. literally never. not once. ๐Ÿ’€
  • --return-child-result โ€” ROCGDB's exit code will be the same as the child's exit code. good parenting, honestly ๐Ÿซถ
  • --configuration โ€” Print details about GDB configuration and then exit. ๐Ÿ‘€ (note: this one says GDB, and we're keeping it exactly as written, bestie โ€” you're welcome)
  • --version โ€” Print version information and then exit. ๐Ÿท๏ธ
  • --cd=directory โ€” Run ROCGDB using directory as its working directory, instead of the current directory. ๐Ÿ 
  • --data-directory=directory, -D โ€” Run ROCGDB using directory as its data directory. The data directory is where ROCGDB searches for its auxiliary files. ๐Ÿ“
  • --fullname, -f โ€” Emacs sets this option when it runs ROCGDB as a subprocess. It tells ROCGDB to output the full file name and line number in a standard, recognizable fashion each time a stack frame is displayed (which includes each time the program stops). This recognizable format looks like two \032 characters, followed by the file name, line number and character position separated by colons, and a newline. The Emacs-to-ROCGDB interface program uses the two \032 characters as a signal to display the source code for the frame. emacs girlies stay winning ๐Ÿงšโœจ
  • -b baudrate โ€” Set the line speed (baud rate or bits per second) of any serial interface used by ROCGDB for remote debugging. baudrate, she's retro, she's chic ๐Ÿ“ป
  • -l timeout โ€” Set timeout, in seconds, for remote debugging. โณ
  • --tty=device โ€” Run using device for your program's standard input and output. ๐Ÿ–ฅ๏ธ

๐ŸŒˆ ENVIRONMENT ๐ŸŒˆ

(nothing listed here in this manual โ€” the section exists, it's just living its minimalist truth. a quiet icon. an empty queen.) โœจ

๐ŸŽ€ SEE ALSO ๐ŸŽ€

the full documentation for ROCGDB is maintained as a Texinfo manual. if the info and gdb programs and ROCGDB's Texinfo documentation are properly installed at your site, the command

info gdb

should give you access to the complete manual. ๐Ÿ“–๐Ÿ’–

Using GDB: A Guide to the GNU Source-Level Debugger, Richard M. Stallman and Roland H. Pesch, July 1991. vintage but still eating ๐Ÿ“

Okay bestie, legal era ๐Ÿ’… โ€” but like, important legal era, so stay with me.

Copyright ยฉ 1988-2024 Free Software Foundation, Inc.

So here's the tea: you're literally allowed to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation. Iconic of them, honestly ๐Ÿซถ

But there are โœจconditionsโœจ (iykyk): the Invariant Sections are "Free Software" and "Free Software Needs Free Documentation", the Front-Cover Texts are "A GNU Manual," and the Back-Cover Texts are as in (a) down below ๐Ÿ‘‡

  • (a) the FSF's Back-Cover Text, verbatim, no cap: "You are free to copy and modify this GNU Manual. Buying copies from GNU Press supports the FSF in developing GNU and promoting software freedom."

Now we're getting into the AMD part, bestie โ€” buckle up ๐ŸŽ€

AMD ROCm software is made available by Advanced Micro Devices, Inc. under the open source license identified in the top-level directory for the library in the repository on @url{https://github.com/ROCm/,Github.com} โ€” and real quick, parenthetically: portions of AMD ROCm software are licensed under MITx11 and UIL/NCSA, and for more info on the license you should review the license.txt in the top-level directory for the library on @url{https://github.com/ROCm/,Github.com}. The additional terms and conditions below apply to your use of AMD ROCm technical documentation, periodt.

ยฉ2019-2024 Advanced Micro Devices, Inc. All rights reserved.

So likeโ€ฆ the info in this document is for informational purposes only and may contain technical inaccuracies, omissions, and typographical errors ๐Ÿ˜ญ โ€” it's giving "we're human". The info herein is subject to change and may be rendered inaccurate for many reasons, including but not limited to: product and roadmap changes, component and motherboard version changes, new model and/or product releases, product differences between differing manufacturers, software changes, BIOS flashes, firmware upgrades, or the like. And ngl, any computer system has risks of security vulnerabilities that cannot be completely prevented or mitigated. AMD assumes no obligation to update or otherwise correct or revise this information. However โ€” and this is the main character clause โ€” AMD reserves the right to revise this information and to make changes from time to time to the content hereof without obligation of AMD to notify any person of such revisions or changes ๐Ÿ’€

And now the shouty part, which I'm keeping exactly as loud as it was, because legal caps are sacred:

THIS INFORMATION IS PROVIDED "AS IS." AMD MAKES NO REPRESENTATIONS OR WARRANTIES WITH RESPECT TO THE CONTENTS HEREOF AND ASSUMES NO RESPONSIBILITY FOR ANY INACCURACIES, ERRORS, OR OMISSIONS THAT MAY APPEAR IN THIS INFORMATION. AMD SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR ANY PARTICULAR PURPOSE. IN NO EVENT WILL AMD BE LIABLE TO ANY PERSON FOR ANY RELIANCE, DIRECT, INDIRECT, SPECIAL, OR OTHER CONSEQUENTIAL DAMAGES ARISING FROM THE USE OF ANY INFORMATION CONTAINED HEREIN, EVEN IF AMD IS EXPRESSLY ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

๐ŸŒธ Trademarks (the โ„ข zone)

  • AMD, the AMD Arrow logo, AMD Instinctโ„ข, Radeonโ„ข, AMD ROCmโ„ข, and combinations thereof are trademarks of Advanced Micro Devices, Inc.
  • Linuxยฎ is the registered trademark of Linus Torvalds in the U.S. and other countries.
  • PCIeยฎ is a registered trademark of PCI-SIG Corporation.
  • Other product names used in this publication are for identification purposes only and may be trademarks of their respective companies.

Like, that's it, that's the whole legal vibe check ๐ŸŒˆ โ€” you read the fine print, I'm so proud of you fr fr ๐Ÿงš


And that's a wrap on the entire page, bestie!! ๐ŸŽ€โœจ This lil doc ships as gdb-16.3, dated 2026-05-31 โ€” go forth and debug your heart out ๐Ÿ’œ๐Ÿฆ‹๐Ÿ‘‘

๐Ÿ“ฆ where this page comes from