Skip to content

Commit a7a8efd

Browse files
committed
Include more values in validation errors
1 parent 175a7fe commit a7a8efd

File tree

12 files changed

+85
-78
lines changed

12 files changed

+85
-78
lines changed

src/read/abbrev.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,9 @@ impl Abbreviations {
267267
let mut abbrevs = Abbreviations::empty();
268268

269269
while let Some(abbrev) = Abbreviation::parse(input)? {
270+
let code = abbrev.code;
270271
if abbrevs.insert(abbrev).is_err() {
271-
return Err(Error::DuplicateAbbreviationCode);
272+
return Err(Error::DuplicateAbbreviationCode(code));
272273
}
273274
}
274275

@@ -348,7 +349,7 @@ impl Abbreviation {
348349
if val == constants::DW_CHILDREN_no || val == constants::DW_CHILDREN_yes {
349350
Ok(val)
350351
} else {
351-
Err(Error::BadHasChildren)
352+
Err(Error::InvalidAbbreviationChildren(val))
352353
}
353354
}
354355

@@ -894,7 +895,7 @@ pub(crate) mod tests {
894895
let buf = &mut EndianSlice::new(&buf, LittleEndian);
895896

896897
match Abbreviations::parse(buf) {
897-
Err(Error::DuplicateAbbreviationCode) => {}
898+
Err(Error::DuplicateAbbreviationCode(1)) => {}
898899
otherwise => panic!("Unexpected result: {:?}", otherwise),
899900
};
900901
}
@@ -927,7 +928,7 @@ pub(crate) mod tests {
927928
let val = Abbreviation::parse_has_children(rest).expect("Should parse children");
928929
assert_eq!(val, constants::DW_CHILDREN_yes);
929930
match Abbreviation::parse_has_children(rest) {
930-
Err(Error::BadHasChildren) => {}
931+
Err(Error::InvalidAbbreviationChildren(_)) => {}
931932
otherwise => panic!("Unexpected result: {:?}", otherwise),
932933
};
933934
}

src/read/addr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ where
156156
let address_size = rest.read_address_size()?;
157157
let segment_size = rest.read_u8()?;
158158
if segment_size != 0 {
159-
return Err(Error::UnsupportedSegmentSize);
159+
return Err(Error::UnsupportedSegmentSize(segment_size));
160160
}
161161

162162
// unit_length + version + address_size + segment_size

src/read/aranges.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ where
170170
let address_size = rest.read_address_size()?;
171171
let segment_size = rest.read_u8()?;
172172
if segment_size != 0 {
173-
return Err(Error::UnsupportedSegmentSize);
173+
return Err(Error::UnsupportedSegmentSize(segment_size));
174174
}
175175

176176
// unit_length + version + offset + address_size + segment_size

src/read/cfi.rs

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ pub trait UnwindSection<R: Reader>: Clone + Debug + _UnwindSectionPrivate<R> {
656656
let offset = UnwindOffset::into(offset);
657657
let input = &mut self.section().clone();
658658
input.skip(offset)?;
659-
CommonInformationEntry::parse(bases, self, input)
659+
CommonInformationEntry::parse(bases, self, input, offset)
660660
}
661661

662662
/// Parse the `PartialFrameDescriptionEntry` at the given offset.
@@ -668,7 +668,7 @@ pub trait UnwindSection<R: Reader>: Clone + Debug + _UnwindSectionPrivate<R> {
668668
let offset = UnwindOffset::into(offset);
669669
let input = &mut self.section().clone();
670670
input.skip(offset)?;
671-
PartialFrameDescriptionEntry::parse_partial(self, bases, input)
671+
PartialFrameDescriptionEntry::parse_partial(self, bases, input, offset)
672672
}
673673

674674
/// Parse the `FrameDescriptionEntry` at the given offset.
@@ -1103,7 +1103,7 @@ where
11031103
} else {
11041104
let cie_offset = R::Offset::from_u64(cie_id_or_offset)?;
11051105
let cie_offset = match section.resolve_cie_offset(cie_offset_base, cie_offset) {
1106-
None => return Err(Error::OffsetOutOfBounds),
1106+
None => return Err(Error::OffsetOutOfBounds(cie_id_or_offset)),
11071107
Some(cie_offset) => cie_offset,
11081108
};
11091109

@@ -1316,11 +1316,12 @@ impl<R: Reader> CommonInformationEntry<R> {
13161316
bases: &BaseAddresses,
13171317
section: &Section,
13181318
input: &mut R,
1319+
offset: R::Offset,
13191320
) -> Result<CommonInformationEntry<R>> {
13201321
match parse_cfi_entry(bases, section, input)? {
13211322
Some(CieOrFde::Cie(cie)) => Ok(cie),
1322-
Some(CieOrFde::Fde(_)) => Err(Error::NotCieId),
1323-
None => Err(Error::NoEntryAtGivenOffset),
1323+
Some(CieOrFde::Fde(_)) => Err(Error::NotCieId(offset.into_u64())),
1324+
None => Err(Error::NoEntryAtGivenOffset(offset.into_u64())),
13241325
}
13251326
}
13261327

@@ -1348,7 +1349,7 @@ impl<R: Reader> CommonInformationEntry<R> {
13481349
let address_size = rest.read_address_size()?;
13491350
let segment_size = rest.read_u8()?;
13501351
if segment_size != 0 {
1351-
return Err(Error::UnsupportedSegmentSize);
1352+
return Err(Error::UnsupportedSegmentSize(segment_size));
13521353
}
13531354
address_size
13541355
} else {
@@ -1543,11 +1544,12 @@ where
15431544
section: &Section,
15441545
bases: &'bases BaseAddresses,
15451546
input: &mut R,
1547+
offset: R::Offset,
15461548
) -> Result<PartialFrameDescriptionEntry<'bases, Section, R>> {
15471549
match parse_cfi_entry(bases, section, input)? {
1548-
Some(CieOrFde::Cie(_)) => Err(Error::NotFdePointer),
1550+
Some(CieOrFde::Cie(_)) => Err(Error::NotFdePointer(offset.into_u64())),
15491551
Some(CieOrFde::Fde(partial)) => Ok(partial),
1550-
None => Err(Error::NoEntryAtGivenOffset),
1552+
None => Err(Error::NoEntryAtGivenOffset(offset.into_u64())),
15511553
}
15521554
}
15531555

@@ -3780,7 +3782,7 @@ mod tests {
37803782
let bases = Default::default();
37813783
match parse_cfi_entry(&bases, &section, input) {
37823784
Ok(Some(CieOrFde::Fde(partial))) => partial.parse(get_cie),
3783-
Ok(_) => Err(Error::NoEntryAtGivenOffset),
3785+
Ok(_) => Err(Error::NoEntryAtGivenOffset(0)),
37843786
Err(e) => Err(e),
37853787
}
37863788
}
@@ -3984,7 +3986,7 @@ mod tests {
39843986
debug_frame.set_address_size(address_size);
39853987
let input = &mut EndianSlice::new(&section, E::default());
39863988
let bases = Default::default();
3987-
let result = CommonInformationEntry::parse(&bases, &debug_frame, input);
3989+
let result = CommonInformationEntry::parse(&bases, &debug_frame, input, 0);
39883990
let result = result.map(|cie| (*input, cie)).map_eof(&section);
39893991
assert_eq!(result, expected);
39903992
}
@@ -4038,7 +4040,7 @@ mod tests {
40384040
.B32(4)
40394041
// Not the CIE Id.
40404042
.B32(0xbad1_bad2);
4041-
assert_parse_cie(kind, section, 8, Err(Error::NotCieId));
4043+
assert_parse_cie(kind, section, 8, Err(Error::NotCieId(0)));
40424044
}
40434045

40444046
#[test]
@@ -4179,7 +4181,8 @@ mod tests {
41794181
CommonInformationEntry::parse(
41804182
&bases,
41814183
&debug_frame,
4182-
&mut EndianSlice::new(&contents, LittleEndian)
4184+
&mut EndianSlice::new(&contents, LittleEndian),
4185+
0,
41834186
)
41844187
.map_eof(&contents),
41854188
Err(Error::UnexpectedEof(ReaderOffsetId(4)))
@@ -6691,7 +6694,7 @@ mod tests {
66916694

66926695
assert_eq!(
66936696
eh_frame.cie_from_offset(&bases, EhFrameOffset(0)),
6694-
Err(Error::NoEntryAtGivenOffset)
6697+
Err(Error::NoEntryAtGivenOffset(0))
66956698
);
66966699
}
66976700

@@ -6713,7 +6716,7 @@ mod tests {
67136716

67146717
assert_eq!(
67156718
debug_frame.cie_from_offset(&bases, DebugFrameOffset(0)),
6716-
Err(Error::NoEntryAtGivenOffset)
6719+
Err(Error::NoEntryAtGivenOffset(0))
67176720
);
67186721
}
67196722

@@ -6763,7 +6766,7 @@ mod tests {
67636766
let buf = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
67646767
assert_eq!(
67656768
resolve_cie_offset(&buf, buf.len() + 4 + 2),
6766-
Err(Error::OffsetOutOfBounds)
6769+
Err(Error::OffsetOutOfBounds(buf.len() as u64 + 4 + 2))
67676770
);
67686771
}
67696772

@@ -6772,7 +6775,7 @@ mod tests {
67726775
let buf = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
67736776
assert_eq!(
67746777
resolve_cie_offset(&buf, usize::MAX),
6775-
Err(Error::OffsetOutOfBounds)
6778+
Err(Error::OffsetOutOfBounds(u32::MAX as u64))
67766779
);
67776780
}
67786781

@@ -6853,7 +6856,7 @@ mod tests {
68536856
let section = Section::with_endian(kind.endian())
68546857
.cie(kind, None, &mut cie)
68556858
.mark(&end_of_cie)
6856-
.fde(kind, 99_999_999_999_999, &mut fde);
6859+
.fde(kind, 99_999_999, &mut fde);
68576860

68586861
section.start().set_const(0);
68596862
let section = section.get_contents().unwrap();
@@ -6865,7 +6868,7 @@ mod tests {
68656868
&mut section.range_from(end_of_cie.value().unwrap() as usize..),
68666869
UnwindSection::cie_from_offset,
68676870
);
6868-
assert_eq!(result, Err(Error::OffsetOutOfBounds));
6871+
assert_eq!(result, Err(Error::OffsetOutOfBounds(99_999_999)));
68696872
}
68706873

68716874
#[test]

src/read/index.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,15 +167,15 @@ impl<R: Reader> UnitIndex<R> {
167167
let unit_count = input.read_u32()?;
168168
let slot_count = input.read_u32()?;
169169
if slot_count != 0 && (slot_count & (slot_count - 1) != 0 || slot_count <= unit_count) {
170-
return Err(Error::InvalidIndexSlotCount);
170+
return Err(Error::InvalidIndexSlotCount(slot_count));
171171
}
172172

173173
let hash_ids = input.split(R::Offset::from_u64(u64::from(slot_count) * 8)?)?;
174174
let hash_rows = input.split(R::Offset::from_u64(u64::from(slot_count) * 4)?)?;
175175

176176
let mut sections = [IndexSectionId::DebugAbbrev; SECTION_COUNT_MAX as usize];
177177
if section_count > SECTION_COUNT_MAX.into() {
178-
return Err(Error::InvalidIndexSectionCount);
178+
return Err(Error::UnsupportedIndexSectionCount(section_count));
179179
}
180180
for i in 0..section_count {
181181
let section = input.read_u32()?;
@@ -258,11 +258,11 @@ impl<R: Reader> UnitIndex<R> {
258258
/// Return the section offsets and sizes for the given row index.
259259
pub fn sections(&self, mut row: u32) -> Result<UnitIndexSectionIterator<'_, R>> {
260260
if row == 0 {
261-
return Err(Error::InvalidIndexRow);
261+
return Err(Error::InvalidIndexRow(row));
262262
}
263263
row -= 1;
264264
if row >= self.unit_count {
265-
return Err(Error::InvalidIndexRow);
265+
return Err(Error::InvalidIndexRow(row));
266266
}
267267
let mut offsets = self.offsets.clone();
268268
offsets.skip(R::Offset::from_u64(

src/read/line.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1246,7 +1246,7 @@ where
12461246
address_size = rest.read_address_size()?;
12471247
let segment_selector_size = rest.read_u8()?;
12481248
if segment_selector_size != 0 {
1249-
return Err(Error::UnsupportedSegmentSize);
1249+
return Err(Error::UnsupportedSegmentSize(segment_selector_size));
12501250
}
12511251
}
12521252

src/read/lists.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ fn parse_header<R: Reader>(input: &mut R) -> Result<ListsHeader> {
5252
let address_size = input.read_address_size()?;
5353
let segment_selector_size = input.read_u8()?;
5454
if segment_selector_size != 0 {
55-
return Err(Error::UnsupportedSegmentSize);
55+
return Err(Error::UnsupportedSegmentSize(segment_selector_size));
5656
}
5757
let offset_entry_count = input.read_u32()?;
5858

0 commit comments

Comments
 (0)