Online GDB Debugger: Debug C and C++ Code in Your Browser
OnlineGDB is a free, browser-based compiler and debugger built on gcc/g++ and GDB. You paste or write C or C++ code, click Debug, set breakpoints by clicking next to line numbers, and step through the program while watching local variables and the call stack, with nothing to install. It also compiles and runs dozens of other languages, but its step-by-step debugger is built for C and C++.
What OnlineGDB is
OnlineGDB (often searched as "online gdb" or "onlinegdb compiler") describes itself as an "online compiler and debugger for C/C++". Under the hood it compiles with gcc/g++ and debugs with GDB, the GNU debugger, and gives you a web UI on top: an editor, a console for program input and output, and debugger panels.
You can use it without an account. Signing in (Google, Facebook or GitHub) lets you save projects under My Projects and create permanent share links. The free site shows ads; OnlineGDB sells a premium upgrade that removes them.
Languages it supports
The language menu on onlinegdb.com currently lists: C, C++ (plus C++14, C++17, C++20, C++23 and C++26), C and C++ in TurboC mode, Java, Python 3, Kotlin, PHP, C# (Mono and .NET), OCaml, VB, HTML/JS/CSS, Ruby, Perl, Pascal, PascalABC.NET, COBOL, R, Fortran, Haskell, Assembly (GCC and NASM), Objective-C, SQLite, Dart, Smalltalk, Groovy, Tcl, C3, Lua, Zig, TypeScript, D, Ada, JavaScript (Rhino and Node), Prolog, Swift, Rust, Go and Bash.
Every one of those can be compiled and run. Debugging is a different matter. The debugger is GDB, so it is built for C and C++ (GDB can handle some other compiled languages too). The site itself says debug mode is not yet supported for Python. If you search "online gdb python" or "onlinegdb java", you can run that code on OnlineGDB, but for real step-through debugging in those languages a local IDE is the better choice (see alternatives below).
How to debug C or C++ in OnlineGDB, step by step
- Open onlinegdb.com and pick C or C++ (or a specific standard such as C++20) from the Language menu in the top-right corner.
- Write or paste your code. Here is a small program with a bug you can try:
#include <stdio.h>
int sum_to(int n) {
int total = 0;
for (int i = 1; i < n; i++) { /* bug: should be i <= n */
total += i;
}
return total;
}
int main(void) {
int n = 5;
printf("sum_to(%d) = %d\n", n, sum_to(n)); /* expect 15, prints 10 */
return 0;
}
- Set a breakpoint. Click the blank gutter to the left of a line number, for example the
total += i;line. A red dot marks the breakpoint. Per OnlineGDB's own debugger guide, execution will pause each time it reaches that line. - Click Debug in the toolbar (next to Run). The program compiles with debug info and starts under GDB. It stops at your first breakpoint.
- Step through the code with the debugger buttons:
- Continue: run until the next breakpoint.
- Step over: run the current line without going inside function calls.
- Step into: go inside the function called on the current line.
- Step out: finish the current function and stop in its caller.
- Pause and Start (restart) are also there.
- Watch your variables. While paused, the Local Variables panel shows each local and its value (here
total,iandn). The Call Stack panel shows which function called which, with file and line. In the example, you will see the loop exit wheniis 5 without adding it, which is the bug. - Use the extra panels when you need them. Display Expressions lets you add an expression (such as
total + iorarr[2]) that is re-evaluated at every stop. Breakpoints and Watchpoints lists everything you have set. Registers shows CPU registers, which is useful for the Assembly modes. - Type GDB commands directly if you prefer. The console at the bottom accepts standard GDB commands while debugging, for example:
break sum_to
run
next
step
print total
watch total
info locals
backtrace
continue
A watch total watchpoint stops the program every time total changes, which is often faster than stepping through a long loop. The GDB manual documents every command.
- Fix the bug (
i <= n), click Run, and confirm the output issum_to(5) = 15.
Input, files and sharing
- Standard input. By default the console is interactive: when your program calls
scanforstd::cin, type the value in the console. In debug mode the console also pauses at input points so you can type. You can switch Standard Input to Text and paste all input up front, which is handy for competitive-programming test cases. If a program waits for input you never give, it can end with a runtime error. - Command-line arguments. There is a field for them, read through
argcandargv. - Extra compiler flags. You can add flags such as
-Wall -Wextraor-O2for gcc/g++. - Multiple files. You can add, rename and delete files (for example
main.c,list.c,list.h) and download all files. - Sharing. Share gives you either a live public link that always shows your latest saved code, or a copy (snapshot) that can expire after 1 day, 1 week, 1 month, or never. Permanent links need a login.
Limits to know about
- Debugger language coverage. The step debugger is for C and C++. Python debugging is not supported, and other languages are run-only in practice.
- Execution limits. OnlineGDB does not publish exact time or memory limits. Infinite loops, unbounded recursion and very large data processing end with a runtime-exceeded error.
- Idle sessions stop. Run and debug consoles stop after inactivity, and a "Lost connection to server" message means you need to refresh the page.
- Your code runs on someone else's server. Do not paste proprietary code, secrets or API keys into it, and remember that public share links are public.
- No real project tooling. There is no CMake, no package manager and no way to install libraries. Anything beyond the standard library and a few files is better done locally.
OnlineGDB alternatives
| Tool | Best for | Step debugger | Cost |
|---|---|---|---|
| OnlineGDB | Quick C/C++ debugging in a browser, classwork, sharing snippets | Yes, GDB (C/C++) | Free with ads, premium removes ads |
| Compiler Explorer | Seeing the assembly a compiler produces, comparing compilers and flags | No (it can execute code, but it does not step through it) | Free, open source |
| Replit | Full projects in a cloud workspace, many languages, collaboration | Depends on language and setup | Free tier, paid plans |
| GitHub Codespaces | A full VS Code in the browser on a cloud Linux machine, with real gdb | Yes (VS Code debugger + gdb) | Free monthly hours on personal accounts |
| Local gdb + VS Code | Serious debugging, large projects, any library | Yes | Free |
Local gdb in VS Code (the step up)
When you outgrow OnlineGDB, the same GDB debugger runs locally with a graphical front end. On Linux (or WSL on Windows), Microsoft's C/C++ debugging guide boils down to:
- Install gcc/g++ and gdb, for example
sudo apt install build-essential gdbon Ubuntu. - Install the C/C++ extension (
ms-vscode.cpptools) in VS Code. - Open your
.cor.cppfile, click in the margin (or press F9) to set a breakpoint. - From the drop-down next to the play button choose Debug C/C++ File, then C/C++: g++ build and debug active file.
VS Code writes a launch.json for you. The important parts are:
{
"version": "0.2.0",
"configurations": [
{
"name": "C/C++: g++ build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"cwd": "${fileDirname}",
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb",
"preLaunchTask": "C/C++: g++ build active file"
}
]
}
You get the same breakpoints, stepping, variables and call stack as OnlineGDB, plus conditional breakpoints, memory views and no limits on project size. On macOS, the default toolchain is clang with LLDB rather than gdb, which the same extension also supports. More options are in DevHunt's list of IDEs and code editors.
FAQ
Is OnlineGDB free?
Yes. You can compile, run and debug without paying or signing up. The free site shows ads; a paid premium option removes them. An account (free) is needed to save projects and create permanent share links.
Can I debug Python on OnlineGDB?
You can run Python 3 code, but OnlineGDB states that debug mode for Python is not yet supported. For step-through Python debugging, use a local editor such as VS Code with the Python extension, or Python's built-in pdb.
What compiler does OnlineGDB use for C and C++?
It uses gcc for C and g++ for C++, with GDB as the debugger. You can pick the C++ standard (C++14 through C++26) from the language menu and add extra compiler flags.
Why does my program show a runtime error on OnlineGDB?
The usual causes are an infinite loop, unbounded recursion, processing too much data for the server's limits, or a program waiting on input you didn't provide. Check your loop conditions with a breakpoint, and supply input in the console or switch Standard Input to Text.
Is there an OnlineGDB download or desktop app?
No. OnlineGDB is a website only. If you want the same debugger offline, install gcc and gdb locally and use them from the terminal or through VS Code, as shown above.