Hey :wave:
There is an issue with the emitted code, and I can't find what needs to change to make it work. It would help if I could run the output step by step and display registers, stack etc. Is it possible with lldb ? How can I add a breakpoint ?
Thanks :smile:
components or wasi p1?
if components: https://hachyderm.io/@squillace/112989210932769282
wasi p1
then that works even better:
whether in vscode or not, the magic invocation is https://github.com/squillace/hello-wasi-http/blob/ff567823aed4451142f31bd0a90b196d576fabf7/.vscode/launch.json#L11-L17
lemme know how that works for you, because IT IS NOT PERFECT
you can also use wamr debugger for wasi p1, but to do so I think you have to build llvm and lldb from scratch and apply a patch and then build the vscode extension... so, harder
Thank you, but my situation is a bit specific. I am working on winch, and dwarf has not been developed yet. Also, I don't have any source language, I just wrote the module in WAT
I have an llvm & lldb built from scratch on my machine, so I will try the wamr debugger
Ok, I can't debug the machine instructions emitted from another compiler with wamr. Thank you again for trying to help me
ah
yeah, that's interesting. It's almost like you need a debugger that steps through wat
or the binary wasm, rather
I think we'd need a wasm language server for that, which..... https://github.com/wasm-lsp/wasm-lsp-server is archived, so... hmmm.
Geez, that would be helpful to have.
Yeah it would be cool, but I actually don't need source code mapping or any debug info at all. I just want to run the machine code (arm) step by step
image.png
I think it is possible because if I introduce a memory error, it actually stops in the guest code. I just don't know how to add a proper breakpoint
actually, I think we might be able to make one that does this fairly easily.....
if you use vscode, there's something called a "mock-debug" extension that implements step-by-step walkthrough using markdown. Functionally speaking, that could easily be modified to walk over WAT
Vulcain said:
image.png
I think it is possible because if I introduce a memory error, it actually stops in the guest code. I just don't know how to add a proper breakpoint
oh wait, that's lldb
dammit, I've done this....
Yes, but there is no file, I am trying to debug the arm code emitted by the winch compiler
I was thinking the arm code was a text format, but if it's not, yeah -- you're sol there
Thank you again for trying !
https://marketplace.visualstudio.com/items?itemName=Arm.arm-debugger ?????
I have no way to tell this extension where to add the breakpoint as the code does not exist before execution :oh_no:
it would need to be run once the code is laid down so that sounds like an attach?
at execution time, is the code just held in memory? not on the disk once created?
I doubt I have a solution, just trying to imagine what one could look like.
I think so, but this is not a part of the codebase I am familiar with
I can compile AOT, but I don't think the debugger binds cwasm
My guess is it adds the generated code to the heap and jump to this address to execute the code. If it is what is happening, then I have to breakpoint this place. I don't know where it is though
@Vulcain if it helps, a technique that I've used to debug emitted-JIT-code issues is to insert artificial breakpoints (ud2
on Intel, udf
on aarch64) by just... emitting them in sequence in the JIT compiler. Then I run the whole wasmtime process under gdb/lldb; I hit the breakpoint in the code; and (at least in gdb) you can "jump" over the opcode ($pc+2
on Intel, $pc+4
on aarch64) and single-step from there
very low-level and manual technique but it lets you examine the whole machine state
A technique that I usually use with LLDB in macOS is to put a breakpoint in https://github.com/bytecodealliance/wasmtime/blob/main/crates/wasmtime/src/runtime/func.rs#L1073 (if you're invoking wasmtime from the CLI)
That should get you a debugger at where the function call starts. The complex thing about this approach is that you need to be familiar with how trampolines work in Wasmtime in order to navigate to the assembly of the Wasm function that you're trying to inspect.
separately, rr
(the reversible debugger) is extraordinarily useful for things like these -- Mozilla developed it originally to debug Firefox and its JITs -- and it has certain CPU requirements, on x86 requires recent Intel chips, but I think it also supports Apple aarch64 CPUs if you're running native Asahi Linux (if that applies)
Saúl Cabrera said:
A technique that I usually use with LLDB in macOS is to put a breakpoint in https://github.com/bytecodealliance/wasmtime/blob/main/crates/wasmtime/src/runtime/func.rs#L1073 (if you're invoking wasmtime from the CLI)
That should get you a debugger at where the function call starts. The complex thing about this approach is that you need to be familiar with how trampolines work in Wasmtime in order to navigate to the assembly of the Wasm function that you're trying to inspect.
That's the place I was looking for ! I will also try the udf technique, and take a look at rr
. Thank you both for the info :grinning:
Vulcain has marked this topic as resolved.
Last updated: Nov 22 2024 at 16:03 UTC