Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include the unknown version number in Error::UnknownVersion #245

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/abbrev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ pub mod tests {
use endianity::{EndianBuf, LittleEndian};
use parser::Error;
use self::test_assembler::Section;
use std::{u32, u64};
use std::u64;
use test_util::GimliSectionMethods;

pub trait AbbrevSectionMethods {
Expand Down
2 changes: 1 addition & 1 deletion src/aranges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl<R: Reader> LookupParser<R> for ArangeParser<R> {

let version = rest.read_u16()?;
if version != 2 {
return Err(Error::UnknownVersion);
return Err(Error::UnknownVersion(version as u64));
}

let offset = parse_debug_info_offset(&mut rest, format)?;
Expand Down
4 changes: 2 additions & 2 deletions src/cfi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,7 @@ where
) -> Result<CommonInformationEntry<Section, R, Offset>> {
let version = rest.read_u8()?;
if !Section::compatible_version(version) {
return Err(Error::UnknownVersion);
return Err(Error::UnknownVersion(version as u64));
}

let mut augmentation_string = rest.read_null_terminated_slice()?;
Expand Down Expand Up @@ -3219,7 +3219,7 @@ mod tests {
};

let section = Section::with_endian(Endian::Little).cie(Endian::Little, None, &mut cie);
assert_parse_cie::<LittleEndian>(section, Err(Error::UnknownVersion));
assert_parse_cie::<LittleEndian>(section, Err(Error::UnknownVersion(99)));
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1138,7 +1138,7 @@ impl<R: Reader> LineNumberProgramHeader<R> {

let version = rest.read_u16()?;
if version < 2 || version > 4 {
return Err(parser::Error::UnknownVersion);
return Err(parser::Error::UnknownVersion(version as u64));
}

let header_length = rest.read_word(format).and_then(R::Offset::from_u64)?;
Expand Down
2 changes: 1 addition & 1 deletion src/lookup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ where

let version = rest.read_u16()?;
if version != 2 {
return Err(Error::UnknownVersion);
return Err(Error::UnknownVersion(version as u64));
}

let unit_offset = parse_debug_info_offset(&mut rest, format)?;
Expand Down
4 changes: 2 additions & 2 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub enum Error {
/// Found an unknown reserved length value.
UnknownReservedLength,
/// Found an unknown DWARF version.
UnknownVersion,
UnknownVersion(u64),
/// Found a record with an unknown abbreviation code.
UnknownAbbreviation,
/// Hit the end of input before it was expected.
Expand Down Expand Up @@ -176,7 +176,7 @@ impl error::Error for Error {
}
Error::DuplicateArange => "Found a duplicate arange",
Error::UnknownReservedLength => "Found an unknown reserved length value",
Error::UnknownVersion => "Found an unknown DWARF version",
Error::UnknownVersion(_) => "Found an unknown DWARF version",
Error::UnknownAbbreviation => "Found a record with an unknown abbreviation code",
Error::UnexpectedEof => "Hit the end of input before it was expected",
Error::UnexpectedNull => "Read a null entry before it was expected.",
Expand Down
6 changes: 3 additions & 3 deletions src/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ fn parse_version<R: Reader>(input: &mut R) -> Result<u16> {
if 2 <= val && val <= 4 {
Ok(val)
} else {
Err(Error::UnknownVersion)
Err(Error::UnknownVersion(val as u64))
}
}

Expand Down Expand Up @@ -3073,15 +3073,15 @@ mod tests {
let rest = &mut EndianBuf::new(&buf, LittleEndian);

match parse_version(rest) {
Err(Error::UnknownVersion) => assert!(true),
Err(Error::UnknownVersion(0xcdab)) => assert!(true),
otherwise => panic!("Unexpected result: {:?}", otherwise),
};

let buf = [0x1, 0x0];
let rest = &mut EndianBuf::new(&buf, LittleEndian);

match parse_version(rest) {
Err(Error::UnknownVersion) => assert!(true),
Err(Error::UnknownVersion(1)) => assert!(true),
otherwise => panic!("Unexpected result: {:?}", otherwise),
};
}
Expand Down