bytecodealliance / bytecodealliance/wasmtime

Problem with debugging wasm module compiled from C++

Open
#1,896 6 comments 0 reactions 1 assignee Claimed by @yurydelendik View on GitHub
wasmtime:debugging
Dominant language
Rust
Stars
18.6k
Forks
1.8k
Avg merge
1d 18h
Merged PRs (30d)
126

Description

Hi,

I'm trying to use wasmtime's debug support. I followed the simple demo from https://github.com/bytecodealliance/wasmtime/issues/1613, and it works as expected. But when I try to debug a slightly more complex C++ program, there's some problem.

Here's the C++ snippet:
```cpp
#include

std::string hello(int x) {
const char* s1 = "Hello";
std::string s2 = "World";
return s1 + s2 + std::to_string(x);
}

int main() {
auto s = hello(12345);
return s.length();
}
```

I compiled it with a freshly built clang ([commit](https://github.com/llvm/llvm-project/commit/7965dd79a3da76f68a65e942f2ad4d78270491e6)), coupled with prebuilt wasi-sysroot from [wasi-sdk](https://github.com/WebAssembly/wasi-sdk):
```
$ clang++ --target=wasm32-wasi --sysroot ./wasi-sysroot -fno-exceptions -g t.cc -o t.wasm
```

Then I use lldb (8.0.1) and a freshly built wasmtime ([commit](https://github.com/bytecodealliance/wasmtime/commit/06a69d18fa9bb5d19625a8b5411c67b40d35fe78)) to debug it:
```
$ lldb -- ./wasmtime/target/release/wasmtime -g t.wasm
```

Setting breakpoint and stepping thru statements all work fine. But somehow none of the local variables are printed as expected:
```
Process 26379 stopped
* thread #1, name = 'wasmtime', stop reason = step over
frame #0: 0x00007ffff7fcf5af JIT(0x5555562ec490)`hello(x=0) at t.cc:6:12
3 std::string hello(int x) {
4 const char* s1 = "Hello";
5 std::string s2 = "World";
-> 6 return s1 + s2 + std::to_string(x);
7 }
8
9 int main() {
(lldb) p x
(int) $0 = 0
(lldb) p s1
(WebAssemblyPtrWrapper) $1 = (__ptr = 0)
(lldb) p s2
(std::__2::string) $2 = {}
```

Any hints?

P.S. I'm doing all the experiments on Linux.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.