Skip to content

Commit

Permalink
read: add DwarfPackageSections::borrow
Browse files Browse the repository at this point in the history
Also replace Dwarf::borrow with DwarfSections::borrow
for consistency.
  • Loading branch information
philipc committed Mar 14, 2024
1 parent d8361e8 commit e6e90c9
Show file tree
Hide file tree
Showing 13 changed files with 409 additions and 174 deletions.
3 changes: 2 additions & 1 deletion crates/examples/src/bin/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn dump_file(object: &object::File, endian: gimli::RunTimeEndian) -> Result<(),
};

// Load all of the sections.
let dwarf_cow = gimli::Dwarf::load(&load_section)?;
let dwarf_cow = gimli::DwarfSections::load(&load_section)?;

// Borrow a `Cow<[u8]>` to create an `EndianSlice`.
let borrow_section: &dyn for<'a> Fn(
Expand All @@ -38,6 +38,7 @@ fn dump_file(object: &object::File, endian: gimli::RunTimeEndian) -> Result<(),
&|section| gimli::EndianSlice::new(section, endian);

// Create `EndianSlice`s for all of the sections.
// Alternatively, we could have used `Dwarf::load` with an owned type such as `EndianRcSlice`.
let dwarf = dwarf_cow.borrow(&borrow_section);

// Iterate over the compilation units.
Expand Down
2 changes: 1 addition & 1 deletion crates/examples/src/bin/simple_line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn dump_file(object: &object::File, endian: gimli::RunTimeEndian) -> Result<(),
};

// Load all of the sections.
let dwarf_cow = gimli::Dwarf::load(&load_section)?;
let dwarf_cow = gimli::DwarfSections::load(&load_section)?;

// Borrow a `Cow<[u8]>` to create an `EndianSlice`.
let borrow_section: &dyn for<'a> Fn(
Expand Down
12 changes: 1 addition & 11 deletions src/read/abbrev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,7 @@ impl<T> DebugAbbrev<T> {
///
/// This is useful when `R` implements `Reader` but `T` does not.
///
/// ## Example Usage
///
/// ```rust,no_run
/// # let load_section = || unimplemented!();
/// // Read the DWARF section into a `Vec` with whatever object loader you're using.
/// let owned_section: gimli::DebugAbbrev<Vec<u8>> = load_section();
/// // Create a reference to the DWARF section.
/// let section = owned_section.borrow(|section| {
/// gimli::EndianSlice::new(&section, gimli::LittleEndian)
/// });
/// ```
/// Used by `DwarfSections::borrow`.
pub fn borrow<'a, F, R>(&'a self, mut borrow: F) -> DebugAbbrev<R>
where
F: FnMut(&'a T) -> R,
Expand Down
12 changes: 1 addition & 11 deletions src/read/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,7 @@ impl<T> DebugAddr<T> {
///
/// This is useful when `R` implements `Reader` but `T` does not.
///
/// ## Example Usage
///
/// ```rust,no_run
/// # let load_section = || unimplemented!();
/// // Read the DWARF section into a `Vec` with whatever object loader you're using.
/// let owned_section: gimli::DebugAddr<Vec<u8>> = load_section();
/// // Create a reference to the DWARF section.
/// let section = owned_section.borrow(|section| {
/// gimli::EndianSlice::new(&section, gimli::LittleEndian)
/// });
/// ```
/// Used by `DwarfSections::borrow`.
pub fn borrow<'a, F, R>(&'a self, mut borrow: F) -> DebugAddr<R>
where
F: FnMut(&'a T) -> R,
Expand Down
12 changes: 1 addition & 11 deletions src/read/aranges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,7 @@ impl<T> DebugAranges<T> {
///
/// This is useful when `R` implements `Reader` but `T` does not.
///
/// ## Example Usage
///
/// ```rust,no_run
/// # let load_section = || unimplemented!();
/// // Read the DWARF section into a `Vec` with whatever object loader you're using.
/// let owned_section: gimli::DebugAranges<Vec<u8>> = load_section();
/// // Create a reference to the DWARF section.
/// let section = owned_section.borrow(|section| {
/// gimli::EndianSlice::new(&section, gimli::LittleEndian)
/// });
/// ```
/// Used by `DwarfSections::borrow`.
pub fn borrow<'a, F, R>(&'a self, mut borrow: F) -> DebugAranges<R>
where
F: FnMut(&'a T) -> R,
Expand Down
Loading

0 comments on commit e6e90c9

Please sign in to comment.