From 98e915822783e0bb769f67608d6e3c12a8b64e34 Mon Sep 17 00:00:00 2001 From: Philip Craig Date: Thu, 15 Nov 2018 14:52:09 +1000 Subject: [PATCH] Fix UnitHeader::length_including_self() for Dwarf64 --- src/read/unit.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/read/unit.rs b/src/read/unit.rs index 62732296e..c954e5af8 100644 --- a/src/read/unit.rs +++ b/src/read/unit.rs @@ -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. @@ -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); + } }