Skip to content

Commit

Permalink
Fix UnitHeader::length_including_self() for Dwarf64
Browse files Browse the repository at this point in the history
  • Loading branch information
philipc committed Nov 15, 2018
1 parent 2138f48 commit 98e9158
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/read/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ where
/// Get the length of the debugging info for this compilation unit,
/// including the byte length of the encoded length itself.
pub fn length_including_self(&self) -> R::Offset {
R::Offset::from_u8(self.format.word_size()) + self.unit_length
R::Offset::from_u8(self.format.initial_length_size()) + self.unit_length
}

/// Get the DWARF version of the debugging info for this compilation unit.
Expand Down Expand Up @@ -4996,4 +4996,22 @@ mod tests {
DebugTypesOffset(offset + length - 1)
);
}

#[test]
fn test_length_including_self() {
let mut unit = UnitHeader {
unit_length: 0,
version: 4,
debug_abbrev_offset: DebugAbbrevOffset(0),
address_size: 4,
format: Format::Dwarf32,
entries_buf: EndianSlice::new(&[], LittleEndian),
};
unit.format = Format::Dwarf32;
assert_eq!(unit.length_including_self(), 4);
unit.format = Format::Dwarf64;
assert_eq!(unit.length_including_self(), 12);
unit.unit_length = 10;
assert_eq!(unit.length_including_self(), 22);
}
}

0 comments on commit 98e9158

Please sign in to comment.