pacak/cargo-show-asm

Fails to find rust sources on windows

pm100 opened this issue · 23 comments

pm100 commented

Windows

cargo asm to_block --rust -p tui-textarea --lib

produces

      ......
      .....
        Self::default().content(value.into())
        mov rax, qword ptr [rbp + 568]
        mov qword ptr [rbp + 592], rax
        movups xmm0, xmmword ptr [rbp + 552]
        movaps xmmword ptr [rbp + 576], xmm0
        .cv_inline_site_id 1217 within 1215 inlined_at 55 117 0
thread 'main' panicked at C:\Users\paulm\.cargo\registry\src\index.crates.io-6f17d22bba15001f\cargo-show-asm-0.2.21\src\asm.rs:168:42:
index out of bounds: the len is 0 but the index is 715
stack backtrace:
   0:     0x7ff76cd4d89a - <unknown>
   1:     0x7ff76cd6c8fb - <unknown>
   2:     0x7ff76cd49341 - <unknown>
   3:     0x7ff76cd4d61a - <unknown>
   4:     0x7ff76cd5023a - <unknown>
   5:     0x7ff76cd4fea8 - <unknown>
   6:     0x7ff76cd508ee - <unknown>
   7:     0x7ff76cd507dd - <unknown>
   8:     0x7ff76cd4e559 - <unknown>
   9:     0x7ff76cd504e0 - <unknown>
  10:     0x7ff76cd7b625 - <unknown>
  11:     0x7ff76cd7b79e - <unknown>
  12:     0x7ff76cba9960 - <unknown>
  13:     0x7ff76cbab496 - <unknown>
  14:     0x7ff76cb7e47d - <unknown>
  15:     0x7ff76cb91cd6 - <unknown>
  16:     0x7ff76cb962ca - <unknown>
  17:     0x7ff76cd436d8 - <unknown>
  18:     0x7ff76cb8165c - <unknown>
  19:     0x7ff76cd72888 - <unknown>
  20:     0x7ffc56d826ad - BaseThreadInitThunk
  21:     0x7ffc58aaaa68 - RtlUserThreadStart
pm100 commented

PS - thanks for this project, much better than the original cargo asm.

pacak commented

index out of bounds: the len is 0 but the index is 715

I think this means it fails to find the sources. Can you run it with -vvv and see where exactly it tries to find them?

pm100 commented

I dont understand all this output so here is a complete capture of it
asm_crash.txt

pacak commented

At the end, just before crash it tried to read file 56, line 716

Directive(Loc(Loc { file: 56, line: 716, column: 0, extra: None }))

file 56 is defined a bit higher:

Directive(File(File { index: 56, path: FullPath("/rustc/cc66ad468955717ab92600c770da8c1601a4ff33\\library\\core\\src\\convert\\mod.rs"), md5: None }))

also printed at the beginning

Reading file #56 /rustc/cc66ad468955717ab92600c770da8c1601a4ff33\library\core\src\convert\mod.rs

This mix of forward and backward slashes looks odd :) Do you have rustc sources component installed?

pm100 commented

This mix of forward and backward slashes looks odd :)

its pretty normal on windows nowadays. Almost everything on windows accepts / or \ as a dir delimiter. It just depends on how the path was assembled. Like this


PS C:\work\tui-textarea> ls ./asm_crash.txt


    Directory: C:\work\tui-textarea


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----         11/8/2023   4:38 PM         134604 asm_crash.txt


PS C:\work\tui-textarea>

see that the command used forward slash, the response has backslash

Do you have rustc sources component installed?

I dont know what that is so probably not

pacak commented

You install them with something like that

rustup component add rust-src
pacak commented

I pushed a branch called windows, can you try to install cargo-show-asm from it and run with -vvv one more time? When reading files it should print a bit more diagnostic about each file - it's actual name and how many bytes it is. You can attach the whole output or just the bit around "reading file 56".

pm100 commented

Note that it works for other functions, just doesnt seem to like this one.

here is the console output


Found sysroot: C:\Users\paulm\.rustup\toolchains\stable-x86_64-pc-windows-msvc
       Fresh cfg-if v1.0.0
       Fresh autocfg v1.1.0
       Fresh version_check v0.9.4
       Fresh unicode-ident v1.0.12
       Fresh proc-macro2 v1.0.69
       Fresh once_cell v1.18.0
       Fresh windows_x86_64_msvc v0.48.5
       Fresh quote v1.0.33
       Fresh smallvec v1.11.1
       Fresh scopeguard v1.2.0
       Fresh zerocopy v0.7.23
       Fresh windows-targets v0.48.5
       Fresh lock_api v0.4.11
       Fresh syn v2.0.38
       Fresh winapi v0.3.9
       Fresh ahash v0.8.6
       Fresh rustversion v1.0.14
       Fresh heck v0.4.1
       Fresh parking_lot_core v0.9.9
       Fresh allocator-api2 v0.2.16
       Fresh crossterm_winapi v0.9.1
       Fresh strum_macros v0.25.3
       Fresh bitflags v2.4.1
       Fresh either v1.9.0
       Fresh cassowary v0.3.0
       Fresh parking_lot v0.12.1
       Fresh hashbrown v0.14.2
       Fresh strum v0.25.0
       Fresh paste v1.0.14
       Fresh itertools v0.11.0
       Fresh indoc v2.0.4
       Fresh unicode-segmentation v1.10.1
       Fresh unicode-width v0.1.11
       Fresh crossterm v0.27.0
       Fresh lru v0.12.0
       Fresh ratatui v0.24.0
       Fresh tui-textarea v0.3.0 (C:\work\tui-textarea)

Artifact files: [  "C: Finished release [optimized] target(s) in 0.10s\
\work\\tui-textarea\\target\\release\\libtui_textarea.rlib", "C:\\work\\tui-textarea\\target\\release\\deps\\libtui_textarea-08fc92aa894971d8.rmeta"]
Asm file: C:\work\tui-textarea\target\release\deps\tui_textarea-08fc92aa894971d8.s
thread 'main' panicked at src\asm.rs:168:42:
index out of bounds: the len is 0 but the index is 715
stack backtrace:
   0:     0x7ff6cbbb2f2a - std::sys_common::backtrace::_print::impl$0::fmt
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library\std\src\sys_common\backtrace.rs:44
   1:     0x7ff6cbbd22ab - core::fmt::rt::Argument::fmt
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library\core\src\fmt\rt.rs:138
   2:     0x7ff6cbbd22ab - core::fmt::write
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library\core\src\fmt\mod.rs:1094
   3:     0x7ff6cbbae851 - std::io::Write::write_fmt<std::sys::windows::stdio::Stderr>
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library\std\src\io\mod.rs:1714
   4:     0x7ff6cbbb2caa - std::sys_common::backtrace::_print
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library\std\src\sys_common\backtrace.rs:47
   5:     0x7ff6cbbb2caa - std::sys_common::backtrace::print
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library\std\src\sys_common\backtrace.rs:34
   6:     0x7ff6cbbb58ca - std::panicking::default_hook::closure$1
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library\std\src\panicking.rs:270
   7:     0x7ff6cbbb5538 - std::panicking::default_hook
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library\std\src\panicking.rs:290
   8:     0x7ff6cbbb5f7e - std::panicking::rust_panic_with_hook
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library\std\src\panicking.rs:707
   9:     0x7ff6cbbb5e6d - std::panicking::begin_panic_handler::closure$0
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library\std\src\panicking.rs:599
  10:     0x7ff6cbbb3be9 - std::sys_common::backtrace::__rust_end_short_backtrace<std::panicking::begin_panic_handler::closure_env$0,never$>
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library\std\src\sys_common\backtrace.rs:170
  11:     0x7ff6cbbb5b70 - std::panicking::begin_panic_handler
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library\std\src\panicking.rs:595
  12:     0x7ff6cbbda315 - core::panicking::panic_fmt
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library\core\src\panicking.rs:67
  13:     0x7ff6cbbda48e - core::panicking::panic_bounds_check
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library\core\src\panicking.rs:162
  14:     0x7ff6cb82f0ed - core::slice::index::impl$2::index<core::ops::range::Range<usize> >
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33\library\core\src\slice\index.rs:261
  15:     0x7ff6cb7db7a6 - alloc::vec::impl$12::index<core::ops::range::Range<usize>,usize,alloc::alloc::Global>
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33\library\alloc\src\vec\mod.rs:2675
  16:     0x7ff6cb81f5b1 - cargo_show_asm::cached_lines::impl$1::index
                               at C:\work\cargo-show-asm\src\cached_lines.rs:34
  17:     0x7ff6cb7bd3b5 - cargo_show_asm::asm::dump_range
                               at C:\work\cargo-show-asm\src\asm.rs:168
  18:     0x7ff6cb7bf01f - cargo_show_asm::asm::dump_function
                               at C:\work\cargo-show-asm\src\asm.rs:365
  19:     0x7ff6cb753431 - cargo_asm::main
                               at C:\work\cargo-show-asm\src\main.rs:238
  20:     0x7ff6cb79e1cb - core::ops::function::FnOnce::call_once<enum2$<core::result::Result<tuple$<>,anyhow::Error> > (*)(),tuple$<> >
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33\library\core\src\ops\function.rs:250
  21:     0x7ff6cb76bcce - std::sys_common::backtrace::__rust_begin_short_backtrace<enum2$<core::result::Result<tuple$<>,anyhow::Error> > (*)(),enum2$<core::result::Result<tuple$<>,anyhow::Error> > >
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33\library\std\src\sys_common\backtrace.rs:154
  22:     0x7ff6cb7571e1 - std::rt::lang_start::closure$0<enum2$<core::result::Result<tuple$<>,anyhow::Error> > >
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33\library\std\src\rt.rs:166
  23:     0x7ff6cbba8bc8 - std::rt::lang_start_internal::closure$2
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library\std\src\rt.rs:148
  24:     0x7ff6cbba8bc8 - std::panicking::try::do_call
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library\std\src\panicking.rs:502
  25:     0x7ff6cbba8bc8 - std::panicking::try
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library\std\src\panicking.rs:466
  26:     0x7ff6cbba8bc8 - std::panic::catch_unwind
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library\std\src\panic.rs:142
  27:     0x7ff6cbba8bc8 - std::rt::lang_start_internal
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library\std\src\rt.rs:148
  28:     0x7ff6cb7571ba - std::rt::lang_start<enum2$<core::result::Result<tuple$<>,anyhow::Error> > >
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33\library\std\src\rt.rs:165
  29:     0x7ff6cb755889 - main
  30:     0x7ff6cbbd8540 - invoke_main
                               at D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:78
  31:     0x7ff6cbbd8540 - __scrt_common_main_seh
                               at D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288
  32:     0x7ffc56d826ad - BaseThreadInitThunk
  33:     0x7ffc58aaaa68 - RtlUserThreadStart

here is the stdout

asm_crash.txt

pacak commented

Hmm... This is strange. This file seem to work, it is resolved and read successfully

Reading file #53 /rustc/cc66ad468955717ab92600c770da8c1601a4ff33\library\alloc\src\boxed.rs
Resolved name is "C:\\Users\\paulm\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib/rustlib/src/rust\\library\\alloc\\src\\boxed.rs"
Got 78860 bytes

This file fails to resolve and causes a crash...

Reading file #56 /rustc/cc66ad468955717ab92600c770da8c1601a4ff33\library\core\src\convert\mod.rs
Resolved name is "/rustc/cc66ad468955717ab92600c770da8c1601a4ff33\\library\\core\\src\\convert\\mod.rs"
Got 0 bytes

Can you check if this file is present: C:\\Users\\paulm\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib/rustlib/src/rust\\library\\core\\src\\convert\\mod.rs ?

pm100 commented

its there

PS C:\work\git3\gitui> ls C:\Users\paulm\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\convert


    Directory: C:\Users\paulm\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\convert


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----        10/10/2023  11:31 AM          31635 mod.rs
-a----        10/10/2023  11:31 AM          26407 num.rs

pacak commented

Hmm..... I'm slowly running out of ideas :) Can you try adding your own debug printing around the file resolving place (it's in src/asm.rs, line 313 and possibly inside locate_sources method) to try to understand what's going on? I can add something to stop it from crashing, but ideally it should be able to load files if they are there...

pm100 commented

ok, it was a different file Resolved name is "/rustc/cc66ad468955717ab92600c770da8c1601a4ff33\\library\\core\\src\\convert\\mod.rs"

somehow this file is empty, and is the only one in that directory. But now I see all files in that sparsely populated dir tree are empty.

I dont know enough about the layout of rust files or what it is you are looking for. Seems to be to do with the --rust option

pacak commented

Those files are just regular sources used to compile that specific version of the stdlib. debug info contains references to specific lines of info and cargo-show-asm decodes this info, tries to read those files, gets corresponding line and renders it when --rust option is used. So the file is there but it is empty? Not sure what's going on... Anyway, I'll try to make something that prints an error instead of panic soon-ish so you'll be able to see at least the files that are okay.

pm100 commented

not only empty but there are like on 3 or 4 files in the entire tree of /rustc/cc...........ff33/ and they are all empty

pacak commented

Seems like a bug with your installed rust sources then. 🤔

pm100 commented

As far as I know I never installed them - I dont know why I would do it, nor how to do it

this is what is there

pm100@paul-think:/mnt/c/work/tui-textarea$ ls -lR /mnt/c/rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src
/mnt/c/rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src:
total 0
drwxrwxrwx 1 pm100 pm100 4096 Nov  3 14:36 convert

/mnt/c/rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/convert:
total 0
-rwxrwxrwx 1 pm100 pm100 0 Nov  3 14:36 mod.rs
pm100@paul-think:/mnt/c/work/tui-textarea$ ls -lR /mnt/c/rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library
/mnt/c/rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library:
total 0
drwxrwxrwx 1 pm100 pm100 4096 Nov  3 14:36 core
drwxrwxrwx 1 pm100 pm100 4096 Oct 16 21:37 test

/mnt/c/rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core:
total 0
drwxrwxrwx 1 pm100 pm100 4096 Nov  3 14:36 src

/mnt/c/rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src:
total 0
drwxrwxrwx 1 pm100 pm100 4096 Nov  3 14:36 convert

/mnt/c/rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/convert:
total 0
-rwxrwxrwx 1 pm100 pm100 0 Nov  3 14:36 mod.rs

/mnt/c/rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/test:
total 0
drwxrwxrwx 1 pm100 pm100 4096 Oct 16 21:37 src

/mnt/c/rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/test/src:
total 0
-rwxrwxrwx 1 pm100 pm100 0 Oct 16 21:37 lib.rs
pm100 commented

I have a secons /rustc/{guid} tree with only one empty file in it

pacak commented

As far as I know I never installed them - I dont know why I would do it, nor how to do it

rustup component add rust-src

Installed sources help to rust-analyzer or tools like cargo-show-asm. They don't take much space compared to a typical target folder so not much harm having it installed. Can you try installing and check if it helps?

pm100 commented

nope

PS C:\work\tui-textarea> rustup component add rust-src
info: component 'rust-src' is up to date
PS C:\work\tui-textarea> rustup component remove rust-src
info: removing component 'rust-src'
PS C:\work\tui-textarea> rustup component add rust-src
info: downloading component 'rust-src'
info: installing component 'rust-src'

same crash. Maybe the file layout is different on windows

pm100 commented

if i remove that 0 length file all works fine, it because that locate file fn says 'if the file exists then thats the one'. I have no idea how that file got there. Maybe some other tool did something

pacak commented

Pushed a change to windows branch to skip those empty files. Can you check if it fixes your crashes?

pm100 commented

that works

pacak commented

I released 0.2.22 (#218)