Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debugging example from the docs with LLDB shows local variables as not available #9716

Open
bkolobara opened this issue Dec 3, 2024 · 3 comments
Labels
bug Incorrect behavior in the current implementation that needs fixing

Comments

@bkolobara
Copy link

I'm trying to get the following example working inside of a debugger: https://docs.wasmtime.dev/examples-rust-debugging.html, but lldb can't read any of the local variables when a break point is triggered.

Test Case

The wasm file and executable are compiled directly from wasmtime examples.

> cargo build -p example-fib-debug-wasm --target wasm32-unknown-unknown
> cargo build --example fib-debug

Steps to Reproduce

Run the fib-debug executable inside lldb with the jit plugin enabled.

> lldb -- ./target/debug/examples/fib-debug                         
(lldb) target create "./target/debug/examples/fib-debug"
Current executable set to '/Users/bkolobara/dev/wasmtime/target/debug/examples/fib-debug' (arm64).
(lldb) settings set plugin.jit-loader.gdb.enable on
(lldb) b fib.rs:6
Breakpoint 1: no locations (pending).
WARNING:  Unable to resolve breakpoint to any actual locations.
(lldb) r
Process 87206 launched: '/Users/bkolobara/dev/wasmtime/target/debug/examples/fib-debug' (arm64)
1 location added to breakpoint 1
Process 87206 stopped
* thread #1, name = 'main', queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
    frame #0: 0x00000001041381c4 JIT(0x1381c8000)`fib(n=<unavailable>) at fib.rs:6:17
   3        let mut a = 1;
   4        let mut b = 1;
   5        for _ in 0..n {
-> 6            let t = a;
   7            a = b;
   8            b += t;
   9        }
Target 0: (fib-debug) stopped.
warning: This version of LLDB has no plugin for the language "rust". Inspection of frame variables will be limited.
(lldb) fr v
(WasmtimeVMContext *) __vmctx = <variable not available>

(unsigned int) n = <read memory from 0xffff8 failed (0 of 4 bytes read)>

(unsigned int) a = <no location, value may have been optimized out>

(unsigned int) b = <no location, value may have been optimized out>

(core::ops::range::Range<unsigned int>) iter = <no location, value may have been optimized out>

Expected Results

Running fr v in lldb in this context should display the values of the variables:

(unsigned int) a = 1

(unsigned int) b = 1

Actual Results

(unsigned int) a = <no location, value may have been optimized out>

(unsigned int) b = <no location, value may have been optimized out>

Versions and Environment

Wasmtime version or commit: 27.0

Operating system: macOs Sequoia 15.1.1

Architecture: Apple M1 Pro

Extra Info

> lldb --version
lldb-1600.0.39.3
Apple Swift version 6.0.2 (swiftlang-6.0.2.1.2 clang-1600.0.26.4)

There was a similar issue #3884, but it was closed as fixed 2 years ago.

I'm also aware that there is some work being done on improving the debug info translation in #5537.

@bkolobara bkolobara added the bug Incorrect behavior in the current implementation that needs fixing label Dec 3, 2024
@alexcrichton
Copy link
Member

cc @SingleAccretion since you've been looking at the DWARF stuff recently would you happen to recognize this?

@SingleAccretion
Copy link
Contributor

SingleAccretion commented Dec 4, 2024

would you happen to recognize this?

Hmm, not immediately, considering this is trivial code at -Oopt-level=0. What is the Rust->WASM optimization level here?

Generically, non-trivial examples do fall apart very easily because SSA+RA do not preserve everything, and so Cranelift's preservation of variable ranges is quite poor.

The way to self-diagnose this is to look at the DWARF produced for WASM, check if a and b in it have reasonable ranges, then in LLDB do:

(lldb) image lookup -r -n fib --verbose

And check the coverage for ranges that will be dumped.

@bkolobara
Copy link
Author

What is the Rust->WASM optimization level here?

This uses a debug build of the fib.rs file, so opt-level = 0, with debug info included.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Incorrect behavior in the current implementation that needs fixing
Projects
None yet
Development

No branches or pull requests

3 participants