Online GDB Compiler
Compile and run C and C++ code in your browser.
What Is an Online GDB Compiler?
GDB, the GNU Debugger, is the standard debugger for C and C++ programs on Linux. People often search for an online GDB compiler when they want to test C or C++ code without installing a toolchain.
This tool compiles and runs your code with GCC in a sandbox, and shows the output, compiler errors and any crash signal. It doesn't include an interactive GDB session, so you can't set breakpoints or step through code here. For that, install GDB on your own computer and use the commands listed in this article.
How to Use It
- The editor opens with a C sample. Use the language menu to switch to C++ or another language.
- Write or paste your program.
- If your program reads input, add it to the Standard Input panel before you run it. The program can't stop and wait for you to type.
- Select Run code, or press Ctrl+Enter (Cmd+Enter on a Mac).
Reading the Result
| Result | What it means | What to do |
|---|---|---|
| Compile error | GCC couldn't build the program | Start with the first error, since later ones often follow from it |
| Runtime Error (SIGSEGV) | The program accessed memory it shouldn't, often through a null or invalid pointer or by going past the end of an array | Check pointers and array bounds near the last output you see |
| Runtime Error (SIGFPE) | An arithmetic error, usually an integer divided by zero | Check divisors before dividing |
| Runtime Error (SIGABRT) | The program stopped itself, often through a failed assert, an uncaught C++ exception or corrupted memory | Check assertions, exceptions and free or delete calls |
| Runtime Error (NZEC) | main returned a value other than zero | Check your return and exit values |
| Time limit exceeded | The program ran past the time limit, usually in an endless loop | Check loop conditions, including loops that keep reading after the input runs out |
Debugging Without GDB
Without breakpoints, print statements are the quickest way to find where a program goes wrong. Output is often held in a buffer and can be lost in a crash, so write it out straight away:
#include <stdio.h>
int main(void) {
/* Write all output immediately, so a crash can't discard it */
setvbuf(stdout, NULL, _IONBF, 0);
printf("Before the suspect line\n");
/* ... */
printf("After the suspect line\n");
return 0;
}The last message you see shows that the problem comes after that line. Move the messages closer together until you find it.
Debugging With GDB on Your Computer
To use GDB itself, compile with debug information and without optimization, then start the program in GDB:
gcc -g -O0 main.c -o main
gdb ./mainFor C++, use g++ in place of gcc. These commands cover most debugging sessions:
| Command | What it does |
|---|---|
break main or break main.c:12 | Stop at a function or line |
run or run < input.txt | Start the program, with input from a file if you need it |
next | Run the next line without entering function calls |
step | Run the next line and enter any function it calls |
continue | Run until the next breakpoint |
print total | Show the value of a variable or expression |
watch total | Stop whenever a variable changes |
backtrace | Show the chain of function calls, which is the first thing to check after a crash |
info locals | Show the local variables in the current function |
quit | Exit GDB |
To find memory errors, also try compiling with -fsanitize=address. The program then reports invalid memory access with the location of the problem.
Limits
| Limit | Value |
|---|---|
| C and C++ compiler | GCC 9.2.0 |
| Source code size | 100,000 characters |
| Standard input size | 10,000 characters |
| CPU time per run | 5 seconds |
| Wall-clock time per run | 10 seconds |
| Network access | Disabled |
Programs run from a single file, so you can't add your own headers or libraries.
For the full list of languages, see the Online Compiler. It uses the same engine and opens on Python.
Building your own app? Try the Geekflare API.
One API key for scraping, search, screenshots, DNS, PDF, and more.
curl -X POST https://api.geekflare.com/webscraping \
-H "x-api-key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"url":"https://example.com"}'