wasmtime icon indicating copy to clipboard operation
wasmtime copied to clipboard

Question regarding wasmtime AOT code panic debugging

Open wilsonwang371 opened this issue 3 years ago • 1 comments

Hi all,

I was running AOT code using wasmtime. However, my code generated a HeapOutOfBound trap and I need to find the root cause of this issue.

Currently, all that I can get is the AOT module & function line numbers information from which I can find out the original wasm module offset. However, I could not extract any more useful information. Is there any tips or suggestions about how to get more information out of the WASM state at the time of the trap?

Thanks

wilsonwang371 avatar Aug 09 '22 04:08 wilsonwang371

Whether or not the *.wasm is AOT compiled in theory shouldn't matter here. Wasmtime should be able to report the WebAssembly file offset of the trapping instruction, and if the original source module is compiled with debuginfo enabled in the *.wasm (this is distinct from debuginfo support in Wasmtime which is different) then Wasmtime should also print a backtrace on the trap with filenames/line numbers.

If you're not seeing this, though, could you compile the original *.wasm file with debug information?

alexcrichton avatar Aug 09 '22 14:08 alexcrichton

Whether or not the *.wasm is AOT compiled in theory shouldn't matter here. Wasmtime should be able to report the WebAssembly file offset of the trapping instruction, and if the original source module is compiled with debuginfo enabled in the *.wasm (this is distinct from debuginfo support in Wasmtime which is different) then Wasmtime should also print a backtrace on the trap with filenames/line numbers.

If you're not seeing this, though, could you compile the original *.wasm file with debug information?

Hi Alex, thanks for reply. I found where the issue is. But I need to access the VM state(example, the stack top pointer and other related data values) to get a better understanding of why it is happening. Is there any way or is there any example code for me to follow?

Thanks

wilsonwang371 avatar Aug 10 '22 18:08 wilsonwang371

Do you mean the native stack pointer (this is stored in the same register as always), the emulated stack pointer of the wasm module (stored in a wasm global, which you can access through the vmcontext, which in turn is the last argument for function calls) or something else?

bjorn3 avatar Aug 10 '22 19:08 bjorn3

Do you mean the native stack pointer (this is stored in the same register as always), the emulated stack pointer of the wasm module (stored in a wasm global, which you can access through the vmcontext, which in turn is the last argument for function calls) or something else?

I mean the emulated stack pointer of wasm module. Yes. The vmcontext. How do i print them? Can you point out the place of the code that can help me print out the wasm module vmcontext when trap happens?

wilsonwang371 avatar Aug 11 '22 06:08 wilsonwang371

We don't currently generate debuginfo for this AFAIK, so you will have to manually locate where the vmcontext pointer is stored and at what offset in the vmcontext the global value is stored I think.

bjorn3 avatar Aug 11 '22 07:08 bjorn3