Skip to content

Commit

Permalink
Merge pull request gimli-rs#455 from philipc/entries_raw
Browse files Browse the repository at this point in the history
 read: add `EntriesRaw`
  • Loading branch information
philipc committed Nov 26, 2019
2 parents e516309 + 0b04978 commit 1b7706b
Show file tree
Hide file tree
Showing 5 changed files with 377 additions and 48 deletions.
34 changes: 34 additions & 0 deletions benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,40 @@ fn parse_debug_info_tree<R: Reader>(node: EntriesTreeNode<R>) {
}
}

#[bench]
fn bench_parsing_debug_info_raw(b: &mut test::Bencher) {
let debug_abbrev = read_section("debug_abbrev");
let debug_abbrev = DebugAbbrev::new(&debug_abbrev, LittleEndian);

let debug_info = read_section("debug_info");

b.iter(|| {
let debug_info = DebugInfo::new(&debug_info, LittleEndian);

let mut iter = debug_info.units();
while let Some(unit) = iter.next().expect("Should parse compilation unit") {
let abbrevs = unit
.abbreviations(&debug_abbrev)
.expect("Should parse abbreviations");

let mut raw = unit
.entries_raw(&abbrevs, None)
.expect("Should have entries");
while !raw.is_empty() {
if let Some(abbrev) = raw
.read_abbreviation()
.expect("Should parse abbreviation code")
{
for spec in abbrev.attributes().iter().cloned() {
let attr = raw.read_attribute(spec).expect("Should parse attribute");
test::black_box(&attr);
}
}
}
}
});
}

#[bench]
fn bench_parsing_debug_aranges(b: &mut test::Bencher) {
let debug_aranges = read_section("debug_aranges");
Expand Down
17 changes: 10 additions & 7 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Format {
/// 64-bit DWARF
Dwarf64,
Dwarf64 = 8,
/// 32-bit DWARF
Dwarf32,
Dwarf32 = 4,
}

impl Format {
Expand All @@ -31,17 +31,20 @@ impl Format {
///
/// This is intended to be small enough to pass by value.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
// `address_size` and `format` are used more often than `version`, so keep
// them first.
#[repr(C)]
pub struct Encoding {
/// The size of an address.
pub address_size: u8,

// The size of a segment selector.
// TODO: pub segment_size: u8,
/// Whether the DWARF format is 32- or 64-bit.
pub format: Format,

/// The DWARF version of the header.
pub version: u16,

/// The size of an address.
pub address_size: u8,
// The size of a segment selector.
// TODO: pub segment_size: u8,
}

/// Encoding parameters for a line number program.
Expand Down
13 changes: 10 additions & 3 deletions src/read/dwarf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ use crate::constants;
use crate::read::{
Abbreviations, AttributeValue, CompilationUnitHeader, CompilationUnitHeadersIter, DebugAbbrev,
DebugAddr, DebugInfo, DebugLine, DebugLineStr, DebugStr, DebugStrOffsets, DebugTypes,
DebuggingInformationEntry, EntriesCursor, EntriesTree, Error, IncompleteLineProgram,
LocListIter, LocationLists, Range, RangeLists, Reader, ReaderOffset, ReaderOffsetId, Result,
RngListIter, Section, TypeUnitHeader, TypeUnitHeadersIter, UnitHeader, UnitOffset,
DebuggingInformationEntry, EntriesCursor, EntriesRaw, EntriesTree, Error,
IncompleteLineProgram, LocListIter, LocationLists, Range, RangeLists, Reader, ReaderOffset,
ReaderOffsetId, Result, RngListIter, Section, TypeUnitHeader, TypeUnitHeadersIter, UnitHeader,
UnitOffset,
};
use crate::string::String;

Expand Down Expand Up @@ -652,6 +653,12 @@ impl<R: Reader> Unit<R> {
pub fn entries_tree(&self, offset: Option<UnitOffset<R::Offset>>) -> Result<EntriesTree<R>> {
self.header.entries_tree(&self.abbreviations, offset)
}

/// Read the raw data that defines the Debugging Information Entries.
#[inline]
pub fn entries_raw(&self, offset: Option<UnitOffset<R::Offset>>) -> Result<EntriesRaw<R>> {
self.header.entries_raw(&self.abbreviations, offset)
}
}

impl<T: ReaderOffset> UnitSectionOffset<T> {
Expand Down
Loading

0 comments on commit 1b7706b

Please sign in to comment.