Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake-Shadle committed Oct 13, 2023
1 parent b2d0562 commit 8ac914f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 11 deletions.
9 changes: 9 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[target.'cfg(all(target_os = "linux", target_arch = "x86_64"))']
rustflags = [
"-C",
"link-arg=-fuse-ld=lld",
# LLD by default uses xxhash for build ids now, which breaks tests that assume
# GUIDS or longer
"-C",
"link-arg=-Wl,--build-id=sha1",
]
18 changes: 9 additions & 9 deletions src/linux/minidump_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use crate::{
mem_writer::{Buffer, MemoryArrayWriter, MemoryWriter, MemoryWriterError},
minidump_format::*,
};
use std::fs::read_dir;
use std::io::{Seek, Write};

pub enum CrashingThreadContext {
Expand Down Expand Up @@ -371,18 +370,19 @@ impl MinidumpWriter {
buffer: &mut DumpBuf,
dirname: &str,
) -> std::result::Result<MDLocationDescriptor, MemoryWriterError> {
let num = match read_dir(dirname) {
let num_entries = match std::fs::read_dir(dirname) {
Ok(location) => location
.into_iter()
.map(|x| x.expect("Unable to get path()").path())
.filter(|x| x.is_file() || x.is_symlink())
.collect::<Vec<_>>()
.len()
.to_string(),
Err(_) => Default::default(),
.filter_map(|de| {
let de = de.ok()?;
let ft = de.file_type().ok()?;
(ft.is_file() || ft.is_symlink()).then_some(())
})
.count() as u64,
Err(_) => 0,
};

let section = MemoryArrayWriter::write_bytes(buffer, num.as_bytes());
let section = MemoryWriter::alloc_with_val(buffer, num_entries)?;
Ok(section.location())
}
}
29 changes: 27 additions & 2 deletions tests/linux_minidump_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,34 @@ contextual_tests! {
let _ = dump
.get_raw_stream(LinuxDsoDebug as u32)
.expect("Couldn't find LinuxDsoDebug");
let _ = dump
.get_raw_stream(MozLinuxFDs as u32)

struct MinidumpFd {
num: u64,
}

impl<'a> MinidumpStream<'a> for MinidumpFd {
const STREAM_TYPE: u32 = minidump_common::format::MINIDUMP_STREAM_TYPE::MozLinuxFDs as u32;

fn read(
bytes: &'a [u8],
all: &'a [u8],
endian: scroll::Endian,
_system_info: Option<&MinidumpSystemInfo>,
) -> std::result::Result<Self, minidump::Error> {
use scroll::Pread;
let mut offset = 0;
let num: u64 = bytes
.gread_with(&mut offset, endian)
.or(Err(minidump::Error::StreamReadFailure))?;
Ok(Self{num})
}
}

let fds: MinidumpFd = dump
.get_stream()
.expect("Couldn't find MozLinuxFDs");

assert!(fds.num > 0);
let _ = dump
.get_raw_stream(MozLinuxLimits as u32)
.expect("Couldn't find MozLinuxLimits");
Expand Down

0 comments on commit 8ac914f

Please sign in to comment.