Debian Codegraph @

third_party/rust/minidump-writer/README.md

raw
1 <div align="center">
2
3 # `minidump-writer`
4
5 **Rust rewrite of Breakpad's minidump_writer (client)**
6
7 [![Rust CI](https://github.com/rust-minidump/minidump-writer/actions/workflows/ci.yml/badge.svg)](https://github.com/rust-minidump/minidump-writer/actions/workflows/ci.yml)
8 [![crates.io](https://img.shields.io/crates/v/minidump-writer.svg)](https://crates.io/crates/minidump-writer)
9 [![docs.rs](https://docs.rs/minidump-writer/badge.svg)](https://docs.rs/minidump-writer)
10
11 </div>
12
13 This project is currently being very actively brought up from nothing, and is really ultimately many separate client implementations for different platforms.
14
15 ## Usage / Examples
16
17 The primary use case of this crate is for creating a minidump for an **external** process (ie a process other than the one that writes the minidump) as writing minidumps from within a crashing process is inherently unreliable. That being said, there are scenarios where creating a minidump can be useful outside of a crash scenario thus each supported platforms has a way to generate a minidump for a local process as well.
18
19 For more information on how to dump an external process you can check out the documentation or code for the [minidumper](https://docs.rs/minidumper/latest/minidumper/) crate.
20
21 ### Linux
22
23 #### Local process
24
25 The Linux implementation uses ptrace to gather information about the process when writing a minidump for it, which cannot be done from the process itself. It's possible to clone the process and dump the current process from that clone, but that's out of scope for an example.
26
27 #### External process
28
29 ```rust
30 fn write_minidump(crash_context: crash_context::CrashContext) {
31 // At a minimum, the crashdump writer needs to know the process and thread that the crash occurred in
32 let mut writer = minidump_writer::minidump_writer::MinidumpWriter::new(crash_context.pid, crash_context.tid);
33
34 // If provided with a full [crash_context::CrashContext](https://docs.rs/crash-context/latest/crash_context/struct.CrashContext.html),
35 // the crash will contain more info on the crash cause, such as the signal
36 writer.set_crash_context(minidump_writer::crash_context::CrashContext { inner: crash_context });
37
38 // Here we could add more context or modify how the minidump is written, eg
39 // Add application specific memory blocks to the minidump
40 //writer.set_app_memory()
41 // Sanitize stack memory before it is written to the minidump by replacing
42 // non-pointer values with a sentinel value
43 //writer.sanitize_stack();
44
45 let mut minidump_file = std::fs::File::create("example_dump.mdmp").expect("failed to create file");
46 writer.dump(&mut minidump_file).expect("failed to write minidump");
47 }
48 ```
49
50 ### Windows
51
52 #### Local process
53
54 ```rust
55 fn write_minidump() {
56 let mut minidump_file = std::fs::File::create("example_dump.mdmp").expect("failed to create file");
57
58 // Attempts to the write the minidump
59 minidump_writer::minidump_writer::MinidumpWriter::dump_local_context(
60 // The exception code, presumably one of STATUS_*. Defaults to STATUS_NONCONTINUABLE_EXCEPTION if not specified
61 None,
62 // If not specified, uses the current thread as the "crashing" thread,
63 // so this is equivalent to passing `None`, but it could be any thread
64 // in the process
65 Some(unsafe { windows_sys::Win32::System::Threading::GetCurrentThreadId() }),
66 &mut minidump_file,
67 ).expect("failed to write minidump");;
68 }
69 ```
70
71 #### External process
72
73 ```rust
74 fn write_minidump(crash_context: crash_context::CrashContext) {
75 use std::io::{Read, Seek};
76
77 // Create the file to write the minidump to. Unlike MacOS and Linux, the
78 // system call used to write the minidump only supports outputting to a file
79 let mut minidump_file = std::fs::File::create("example_dump.mdmp").expect("failed to create file");
80 // Attempts to the write the minidump for the crash context
81 minidump_writer::minidump_writer::MinidumpWriter::dump_crash_context(crash_context, &mut minidump_file).expect("failed to write minidump");;
82
83 let mut minidump_contents = Vec::with_capacity(minidump_file.stream_position().expect("failed to get stream length") as usize);
84 minidump_file.rewind().expect("failed to rewind minidump file");
85
86 minidump_file.read_to_end(&mut minidump_contents).expect("failed to read minidump");
87 }
88 ```
89
90 ### MacOS
91
92 #### Local process
93
94 ```rust
95 fn write_minidump() {
96 // Defaults to dumping the current process and thread.
97 let mut writer = minidump_writer::minidump_writer::MinidumpWriter::new(None, None)?;
98
99 let mut minidump_file = std::fs::File::create("example_dump.mdmp").expect("failed to create file");
100 writer.dump(&mut minidump_file).expect("failed to write minidump");
101 }
102 ```
103
104 #### External process
105
106 ```rust
107 fn write_minidump(crash_context: crash_context::CrashContext) {
108 let mut writer = minidump_writer::minidump_writer::MinidumpWriter::with_crash_context(crash_context)?;
109
110 let mut minidump_file = std::fs::File::create("example_dump.mdmp").expect("failed to create file");
111 writer.dump(&mut minidump_file).expect("failed to write minidump");
112 }
113 ```
114
115 ## Client Statuses
116
117 - ✅ Usable, but care should be taken in production environments
118 - ⚠️ Implemented (ie compiles), but untested and needs more work to be usable
119 - ⭕️ Unimplemented, but could be implemented in the future
120 - ❌ Unimplemented, and unlikely to ever be implemented
121
122 | Arch | unknown-linux-gnu | unknown-linux-musl | linux-android | pc-windows-msvc | apple-darwin | apple-ios |
123 ----------- | ----------------- | ------------------ | ------------- | --------------- | ------------ | --------- |
124 `x86_64` | ✅ | ✅ | ⚠️ | ✅ | ✅ | ⭕️ |
125 `i686` | ✅ | ✅ | ❌ | ⭕️ | ❌ | ❌ |
126 `arm` | ⚠️ | ⚠️ | ⚠️ | ⭕️ | ❌ | ❌ |
127 `aarch64` | ⚠️ | ⚠️ | ⚠️ | ⭕️ | ✅ | ⭕️ |
128 `mips` | ⭕️ | ⭕️ | ❌ | ❌ | ❌ | ❌ |
129 `mips64` | ⭕️ | ⭕️ | ❌ | ❌ | ❌ | ❌ |
130 `powerpc` | ⭕️ | ⭕️ | ❌ | ❌ | ❌ | ❌ |
131 `powerpc64` | ⭕️ | ⭕️ | ❌ | ❌ | ❌ | ❌ |