Skip to content

Commit

Permalink
Merge pull request #295 from fitzgen/rename-EndianBuf-to-EndianSlice
Browse files Browse the repository at this point in the history
Rename EndianBuf to EndianSlice
  • Loading branch information
fitzgen committed Apr 29, 2018
2 parents c3689f7 + 7011449 commit f177b94
Show file tree
Hide file tree
Showing 18 changed files with 956 additions and 916 deletions.
6 changes: 3 additions & 3 deletions examples/dwarf-validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ trait Reader: gimli::Reader<Offset = usize> + Send + Sync {
type SyncSendEndian: gimli::Endianity + Send + Sync;
}

impl<'input, Endian> Reader for gimli::EndianBuf<'input, Endian>
impl<'input, Endian> Reader for gimli::EndianSlice<'input, Endian>
where
Endian: gimli::Endianity + Send + Sync,
{
Expand Down Expand Up @@ -106,12 +106,12 @@ where
endian: Endian,
) -> S
where
S: gimli::Section<gimli::EndianBuf<'input, Endian>>,
S: gimli::Section<gimli::EndianSlice<'input, Endian>>,
Endian: gimli::Endianity + Send + Sync,
'file: 'input,
{
let data = file.section_data_by_name(S::section_name()).unwrap_or(&[]);
S::from(gimli::EndianBuf::new(data, endian))
S::from(gimli::EndianSlice::new(data, endian))
}

// Variables representing sections of the file. The type of each is inferred from its use in the
Expand Down
6 changes: 3 additions & 3 deletions examples/dwarfdump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ trait Reader: gimli::Reader<Offset = usize> + Send + Sync {
type SyncSendEndian: gimli::Endianity + Send + Sync;
}

impl<'input, Endian> Reader for gimli::EndianBuf<'input, Endian>
impl<'input, Endian> Reader for gimli::EndianSlice<'input, Endian>
where
Endian: gimli::Endianity + Send + Sync,
{
Expand Down Expand Up @@ -312,12 +312,12 @@ where
endian: Endian,
) -> S
where
S: gimli::Section<gimli::EndianBuf<'input, Endian>>,
S: gimli::Section<gimli::EndianSlice<'input, Endian>>,
Endian: gimli::Endianity + Send + Sync,
'file: 'input,
{
let data = file.section_data_by_name(S::section_name()).unwrap_or(&[]);
S::from(gimli::EndianBuf::new(data, endian))
S::from(gimli::EndianSlice::new(data, endian))
}

// Variables representing sections of the file. The type of each is inferred from its use in the
Expand Down
53 changes: 28 additions & 25 deletions src/abbrev.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
//! Functions for parsing DWARF debugging abbreviations.

use constants;
use endianity::{EndianBuf, Endianity};
use endianity::Endianity;
use endian_slice::EndianSlice;
use parser::{Error, Result};
use reader::Reader;
use unit::UnitHeader;
Expand All @@ -21,7 +22,7 @@ pub struct DebugAbbrev<R: Reader> {
debug_abbrev_section: R,
}

impl<'input, Endian> DebugAbbrev<EndianBuf<'input, Endian>>
impl<'input, Endian> DebugAbbrev<EndianSlice<'input, Endian>>
where
Endian: Endianity,
{
Expand All @@ -40,7 +41,7 @@ where
/// let debug_abbrev = DebugAbbrev::new(read_debug_abbrev_section_somehow(), LittleEndian);
/// ```
pub fn new(debug_abbrev_section: &'input [u8], endian: Endian) -> Self {
Self::from(EndianBuf::new(debug_abbrev_section, endian))
Self::from(EndianSlice::new(debug_abbrev_section, endian))
}
}

Expand Down Expand Up @@ -390,7 +391,8 @@ pub mod tests {

use super::*;
use constants;
use endianity::{EndianBuf, LittleEndian};
use endianity::LittleEndian;
use endian_slice::EndianSlice;
use parser::Error;
use self::test_assembler::Section;
#[cfg(target_pointer_width = "32")]
Expand Down Expand Up @@ -601,7 +603,7 @@ pub mod tests {
.append_bytes(&expected_rest)
.get_contents()
.unwrap();
let rest = &mut EndianBuf::new(&*buf, LittleEndian);
let rest = &mut EndianSlice::new(&*buf, LittleEndian);

let abbrev1 = Abbreviation::new(
1,
Expand Down Expand Up @@ -633,7 +635,7 @@ pub mod tests {
let abbrevs = Abbreviations::parse(rest).expect("Should parse abbreviations");
assert_eq!(abbrevs.get(1), Some(&abbrev1));
assert_eq!(abbrevs.get(2), Some(&abbrev2));
assert_eq!(*rest, EndianBuf::new(&expected_rest, LittleEndian));
assert_eq!(*rest, EndianSlice::new(&expected_rest, LittleEndian));
}

#[test]
Expand All @@ -655,7 +657,7 @@ pub mod tests {
.append_bytes(&expected_rest)
.get_contents()
.unwrap();
let buf = &mut EndianBuf::new(&*buf, LittleEndian);
let buf = &mut EndianSlice::new(&*buf, LittleEndian);

match Abbreviations::parse(buf) {
Err(Error::DuplicateAbbreviationCode) => {}
Expand All @@ -666,16 +668,16 @@ pub mod tests {
#[test]
fn test_parse_abbreviation_tag_ok() {
let buf = [0x01, 0x02];
let rest = &mut EndianBuf::new(&buf, LittleEndian);
let rest = &mut EndianSlice::new(&buf, LittleEndian);
let tag = Abbreviation::parse_tag(rest).expect("Should parse tag");
assert_eq!(tag, constants::DW_TAG_array_type);
assert_eq!(*rest, EndianBuf::new(&buf[1..], LittleEndian));
assert_eq!(*rest, EndianSlice::new(&buf[1..], LittleEndian));
}

#[test]
fn test_parse_abbreviation_tag_zero() {
let buf = [0x00];
let buf = &mut EndianBuf::new(&buf, LittleEndian);
let buf = &mut EndianSlice::new(&buf, LittleEndian);
match Abbreviation::parse_tag(buf) {
Err(Error::AbbreviationTagZero) => {}
otherwise => panic!("Unexpected result: {:?}", otherwise),
Expand All @@ -685,7 +687,7 @@ pub mod tests {
#[test]
fn test_parse_abbreviation_has_children() {
let buf = [0x00, 0x01, 0x02];
let rest = &mut EndianBuf::new(&buf, LittleEndian);
let rest = &mut EndianSlice::new(&buf, LittleEndian);
let val = Abbreviation::parse_has_children(rest).expect("Should parse children");
assert_eq!(val, constants::DW_CHILDREN_no);
let val = Abbreviation::parse_has_children(rest).expect("Should parse children");
Expand All @@ -706,7 +708,7 @@ pub mod tests {
.append_bytes(&expected_rest)
.get_contents()
.unwrap();
let rest = &mut EndianBuf::new(&*buf, LittleEndian);
let rest = &mut EndianSlice::new(&*buf, LittleEndian);

let expect = Some(Abbreviation::new(
1,
Expand All @@ -719,7 +721,7 @@ pub mod tests {

let abbrev = Abbreviation::parse(rest).expect("Should parse abbreviation");
assert_eq!(abbrev, expect);
assert_eq!(*rest, EndianBuf::new(&expected_rest, LittleEndian));
assert_eq!(*rest, EndianSlice::new(&expected_rest, LittleEndian));
}

#[test]
Expand All @@ -732,7 +734,7 @@ pub mod tests {
.append_bytes(&expected_rest)
.get_contents()
.unwrap();
let rest = &mut EndianBuf::new(&*buf, LittleEndian);
let rest = &mut EndianSlice::new(&*buf, LittleEndian);

let expect = Some(Abbreviation::new(
1,
Expand All @@ -749,16 +751,17 @@ pub mod tests {

let abbrev = Abbreviation::parse(rest).expect("Should parse abbreviation");
assert_eq!(abbrev, expect);
assert_eq!(*rest, EndianBuf::new(&expected_rest, LittleEndian));
assert_eq!(*rest, EndianSlice::new(&expected_rest, LittleEndian));
}

#[test]
fn test_parse_abbreviation_implicit_const_no_const() {
let buf = Section::new()
.abbrev(1, constants::DW_TAG_subprogram, constants::DW_CHILDREN_no)
.abbrev_attr(constants::DW_AT_name, constants::DW_FORM_implicit_const)
.get_contents()
.unwrap();
let buf = &mut EndianBuf::new(&*buf, LittleEndian);
let buf = &mut EndianSlice::new(&*buf, LittleEndian);

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

let abbrev = Abbreviation::parse(rest).expect("Should parse null abbreviation");
assert!(abbrev.is_none());
assert_eq!(*rest, EndianBuf::new(&expected_rest, LittleEndian));
assert_eq!(*rest, EndianSlice::new(&expected_rest, LittleEndian));
}

#[test]
fn test_parse_attribute_form_ok() {
let buf = [0x01, 0x02];
let rest = &mut EndianBuf::new(&buf, LittleEndian);
let rest = &mut EndianSlice::new(&buf, LittleEndian);
let tag = AttributeSpecification::parse_form(rest).expect("Should parse form");
assert_eq!(tag, constants::DW_FORM_addr);
assert_eq!(*rest, EndianBuf::new(&buf[1..], LittleEndian));
assert_eq!(*rest, EndianSlice::new(&buf[1..], LittleEndian));
}

#[test]
fn test_parse_attribute_form_zero() {
let buf = [0x00];
let buf = &mut EndianBuf::new(&buf, LittleEndian);
let buf = &mut EndianSlice::new(&buf, LittleEndian);
match AttributeSpecification::parse_form(buf) {
Err(Error::AttributeFormZero) => {}
otherwise => panic!("Unexpected result: {:?}", otherwise),
Expand All @@ -803,17 +806,17 @@ pub mod tests {
#[test]
fn test_parse_null_attribute_specification_ok() {
let buf = [0x00, 0x00, 0x01];
let rest = &mut EndianBuf::new(&buf, LittleEndian);
let rest = &mut EndianSlice::new(&buf, LittleEndian);
let attr =
AttributeSpecification::parse(rest).expect("Should parse null attribute specification");
assert!(attr.is_none());
assert_eq!(*rest, EndianBuf::new(&buf[2..], LittleEndian));
assert_eq!(*rest, EndianSlice::new(&buf[2..], LittleEndian));
}

#[test]
fn test_parse_attribute_specifications_name_zero() {
let buf = [0x00, 0x01, 0x00, 0x00];
let buf = &mut EndianBuf::new(&buf, LittleEndian);
let buf = &mut EndianSlice::new(&buf, LittleEndian);
match AttributeSpecification::parse(buf) {
Err(Error::ExpectedZero) => {}
otherwise => panic!("Unexpected result: {:?}", otherwise),
Expand All @@ -823,7 +826,7 @@ pub mod tests {
#[test]
fn test_parse_attribute_specifications_form_zero() {
let buf = [0x01, 0x00, 0x00, 0x00];
let buf = &mut EndianBuf::new(&buf, LittleEndian);
let buf = &mut EndianSlice::new(&buf, LittleEndian);
match AttributeSpecification::parse(buf) {
Err(Error::AttributeFormZero) => {}
otherwise => panic!("Unexpected result: {:?}", otherwise),
Expand Down
30 changes: 16 additions & 14 deletions src/aranges.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use endianity::{EndianBuf, Endianity};
use endianity::Endianity;
use endian_slice::EndianSlice;
use fallible_iterator::FallibleIterator;
use lookup::{DebugLookup, LookupEntryIter, LookupParser};
use parser::{parse_initial_length, Error, Format, Result};
Expand Down Expand Up @@ -174,7 +175,7 @@ impl<R: Reader> LookupParser<R> for ArangeParser<R> {
#[derive(Debug, Clone)]
pub struct DebugAranges<R: Reader>(DebugLookup<R, ArangeParser<R>>);

impl<'input, Endian> DebugAranges<EndianBuf<'input, Endian>>
impl<'input, Endian> DebugAranges<EndianSlice<'input, Endian>>
where
Endian: Endianity,
{
Expand All @@ -194,15 +195,15 @@ where
/// DebugAranges::new(read_debug_aranges_section(), LittleEndian);
/// ```
pub fn new(debug_aranges_section: &'input [u8], endian: Endian) -> Self {
Self::from(EndianBuf::new(debug_aranges_section, endian))
Self::from(EndianSlice::new(debug_aranges_section, endian))
}
}

impl<R: Reader> DebugAranges<R> {
/// Iterate the aranges in the `.debug_aranges` section.
///
/// ```
/// use gimli::{DebugAranges, EndianBuf, LittleEndian};
/// use gimli::{DebugAranges, EndianSlice, LittleEndian};
///
/// # let buf = [];
/// # let read_debug_aranges_section = || &buf;
Expand Down Expand Up @@ -262,7 +263,8 @@ impl<R: Reader> FallibleIterator for ArangeEntryIter<R> {
mod tests {
use super::*;
use lookup::LookupParser;
use endianity::{EndianBuf, LittleEndian};
use endianity::LittleEndian;
use endian_slice::EndianSlice;
use parser::Format;
use unit::DebugInfoOffset;

Expand Down Expand Up @@ -298,13 +300,13 @@ mod tests {
0x00, 0x00, 0x00, 0x00,
];

let rest = &mut EndianBuf::new(&buf, LittleEndian);
let rest = &mut EndianSlice::new(&buf, LittleEndian);

let (tuples, header) = ArangeParser::parse_header(rest)
.expect("should parse header ok");

assert_eq!(*rest, EndianBuf::new(&buf[buf.len() - 16..], LittleEndian));
assert_eq!(tuples, EndianBuf::new(&buf[buf.len() - 32..buf.len() - 16], LittleEndian));
assert_eq!(*rest, EndianSlice::new(&buf[buf.len() - 16..], LittleEndian));
assert_eq!(tuples, EndianSlice::new(&buf[buf.len() - 32..buf.len() - 16], LittleEndian));
assert_eq!(header,
ArangeHeader {
format: Format::Dwarf32,
Expand All @@ -327,9 +329,9 @@ mod tests {
segment_size: 0,
};
let buf = [0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09];
let rest = &mut EndianBuf::new(&buf, LittleEndian);
let rest = &mut EndianSlice::new(&buf, LittleEndian);
let entry = ArangeParser::parse_entry(rest, &header).expect("should parse entry ok");
assert_eq!(*rest, EndianBuf::new(&buf[buf.len() - 1..], LittleEndian));
assert_eq!(*rest, EndianSlice::new(&buf[buf.len() - 1..], LittleEndian));
assert_eq!(
entry,
Some(ArangeEntry {
Expand Down Expand Up @@ -362,10 +364,10 @@ mod tests {
// Next tuple.
0x09
];
let rest = &mut EndianBuf::new(&buf, LittleEndian);
let rest = &mut EndianSlice::new(&buf, LittleEndian);
let entry = ArangeParser::parse_entry(rest, &header)
.expect("should parse entry ok");
assert_eq!(*rest, EndianBuf::new(&buf[buf.len() - 1..], LittleEndian));
assert_eq!(*rest, EndianSlice::new(&buf[buf.len() - 1..], LittleEndian));
assert_eq!(entry,
Some(ArangeEntry {
segment: Some(0x1817161514131211),
Expand Down Expand Up @@ -396,10 +398,10 @@ mod tests {
// Next tuple.
0x09
];
let rest = &mut EndianBuf::new(&buf, LittleEndian);
let rest = &mut EndianSlice::new(&buf, LittleEndian);
let entry = ArangeParser::parse_entry(rest, &header)
.expect("should parse entry ok");
assert_eq!(*rest, EndianBuf::new(&buf[buf.len() - 1..], LittleEndian));
assert_eq!(*rest, EndianSlice::new(&buf[buf.len() - 1..], LittleEndian));
assert_eq!(entry,
Some(ArangeEntry {
segment: None,
Expand Down
Loading

0 comments on commit f177b94

Please sign in to comment.