Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions bot-articles/beginner/debugger.md

This file was deleted.

45 changes: 0 additions & 45 deletions bot-articles/gdb.md

This file was deleted.

21 changes: 12 additions & 9 deletions wiki/cpp-tutorial/debugging-gdb.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
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
Expand All @@ -21,14 +23,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)
Expand All @@ -50,15 +53,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
Expand Down
7 changes: 6 additions & 1 deletion wiki/cpp-tutorial/debugging.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
alias: debugging
bot_article: |
# Debugging Your Program

Expand All @@ -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
Expand Down