# Release builds and debug files


A Rust binary is machine code. When your app panics, its stack trace is really a list of addresses in that code, and turning those addresses back into functions, files and lines takes the debug info the compiler writes during your build.

You can get that debug info to Flare in two ways:

- **Ship it with your binary.** The SDK resolves the stack trace inside your app, before it sends the report. This is the simplest setup, and it's the one the [quick start](/docs/rust/getting-started/quick-start#keep-stack-traces-readable-in-release-builds) uses.
- **Upload it to Flare.** You ship a stripped binary and upload its debug files from your build pipeline. Flare resolves the stack trace when the report arrives. Your binary stays small, and your app does less work when something goes wrong.

Both work on Linux, macOS and Windows. Uploading takes a bit more setup in your pipeline, and in return you get smaller binaries.

## Shipping debug info with your binary

Cargo builds release binaries without debug info by default. Turn it on in your `Cargo.toml`:

```toml
# Cargo.toml
[profile.release]
debug = "limited"
```

How much Flare can show depends on the debug info in the binary:

| Your release profile | What Flare shows |
|---|---|
| `debug = "limited"` | The function with its module path, the file and the line. This is what we recommend. |
| `debug = "line-tables-only"` | The file and the line. Function names lose their module, so you get `create` instead of `my_app::orders::OrderService::create`. |
| No `debug` setting, the Cargo default | Function names, but no files or lines. |
| `strip = "symbols"` or `strip = true` | No functions, files or lines, unless you upload the debug files. |

Debug info makes your binary bigger, but not slower. The compiler generates the same machine code either way.

On Windows, the debug info doesn't end up in the `.exe` itself, but in a `.pdb` file next to it. Deploy that `.pdb` together with the `.exe`, or your stack traces end up without functions, files or lines.

## Uploading debug files

With this setup, you build with debug info, upload the debug files to Flare, and then ship the binary without them.

Every build gets a debug ID, which is stored in the binary and in its debug files. With every report, the SDK sends the debug IDs of the binaries in the stack trace, and Flare uses them to find the right debug files. Changing your code gives the next build a new debug ID, so upload the debug files of every build you deploy. The best place for that is your CI. See [uploading debug files in CI](/docs/rust/errors/uploading-debug-files-in-ci) for complete Linux, macOS and Windows pipelines.

### Step 1: Install the CLI

The `cargo-flareapp` command line tool finds the debug files of your build and uploads them. Install it on the machine that builds your app:

```bash
cargo install cargo-flareapp --locked
```

This compiles the CLI from source and puts the `cargo-flareapp` binary in `~/.cargo/bin`. Cargo then runs the tool as `cargo flareapp`.

### Step 2: Build with debug info

Each platform keeps its debug info somewhere else, so the build settings differ a little. Every platform starts from the same release profile:

```toml
# Cargo.toml
[profile.release]
debug = "limited"
```

```toml tab=linux
# .cargo/config.toml
[target.'cfg(target_os = "linux")']
rustflags = ["-C", "link-arg=-Wl,--build-id"]
```

```bash tab=macos
CARGO_PROFILE_RELEASE_SPLIT_DEBUGINFO=packed cargo build --release
```

```bash tab=windows
cargo build --release
```

**Linux** needs a build ID: a note in the binary that the linker writes. On Linux, the debug ID is made from the build ID. Depending on your linker, a Rust binary may not get one, and without it Flare can't match a stripped binary to its debug file. Putting the flag in `.cargo/config.toml` means every build gets it, on your machine, in CI and in Docker. One thing to watch: a `RUSTFLAGS` environment variable replaces the flags from that file, so if your pipeline sets `RUSTFLAGS`, add `-C link-arg=-Wl,--build-id` to it.

Don't set `split-debuginfo = "packed"` on Linux. That writes a `.dwp` file, which Flare can't read.

**macOS** needs `split-debuginfo = "packed"`. Cargo then writes the debug info to a `.dSYM` bundle next to your binary. The macOS default is `unpacked`, which leaves the debug info scattered over the object files of your build, where the CLI can't pick it up. Setting it with an environment variable on your macOS build keeps it away from a Linux build that shares the same `Cargo.toml`. If you only ever build on macOS, you can put `split-debuginfo = "packed"` in your release profile instead.

**Windows** needs nothing extra. With the MSVC toolchain, which is the default for Rust on Windows, the debug info goes into the `.pdb` file next to your `.exe`.

### Step 3: Split off the debug info on Linux

On macOS and Windows, the debug info is already in a file of its own, so skip this step.

On Linux, the debug info is inside the binary. Move it to a separate `.debug` file with `objcopy`:

```bash
objcopy --only-keep-debug target/release/my-app target/release/my-app.debug
objcopy --strip-debug --strip-unneeded target/release/my-app
objcopy --add-gnu-debuglink=target/release/my-app.debug target/release/my-app
```

Replace `my-app` with the name of your binary. The three commands do this:

1. Copy the debug info to `my-app.debug`. This is the file you upload.
2. Remove the debug info and the symbol table from the binary. This is the binary you deploy.
3. Write the name of the debug file into the binary. Tools like `gdb` use that link to find `my-app.debug` when it's next to the binary.

Both files keep the build ID, so they have the same debug ID, and Flare can match one to the other.

### Step 4: Upload the debug files

Run the upload right after the build, in the same CI job or Docker stage. The CLI reads the private API key of your project from `FLARE_KEY`:

```bash
FLARE_KEY=YOUR-API-KEY cargo flareapp upload-debug-files target/release
```

The CLI searches the folders you give it, or `target/release` when you don't give any. It reads the debug ID of every binary and debug file it finds, and only uploads what Flare doesn't have yet. Running it twice for the same build is safe: the second run uploads nothing. Before it sends a file, the CLI compresses it, which usually makes it 4 to 5 times smaller.

You get one line per file, telling you whether it was uploaded, was already on Flare, or was skipped and why:

```
uploaded          target/release/my-app.debug  (c1877035-9a24-3a67-aa37-a2c7360781ed)
```

The stripped binary in the same folder has the same debug ID as its debug file, so the CLI leaves it out without a line of its own.

Want to see what it would upload first? `--dry-run` lists the files without uploading anything, and doesn't need an API key:

```bash
cargo flareapp upload-debug-files --dry-run
```

### Step 5: Ship the binary without its debug files

Deploy the binary, and leave out the `.debug` file, the `.dSYM` bundle or the `.pdb` file. Flare has its own copy now.

If you do deploy a debug file next to the binary, the SDK finds it and resolves the stack traces inside your app, just like with a binary that has debug info.

On macOS, the binary still holds the names of its functions. Run `strip target/release/my-app` if you want it smaller. That doesn't change its debug ID.

### Upload before you deploy

Flare resolves a stack trace once, when the report arrives. If the report gets there before its debug file, Flare keeps the frames that the SDK could resolve in your app, and uploading the file later won't change that report. So upload in your pipeline before the new build goes live.

After an upload, Flare prepares the debug file in the background. Reports that arrive in the meantime wait for it, for up to 10 minutes.

### Requirements

- The private API key of your project. The public key doesn't work for uploads.
- A Flare subscription or a trial.
- Debug files of at most 2 GiB.
- HTTPS access from your build machine to Flare's file storage. The CLI uploads each file straight to storage, not through the Flare API, so a strict firewall needs to let those requests through.

## Checking a debug file

`cargo flareapp check` shows what Flare reads from a single file, without touching the network. Run it on the binary you deploy and on the debug file you upload, and compare the two:

```bash
cargo flareapp check target/release/my-app
```

```
target/release/my-app
  format        elf
  kind          executable
  architecture  x86_64
  debug ID      c1877035-9a24-3a67-aa37-a2c7360781ed
  code ID       357087c1249a673aaa37a2c7360781edd3a1f0b2
  symbols       yes
  debug info    yes
  unwind info   yes
  sources       no
  Flare can use this file.
```

The binary you deploy and the file you upload must have the same debug ID. When Flare can't use a file, the last line tells you why.

A binary without its debug info, like a stripped Linux binary or a macOS binary next to its `.dSYM` bundle, says `Flare cannot use this file: the file has no debug information.` That's expected: you upload its debug file instead.

On macOS, `check` takes the file inside the `.dSYM` bundle, not the bundle itself. You'll find it in `my-app.dSYM/Contents/Resources/DWARF/`.

## What Flare shows

Every frame of a Rust error that has an address gets a chip icon next to its file. Hover it to see the status of the frame, the debug ID of the binary, and what to do next:

| Status | What it means |
|---|---|
| Symbolicated | Flare resolved the frame with your uploaded debug file. |
| No debug file | Flare has no usable debug file for the build that sent this error. Upload the debug file with the debug ID from the tooltip. |
| Outside the loaded binaries | The address isn't inside any binary or library that your app reported, so Flare can't tell which debug file it belongs to. |
| No function at this address | The uploaded debug file has no function at this address. |
| Lookup failed | Flare couldn't look up the frame. The problem is on our side, so uploading the debug file again won't help. |

Without a debug file, Flare keeps the frames the SDK resolved in your app. For a binary with debug info, those frames are complete already, and the status only tells you that nothing was uploaded. For a stripped binary, they have no function, file or line.

A frame that Flare resolves from a debug file has its function, file and line. When the compiler inlined functions at that address, Flare shows each of them as a frame of its own. Rust frames never have code snippets, because Flare doesn't have your source code.

## Read more

- [Uploading debug files in CI](/docs/rust/errors/uploading-debug-files-in-ci): ready-made pipelines for GitHub Actions, Docker and other CI systems.
- [Troubleshooting](/docs/rust/getting-started/troubleshooting#debug-file-uploads): fixes for the most common upload errors.
