Skip to content

Commit a336e8f

Browse files
authored
Delete some trivial functions (#861)
These are simple enough that the code is clearer if they are inline.
1 parent 31d16f9 commit a336e8f

File tree

2 files changed

+21
-209
lines changed

2 files changed

+21
-209
lines changed

src/read/lookup.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use core::marker::PhantomData;
22

33
use crate::common::{DebugInfoOffset, Format};
4-
use crate::read::{Error, Reader, ReaderOffset, Result, UnitOffset, parse_debug_info_offset};
4+
use crate::read::{Error, Reader, ReaderOffset, Result, UnitOffset};
55

66
// The various "Accelerated Access" sections (DWARF standard v4 Section 6.1) all have
77
// similar structures. They consist of a header with metadata and an offset into the
@@ -169,7 +169,7 @@ where
169169
return Err(Error::UnknownVersion(u64::from(version)));
170170
}
171171

172-
let unit_offset = parse_debug_info_offset(&mut rest, format)?;
172+
let unit_offset = rest.read_offset(format).map(DebugInfoOffset)?;
173173
let unit_length = rest.read_length(format)?;
174174

175175
let header = PubStuffHeader {

src/read/unit.rs

Lines changed: 19 additions & 207 deletions
Original file line numberDiff line numberDiff line change
@@ -307,28 +307,6 @@ impl<R: Reader> Iterator for DebugInfoUnitHeadersIter<R> {
307307
}
308308
}
309309

310-
/// Parse the unit type from the unit header.
311-
fn parse_unit_type<R: Reader>(input: &mut R) -> Result<constants::DwUt> {
312-
let val = input.read_u8()?;
313-
Ok(constants::DwUt(val))
314-
}
315-
316-
/// Parse the `debug_abbrev_offset` in the compilation unit header.
317-
fn parse_debug_abbrev_offset<R: Reader>(
318-
input: &mut R,
319-
format: Format,
320-
) -> Result<DebugAbbrevOffset<R::Offset>> {
321-
input.read_offset(format).map(DebugAbbrevOffset)
322-
}
323-
324-
/// Parse the `debug_info_offset` in the arange header.
325-
pub(crate) fn parse_debug_info_offset<R: Reader>(
326-
input: &mut R,
327-
format: Format,
328-
) -> Result<DebugInfoOffset<R::Offset>> {
329-
input.read_offset(format).map(DebugInfoOffset)
330-
}
331-
332310
/// This enum specifies the type of the unit and any type
333311
/// specific data carried in the header (e.g. the type
334312
/// signature/type offset of a type unit).
@@ -712,7 +690,7 @@ where
712690
// DWARF 1 was very different, and is obsolete, so isn't supported by this
713691
// reader.
714692
if 2 <= version && version <= 4 {
715-
abbrev_offset = parse_debug_abbrev_offset(&mut rest, format)?;
693+
abbrev_offset = rest.read_offset(format).map(DebugAbbrevOffset)?;
716694
address_size = rest.read_address_size()?;
717695
// Before DWARF5, all units in the .debug_info section are compilation
718696
// units, and all units in the .debug_types section are type units.
@@ -721,9 +699,9 @@ where
721699
_ => constants::DW_UT_compile,
722700
};
723701
} else if version == 5 {
724-
unit_type = parse_unit_type(&mut rest)?;
702+
unit_type = rest.read_u8().map(constants::DwUt)?;
725703
address_size = rest.read_address_size()?;
726-
abbrev_offset = parse_debug_abbrev_offset(&mut rest, format)?;
704+
abbrev_offset = rest.read_offset(format).map(DebugAbbrevOffset)?;
727705
} else {
728706
return Err(Error::UnknownVersion(u64::from(version)));
729707
}
@@ -737,25 +715,25 @@ where
737715
let unit_type = match unit_type {
738716
constants::DW_UT_compile => UnitType::Compilation,
739717
constants::DW_UT_type => {
740-
let type_signature = parse_type_signature(&mut rest)?;
741-
let type_offset = parse_type_offset(&mut rest, format)?;
718+
let type_signature = rest.read_u64().map(DebugTypeSignature)?;
719+
let type_offset = rest.read_offset(format).map(UnitOffset)?;
742720
UnitType::Type {
743721
type_signature,
744722
type_offset,
745723
}
746724
}
747725
constants::DW_UT_partial => UnitType::Partial,
748726
constants::DW_UT_skeleton => {
749-
let dwo_id = parse_dwo_id(&mut rest)?;
727+
let dwo_id = rest.read_u64().map(DwoId)?;
750728
UnitType::Skeleton(dwo_id)
751729
}
752730
constants::DW_UT_split_compile => {
753-
let dwo_id = parse_dwo_id(&mut rest)?;
731+
let dwo_id = rest.read_u64().map(DwoId)?;
754732
UnitType::SplitCompilation(dwo_id)
755733
}
756734
constants::DW_UT_split_type => {
757-
let type_signature = parse_type_signature(&mut rest)?;
758-
let type_offset = parse_type_offset(&mut rest, format)?;
735+
let type_signature = rest.read_u64().map(DebugTypeSignature)?;
736+
let type_offset = rest.read_offset(format).map(UnitOffset)?;
759737
UnitType::SplitType {
760738
type_signature,
761739
type_offset,
@@ -775,11 +753,6 @@ where
775753
))
776754
}
777755

778-
/// Parse a dwo_id from a header
779-
fn parse_dwo_id<R: Reader>(input: &mut R) -> Result<DwoId> {
780-
Ok(DwoId(input.read_u64()?))
781-
}
782-
783756
/// A Debugging Information Entry (DIE).
784757
///
785758
/// DIEs have a set of attributes and optionally have children DIEs as well.
@@ -1934,26 +1907,6 @@ where
19341907
}
19351908
}
19361909

1937-
fn length_u8_value<R: Reader>(input: &mut R) -> Result<R> {
1938-
let len = input.read_u8().map(R::Offset::from_u8)?;
1939-
input.split(len)
1940-
}
1941-
1942-
fn length_u16_value<R: Reader>(input: &mut R) -> Result<R> {
1943-
let len = input.read_u16().map(R::Offset::from_u16)?;
1944-
input.split(len)
1945-
}
1946-
1947-
fn length_u32_value<R: Reader>(input: &mut R) -> Result<R> {
1948-
let len = input.read_u32().map(R::Offset::from_u32)?;
1949-
input.split(len)
1950-
}
1951-
1952-
fn length_uleb128_value<R: Reader>(input: &mut R) -> Result<R> {
1953-
let len = input.read_uleb128().and_then(R::Offset::from_u64)?;
1954-
input.split(len)
1955-
}
1956-
19571910
// Return true if the given `name` can be a section offset in DWARF version 2/3.
19581911
// This is required to correctly handle relocations.
19591912
fn allow_section_offset(name: constants::DwAt, version: u16) -> bool {
@@ -1997,19 +1950,23 @@ pub(crate) fn parse_attribute<R: Reader>(
19971950
AttributeValue::Addr(addr)
19981951
}
19991952
constants::DW_FORM_block1 => {
2000-
let block = length_u8_value(input)?;
1953+
let len = input.read_u8().map(R::Offset::from_u8)?;
1954+
let block = input.split(len)?;
20011955
AttributeValue::Block(block)
20021956
}
20031957
constants::DW_FORM_block2 => {
2004-
let block = length_u16_value(input)?;
1958+
let len = input.read_u16().map(R::Offset::from_u16)?;
1959+
let block = input.split(len)?;
20051960
AttributeValue::Block(block)
20061961
}
20071962
constants::DW_FORM_block4 => {
2008-
let block = length_u32_value(input)?;
1963+
let len = input.read_u32().map(R::Offset::from_u32)?;
1964+
let block = input.split(len)?;
20091965
AttributeValue::Block(block)
20101966
}
20111967
constants::DW_FORM_block => {
2012-
let block = length_uleb128_value(input)?;
1968+
let len = input.read_uleb128().and_then(R::Offset::from_u64)?;
1969+
let block = input.split(len)?;
20131970
AttributeValue::Block(block)
20141971
}
20151972
constants::DW_FORM_data1 => {
@@ -2059,7 +2016,8 @@ pub(crate) fn parse_attribute<R: Reader>(
20592016
AttributeValue::Sdata(data)
20602017
}
20612018
constants::DW_FORM_exprloc => {
2062-
let block = length_uleb128_value(input)?;
2019+
let len = input.read_uleb128().and_then(R::Offset::from_u64)?;
2020+
let block = input.split(len)?;
20632021
AttributeValue::Exprloc(Expression(block))
20642022
}
20652023
constants::DW_FORM_flag => {
@@ -3038,17 +2996,6 @@ impl<'abbrev, 'tree, R: Reader> EntriesTreeIter<'abbrev, 'tree, R> {
30382996
}
30392997
}
30402998

3041-
/// Parse a type unit header's unique type signature. Callers should handle
3042-
/// unique-ness checking.
3043-
fn parse_type_signature<R: Reader>(input: &mut R) -> Result<DebugTypeSignature> {
3044-
input.read_u64().map(DebugTypeSignature)
3045-
}
3046-
3047-
/// Parse a type unit header's type offset.
3048-
fn parse_type_offset<R: Reader>(input: &mut R, format: Format) -> Result<UnitOffset<R::Offset>> {
3049-
input.read_offset(format).map(UnitOffset)
3050-
}
3051-
30522999
/// The `DebugTypes` struct represents the DWARF type information
30533000
/// found in the `.debug_types` section.
30543001
#[derive(Debug, Default, Clone, Copy)]
@@ -3310,100 +3257,6 @@ mod tests {
33103257
}
33113258
}
33123259

3313-
#[test]
3314-
fn test_parse_debug_abbrev_offset_32() {
3315-
let section = Section::with_endian(Endian::Little).L32(0x0403_0201);
3316-
let buf = section.get_contents().unwrap();
3317-
let buf = &mut EndianSlice::new(&buf, LittleEndian);
3318-
3319-
match parse_debug_abbrev_offset(buf, Format::Dwarf32) {
3320-
Ok(val) => assert_eq!(val, DebugAbbrevOffset(0x0403_0201)),
3321-
otherwise => panic!("Unexpected result: {:?}", otherwise),
3322-
};
3323-
}
3324-
3325-
#[test]
3326-
fn test_parse_debug_abbrev_offset_32_incomplete() {
3327-
let buf = [0x01, 0x02];
3328-
let buf = &mut EndianSlice::new(&buf, LittleEndian);
3329-
3330-
match parse_debug_abbrev_offset(buf, Format::Dwarf32) {
3331-
Err(Error::UnexpectedEof(_)) => {}
3332-
otherwise => panic!("Unexpected result: {:?}", otherwise),
3333-
};
3334-
}
3335-
3336-
#[test]
3337-
#[cfg(target_pointer_width = "64")]
3338-
fn test_parse_debug_abbrev_offset_64() {
3339-
let section = Section::with_endian(Endian::Little).L64(0x0807_0605_0403_0201);
3340-
let buf = section.get_contents().unwrap();
3341-
let buf = &mut EndianSlice::new(&buf, LittleEndian);
3342-
3343-
match parse_debug_abbrev_offset(buf, Format::Dwarf64) {
3344-
Ok(val) => assert_eq!(val, DebugAbbrevOffset(0x0807_0605_0403_0201)),
3345-
otherwise => panic!("Unexpected result: {:?}", otherwise),
3346-
};
3347-
}
3348-
3349-
#[test]
3350-
fn test_parse_debug_abbrev_offset_64_incomplete() {
3351-
let buf = [0x01, 0x02];
3352-
let buf = &mut EndianSlice::new(&buf, LittleEndian);
3353-
3354-
match parse_debug_abbrev_offset(buf, Format::Dwarf64) {
3355-
Err(Error::UnexpectedEof(_)) => {}
3356-
otherwise => panic!("Unexpected result: {:?}", otherwise),
3357-
};
3358-
}
3359-
3360-
#[test]
3361-
fn test_parse_debug_info_offset_32() {
3362-
let section = Section::with_endian(Endian::Little).L32(0x0403_0201);
3363-
let buf = section.get_contents().unwrap();
3364-
let buf = &mut EndianSlice::new(&buf, LittleEndian);
3365-
3366-
match parse_debug_info_offset(buf, Format::Dwarf32) {
3367-
Ok(val) => assert_eq!(val, DebugInfoOffset(0x0403_0201)),
3368-
otherwise => panic!("Unexpected result: {:?}", otherwise),
3369-
};
3370-
}
3371-
3372-
#[test]
3373-
fn test_parse_debug_info_offset_32_incomplete() {
3374-
let buf = [0x01, 0x02];
3375-
let buf = &mut EndianSlice::new(&buf, LittleEndian);
3376-
3377-
match parse_debug_info_offset(buf, Format::Dwarf32) {
3378-
Err(Error::UnexpectedEof(_)) => {}
3379-
otherwise => panic!("Unexpected result: {:?}", otherwise),
3380-
};
3381-
}
3382-
3383-
#[test]
3384-
#[cfg(target_pointer_width = "64")]
3385-
fn test_parse_debug_info_offset_64() {
3386-
let section = Section::with_endian(Endian::Little).L64(0x0807_0605_0403_0201);
3387-
let buf = section.get_contents().unwrap();
3388-
let buf = &mut EndianSlice::new(&buf, LittleEndian);
3389-
3390-
match parse_debug_info_offset(buf, Format::Dwarf64) {
3391-
Ok(val) => assert_eq!(val, DebugInfoOffset(0x0807_0605_0403_0201)),
3392-
otherwise => panic!("Unexpected result: {:?}", otherwise),
3393-
};
3394-
}
3395-
3396-
#[test]
3397-
fn test_parse_debug_info_offset_64_incomplete() {
3398-
let buf = [0x01, 0x02];
3399-
let buf = &mut EndianSlice::new(&buf, LittleEndian);
3400-
3401-
match parse_debug_info_offset(buf, Format::Dwarf64) {
3402-
Err(Error::UnexpectedEof(_)) => {}
3403-
otherwise => panic!("Unexpected result: {:?}", otherwise),
3404-
};
3405-
}
3406-
34073260
#[test]
34083261
#[cfg(target_pointer_width = "64")]
34093262
fn test_units() {
@@ -3782,47 +3635,6 @@ mod tests {
37823635
assert_eq!(*rest, EndianSlice::new(expected_rest, LittleEndian));
37833636
}
37843637

3785-
#[test]
3786-
fn test_parse_type_offset_32_ok() {
3787-
let buf = [0x12, 0x34, 0x56, 0x78, 0x00];
3788-
let rest = &mut EndianSlice::new(&buf, LittleEndian);
3789-
3790-
match parse_type_offset(rest, Format::Dwarf32) {
3791-
Ok(offset) => {
3792-
assert_eq!(rest.len(), 1);
3793-
assert_eq!(UnitOffset(0x7856_3412), offset);
3794-
}
3795-
otherwise => panic!("Unexpected result: {:?}", otherwise),
3796-
}
3797-
}
3798-
3799-
#[test]
3800-
#[cfg(target_pointer_width = "64")]
3801-
fn test_parse_type_offset_64_ok() {
3802-
let buf = [0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xff, 0x00];
3803-
let rest = &mut EndianSlice::new(&buf, LittleEndian);
3804-
3805-
match parse_type_offset(rest, Format::Dwarf64) {
3806-
Ok(offset) => {
3807-
assert_eq!(rest.len(), 1);
3808-
assert_eq!(UnitOffset(0xffde_bc9a_7856_3412), offset);
3809-
}
3810-
otherwise => panic!("Unexpected result: {:?}", otherwise),
3811-
}
3812-
}
3813-
3814-
#[test]
3815-
fn test_parse_type_offset_incomplete() {
3816-
// Need at least 4 bytes.
3817-
let buf = [0xff, 0xff, 0xff];
3818-
let rest = &mut EndianSlice::new(&buf, LittleEndian);
3819-
3820-
match parse_type_offset(rest, Format::Dwarf32) {
3821-
Err(Error::UnexpectedEof(_)) => {}
3822-
otherwise => panic!("Unexpected result: {:?}", otherwise),
3823-
};
3824-
}
3825-
38263638
#[test]
38273639
fn test_parse_type_unit_header_32_ok() {
38283640
let expected_rest = &[1, 2, 3, 4, 5, 6, 7, 8, 9];

0 commit comments

Comments
 (0)