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..6b28ad3 100644 --- a/wiki/cpp-tutorial/debugging-gdb.md +++ b/wiki/cpp-tutorial/debugging-gdb.md @@ -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 @@ -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) @@ -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