Step by step
- Paste your program Open the IDE on the home page, choose C or C++ and paste your code. If it reads input with scanf or cin, type that input in the Input box.
- Set breakpoints Click the line number next to the first line you want to inspect. A red dot appears. You can also type break 12 or break main in the GDB console.
- Start the debugger Press Debug. Online GDB Pro compiles the program with Clang, runs it and stops at the first breakpoint. The current line is highlighted.
- Move through the code Use Next to run one line, Step to enter a function call, Finish to leave the current function and Continue to jump to the next breakpoint. The same commands work in the console as n, s, finish and c.
- Inspect the state The Variables panel lists the locals of the selected frame; values that just changed are highlighted. The Call stack panel shows how you got here; click a frame to see its variables. In the console, print x, print p.x or print v[2] shows one value.
- Go back when you overshoot Press Back or type reverse-next to return to the previous line, reverse-step to step back into a call and reverse-continue to go back to the previous breakpoint.
Finding common bugs
- Wrong result: put a breakpoint inside the loop and watch the variable with watch total; the debugger stops every time it changes.
- Crash (segmentation fault): debug the program; it stops at the line that read or wrote invalid memory, with the call stack that led there.
- Infinite loop: the debugger stops at its step limit. Step back a few lines to see which condition never becomes false.
- Recursion: Step into the function and look at the Call stack panel; each call is its own frame with its own n.
How it differs from GDB in a terminal
Online GDB Pro is not the GNU GDB program: it is a browser debugger that follows GDB’s commands. It records the program as it runs and then lets you move through that recording, which is why stepping backwards is always available. The run is recorded up to 20,000 line steps (300,000 with VIP), and input comes from the Input box rather than being typed while the program waits.