From d90f22d262751360f1224bb359134e8635ce71e2 Mon Sep 17 00:00:00 2001 From: Menace Date: Mon, 26 Jan 2026 03:59:46 +0100 Subject: [PATCH 1/3] GDB basics - merging bot articles https://github.com/TCCPP/wiki/issues/69 --- bot-articles/gdb.md | 45 ------------------------------ wiki/cpp-tutorial/debugging-gdb.md | 26 +++++++++++------ 2 files changed, 17 insertions(+), 54 deletions(-) delete mode 100644 bot-articles/gdb.md diff --git a/bot-articles/gdb.md b/bot-articles/gdb.md deleted file mode 100644 index 402bb39..0000000 --- a/bot-articles/gdb.md +++ /dev/null @@ -1,45 +0,0 @@ -# Debugging with GDB -Compile your program with `-g` flag and run your program using gdb: `gdb yourprogname`. -From there, you can debug using GDB commands. Use `help` to list commands and their options. - - -## Break -Set a breakpoint to pause execution at a certain line or a function: -- `break main` -- `b 42` - - -## Run -Run your program inside gdb after setting breakpoints: -- `run` -- `r` - - -## Print -Print value of expression: -- `print my_var` -- `p (char) ch` - - -## Walk & Step -Execute next line of code, where `next` stays in the function and `step` enters functions: -- `n` -- `s` - - -## Continue -Continue execution until (Nth) next breakpoint -- `continue` -- `c 3` - - -## Backtrace -Print backtrace of all or N stack frames: -- `backtrace -full` -- `bt 3` - -## Learn More: -- [TCCPPCon#1: Debugging with GDB](https://www.youtube.com/watch?v=bSEW0BvMiGc) -- [How to Debug Using GDB](https://cs.baylor.edu/~donahoo/tools/gdb/tutorial.html) -- [GDB Step By Step Instruction](https://www.geeksforgeeks.org/gdb-step-by-step-introduction/) -- [GDB Cheatsheet](https://gist.githubusercontent.com/rkubik/b96c23bd8ed58333de37f2b8cd052c30/raw/ead6be96ed4dd4a9fc0bd318adcfa9d3a3afb109/cheat_sheet.txt) diff --git a/wiki/cpp-tutorial/debugging-gdb.md b/wiki/cpp-tutorial/debugging-gdb.md index 240951b..a54fd65 100644 --- a/wiki/cpp-tutorial/debugging-gdb.md +++ b/wiki/cpp-tutorial/debugging-gdb.md @@ -2,17 +2,24 @@ bot_article: | # GNU Debugger (GDB) - Compile with debug symbols: `g++ main.cpp -o prog -Og -g` + Compile with debug symbols: `g++ main.cpp -o program -Og -g` **Quick reference:** - - `gdb prog` - Launch debugger - - `break 10` / `b main` - Set breakpoint + - `gdb program` - Launch debugger (`--tui` for terminal user interface mode) + - `break 10` / `b main` - Set a breakpoint at a certain line / function + - `info b` - List all active breakpoints - `run` / `start` - Start execution - - `next` / `step` - Step over / into + - `next` - Step over (next stays in the function) + - `step` - Step into (step goes inside calls) - `print var` - Inspect variable - `backtrace` - Show call stack - `continue` - Resume to next breakpoint - `quit` - Exit GDB + + ## Learn More: + - [See the official documentation](https://www.sourceware.org/gdb/documentation/) + - [TCCPPCon#1: Debugging with GDB](https://www.youtube.com/watch?v=bSEW0BvMiGc) + - [How to Debug Using GDB](https://cs.baylor.edu/~donahoo/tools/gdb/tutorial.html) --- # GNU Debugger @@ -21,14 +28,15 @@ The GNU Debugger (GDB) is one of the most widely used debuggers today, with nume GDB is freely available under the GPLv3 license. - [See the official documentation](https://www.sourceware.org/gdb/documentation/) -- [See a TCCPP video tutorial](https://www.youtube.com/watch?v=bSEW0BvMiGc) +- [See a TCCPPCon#1: Debugging with GDB](https://www.youtube.com/watch?v=bSEW0BvMiGc) +- [How to Debug Using GDB](https://cs.baylor.edu/~donahoo/tools/gdb/tutorial.html) ## GDB Quickstart ### Create an executable with debug symbols ```bash -g++ main.cpp -o executable.file -Og -g +g++ main.cpp -o program -Og -g ``` - `-O0` - enables no optimizations (maybe preferred) @@ -50,15 +58,15 @@ GDB is self documented. ### Launch a debugger with a file attached ```bash -gdb executable.file +gdb program ``` - GNU debugger `gdb` -- Executable `executable.file` you want to inspect +- Executable `program` you want to inspect ### Layouts `layout, lay` -- Launch TUI directly `gdb executable.file --tui` (equivalent to `layout src`) +- Launch TUI directly `gdb program --tui` (equivalent to `layout src`) - Layout source `layout src` - displays source code (if not available recompile with `-g` flag enabled) - Layout assembly `layout asm` - displays assembly - Layout split `layout split` - displays both assembly and source layout From 2fcee423bb4248b765758989e93fb98aaeb2c13d Mon Sep 17 00:00:00 2001 From: Menace <155697298+ProfessionalMenace@users.noreply.github.com> Date: Mon, 26 Jan 2026 09:44:04 +0100 Subject: [PATCH 2/3] whitespace fix Co-authored-by: Jeremy Rifkin <51220084+jeremy-rifkin@users.noreply.github.com> --- wiki/cpp-tutorial/debugging-gdb.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wiki/cpp-tutorial/debugging-gdb.md b/wiki/cpp-tutorial/debugging-gdb.md index a54fd65..76b17e9 100644 --- a/wiki/cpp-tutorial/debugging-gdb.md +++ b/wiki/cpp-tutorial/debugging-gdb.md @@ -10,7 +10,7 @@ bot_article: | - `info b` - List all active breakpoints - `run` / `start` - Start execution - `next` - Step over (next stays in the function) - - `step` - Step into (step goes inside calls) + - `step` - Step into (step goes inside calls) - `print var` - Inspect variable - `backtrace` - Show call stack - `continue` - Resume to next breakpoint From 8da801eb4478d79eafa9ec27ab9551f45344901c Mon Sep 17 00:00:00 2001 From: Menace Date: Mon, 26 Jan 2026 09:46:22 +0100 Subject: [PATCH 3/3] removed see also articles from bot command --- wiki/cpp-tutorial/debugging-gdb.md | 5 ----- 1 file changed, 5 deletions(-) diff --git a/wiki/cpp-tutorial/debugging-gdb.md b/wiki/cpp-tutorial/debugging-gdb.md index 76b17e9..6b28ad3 100644 --- a/wiki/cpp-tutorial/debugging-gdb.md +++ b/wiki/cpp-tutorial/debugging-gdb.md @@ -15,11 +15,6 @@ bot_article: | - `backtrace` - Show call stack - `continue` - Resume to next breakpoint - `quit` - Exit GDB - - ## Learn More: - - [See the official documentation](https://www.sourceware.org/gdb/documentation/) - - [TCCPPCon#1: Debugging with GDB](https://www.youtube.com/watch?v=bSEW0BvMiGc) - - [How to Debug Using GDB](https://cs.baylor.edu/~donahoo/tools/gdb/tutorial.html) --- # GNU Debugger