-
Notifications
You must be signed in to change notification settings - Fork 307
Add Wasm coredump
builder
#1461
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
I also have a few simple smoke tests but they use third-party std dependencies, so I decided to not bring them into wasmi. #[cfg(test)]
mod tests {
use crate::*;
#[test]
fn test_write_u64() {
use super::write_u64;
for x in &[0u64, 1, 2, 3, 4, 10, 21, 49, 1033, 1231245, u64::MAX] {
let mut act = Vec::new();
write_u64(&mut act, *x);
let mut exp = Vec::new();
leb128::write::unsigned(&mut exp, *x).unwrap();
assert_eq!(act, exp);
}
}
#[test]
fn test_serialize() {
let frame = Frame {
func_idx: 6,
code_offset: 123,
};
let thread = Thread {
name: "main",
frames: &[frame],
};
let proc = Process {
name: "/usr/bin/true.exe",
threads: &[thread],
memories: &[Memory { min: 0, max: None }],
data: &[],
};
let mut act = Vec::new();
serialize(&mut act, &proc);
use wasm_coredump_builder::*;
let mut coredump = CoredumpBuilder::new().executable_name("/usr/bin/true.exe");
let mut thread = ThreadBuilder::new().thread_name("main");
let frame = FrameBuilder::new().codeoffset(123).funcidx(6).build();
thread.add_frame(frame);
coredump.add_thread(thread.build());
let exp = coredump.serialize().unwrap();
assert_eq!(act, exp);
}
} |
Also, clippy naturally fails because the code I've added is unused. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1461 +/- ##
==========================================
- Coverage 71.40% 71.06% -0.34%
==========================================
Files 162 163 +1
Lines 16420 16502 +82
==========================================
+ Hits 11724 11727 +3
- Misses 4696 4775 +79 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
What is the difference between this PR and what |
@orsinium thanks a lot for your PR! All in all this PR still needs some work before we can merge. How willing are you to do this? Otherwise I could drive this to finalization. The main question is how users would interact with this feature via Wasmi's API and what the performance implications are (if any) if enabled. I suppose this serializes to this encoding: |
I'd be happy to properly integrate it with wasmi but it's a big project and I don't know where to start. I hoped that
I've added no_std support into wasm_coredump_builder but it still depends on leb128 which requires std. I tried to add no_std support there as well but they don't want to depend on embedded_io for std, and doing it that way would require so much work: So, when I started to dig into both crates, I learned that they don't really do much. So, here is a simple implementation, without std or any dependencies. If you don't want to maintain it as part of wasmi, I can release it as a separate crate.
My preferred API would be
Yes! It's pretty much a wasm file with some custom sections. |
Concerning your implementation questions: Wasmi does not really store a mapping of the actual functions on the call stack for performance reasons. However, with the information that you can find on the call stack it is possible to compute this information and create the backtrace. This will be slow but having a trap + backtrace situation usually is not a case that needs to be optimized for anyways as long as the backtrace eventually is created, right? Here are the important parts of the Wasmi executor:
As you can see, adding backtrace support to Wasmi's executor is somewhat of a mess since Wasmi's executor is highly optimized for execution and nothing else. |
We don't need the function name. All we need is the function index and the instruction index within the function. That's it, that's all we put in coredump. The function name, function signature, line of code etc are inferred by a third-party coredump inspector based on dwarf files or other debug info. It would be helpful to have values of locals and the call stack as well but it's totally fine to keep it out of PoC. |
|
Concerning user facing API of how to get the Wasm coredump, I think we should simply do what Wasmtime does and embed |
Implements #538.
This is the first step to adding support for coredumps. The PR introduces a
wasmi::coredump
module withserialize
function. The function can be used to serialize the given process info as coredump. For example:The provided code is not used anywhere just yet.
Related to #538