lei-april opened Issue #1896:
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:
#include <string> 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), coupled with prebuilt wasi-sysroot from 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) 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<const char>) $1 = (__ptr = 0) (lldb) p s2 (std::__2::string) $2 = {}
Any hints?
lei-april edited Issue #1896:
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:
#include <string> 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), coupled with prebuilt wasi-sysroot from 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) 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<const char>) $1 = (__ptr = 0) (lldb) p s2 (std::__2::string) $2 = {}
Any hints?
P.S. I'm doing all the experiments on Linux.
yurydelendik commented on Issue #1896:
hen I use lldb (8.0.1) and a freshly built wasmtime (commit) to debug it.
At this moment recommended debuggers lldb-10 and gdb for various reasons/issues.
(WebAssemblyPtrWrapper<const char>) $1 = (__ptr = 0)
The wasm pointer is not really a pointer in computer memory that can be accessed. You may check https://github.com/bytecodealliance/wasmtime/pull/1482 on how to use helpers to unwrap wasm pointers in a debugger.
(WebAssemblyPtrWrapper<const char>) $1 = (__ptr = 0)
Not sure why
s1
points to the memory offset 0. Did you try debugging non-optimized-O0
wasm?
yurydelendik edited a comment on Issue #1896:
hen I use lldb (8.0.1) and a freshly built wasmtime (commit) to debug it.
At this moment recommended debuggers lldb-10 and gdb for various reasons/issues.
(WebAssemblyPtrWrapper<const char>) $1 = (__ptr = 0)
The wasm pointer is not really a pointer in computer memory that can be accessed. You may check https://github.com/bytecodealliance/wasmtime/pull/1482 on how to use helpers to unwrap wasm pointers in a debugger.
Not sure why
s1
points to the memory offset 0. Did you try debugging non-optimized-O0
wasm?
yurydelendik commented on Issue #1896:
Okay, I just check that with or without optimization -- the issue is the same.
yurydelendik assigned Issue #1896:
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:
#include <string> 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), coupled with prebuilt wasi-sysroot from 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) 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<const char>) $1 = (__ptr = 0) (lldb) p s2 (std::__2::string) $2 = {}
Any hints?
P.S. I'm doing all the experiments on Linux.
lei-april commented on Issue #1896:
Thanks for you reply :) @yurydelendik
At this moment recommended debuggers lldb-10 and gdb for various reasons/issues.
I retried the previous experiment with lldb 11.0.0 (freshly built) and gdb 8.2, respectively. Here are the results:
lldb
Process 101273 stopped * thread #1, name = 'wasmtime', stop reason = step over frame #0: 0x00007ffff7fcf5af JIT(0x5555562ef450)`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<const char>) $1 = (__ptr = 0) (lldb) p s2 (std::string) $2 = Summary Unavailable
gdb
Thread 1 "wasmtime" hit Breakpoint 1, hello (x=0) at t.cc:4 4 const char* s1 = "Hello"; (gdb) n 5 std::string s2 = "World"; (gdb) n 6 return s1 + s2 + std::to_string(x); (gdb) p x $1 = 0 (gdb) p s1 $2 = {__ptr = 0} (gdb) p s2 $3 = <incomplete type>
It seems switching debugger version doesn't help much.
The wasm pointer is not really a pointer in computer memory that can be accessed. You may check #1482 on how to use helpers to unwrap wasm pointers in a debugger.
Cool. I'll give it a try.
yurydelendik commented on Issue #1896:
I looked at the issue. There are at least two problems:
- [ ]
TODO
related to reference types (specific to C++) at https://github.com/bytecodealliance/wasmtime/blob/master/crates/debug/src/transform/unit.rs#L398- [ ] There is an issue with CL value tracking, which is a cause for wrong location in DWARF
@lei-april you can also turn off option at CL via
--opt-level 0
I will try to address the above issues soon.
lei-april commented on Issue #1896:
you can also turn off option at CL via --opt-level 0
Thanks. This does help :)
The result looks better now (with lldb 11.0.0):
Process 76848 stopped * thread #1, name = 'wasmtime', stop reason = step over frame #0: 0x00007ffff7fc369e JIT(0x55555639a690)`hello(x=12345) 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 = 12345 (lldb) p s1 (WebAssemblyPtrWrapper<const char>) $1 = (__ptr = 1024) (lldb) p s2 (std::string) $2 = Summary Unavailable
yurydelendik commented on Issue #1896:
(std::string) $2 = Summary Unavailable
C++ types with reference types in them will likely fail due to TODO mentioned above.
yurydelendik labeled Issue #1896 (assigned to yurydelendik):
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:
#include <string> 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), coupled with prebuilt wasi-sysroot from 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) 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<const char>) $1 = (__ptr = 0) (lldb) p s2 (std::__2::string) $2 = {}
Any hints?
P.S. I'm doing all the experiments on Linux.
Last updated: Dec 23 2024 at 12:05 UTC