pacak / cargo-show-asm

cargo subcommand showing the assembly, LLVM-IR and MIR generated for Rust code
Apache License 2.0
712 stars 35 forks source link

--rust flag shows code from libstd #241

Closed kornelski closed 10 months ago

kornelski commented 10 months ago

It seems that debug info and code locations are inlined along with the code. However, often this is counter-productive, because I don't see what my code does, and where assembly came from in my crate.

For example, arithmetic operations can look like this:

// /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/num/mod.rs : 1145
        uint_impl! {

and slice operations can look like this:

        // /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/slice/index.rs : 383
        let new_len = unchecked_sub(self.end, self.start);

But I'd prefer to see locations of lines with 1 << 8 and buf[n..] in my crate, rather than their raw desugared guts from libstd.

Is this possible? I wonder if that's a feature request for this crate, or whether that's how rustc works, and needs to be changed there.

pacak commented 10 months ago

This crate asks rustc to compile your code with debug info enabled, debug info contains bits like this:

.Ltmp20:
        .file   6 "/rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/num" "uint_macros.rs"
        .loc    6 2151 21
        mov     rcx, r12
        shr     rcx, 4

.file introduces a new rust source, .loc refers to a previously defined rust source. There's no references to the original code as far as I can see.

kornelski commented 10 months ago

In that case, could you add an option to hide lines that come from libstd?

pacak commented 10 months ago

In that case, could you add an option to hide lines that come from libstd?

I pushed limit-src branch. Is this what you had in mind?

kornelski commented 10 months ago

Yes, that is much better. Thank you!