| 1 |
use super::minidump_writer::CrashingThreadContext; |
| 2 |
use super::*; |
| 3 |
use minidump_common::errors::ExceptionCodeLinux; |
| 4 |
|
| 5 |
pub fn write( |
| 6 |
config: &mut MinidumpWriter, |
| 7 |
buffer: &mut DumpBuf, |
| 8 |
) -> Result<MDRawDirectory, errors::SectionExceptionStreamError> { |
| 9 |
let exception = if let Some(context) = &config.crash_context { |
| 10 |
MDException { |
| 11 |
exception_code: context.inner.siginfo.ssi_signo, |
| 12 |
exception_flags: context.inner.siginfo.ssi_code as u32, |
| 13 |
exception_address: context.inner.siginfo.ssi_addr, |
| 14 |
..Default::default() |
| 15 |
} |
| 16 |
} else { |
| 17 |
let addr = match &config.crashing_thread_context { |
| 18 |
CrashingThreadContext::CrashContextPlusAddress((_, addr)) => *addr, |
| 19 |
_ => 0, |
| 20 |
}; |
| 21 |
MDException { |
| 22 |
exception_code: ExceptionCodeLinux::DUMP_REQUESTED as u32, |
| 23 |
exception_address: addr as u64, |
| 24 |
..Default::default() |
| 25 |
} |
| 26 |
}; |
| 27 |
|
| 28 |
let thread_context = match config.crashing_thread_context { |
| 29 |
CrashingThreadContext::CrashContextPlusAddress((ctx, _)) |
| 30 |
| CrashingThreadContext::CrashContext(ctx) => ctx, |
| 31 |
CrashingThreadContext::None => MDLocationDescriptor { |
| 32 |
data_size: 0, |
| 33 |
rva: 0, |
| 34 |
}, |
| 35 |
}; |
| 36 |
|
| 37 |
let stream = MDRawExceptionStream { |
| 38 |
thread_id: config.blamed_thread as u32, |
| 39 |
exception_record: exception, |
| 40 |
__align: 0, |
| 41 |
thread_context, |
| 42 |
}; |
| 43 |
let exc = MemoryWriter::alloc_with_val(buffer, stream)?; |
| 44 |
let dirent = MDRawDirectory { |
| 45 |
stream_type: MDStreamType::ExceptionStream as u32, |
| 46 |
location: exc.location(), |
| 47 |
}; |
| 48 |
|
| 49 |
Ok(dirent) |
| 50 |
} |