wasmtime
wasmtime copied to clipboard
Debugger helper for JIT code
In this PR:
- Defines helpers to set trap instructions in JIT'ed code
- Code breakpoint and stepping support
- Pilot code
WIP can be run via cargo run tests/all/debug/testsuite/fib-wasm.wasm --invoke fib 4
cc @alexcrichton @fitzgen
TODO:
- [ ] Define scope of this PR
- [ ] Address threading concerns
Subscribe to Label Action
cc @peterhuene
Thus the following users have been cc'd because of the following labels:
- peterhuene: wasmtime:api
To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file.
Run example/server as RUST_LOG="gdb_remote_protocol=trace,wasmtime_cli=trace" cargo run -- tests/all/debug/testsuite/fib-wasm.wasm --gdb-server --opt-level 0 --invoke fib 5
Connect using LLDB (version as in https://reviews.llvm.org/D78801):
(lldb) wasm 22334
Process 1 stopped
* thread #1, stop reason = signal SIGTRAP
frame #0: 0x200000022 module-2.wasm
-> 0x200000022: call 0
0x200000024: end
(lldb) b 0x1000000af
Breakpoint 1: where = module-1.wasm`fib + 109 at fib-wasm.c:11:9, address = 0x1000000af
(lldb) c
Process 1 resuming
Process 1 stopped
* thread #1, stop reason = breakpoint 1.1
frame #0: 0x1000000af module-1.wasm`fib(n=0) at fib-wasm.c:11:9
8 int fib(int n) {
9 int t, a = 0, b = 1;
10 for (int i = 0; i < n; i++) {
-> 11 t = a;
12 a = b;
13 b += t;
14 }
(lldb) s
...
cc: @jlb6740
@abrown Thanks. I've actually used debugging support before based on a gist from @yurydelendik (https://gist.github.com/yurydelendik/4103d782dfc62634bc9f4de98de20835). How does this PR relate to that existing support which allowed breaking and stepping in jitted code with lldb?
How does this PR relate to that existing support which allowed breaking and stepping in jitted code with lldb?
@jlb6740 that is different in terms of now you don't need to transform the DWARF since debuggers have to understand WebAssembly target (see referred above LLVM's patch). In this case, the VM has to provide direct access to wasm-level locals, memory, stack.
rebased LLVM D78801 at https://github.com/yurydelendik/llvm-project/tree/D78801
Going through some old PRs this one is definitely quite old at this time. Lots of time has passed and lots of stuff has changed in the meantime, so I'm going to close this as a result. Nowadays debugging is still an active topic of exploration and the debugging SIG is probably a good place to continue this discussion.