Skip to content

Debugging module with lldb shows local variables as not available #3884

@jeffcharles

Description

@jeffcharles

Test Case

test.wasm.zip

#include <stdio.h>

int main() {
    int i;
    for(i = 0; i < 5; i++) {
        printf("%d\n", i);
    }
    return 0;
}

compiled with: wasi-sdk-14.0/bin/clang -g -O0 test.c -o test.wasm

Steps to Reproduce

> lldb -- wasmtime run -g test.wasm                  
(lldb) target create "wasmtime"
Current executable set to 'wasmtime' (arm64).
(lldb) settings set -- target.run-args  "run" "-g" "test.wasm"
(lldb) settings set plugin.jit-loader.gdb.enable on
(lldb) b test.c:6
Breakpoint 1: no locations (pending).
WARNING:  Unable to resolve breakpoint to any actual locations.
(lldb) run
Process 40146 launched: '/Users/jeffcharles/.cargo/bin/wasmtime' (arm64)
1 location added to breakpoint 1
Process 40146 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
    frame #0: 0x0000000100e940e0 JIT(0x1102b0000)`main at test.c:6:24
   3   	int main() {
   4   	    int i;
   5   	    for(i = 0; i < 5; i++) {
-> 6   	        printf("%d\n", i);
   7   	    }
   8   	    return 0;
   9   	}
Target 0: (wasmtime) stopped.
(lldb) fr v
(WasmtimeVMContext *) __vmctx = <variable not available>

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

Expected Results

Running fr v in lldb in this context should display:

(int) i = 0

Actual Results

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

Versions and Environment

Wasmtime version or commit: 0.34.0

Operating system: MacOS Monterrey (12.2.1)

Architecture: arm64

Extra Info

LLDB version:

> lldb --version
lldb-1300.0.42.3
Swift version 5.5.2-dev

This is what happens when I try to compile and run natively to show what I'm expecting:

> clang -g -O0 test.c -o test
> lldb -- test
(lldb) target create "test"
Current executable set to '/Users/jeffcharles/projects/wasm32-wasi/test-c-app/test' (arm64).
(lldb) b test.c:6
Breakpoint 1: where = test`main + 32 at test.c:6:24, address = 0x0000000100003f6c
(lldb) run
Process 40384 launched: '/Users/jeffcharles/projects/wasm32-wasi/test-c-app/test' (arm64)
Process 40384 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
    frame #0: 0x0000000100003f6c test`main at test.c:6:24
   3   	int main() {
   4   	    int i;
   5   	    for(i = 0; i < 5; i++) {
-> 6   	        printf("%d\n", i);
   7   	    }
   8   	    return 0;
   9   	}
Target 0: (test) stopped.
(lldb) fr v
(int) i = 0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIncorrect behavior in the current implementation that needs fixingwasmtime:debuggingIssues related to debugging of JIT'ed code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions