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
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