I use it in the terminal, but unless I'm just getting a backtrace from a core dump (most common use case), I usually press Ctrl-X A to enable eXtra-Awesome mode (I don't think it's actually called eXtra-Awesome mode, but that's how I remember the keystroke). I very rarely am stepping through code with gdb though, I tend to rely on printf's or just thinking really hard more often. Edit: looked it up, it's apparently called TUI mode Answer from smcameron on reddit.com
🌐
Gdbtutorial
gdbtutorial.com › tutorial › how-use-gdb
How to use GDB? | GDB Tutorial
Type "apropos word" to search for commands related to "word"... Reading symbols from a.out...done. (gdb) As you can see above, GDB read debug symbols from a.out and GDB prompt appeared where we can execute GDB commands. Step 3: Use GDB commands to analyze and debug program
🌐
iO Flood
ioflood.com › blog › gdb-linux-command
Linux gdb: GNU Debugger Usage Guide (with Examples)
December 12, 2023 - Let’s get started and master the GDB Linux command! To use GDB in Linux, you first compile your code with the -g flag, then run it with gdb.
Discussions

How many of you actually use GDB from the terminal?
I use it in the terminal, but unless I'm just getting a backtrace from a core dump (most common use case), I usually press Ctrl-X A to enable eXtra-Awesome mode (I don't think it's actually called eXtra-Awesome mode, but that's how I remember the keystroke). I very rarely am stepping through code with gdb though, I tend to rely on printf's or just thinking really hard more often. Edit: looked it up, it's apparently called TUI mode More on reddit.com
🌐 r/C_Programming
79
87
February 9, 2022
c - How to debug using gdb? - Stack Overflow
I am trying to add a breakpoint in my program using b {line number} but I am always getting an error that says: No symbol table is loaded. Use the "file" command. What should I do? More on stackoverflow.com
🌐 stackoverflow.com
debugging - How to step-into, step-over and step-out with GDB? - Unix & Linux Stack Exchange
I typed help while I was in the GDB but didn't find anything about step-into, step-over and step-out. I put a breakpoint in an Assembly program in _start (break _start). Afterwards I typed next and... More on unix.stackexchange.com
🌐 unix.stackexchange.com
July 24, 2016
Seer – a GUI front end to GDB for Linux
FINALLY A GUI DEBUGGER AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA *explodes in excitement* Yes this is valid because it seems CLI is king, but certainly not the king of usability. A GUI is VERY MUCH APPRECIATED. Yaaaaaaaaaaaaaaaaaaaaaaaaaaaaaay! More on reddit.com
🌐 r/linux
41
317
October 3, 2022
🌐
GeeksforGeeks
geeksforgeeks.org › linux-unix › gdb-command-in-linux-with-examples
gdb command in Linux with examples - GeeksforGeeks
September 2, 2024 - gdb console can be opened using the command gdb command. To debug the executables from the console, file [executable filename] command is used.
🌐
Baylor
cs.baylor.edu › ~donahoo › tools › gdb › tutorial.html
How to Debug Using GDB
The distinction doesn't matter here since there are no functions. You may use the shortest, unambigious spelling of a GDB command to save some typing. Here we use n and s instead of next and step, respectively. If the command is simply a repeat of the previous command, you can just hit return, ...
🌐
University of Michigan
web.eecs.umich.edu › ~sugih › pointers › summary.html
GDB Tutorial
To start gdb, just type gdb at the unix prompt. Gdb will give you a prompt that looks like this: (gdb). From that prompt you can run your program, look at variables, etc., using the commands listed below (and others not listed). Or, you can start gdb and give it the name of the program executable ...
🌐
University of Toronto
cs.toronto.edu › ~krueger › csc209h › tut › gdb_tutorial.html
gdb tutorial
This GDB was configured as "i386-redhat-linux-gnu"...Using host libthread_db library "/lib/tls/libthread_db.so.1". (gdb) Good! We have successfully loaded gdb with crash. Let's run the program with command "run" to see what kind of information we will get. ... The "run" command starts the program. If we do not set up any "breakpoints" (we'll see how to use this command later) the program will run until it terminates or core dumps.
Find elsewhere
Top answer
1 of 5
33

Here is a quick start tutorial for gdb:

/* test.c  */
/* Sample program to debug.  */
#include <stdio.h>
#include <stdlib.h>

int
main (int argc, char **argv) 
{
  if (argc != 3)
    return 1;
  int a = atoi (argv[1]);
  int b = atoi (argv[2]);
  int c = a + b;
  printf ("%d\n", c);
  return 0;
}

Compile with the -g3 option. g3 includes extra information, such as all the macro definitions present in the program.

gcc -g3 -o test test.c

Load the executable, which now contain the debugging symbols, into gdb:

gdb --annotate=3 test.exe 

Now you should find yourself at the gdb prompt. There you can issue commands to gdb. Say you like to place a breakpoint at line 11 and step through the execution, printing the values of the local variables - the following commands sequences will help you do this:

(gdb) break test.c:11
Breakpoint 1 at 0x401329: file test.c, line 11.
(gdb) set args 10 20
(gdb) run
Starting program: c:\Documents and Settings\VMathew\Desktop/test.exe 10 20
[New thread 3824.0x8e8]

Breakpoint 1, main (argc=3, argv=0x3d5a90) at test.c:11
(gdb) n
(gdb) print a
$1 = 10
(gdb) n
(gdb) print b
$2 = 20
(gdb) n
(gdb) print c
$3 = 30
(gdb) c
Continuing.
30

Program exited normally.
(gdb) 

In short, the following commands are all you need to get started using gdb:

break file:lineno - sets a breakpoint in the file at lineno.
set args - sets the command line arguments.
run - executes the debugged program with the given command line arguments.
next (n) and step (s) - step program and step program until it 
                        reaches a different source line, respectively. 
print - prints a local variable
bt -  print backtrace of all stack frames
c - continue execution.

Type help at the (gdb) prompt to get a list and description of all valid commands.

2 of 5
7

Start gdb with the executable as a parameter, so that it knows which program you want to debug:

gdb ./myprogram

Then you should be able to set breakpoints. For example:

b myfile.cpp:25
b some_function
🌐
UCSD
cseweb.ucsd.edu › classes › fa09 › cse141 › tutorial_gcc_gdb.html
Tutorial of gcc and gdb
Continue with the "garbage" example, if we want to debug the program "garbage", we can simply start gdb by: gdb ./garbage Then, you will see the gdb environment similar as following: GNU gdb Red Hat Linux (6.3.0.0-1.162.el4rh) Copyright 2004 Free Software Foundation, Inc.
🌐
Timesys LinuxLink
linuxlink.timesys.com › docs › wiki › engineering › HOWTO_Use_GDBServer
How to Use GDB and GDBServer | Timesys LinuxLink
(gdb) target remote 10.5.5.30:10000 Remote debugging using 10.5.5.30:10000 [New Thread 335] 0x400007c0 in _start () from ~/timesys/omap3530zoom/toolchain/lib/ld-linux.so.3 (gdb)
🌐
GeeksforGeeks
geeksforgeeks.org › c language › gdb-step-by-step-introduction
GDB (Step by Step Introduction) - GeeksforGeeks
January 10, 2025 - In this article we have discussed GDB (GNU Debugger) which is a powerful tool in Linux used for debugging C programs. We have discussed some of the following steps so that we can compile your code with debugging information, run GDB, set breakpoint, examine variables, and analyze program behavior.
🌐
Brendan Gregg
brendangregg.com › blog › 2016-08-09 › gdb-example-ncurses.html
gdb Debugging Full Example (Tutorial): ncurses
August 9, 2016 - This GDB was configured as "x86\_64-linux-gnu". Type "show configuration" for configuration details. For bug reporting instructions, please see: . Find the GDB manual and other documentation resources online at: . For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from /usr/bin/python...(no debugging symbols found)...done. Now to set the breakpoint using b (short for break): (gdb) b *doupdate + 289 No symbol table is loaded. Use the "file" command.
🌐
Linux Man Pages
man7.org › linux › man-pages › man1 › gdb.1.html
gdb(1) - Linux manual page
You can run "gdb" with no arguments or options; but the most usual way to start GDB 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 ...
🌐
Red Hat
docs.redhat.com › en › documentation › red_hat_developer_toolset › 12 › html › user_guide › chap-gdb
Chapter 8. GNU Debugger (GDB) | User Guide | Red Hat Developer Toolset | 12 | Red Hat Documentation
This starts the gdb debugger in interactive mode and displays the default prompt, (gdb). To quit the debugging session and return to the shell prompt, run the following command at any time: ... Copy to Clipboard Copied! ... Note that you can execute any command using the scl utility, causing it to be run with the Red Hat Developer Toolset binaries used in preference to the Red Hat Enterprise Linux system equivalent.
🌐
Kali Linux
kali.org › tools › gdb
gdb | Kali Linux Tools
3 weeks ago - --configuration Print details about GDB configuration and then exit. --help Print this message and then exit. --version Print version information and then exit. Remote debugging options: -b BAUDRATE Set serial port baud rate used for remote debugging. -l TIMEOUT Set timeout in seconds for remote debugging. Other options: --cd=DIR Change current directory to ...
🌐
Sergioprado
sergioprado.blog › home › debugging the linux kernel with gdb
Debugging the Linux kernel with GDB - sergioprado.blog
January 17, 2024 - Connect to the kernel debugger using a GDB client in the host. Let’s start by enabling KGDB support in the Linux kernel. To use KGDB, it is necessary to build the kernel with a few configuration options enabled:
🌐
Medium
medium.com › holberton-school › reverse-engineering-using-linux-gdb-a99611ab2d32
Reverse-engineering: Using Linux GDB | by Rick Harris
May 20, 2016 - GDB, the GNU Project debugger, allows you to see what is going on `inside’ another program while it executes — or what another program was doing at the moment it crashed. When reverse engineering a program, the tool is used to review the compiled Assembly code in either the AT&T or Intel flavors to see step-by-step what is happening.
🌐
GNU Project
sourceware.org › gdb › current › onlinedocs › gdb.html › Starting.html
Starting (Debugging with GDB)
If a shell is available on your target, the shell is used to pass the arguments, so that you may use normal conventions (such as wildcard expansion or variable substitution) in describing the arguments. In Unix systems, you can control which shell is used with the SHELL environment variable. If you do not define SHELL, GDB uses the default shell (/bin/sh).
🌐
Yolinux
yolinux.com › TUTORIALS › GDB-Commands.html
Linux Tutorial - GNU GDB Debugger Command Cheat Sheet
Sl Jun07 1:18 /opt/bin/myapp [prompt]$ gdb /opt/bin/myapp 2812 OR [prompt]$ gdb /opt/bin/myapp --pid=2812 · Command line options: (version 6. Older versions use a single "-") ... Compile with the "-g" option (for most GNU and Intel compilers) which generates added information in the object code so the debugger can match a line of source code with the step of execution. Do not use compiler optimization directive such as "-O" or "-O2" which rearrange computing operations to gain speed as this reordering will not match the order of execution in the source code and it may be impossible to follow.