bytecodealliance / wasmtime

A fast and secure runtime for WebAssembly
https://wasmtime.dev/
Apache License 2.0
15.48k stars 1.31k forks source link

Cranelift: Debugging JIT dwarf data is missing global variables. #3439

Open adv-sw opened 3 years ago

adv-sw commented 3 years ago

test.cpp

int my_global = 4;

class Thing
{
public:
   Thing(int i) 
   { 
      m_i = i + my_global;
   }

   int m_i;
};

int main() {

    auto thing = new Thing(5);

    return thing->m_i == 9;
}

Steps to Reproduce

Compile above, debug mode. Under lldb, open in wasmtime -g Breakpoint in constructor. Run Show globals: (lldb) fr v -g

Expected Results

Expected to see my_global

Actual Results

Just locals observed.

Versions and Environment

Linux & Windows wasmtime trunk used. lldb trunk & 12.0.1 tried.

Architecture: x86/64


Repro:

(lldb) settings set -- target.run-args "-g" ".\test.wasm" (lldb) b test.cpp:7 Breakpoint 1: no locations (pending). WARNING: Unable to resolve breakpoint to any actual locations. (lldb) r Process 8700 launched: 'z:\dev\wasm\wasmtime\target\release\wasmtime.exe' (x86_64) frame #0: 0x00000220c62214a7 JIT(0x220c8093010)`Thing::Thing(this=(__ptr = 131088), i=5) at test.cpp:9:13 6 public: 7 Thing(int i) 8 { -> 9 m_i = i + my_global; 10 } 11 12 int m_i; (lldb) fr v -g (WasmtimeVMContext *) vmctx = 0x00000220c62ed950 (WebAssemblyPtrWrapper) this = (ptr = 131088) (int) i = 5

adv-sw commented 3 years ago

Severity: High. Standard debugging pipeline not complete until this has been resolved.

We've got parse_global_section in wasmtime\cranelift\wasm\src\sections_translator.rs

Perhaps we can work from that.