Skip to content

Debug a Rust executable

Stop inside a Rust binary and inspect its state.

Prerequisites

  • codelldb on PATHcommand -v codelldb
  • a Cargo project

Config

bugsaur init writes this for you; check that program matches your binary name.

version = 1
default = "app"

[profiles.app]
adapter = "codelldb"
program = "target/debug/app"

In a workspace there is one profile per binary, and program is target/debug/<binary name>target/ lives at the workspace root.

Run

cargo build
bugsaur gui --project . --break src/main.rs:15

Order matters: program points at a build artifact, and Bugsaur does not build Rust for you.

What should happen

The window opens, the program runs and stops at line 15. Variables shows the locals of that frame, Call Stack shows how you got there.

Variations

A specific binary in a workspace

cargo build
bugsaur gui --project . --profile daemon --break crates/daemon/src/main.rs:20

With arguments

[profiles.app]
adapter = "codelldb"
program = "target/debug/app"
args = ["import", "--dry-run", "${root}/fixtures/sample.csv"]

With environment from a file

[profiles.app]
adapter = "codelldb"
program = "target/debug/app"
env_file = ".env"
env = { RUST_LOG = "debug" }

Code that reads CARGO_* at runtime

cargo run sets variables a direct launch does not. Add what the code needs:

env = { CARGO_MANIFEST_DIR = "${root}" }

When it does not work

Symptom Fix
program is not readable run cargo build; check the binary name in program
Session never starts codelldb not on PATHAdapter fails to start
Stops but shows no variables you built with --release; debug the debug build
Never stops Breakpoints not hit