2025-03-14 21:59:59 -06:00
|
|
|
# gdb
|
|
|
|
|
|
|
|
|
|
> The GNU Debugger.
|
2025-12-16 10:20:31 -07:00
|
|
|
> More information: <https://sourceware.org/gdb/current/onlinedocs/gdb#Invocation>.
|
2025-03-14 21:59:59 -06:00
|
|
|
|
|
|
|
|
- Debug an executable:
|
|
|
|
|
|
2025-12-16 10:20:31 -07:00
|
|
|
`gdb {{path/to/executable}}`
|
2025-03-14 21:59:59 -06:00
|
|
|
|
2025-12-16 10:20:31 -07:00
|
|
|
- Attach a process to `gdb`:
|
2025-03-14 21:59:59 -06:00
|
|
|
|
2025-03-19 19:23:44 -06:00
|
|
|
`gdb {{[-p|--pid]}} {{procID}}`
|
2025-03-14 21:59:59 -06:00
|
|
|
|
|
|
|
|
- Debug with a core file:
|
|
|
|
|
|
2025-12-16 10:20:31 -07:00
|
|
|
`gdb {{[-c|--core]}} {{path/to/core}} {{path/to/executable}}`
|
2025-03-14 21:59:59 -06:00
|
|
|
|
|
|
|
|
- Execute given GDB commands upon start:
|
|
|
|
|
|
2025-12-16 10:20:31 -07:00
|
|
|
`gdb {{[-ex|--eval-command]}} "{{commands}}" {{path/to/executable}}`
|
2025-03-14 21:59:59 -06:00
|
|
|
|
|
|
|
|
- Start `gdb` and pass arguments to the executable:
|
|
|
|
|
|
2025-12-16 10:20:31 -07:00
|
|
|
`gdb --args {{path/to/executable}} {{argument1 argument2 ...}}`
|
2025-03-14 21:59:59 -06:00
|
|
|
|
2025-12-16 10:20:31 -07:00
|
|
|
- Skip `debuginfod` and pagination prompts and then print the backtrace:
|
2025-03-14 21:59:59 -06:00
|
|
|
|
2025-12-16 10:20:31 -07:00
|
|
|
`gdb {{[-c|--core]}} {{path/to/core}} {{path/to/executable}} -iex 'set debuginfod enabled on' -iex 'set pagination off' -ex bt`
|