Skip to content

Commit

Permalink
Merge 41abcc0 into c6490b3
Browse files Browse the repository at this point in the history
  • Loading branch information
GnomedDev committed Feb 21, 2024
2 parents c6490b3 + 41abcc0 commit 0c014ef
Show file tree
Hide file tree
Showing 21 changed files with 592 additions and 578 deletions.
2 changes: 1 addition & 1 deletion crates/examples/src/bin/dwarf-validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn main() {
let mut errors = 0;
for arg in env::args_os().skip(1) {
let path = Path::new(&arg);
let file = match fs::File::open(&path) {
let file = match fs::File::open(path) {
Ok(file) => file,
Err(err) => {
eprintln!("Failed to open file '{}': {}", path.display(), err);
Expand Down
82 changes: 37 additions & 45 deletions crates/examples/src/bin/dwarfdump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,28 +167,24 @@ fn add_relocations(
if offset as u64 != offset64 {
continue;
}
let offset = offset as usize;
match relocation.kind() {
object::RelocationKind::Absolute => {
match relocation.target() {
object::RelocationTarget::Symbol(symbol_idx) => {
match file.symbol_by_index(symbol_idx) {
Ok(symbol) => {
let addend =
symbol.address().wrapping_add(relocation.addend() as u64);
relocation.set_addend(addend as i64);
}
Err(_) => {
eprintln!(
"Relocation with invalid symbol for section {} at offset 0x{:08x}",
section.name().unwrap(),
offset
);
}
if let object::RelocationTarget::Symbol(symbol_idx) = relocation.target() {
match file.symbol_by_index(symbol_idx) {
Ok(symbol) => {
let addend = symbol.address().wrapping_add(relocation.addend() as u64);
relocation.set_addend(addend as i64);
}
Err(_) => {
eprintln!(
"Relocation with invalid symbol for section {} at offset 0x{:08x}",
section.name().unwrap(),
offset
);
}
}
_ => {}
}
};

if relocations.insert(offset, relocation).is_some() {
eprintln!(
"Multiple relocations for section {} at offset 0x{:08x}",
Expand Down Expand Up @@ -228,16 +224,13 @@ struct Relocate<'a, R: gimli::Reader<Offset = usize>> {
impl<'a, R: gimli::Reader<Offset = usize>> Relocate<'a, R> {
fn relocate(&self, offset: usize, value: u64) -> u64 {
if let Some(relocation) = self.relocations.get(&offset) {
match relocation.kind() {
object::RelocationKind::Absolute => {
if relocation.has_implicit_addend() {
// Use the explicit addend too, because it may have the symbol value.
return value.wrapping_add(relocation.addend() as u64);
} else {
return relocation.addend() as u64;
}
if let object::RelocationKind::Absolute = relocation.kind() {
if relocation.has_implicit_addend() {
// Use the explicit addend too, because it may have the symbol value.
return value.wrapping_add(relocation.addend() as u64);
} else {
return relocation.addend() as u64;
}
_ => {}
}
};
value
Expand Down Expand Up @@ -524,7 +517,7 @@ fn main() {
println!();
}

let file = match fs::File::open(&file_path) {
let file = match fs::File::open(file_path) {
Ok(file) => file,
Err(err) => {
eprintln!("Failed to open file '{}': {}", file_path, err);
Expand Down Expand Up @@ -559,10 +552,10 @@ fn main() {
}
}

fn empty_file_section<'input, 'arena, Endian: gimli::Endianity>(
fn empty_file_section<Endian: gimli::Endianity>(
endian: Endian,
arena_relocations: &'arena Arena<RelocationMap>,
) -> Relocate<'arena, gimli::EndianSlice<'arena, Endian>> {
arena_relocations: &Arena<RelocationMap>,
) -> Relocate<'_, gimli::EndianSlice<'_, Endian>> {
let reader = gimli::EndianSlice::new(&[], endian);
let section = reader;
let relocations = RelocationMap::default();
Expand Down Expand Up @@ -591,7 +584,7 @@ fn load_file_section<'input, 'arena, Endian: gimli::Endianity>(
Some(id.name())
};

let data = match name.and_then(|name| file.section_by_name(&name)) {
let data = match name.and_then(|name| file.section_by_name(name)) {
Some(ref section) => {
// DWO sections never have relocations, so don't bother.
if !is_dwo {
Expand Down Expand Up @@ -680,7 +673,7 @@ where
let mut dwarf = gimli::Dwarf::load(&mut load_section)?;
if flags.dwo {
if let Some(dwo_parent) = dwo_parent {
dwarf.make_dwo(&dwo_parent);
dwarf.make_dwo(dwo_parent);
} else {
dwarf.file_type = gimli::DwarfFileType::Dwo;
}
Expand All @@ -698,7 +691,7 @@ where
dwarf.populate_abbreviations_cache(gimli::AbbreviationsCacheStrategy::All);

if flags.eh_frame {
let eh_frame = gimli::EhFrame::load(&mut load_section).unwrap();
let eh_frame = gimli::EhFrame::load(load_section).unwrap();
dump_eh_frame(w, file, eh_frame)?;
}
if flags.info {
Expand All @@ -709,15 +702,15 @@ where
dump_line(w, &dwarf)?;
}
if flags.pubnames {
let debug_pubnames = &gimli::Section::load(&mut load_section).unwrap();
let debug_pubnames = &gimli::Section::load(load_section).unwrap();
dump_pubnames(w, debug_pubnames, &dwarf.debug_info)?;
}
if flags.aranges {
let debug_aranges = &gimli::Section::load(&mut load_section).unwrap();
let debug_aranges = &gimli::Section::load(load_section).unwrap();
dump_aranges(w, debug_aranges)?;
}
if flags.pubtypes {
let debug_pubtypes = &gimli::Section::load(&mut load_section).unwrap();
let debug_pubtypes = &gimli::Section::load(load_section).unwrap();
dump_pubtypes(w, debug_pubtypes, &dwarf.debug_info)?;
}
w.flush()?;
Expand All @@ -737,9 +730,8 @@ fn dump_eh_frame<R: Reader, W: Write>(
.unwrap_or(mem::size_of::<usize>() as u8);
eh_frame.set_address_size(address_size);

match file.architecture() {
object::Architecture::Aarch64 => eh_frame.set_vendor(gimli::Vendor::AArch64),
_ => {}
if let object::Architecture::Aarch64 = file.architecture() {
eh_frame.set_vendor(gimli::Vendor::AArch64);
}

fn register_name_none(_: gimli::Register) -> Option<&'static str> {
Expand Down Expand Up @@ -1100,7 +1092,7 @@ where
writeln!(w, "\nCU index {}", i)?;
dump_dwp_sections(
w,
&dwp,
dwp,
dwo_parent,
dwo_parent_units,
flags,
Expand All @@ -1122,7 +1114,7 @@ where
writeln!(w, "\nTU index {}", i)?;
dump_dwp_sections(
w,
&dwp,
dwp,
dwo_parent,
dwo_parent_units,
flags,
Expand Down Expand Up @@ -1193,7 +1185,7 @@ where
if !flags
.match_units
.as_ref()
.map(|r| r.is_match(&buf))
.map(|r| r.is_match(buf))
.unwrap_or(true)
{
buf.clear();
Expand Down Expand Up @@ -2203,8 +2195,8 @@ fn dump_line_program<R: Reader, W: Write>(
if header.file_has_md5() {
let md5 = file.md5();
write!(w, "\t")?;
for i in 0..16 {
write!(w, "{:02X}", md5[i])?;
for byte in md5 {
write!(w, "{:02X}", byte)?;
}
}
writeln!(
Expand Down
2 changes: 1 addition & 1 deletion crates/examples/src/bin/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn dump_file(object: &object::File, endian: gimli::RunTimeEndian) -> Result<(),
let borrow_section: &dyn for<'a> Fn(
&'a borrow::Cow<[u8]>,
) -> gimli::EndianSlice<'a, gimli::RunTimeEndian> =
&|section| gimli::EndianSlice::new(&*section, endian);
&|section| gimli::EndianSlice::new(section, endian);

// Create `EndianSlice`s for all of the sections.
let dwarf = dwarf_cow.borrow(&borrow_section);
Expand Down
2 changes: 1 addition & 1 deletion crates/examples/src/bin/simple_line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn dump_file(object: &object::File, endian: gimli::RunTimeEndian) -> Result<(),
let borrow_section: &dyn for<'a> Fn(
&'a borrow::Cow<[u8]>,
) -> gimli::EndianSlice<'a, gimli::RunTimeEndian> =
&|section| gimli::EndianSlice::new(&*section, endian);
&|section| gimli::EndianSlice::new(section, endian);

// Create `EndianSlice`s for all of the sections.
let dwarf = dwarf_cow.borrow(&borrow_section);
Expand Down
8 changes: 4 additions & 4 deletions src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1409,8 +1409,8 @@ mod tests {

#[test]
fn test_dw_eh_pe_is_absent() {
assert_eq!(DW_EH_PE_absptr.is_absent(), false);
assert_eq!(DW_EH_PE_omit.is_absent(), true);
assert!(!DW_EH_PE_absptr.is_absent());
assert!(DW_EH_PE_omit.is_absent());
}

#[test]
Expand All @@ -1424,12 +1424,12 @@ mod tests {
#[test]
fn test_dw_eh_pe_is_valid_encoding_bad_format() {
let encoding = DwEhPe((DW_EH_PE_sdata8.0 + 1) | DW_EH_PE_pcrel.0);
assert_eq!(encoding.is_valid_encoding(), false);
assert!(!encoding.is_valid_encoding());
}

#[test]
fn test_dw_eh_pe_is_valid_encoding_bad_application() {
let encoding = DwEhPe(DW_EH_PE_sdata8.0 | (DW_EH_PE_aligned.0 + 1));
assert_eq!(encoding.is_valid_encoding(), false);
assert!(!encoding.is_valid_encoding());
}
}
12 changes: 6 additions & 6 deletions src/read/abbrev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ pub(crate) mod tests {
.append_bytes(&expected_rest)
.get_contents()
.unwrap();
let rest = &mut EndianSlice::new(&*buf, LittleEndian);
let rest = &mut EndianSlice::new(&buf, LittleEndian);

let abbrev1 = Abbreviation::new(
1,
Expand Down Expand Up @@ -908,7 +908,7 @@ pub(crate) mod tests {
.append_bytes(&expected_rest)
.get_contents()
.unwrap();
let buf = &mut EndianSlice::new(&*buf, LittleEndian);
let buf = &mut EndianSlice::new(&buf, LittleEndian);

match Abbreviations::parse(buf) {
Err(Error::DuplicateAbbreviationCode) => {}
Expand Down Expand Up @@ -959,7 +959,7 @@ pub(crate) mod tests {
.append_bytes(&expected_rest)
.get_contents()
.unwrap();
let rest = &mut EndianSlice::new(&*buf, LittleEndian);
let rest = &mut EndianSlice::new(&buf, LittleEndian);

let expect = Some(Abbreviation::new(
1,
Expand Down Expand Up @@ -988,7 +988,7 @@ pub(crate) mod tests {
.append_bytes(&expected_rest)
.get_contents()
.unwrap();
let rest = &mut EndianSlice::new(&*buf, LittleEndian);
let rest = &mut EndianSlice::new(&buf, LittleEndian);

let expect = Some(Abbreviation::new(
1,
Expand All @@ -1014,7 +1014,7 @@ pub(crate) mod tests {
.abbrev_attr(constants::DW_AT_name, constants::DW_FORM_implicit_const)
.get_contents()
.unwrap();
let buf = &mut EndianSlice::new(&*buf, LittleEndian);
let buf = &mut EndianSlice::new(&buf, LittleEndian);

match Abbreviation::parse(buf) {
Err(Error::UnexpectedEof(_)) => {}
Expand All @@ -1030,7 +1030,7 @@ pub(crate) mod tests {
.append_bytes(&expected_rest)
.get_contents()
.unwrap();
let rest = &mut EndianSlice::new(&*buf, LittleEndian);
let rest = &mut EndianSlice::new(&buf, LittleEndian);

let abbrev = Abbreviation::parse(rest).expect("Should parse null abbreviation");
assert!(abbrev.is_none());
Expand Down
4 changes: 2 additions & 2 deletions src/read/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ mod tests {

#[test]
fn test_get_address() {
for format in vec![Format::Dwarf32, Format::Dwarf64] {
for address_size in vec![4, 8] {
for format in [Format::Dwarf32, Format::Dwarf64] {
for address_size in [4, 8] {
let zero = Label::new();
let length = Label::new();
let start = Label::new();
Expand Down

0 comments on commit 0c014ef

Please sign in to comment.