๐ŸŒ
OnlineGDB
onlinegdb.com
GDB online Debugger | Compiler - Code, Compile, Run, Debug online C, C++
Online GDB is online compiler and debugger for C/C++. You can compile, run and debug code with gdb online. Using gcc/g++ as compiler and gdb as debugger. Currently C and C++ languages are supported.
source-level debugger
GNU_gdb_12.1_screenshot.png
The GNU Debugger (GDB) is a portable debugger that runs on many Unix-like systems and works for many programming languages, including Ada, Assembly, C, C++, D, Fortran, Haskell, Go, Objective-C, OpenCL C, โ€ฆ Wikipedia
Factsheet
Developer GNU Project
Release 1986; 40 years ago (1986)
Stable release 17.2
/ 10 May 2026
Factsheet
Developer GNU Project
Release 1986; 40 years ago (1986)
Stable release 17.2
/ 10 May 2026
๐ŸŒ
Wikipedia
en.wikipedia.org โ€บ wiki โ€บ GNU_Debugger
GNU Debugger - Wikipedia
3 weeks ago - The GNU Debugger (GDB) is a portable debugger that runs on many Unix-like systems and works for many programming languages, including Ada, Assembly, C, C++, D, Fortran, Haskell, Go, Objective-C, OpenCL C, Modula-2, Pascal, Rust, and partially others.
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
81
88
February 9, 2022
c - How to debug using gdb? - Stack Overflow
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 ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
debugging - How do you use gdb to debug your code? - Stack Overflow
Use ddd, a visual front-end for gdb. It lets you do things easily with a few mouse clicks and visualise how the code works, plus in the debugger console you have an intercative gdb. More on stackoverflow.com
๐ŸŒ stackoverflow.com
Using gdb debugger in an efficient way
Dear all, Iโ€™m trying to use gdb debugger to debug an error related to Segmentation fault (core dumped) Unfortunately, this message happens frequently for many different types of errors, also completely not correlated (bad pointer definition, out of memory, etc.). With gdb debugger, I get ... More on geant4-forum.web.cern.ch
๐ŸŒ geant4-forum.web.cern.ch
0
1
November 24, 2021
๐ŸŒ
GNU Project
sourceware.org โ€บ gdb
GDB: The GNU Project Debugger
May 10, 2026 - 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.
๐ŸŒ
Caltech
users.cms.caltech.edu โ€บ ~mvanier โ€บ CS11_C โ€บ misc โ€บ gdb.html
CS 11 C track: Using gdb for debugging
Itโ€™s a good habit to always use these options.) The -g option puts debugging information into the executable. Most importantly, it puts the text of the source code file into the executable so you can examine it as the program executes (weโ€™ll see how below). Type gdb myprog (for the example ...
๐ŸŒ
Florida State University
cs.fsu.edu โ€บ ~myers โ€บ cop3330 โ€บ debug โ€บ debugger.html
How to use the GDB debugger - basics
Most installations of the GNU c++ compiler (g++) also include the GNU debugger, GDB. This page is meant to be a guide to doing some basic debugging with GDB.
๐ŸŒ
GNU Project
sourceware.org โ€บ gdb โ€บ current โ€บ onlinedocs โ€บ gdb
Debugging with GDB
Fred was a long-standing contributor to GDB and to Free software in general. We will miss him. ... The purpose of a debugger such as GDB is to allow you to see what is going on โ€œinsideโ€ another program while it executesโ€”or what another program was doing at the moment it crashed.
Find elsewhere
๐ŸŒ
Red Hat
docs.redhat.com โ€บ en โ€บ documentation โ€บ red_hat_developer_toolset โ€บ 9 โ€บ html โ€บ user_guide โ€บ chap-gdb
Chapter 8. GNU Debugger (GDB) | User Guide | Red Hat Developer Toolset | 9 | Red Hat Documentation
It allows you to inspect memory within the code being debugged, control the execution state of the code, detect the execution of particular sections of code, and much more. Red Hat Developer Toolset is distributed with GDB 8.3.
๐ŸŒ
Medium
medium.com โ€บ havingfun โ€บ debugging-c-code-with-gdb-90adb2f3da96
Debugging C code With GDB | Having Fun | Having Fun
May 15, 2022 - (gdb) run Thread 2 hit Breakpoint 1, main () at source.c:4 4 int i = 0; It does! Nice. ... As none of them are initialized yet, weโ€™re just seeing garbage. Letโ€™s continue the execution of the program by going to the next line: ... โ€œ5โ€ at the start of the output signals what line of the code the debugger is in.
๐ŸŒ
BetterExplained
betterexplained.com โ€บ articles โ€บ debugging-with-gdb
Debugging with GDB โ€“ BetterExplained
Compiles myprogram.c with the debugging option (-g). You still get an a.out, but it contains debugging information that lets you use variables and function names inside GDB, rather than raw memory locations (not fun).
Top answer
1 of 5
34

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
Top answer
1 of 7
3

Some hints:

  • use a graphical frontend (kdbg is quite good, ddd is at least better than command-line gdb, kdevelop has a nice gdb frontend but has some bgs, nemiver looks quite nice as well but is still in the works)
  • make sure to have debug symbols and source code for all important parts (your own code and also some system libs)
    • on RedHat, you can install the -debuginfo packages to make both symbols and source code magically appear in the debugger - really cool because you can looks into libc function calls etc.
    • on Debian/Ubuntu, you can install the -dbg packages to get symbols; installing appropriate source files for system packages seems to be difficult, though
  • I tend to add assert() and abort() calls in places that should not be reached, or in places that I want to study (some kind of heavy-weight breakpoint)
  • ideally the assert() or abort() calls should be wrapped in some method or macro that only enables them in Debug releases, or even better that only enables them if a certain env var is set
  • install a signal handler for SIGSEGV and SIGABRT; personally I check if a certain env var is set before installing the handlers; and in the handler I execute a hardcoded external command which usually lives somewhere in ~/.local/bin/; that command might then start kdbg and attach it to the crashing app. Voila, debugger pops up the moment your app does something bad.
  • If you use unit tests, you could similarly attach a debugger whenever a test case fails, to inspect the app then.
2 of 7
2

In general you find something that isn't how it should be, and work backwards until you understand why.

The most obvious is the most useful: Setting a breakpoint on a function or line number and walking through the code line by line.

Another handy tip is to have show functions for all your structures/objects even if they are never used in your program, because you can run these functions from within gdb:

gdb> p show_my_struct(struct)

My custom display of Foo:
   ...

Watchpoints can be really handy too, but may slow down your program a lot. These break the flow when the value of a variable or address changes.:

gdb> watch foo
Watchpoint4: foo
gdb>
๐ŸŒ
GNU
gnu.org โ€บ software โ€บ gdb โ€บ gdb.html
GDB: The GNU Project Debugger
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.
๐ŸŒ
Visual Studio Marketplace
marketplace.visualstudio.com โ€บ items
GDB Debugger - Beyond - Visual Studio Marketplace
October 2, 2025 - Extension for Visual Studio Code - Debugger with gdb for c,c++,freepascal,fortran and more.
๐ŸŒ
Geant4 Forum
geant4-forum.web.cern.ch โ€บ recording, visualizing and persisting data
Using gdb debugger in an efficient way - Recording, Visualizing and Persisting Data - Geant4 Forum
November 24, 2021 - Dear all, Iโ€™m trying to use gdb debugger to debug an error related to Segmentation fault (core dumped) Unfortunately, this message happens frequently for many different types of errors, also completely not correlated (bad pointer definition, out of memory, etc.). With gdb debugger, I get ...
๐ŸŒ
Baylor
cs.baylor.edu โ€บ ~donahoo โ€บ tools โ€บ gdb โ€บ tutorial.html
How to Debug Using GDB
% g++ -g broken.cpp -o broken % ./broken Whatever the input, the output will be inf. The -g option is important because it enables meaningful GDB debugging.
๐ŸŒ
Kali Linux
kali.org โ€บ tools โ€บ gdb
gdb | Kali Linux Tools
May 25, 2026 - GNU Debugger GDB is a source-level debugger, capable of breaking programs at any specific line, displaying variable values, and determining where errors occurred. Currently, gdb supports C, C++, D, Objective-C, Fortran, Java, OpenCL C, Pascal, ...
๐ŸŒ
Gdbgui
gdbgui.com
gdbgui
gdbgui is a browser-based frontend to gdb, the gnu debugger.