Batch Backtraces With gdb

Run a program under GDB and print a backtrace without an interactive session.

LinuxdevelopercliDiagnosticsLow risk
Run gdb -batch -ex run -ex bt ./program to execute it and print the stack on stop.

01Command

Command
$ gdb -batch -ex run -ex bt ./my-program

02What it does

The -batch and -ex flags turn GDB into a scriptable debugger that runs commands in order, which is perfect for CI crash triage. Interactive GUIs cannot easily be embedded in an automated pipeline, which is why debugging scripts use the CLI.

03Risk

RiskLow risk
Requirementssudo apt install gdb
!Warning: Without debug symbols the backtrace shows addresses only; install -dbg packages or build with -g.

04Undo

✓No undo needed — this command does not change persistent state.

05Sources

  • GDB documentation
    GNU Project · technical · 2026-09-20
    Evidence: Official GDB manual documenting -batch and -ex.

Last verified: 2026-10-13 · Category: Developer

06Related solutions