Investigate current state of guest debugging
Reportedly, wasmtime guest debugging has improved significantly over the past months. We should evaluate it for Spin and - if it's useful enough - consider enabling debug_info either by default or via spin up flag and documenting how to get it working for supported languages.
I had a brief and inexpert explore of this. My test case was setting a breakpoint by function name (on a function with #[no_mangle]). I'm no expert but the omens did not seem auspicious. Adding .debug_info(true) to our Wasmtime config did not magically Just Work. Looking further, what I found was:
- With
lldb-17 -- -- wasmtime run -D debug-info <file>:- It worked when
<file>was a WASI 0.1 module. The breakpoint, although not initially detected, did fire - I guess lldb hooked it up once I resumed execution and the Wasm file had loaded. - It did not work when
<file>was a component (WASI 0.2 command built withcargo component). The breakpoint was again not initially detected, but this time it did not fire as the function ran.
- It worked when
-
llvm-dwarfdump-17 <file>.wasmproduced output on the WASI 0.1 module (including my function name), but gacve an "invalid version number" error when run on a component. - I captured the component generated by Spin to wrap a module-based Spin app, and ran
llvm-dwarfdump-17over it: same error.
So my sense of the current situation is that module debugging works but component debugging is not there, and the latter prevents us from doing guest debugging in Spin for now.
That said, maybe there's a LLVM/LLDB extension that makes it work with the component model? I'm happy to try things further but right now my search skills aren't turning one up...
Asking @squillace to share some of his experience debugging Wasm with Wasmtime.
@itowlson is correct currently. lldb/gdb cannot catch breakpoints navigating components; the problem is that it's quite literally a new file type -- this is the same reason that Ivan notes that llvm-dwarfdump blows chunks. The fixes for this are in flight; but until that happens, you can't turn on debugging in spin and expect it to work with components. :-(
You should lay down the groundwork for this to "suddenly light up" when we teach wasmtime to leave debug symbols in the component modules and lldb to read component files. It won't be "long" but it will be a couple more months, methinks....