Stream: general

Topic: Debugging a WASM module


view this post on Zulip Coulson Liang (Jun 12 2024 at 19:40):

Hi currently is there a way to debug a WASM module, like tracing what's happening in the runtime user space.

view this post on Zulip Alex Crichton (Jun 12 2024 at 19:41):

One option is WASMTIME_LOG=wasmtime_wasi if you're using the wasmtime CLI, otherwise if you have your own embedding wasmtime-wasi-the-crate will emit log messages to tracing::trace!

view this post on Zulip Cheng Shao (Jun 12 2024 at 19:42):

if you're using node to run the wasm module there's --trace-wasm option that prints wasm function calls, you can find other similar options in node --v8-options

view this post on Zulip Coulson Liang (Jun 12 2024 at 19:43):

@Alex Crichton Is this tracing only the "syscalls" calling into the runtime, (the hostfunctions?)

view this post on Zulip Alex Crichton (Jun 12 2024 at 19:43):

Correct yeah, just the imports into wasi

view this post on Zulip Alex Crichton (Jun 12 2024 at 19:44):

Do you have your own embedding of Wasmtime, are you using the wasmtime CLI, or are you using another runtime entirely?

view this post on Zulip Coulson Liang (Jun 12 2024 at 19:46):

Oh yeah, I'm using Wasmer actually, and I'm trying debug what's happening in the user space. Since we compiled glibc to wasm, which is extremely complex, now we can hardly debug any error in the user space, while the syscalls are actually "sparse".

view this post on Zulip Alex Crichton (Jun 12 2024 at 19:47):

Ah ok, sorry I was making a wrong assumption. I fear I will not be of much help in this case

view this post on Zulip Coulson Liang (Jun 12 2024 at 19:52):

Oh that's fine, no worries. Is there any plan of the community to support debugging in the user space? Like a gdb for wasm

view this post on Zulip Chris Fallin (Jun 12 2024 at 20:00):

We do have very basic support for use of gdb in wasmtime (attach gdb to the host process)

view this post on Zulip Chris Fallin (Jun 12 2024 at 20:01):

We don't develop Wasmer here (that's made by a different company) so we unfortunately cannot answer any questions related to that

view this post on Zulip Joel Dice (Jun 12 2024 at 20:05):

Here's a link regarding Wasmtime's debug support: https://github.com/bytecodealliance/wasmtime/blob/main/docs/examples-debugging-native-debugger.md

A fast and secure runtime for WebAssembly. Contribute to bytecodealliance/wasmtime development by creating an account on GitHub.

view this post on Zulip Coulson Liang (Jun 12 2024 at 20:06):

@Chris Fallin Oh we don't really rely on Wasmer, we are a research group at NYU and we mainly work on porting glibc to wasm, we just use the runtime to expose a hostfunction that trivially relays syscalls to our own library OS. We can also move to wasmtime without much engineering overhead. But right now debugging the glibc inside a WASM runtime is our most imminent issue.

view this post on Zulip Coulson Liang (Jun 12 2024 at 20:08):

@Joel Dice Thank you! Trying to use this.

view this post on Zulip Ralph (Jun 13 2024 at 05:31):

lldb works pretty well in general, though some of the local types don't resolve, but you can mostly walk through. You can see me doing that here with the codelldb vscode extension and rust, c, c++ code bases using wasmtime; should work with any runtime, depending on what they use to project the dwarf into the module. YouTube - Nobody Knows the Trouble I've Seen: Debugging Wasm for web and server by N. Venditto & R. Squillace.

view this post on Zulip Ralph (Jun 13 2024 at 05:31):

if you're using components, you're out of luck at the moment.....

view this post on Zulip Ralph (Jun 13 2024 at 05:34):

have a look at https://github.com/squillace/c-wasm-debug/blob/8e97279bf5dd44e585da0080b1aad2299ae2a9d9/.vscode/launch.json#L12-L19 for an example lldb invocation.

Contribute to squillace/c-wasm-debug development by creating an account on GitHub.

view this post on Zulip Ralph (Jun 13 2024 at 05:46):

Not sure that repo still works, but the configuration is correct whether you use vscode or not.

view this post on Zulip Alex Crichton (Jun 13 2024 at 14:43):

Ralph said:

if you're using components, you're out of luck at the moment.....

Oh I'll note that this changed in https://github.com/bytecodealliance/wasmtime/pull/8693 and components + lldb should be supported now

This commit updates the native-DWARF processing (the -D debug-info CLI flag) to support components. Previously component support was not implemented and if there was more than one core wasm module ...

view this post on Zulip Coulson Liang (Jun 13 2024 at 17:29):

Yeah yeah, we just tried gdb with wasmtime + wasi-libc, that's really amazing. Just note that, we shouldn't attempt any interaction with instructions, like si, which will break the gbd. Other than this, things works really well.

view this post on Zulip Coulson Liang (Jun 13 2024 at 17:29):

Thank you guys!

view this post on Zulip Ralph (Jun 17 2024 at 08:05):

Alex Crichton said:

Ralph said:

if you're using components, you're out of luck at the moment.....

Oh I'll note that this changed in https://github.com/bytecodealliance/wasmtime/pull/8693 and components + lldb should be supported now

wait WUT you people are AMAZING --- off to test...


Last updated: Oct 23 2024 at 20:03 UTC