I’ve been attempting to measure code coverage in rustc using a methodology inspired by RustSmith. Below are the steps I’ve followed, along with the issue I’m encountering:
I modified the Rust source (commit b8bb296), specifically in src/bootstrap/src/core/builder/cargo.rs at line 551, by adding the following flags:
if mode != Mode::Std {
rustflags.arg("-Cinstrument-coverage");
rustflags.arg("-Zprofile");
}
This allowed me to successfully run ./x build && ./x install.
I deleted all .profraw files before testing.
I ran the rustc binary from the installation directory, which successfully generated a .profraw file.
I used the following command to merge the profile data:
However, the generated coverage report only includes 36 lines corresponding to the main function in rustc, which is clearly incorrect. Even when I use rustc to compile a simple .rs file, the report still only shows 36 lines, with 100% coverage.
Thank you, everyone. The issue has been resolved, and the detailed steps are in the previous Stack Overflow link. It would be great if an official method for coverage collection could be provided in the future, similar to GCC, where enabling a flag would be sufficient without needing to modify the code.