Debian Codegraph @

third_party/rust/minidump/README.md

raw
1 # minidump
2
3 [![crates.io](https://img.shields.io/crates/v/minidump.svg)](https://crates.io/crates/minidump) [![](https://docs.rs/minidump/badge.svg)](https://docs.rs/minidump)
4
5 Basic parsing of the minidump format.
6
7 If you want richer analysis of the minidump (such as stackwalking and symbolication), use [minidump-processor](https://crates.io/crates/minidump-processor).
8
9
10 # Usage
11
12 The primary API for this library is the `Minidump` struct, which can be
13 instantiated by calling the `Minidump::read` or `Minidump::read_path` methods.
14
15 Succesfully parsing a Minidump struct means the minidump has a minimally valid
16 header and stream directory. Individual streams are only parsed when they're
17 requested.
18
19 Although you may enumerate the streams in a minidump with methods like
20 `Minidump::all_streams`, this is only really useful for debugging. Instead
21 you should statically request streams with `Minidump::get_stream`.
22
23 Depending on what analysis you're trying to perform, you may:
24
25 * Consider it an error for a stream to be missing (using `?` or `unwrap`)
26 * Branch on the presence of stream to conditionally refine your analysis
27 * Use a stream's `Default` implementation to get an "empty" instance
28 (with `unwrap_or_default`)
29
30 ```rust
31 use minidump::*;
32
33 fn main() -> Result<(), Error> {
34 // Read the minidump from a file
35 let mut dump = minidump::Minidump::read_path("../testdata/test.dmp")?;
36
37 // Statically request (and require) several streams we care about:
38 let system_info = dump.get_stream::<MinidumpSystemInfo>()?;
39 let exception = dump.get_stream::<MinidumpException>()?;
40
41 // Combine the contents of the streams to perform more refined analysis
42 let crash_reason = exception.get_crash_reason(system_info.os, system_info.cpu);
43
44 // Conditionally analyze a stream
45 if let Ok(threads) = dump.get_stream::<MinidumpThreadList>() {
46 // Use `Default` to try to make progress when a stream is missing.
47 // This is especially natural for MinidumpMemoryList because
48 // everything needs to handle memory lookups failing anyway.
49 let mem = dump.get_memory().unwrap_or_default();
50
51 for thread in &threads.threads {
52 let stack = thread.stack_memory(&mem);
53 // ...
54 }
55 }
56 Ok(())
57 }
58 ```