bolts: support dump_registers for x86 linux (#1694)

* bolts: support dump_registers for x86 linux

* bolts: fix write_crash fault addr for linux/x86
This commit is contained in:
Mrmaxmeier 2023-11-26 16:39:16 +01:00 committed by GitHub
parent bd12e060ca
commit 84a87f1da8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -50,6 +50,33 @@ pub fn dump_registers<W: Write>(
Ok(()) Ok(())
} }
/// Write the content of all important registers
#[cfg(all(any(target_os = "linux", target_os = "android"), target_arch = "x86"))]
#[allow(clippy::similar_names)]
pub fn dump_registers<W: Write>(
writer: &mut BufWriter<W>,
ucontext: &ucontext_t,
) -> Result<(), std::io::Error> {
use libc::{
REG_EAX, REG_EBP, REG_EBX, REG_ECX, REG_EDI, REG_EDX, REG_EFL, REG_EIP, REG_ESI, REG_ESP,
};
let mcontext = &ucontext.uc_mcontext;
write!(writer, "eax: {:#016x}, ", mcontext.gregs[REG_EAX as usize])?;
write!(writer, "ebx: {:#016x}, ", mcontext.gregs[REG_EBX as usize])?;
write!(writer, "ecx: {:#016x}, ", mcontext.gregs[REG_ECX as usize])?;
writeln!(writer, "edx: {:#016x}, ", mcontext.gregs[REG_EDX as usize])?;
write!(writer, "edi: {:#016x}, ", mcontext.gregs[REG_EDI as usize])?;
write!(writer, "esi: {:#016x}, ", mcontext.gregs[REG_ESI as usize])?;
write!(writer, "esp: {:#016x}, ", mcontext.gregs[REG_ESP as usize])?;
writeln!(writer, "ebp: {:#016x}, ", mcontext.gregs[REG_EBP as usize])?;
write!(writer, "eip: {:#016x}, ", mcontext.gregs[REG_EIP as usize])?;
writeln!(writer, "efl: {:#016x}, ", mcontext.gregs[REG_EFL as usize])?;
Ok(())
}
/// Write the content of all important registers /// Write the content of all important registers
#[cfg(all( #[cfg(all(
any(target_os = "linux", target_os = "android"), any(target_os = "linux", target_os = "android"),
@ -478,7 +505,7 @@ fn write_crash<W: Write>(
"Received signal {} at {:#08x}, fault address: {:#08x}", "Received signal {} at {:#08x}, fault address: {:#08x}",
signal, signal,
ucontext.uc_mcontext.gregs[libc::REG_EIP as usize], ucontext.uc_mcontext.gregs[libc::REG_EIP as usize],
ucontext.uc_mcontext.gregs[libc::REG_ERR as usize] ucontext.uc_mcontext.cr2
)?; )?;
Ok(()) Ok(())