From d90f22d262751360f1224bb359134e8635ce71e2 Mon Sep 17 00:00:00 2001 From: Menace Date: Mon, 26 Jan 2026 03:59:46 +0100 Subject: [PATCH 1/4] 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/4] 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/4] 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 From 36ef6b90fe551a89ac26d15452873d5aaa9d43fb Mon Sep 17 00:00:00 2001 From: Menace Date: Mon, 26 Jan 2026 19:19:52 +0100 Subject: [PATCH 4/4] Using a debugger - merging bot articles --- bot-articles/beginner/debugger.md | 16 ---------------- wiki/cpp-tutorial/debugging.md | 7 ++++++- 2 files changed, 6 insertions(+), 17 deletions(-) delete mode 100644 bot-articles/beginner/debugger.md diff --git a/bot-articles/beginner/debugger.md b/bot-articles/beginner/debugger.md deleted file mode 100644 index deffa41..0000000 --- a/bot-articles/beginner/debugger.md +++ /dev/null @@ -1,16 +0,0 @@ - - - -# Debugger - -Have you tried stepping through your code line by line in a debugger? - -If you don't know how to use a debugger or don't have one set up, we *highly* recommend taking the time to do so.
-Debuggers are immensely helpful tools for figuring out where problems emerge in code and especially when you're first -learning it can help you build intuition and understanding for reasoning through code. - -Resources: -- [Getting started with debugging in Visual Studio]() -- [Getting started with debugging in vscode on windows]() -- [Getting started with debugging in vscode on linux]() -- If your IDE isn't listed here, you can find a guide for your IDE online diff --git a/wiki/cpp-tutorial/debugging.md b/wiki/cpp-tutorial/debugging.md index 81b28b8..7ac3b14 100644 --- a/wiki/cpp-tutorial/debugging.md +++ b/wiki/cpp-tutorial/debugging.md @@ -1,4 +1,5 @@ --- +alias: debugging bot_article: | # Debugging Your Program @@ -10,7 +11,11 @@ bot_article: | - **Static analysis** and unit testing - **Interactive debugging** with GDB, LLDB, or Visual Studio - A debugger lets you pause execution, inspect variables, examine the call stack, and step through code line by line. + ## Have you tried stepping through your code line by line in a debugger? + + If you don't know how to use a debugger or don't have one set up, we *highly* recommend taking the time to do so. + Debuggers are immensely helpful tools for figuring out where problems emerge in code and especially when you're first + learning it can help you build intuition and understanding for reasoning through code. Debuggers let you pause execution, inspect variables, examine the call stack, and step through code line by line. --- # Debugging Your Program