risc0 icon indicating copy to clipboard operation
risc0 copied to clipboard

Enable debugger for guest environments

Open flaub opened this issue 3 years ago • 11 comments

flaub avatar May 25 '22 18:05 flaub

This branch contains an attempt to use the gdb-stub library. It's best to hold off on this until parts of preflight and/or continuations are implemented

SchmErik avatar Jan 05 '23 22:01 SchmErik

Since GDB adds support to Microsoft's debug adapter protocol, maybe an alternative path is to integrate with this. https://www.phoronix.com/news/GDB-Debug-Adapter-Protocol

I can see that it has been held off. I would try on my side a bit to see if a minimal remote debugger can be implemented for https://github.com/weikengchen/zkctf-r0.

weikengchen avatar Nov 26 '23 04:11 weikengchen

Ok I am back to the team of gdb-stub. The key is to avoid reinventing the wheels for RISC-V GDB support.

weikengchen avatar Nov 26 '23 17:11 weikengchen

Hello guys, how is this issue progressing? I am really looking forward to the debugger feature, as it can save lives(without print! or gdb! and re-compile). I can assist with this work.

dyxushuai avatar Jan 30 '24 09:01 dyxushuai

@dyxushuai check this https://github.com/l2iterative/gdb0

weikengchen avatar Jan 30 '24 09:01 weikengchen

@dyxushuai check this l2iterative/gdb0

Great job!

What about lldb support for Rust? It could be more convenient for llvm based langauges. We can integrate with wasm origin guest rust code in a wasm-vm briefly using the vscode extension vscode-lldb without any modification.

image

But additionally, we need to use dwarf instead of fp. However, rust has good support for dwarf.

dyxushuai avatar Jan 30 '24 10:01 dyxushuai

@dyxushuai check this l2iterative/gdb0

Great job!

What about lldb support for Rust? It could be more convenient for llvm based langauges. We can integrate with wasm origin guest rust code in a wasm-vm briefly using the vscode extension vscode-lldb without any modification.

image But additionally, we need to use `dwarf` instead of `fp`. However, rust has good support for `dwarf`.

And, I think we only need very little work to achieve such results in risc0-vm. I am verifying this POC with some simple code locally.

dyxushuai avatar Jan 30 '24 11:01 dyxushuai

current lldb version appears to not support RISC-V

weikengchen avatar Jan 30 '24 12:01 weikengchen

current lldb version appears to not support RISC-V

Yeah, riscv ABI was fully supported only recently in llvm^1, I have noticed that some projects have already worked with riscv-32. Like: https://github.com/compnerd/ds2. Therefore, I believe we can support lldb in risc0. However, you must use a very new version of lldb to be able to use it.

dyxushuai avatar Jan 30 '24 14:01 dyxushuai

That would be something that I need to revisit.

Nevertheless, there is yet another challenge. LLDB remote debugger has some different behaviors from GDB. The Rust crate, gdb-stub, only supports GDB, and appears to be struggling with LLDB. It is uncertain if the issue has been fixed.

So if you encounter weird behaviors like LLDB is single-stepping in a non-stoppable way, it is known and has been a few years.

weikengchen avatar Jan 31 '24 10:01 weikengchen

@weikengchen thanks for your work! I tried implementing this a few months ago and encountered an error in gdbstub saying that it got an error from the version of gdb that I was using so I really appreciate the notes you wrote down (note, i'm using arm macos).

SchmErik avatar Feb 01 '24 23:02 SchmErik