FluffyLabs / FluffyLabs/pvm-debugger-old
Support debug symbols from PolkaVM container format
- Dominant language
- TypeScript
- Stars
- 17
- Forks
- 3
- PR merge metrics
- No merged PRs in 30d
Description
> 3\. Supporting debug info would be amazing, I'd say that if the tool proves to be useful we would be happy to take a shot at implementing that support. We lack a bit of knowledge and experience on this one though, so any pointers would be great.
In general the easiest thing here would most likely be to piggyback on PolkaVM's crates compiled to WASM (at very least until I can get the PolkaVM program blob format somewhat standardized like it is for WASM).
The main two types of interest are [`ProgramBlob`](https://docs.rs/polkavm/0.11.0/polkavm/struct.ProgramBlob.html) and [`ProgramParts`](https://docs.rs/polkavm/0.11.0/polkavm/struct.ProgramParts.html). These are, essentially, mostly equivalent, except a `ProgramParts` is just a `ProgramBlob` split into parts.
So, the bare minimum to do to be able to load PolkaVM blobs would be something like this:
```rust
#[wasm_bindgen]
pub fn polkavm_to_code_blob(raw_blob: Vec) -> Vec {
let parts = polkavm::ProgramParts::from_bytes(&raw_blob).unwrap();
return parts.code_and_jump_table.to_vec();
}
```
This will give you a raw PVM code blob which you can already ingest.
Now, to get debug info working you'd have to use `ProgramBlob::parse` or `ProgramBlob::from_parts` to create a `ProgramBlob`, keep the `ProgramBlob` around, and then you can use [`get_debug_line_program`](https://docs.rs/polkavm/0.11.0/polkavm/struct.ProgramBlob.html#method.get_debug_line_program_at). You give the function a program counter/byte offset into the code, and it will return you an iterator which produces [`FrameInfo`](https://docs.rs/polkavm/0.11.0/polkavm/debug_info/struct.FrameInfo.html) structs, which in turn tell you the function name and/or the source path/line of where the given piece of code comes from. (So if you'd display the source code side-by-side you can use this to make a source-level debugger.)
Currently the debug info support is limited to being able to extract the locations of the code in the original sources, but I'm also planning to add support for getting backtraces and also for reading/writing to local variables, etc. (Basically I want to support full blown rich debugging experience.)
_Originally posted by @koute in https://github.com/FluffyLabs/typeberry-toolkit/issues/81#issuecomment-2306710054_
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.