Skip to content

Support separate PDB with MSVC staticlib #89986

@joverwey

Description

@joverwey

Problem

When compiling staticlib crates using the MSVC toolchain, no PDBs are produced.

This makes it very hard to debug C++ programs that are statically linked to Rust libraries, especially in release mode.

Steps

cargo new --lib test

In Cargo.toml:

[lib]
path = "./src/lib.rs"
crate_type = ["staticlib"]

cargo build

Note that the output is test.lib

Now change Cargo.toml:

[lib]
path = "./src/lib.rs"
crate_type = ["cdylib"]

cargo build

Note that the output is test.lib + test.pdb

Possible Solution(s)

Is there a way to pass a flag to force creating the PDB. In Visual Studio it is /Zi.

Notes

It seems it is still possible to step into the code for debug builds, but not release builds.

Version

cargo 1.55.0 (32da73ab1 2021-08-23)
release: 1.55.0
commit-hash: 32da73ab19417aa89686e1d85c1440b72fdf877d
commit-date: 2021-08-23

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-debuginfoArea: Debugging information in compiled programs (DWARF, PDB, etc.)O-windows-msvcToolchain: MSVC, Operating system: WindowsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.WG-debuggingWorking group: Bad Rust debugging experiences

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions