wasmtime icon indicating copy to clipboard operation
wasmtime copied to clipboard

Debugger helper for JIT code

Open yurydelendik opened this issue 5 years ago • 6 comments

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

yurydelendik avatar May 18 '20 18:05 yurydelendik

Subscribe to Label Action

cc @peterhuene

This issue or pull request has been labeled: "wasmtime:api"

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.

Learn more.

github-actions[bot] avatar May 18 '20 19:05 github-actions[bot]

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
...

yurydelendik avatar Aug 18 '20 19:08 yurydelendik

cc: @jlb6740

abrown avatar Aug 18 '20 20:08 abrown

@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?

jlb6740 avatar Aug 18 '20 22:08 jlb6740

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.

yurydelendik avatar Aug 18 '20 22:08 yurydelendik

rebased LLVM D78801 at https://github.com/yurydelendik/llvm-project/tree/D78801

yurydelendik avatar Sep 11 '20 15:09 yurydelendik

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.

alexcrichton avatar Mar 01 '24 19:03 alexcrichton