Skip to content

Commit

Permalink
Add LazyLines newtype
Browse files Browse the repository at this point in the history
  • Loading branch information
philipc committed Apr 16, 2024
1 parent afa873f commit f96cff9
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/lib.rs
Expand Up @@ -47,7 +47,7 @@ use core::ops::ControlFlow;
use core::u64;

use crate::function::{Function, Functions, InlinedFunction, LazyFunctions};
use crate::line::{LineLocationRangeIter, Lines};
use crate::line::{LazyLines, LineLocationRangeIter, Lines};
use crate::lookup::{LoopingLookup, SimpleLookup};
use crate::unit::{ResUnit, ResUnits, SupUnits};

Expand Down
23 changes: 22 additions & 1 deletion src/line.rs
Expand Up @@ -5,8 +5,29 @@ use core::cmp::Ordering;
use core::mem;
use core::num::NonZeroU64;

use crate::lazy::LazyResult;
use crate::{Error, Location};

pub(crate) struct LazyLines(LazyResult<Lines>);

impl LazyLines {
pub(crate) fn new() -> Self {
LazyLines(LazyResult::new())
}

pub(crate) fn borrow<R: gimli::Reader>(
&self,
dw_unit: &gimli::Unit<R>,
ilnp: &gimli::IncompleteLineProgram<R, R::Offset>,
sections: &gimli::Dwarf<R>,
) -> Result<&Lines, Error> {
self.0
.borrow_with(|| Lines::parse(dw_unit, ilnp.clone(), sections))
.as_ref()
.map_err(Error::clone)
}
}

struct LineSequence {
start: u64,
end: u64,
Expand All @@ -26,7 +47,7 @@ pub(crate) struct Lines {
}

impl Lines {
pub(crate) fn parse<R: gimli::Reader>(
fn parse<R: gimli::Reader>(
dw_unit: &gimli::Unit<R>,
ilnp: gimli::IncompleteLineProgram<R, R::Offset>,
sections: &gimli::Dwarf<R>,
Expand Down
20 changes: 7 additions & 13 deletions src/unit.rs
Expand Up @@ -5,8 +5,9 @@ use core::cmp;

use crate::lazy::LazyResult;
use crate::{
Context, DebugFile, Error, Function, Functions, LazyFunctions, LineLocationRangeIter, Lines,
Location, LookupContinuation, LookupResult, RangeAttributes, SimpleLookup, SplitDwarfLoad,
Context, DebugFile, Error, Function, Functions, LazyFunctions, LazyLines,
LineLocationRangeIter, Lines, Location, LookupContinuation, LookupResult, RangeAttributes,
SimpleLookup, SplitDwarfLoad,
};

pub(crate) struct UnitRange {
Expand All @@ -19,7 +20,7 @@ pub(crate) struct ResUnit<R: gimli::Reader> {
offset: gimli::DebugInfoOffset<R::Offset>,
dw_unit: gimli::Unit<R>,
pub(crate) lang: Option<gimli::DwLang>,
lines: LazyResult<Lines>,
lines: LazyLines,
functions: LazyFunctions<R>,
dwo: LazyResult<Option<Box<DwoUnit<R>>>>,
}
Expand Down Expand Up @@ -112,11 +113,7 @@ impl<R: gimli::Reader> ResUnit<R> {
Some(ref ilnp) => ilnp,
None => return Ok(None),
};
self.lines
.borrow_with(|| Lines::parse(&self.dw_unit, ilnp.clone(), sections))
.as_ref()
.map(Some)
.map_err(Error::clone)
self.lines.borrow(&self.dw_unit, ilnp, sections).map(Some)
}

pub(crate) fn parse_functions<'unit, 'ctx: 'unit>(
Expand Down Expand Up @@ -324,15 +321,12 @@ impl<R: gimli::Reader> ResUnits<R> {
}
}

let lines = LazyResult::new();
let lines = LazyLines::new();
if !have_unit_range {
// The unit did not declare any ranges.
// Try to get some ranges from the line program sequences.
if let Some(ref ilnp) = dw_unit.line_program {
if let Ok(lines) = lines
.borrow_with(|| Lines::parse(&dw_unit, ilnp.clone(), sections))
.as_ref()
{
if let Ok(lines) = lines.borrow(&dw_unit, ilnp, sections) {
for range in lines.ranges() {
unit_ranges.push(UnitRange {
range,
Expand Down

0 comments on commit f96cff9

Please sign in to comment.