A Rust CLI from `cargo build` debugs fine under rust-lldb on your Mac, but copied to another Mac its breakpoints get no locations; why, and what do you ship?
answer
- where macOS keeps the DWARF
- object files and a debug map
- Cargo's macOS default is unpacked
- dsymutil and a matching UUID
basics
~20 sOn macOS, Cargo leaves debug info unpacked in the object files under target/debug/deps, and the binary only points to them. Copied alone, it has no DWARF. Ship a .dSYM bundle, made with split-debuginfo = "packed" or dsymutil.
solid answer
~50 sA macOS executable does not carry its DWARF. Either it stays in the object files, which the executable lists in a **debug map** (OSO entries with absolute paths), or `dsymutil` gathers it into a **.dSYM** bundle. For profiles with debug info, Cargo's default `split-debuginfo` on macOS is `unpacked`, so a debug build leaves the DWARF in `target/debug/deps/*.rcgu.o`. On your Mac, LLDB follows the map to those files. On another Mac, or after `cargo clean`, the paths are missing, and `breakpoint set -f main.rs -l 25` reports `no locations (pending)`. Produce a dSYM instead: set `split-debuginfo = "packed"` for that profile (a Cargo profile key), or run `dsymutil` on the binary while the object files still exist. Ship the binary and its `.dSYM` side by side; LLDB pairs them by UUID. `target/debug/<name>.dSYM` is a symlink into `deps`, so copy it with `cp -RL`.
code
console · 8 lines$ cargo build --offline -q
$ ls target/debug
build deps examples incremental logtool2 logtool2.d
$ cp target/debug/logtool2 ../ship/ && mv target/debug/deps target/debug/deps.hidden
$ cd ../ship && rust-lldb -b -o "breakpoint set -f main.rs -l 25" -o quit ./logtool2
...
Breakpoint 1: no locations (pending).
WARNING: Unable to resolve breakpoint to any actual locations.go deeper
Remember that on macOS debug info can live outside the binary, in object files or a .dSYM bundle next to it.
Explain the two layouts: unpacked object files found through the debug map versus a packed .dSYM made by dsymutil, and Cargo's unpacked default on macOS.
Diagnose a copied or cleaned binary losing breakpoints, then fix it with a packed profile or dsymutil, copying the symlinked bundle with -L and checking UUIDs.
Weigh faster local links from unpacked against shippable debug info, and decide which builds archive a .dSYM for later crash analysis.
## Where a macOS binary keeps its debug info On ELF platforms the DWARF debug info usually sits inside the executable. On macOS it does not. It lives in one of two places: - **Unpacked**: the DWARF stays in the object files the compiler wrote, and the executable carries a **debug map**, symbol-table entries (OSO entries) that name each object file by **absolute path**. A debugger reads the map and opens those files. - **Packed**: `dsymutil` reads the object files once and writes a **.dSYM bundle**, a directory whose `Contents/Resources/DWARF/` holds all the DWARF in one file, stamped with the executable's **UUID**. The rustc book describes the `-C split-debuginfo` values: on macOS `unpacked` means "the original object files will contain debug information", `packed` produces a `*.dSYM` folder, and `off` "prevents the final execution of dsymutil". ## Cargo and rustc pick different defaults | How you build | Default on macOS | Where the DWARF ends up | |---|---|---| | `rustc -g main.rs` directly | `packed` | `main.dSYM` beside the binary | | `cargo build` (dev profile, debug info on) | `unpacked` | `target/debug/deps/*.rcgu.o` | | Cargo with `split-debuginfo = "packed"` | as set | `target/debug/<name>.dSYM` | The Cargo reference states that the default "is unpacked on macOS for profiles that have debug information otherwise enabled". Unpacked skips the `dsymutil` pass on every link, which suits an edit-build-debug loop on one machine. The `split-debuginfo` key itself, with `debug` and `strip`, belongs to Cargo's build profiles; here what matters is what LLDB needs to find. ## Why the copied binary fails 1. A dev build of a small tool carried 62 OSO entries, each an absolute path such as `/private/tmp/.../target/debug/deps/logtool-...rcgu.o`. 2. On the build machine those files exist, so rust-lldb resolves `main.rs:25` to three locations and shows variables. 3. Copied to another directory with `deps` moved away, the same binary gave `Breakpoint 1: no locations (pending)` and `WARNING: Unable to resolve breakpoint to any actual locations.` 4. The same thing happens after `cargo clean`, in a CI artifact that holds only the executable, or on a colleague's Mac. The binary still runs, and symbol names survive, but line tables and variables are gone, so file-and-line breakpoints and `frame variable` have nothing to work with. ## Producing something you can ship - **Packed in the profile**: add `split-debuginfo = "packed"` under the profile you build with. Cargo then runs `dsymutil`, and `target/debug/<name>.dSYM` appears. - **Copy with links followed**: `target/debug/<name>.dSYM` is a symlink into `deps/`, so a plain `cp -R` copies a link that breaks elsewhere; `cp -RL` copies the bundle. - **Or run `dsymutil` yourself** on the finished binary, while the object files still exist. It writes `<binary>.dSYM` next to it, and that bundle works after the object files are gone. - **Ship the pair.** Put the `.dSYM` beside the binary. LLDB pairs them by UUID; `dwarfdump --uuid` printed the same UUID for the executable and for the DWARF file inside the bundle. ```toml [profile.dev] split-debuginfo = "packed" ``` ## Traps that cost an afternoon - **A stale bundle.** Relinking changes the UUID. A `.dSYM` kept from an earlier build, placed beside a new binary, was ignored: the breakpoint again had no locations, and `dwarfdump --uuid` showed two different UUIDs. Regenerate the bundle with every build you ship. - **A broken symlink.** Copying `target/debug/<name>.dSYM` without following links ships a dangling link instead of the bundle. - **Artifacts that hold only the executable.** A CI job that uploads `target/debug/<name>` alone ships an unpacked binary whose object files stayed on the runner. - **A cleaned target directory.** `cargo clean` removes the object files that an unpacked binary still points to, even on the machine that built it. ## Checking which case you have - `ls target/debug` shows a `<name>.dSYM` entry only when packed. - `nm -ap <binary> | grep OSO` lists object-file paths when the binary relies on unpacked debug info. - `dwarfdump --uuid <binary> <bundle>.dSYM` should print one matching UUID; a bundle from another build will not match and is ignored. Editor front-ends built on LLDB follow the same rules, so a missing dSYM looks the same in an editor as in the terminal.
- Why does `rustc -g main.rs` on a Mac leave a `main.dSYM` while `cargo build` does not?rustc's own default for `-C split-debuginfo` on macOS is `packed`, so it runs `dsymutil` and writes the bundle. Cargo overrides that for profiles with debug info and passes `unpacked`, which leaves the DWARF in the object files under `target/debug/deps` and skips `dsymutil`. The Cargo reference warns that the two tools have different defaults.
- How does LLDB know a `.dSYM` belongs to the binary you are debugging?By UUID. The linker stamps the executable with a UUID and `dsymutil` copies it into the DWARF file inside the bundle; `dwarfdump --uuid` prints both. LLDB uses a bundle only when the UUIDs match, so a `.dSYM` left over from an earlier build is ignored rather than misused, and you rebuild the bundle after relinking.
An unpacked binary is like a report whose footnotes cite folders on your own desk: it reads fine at your desk, but mailed alone every footnote leads nowhere. A .dSYM is the appendix bound and mailed with it, stamped with the same serial number so nobody pairs it with the wrong report.
- A macOS debug executable carries all its DWARF inside itself.
- Cargo writes a .dSYM next to every macOS debug build by default.
- LLDB finds a dSYM by file name alone, whatever build it came from.
- Copying target/debug/<name>.dSYM with plain cp -R is enough.
- A release build fixes missing breakpoints on another Mac.