Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to lazycell #94

Merged
merged 2 commits into from
Jun 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fallible-iterator = "0.1"
object = "0.7"
intervaltree = "0.2"
smallvec = "0.6"
lazy-init = "0.3"
lazycell = "1.0"
rustc-demangle = { version = "0.1", optional = true }
cpp_demangle = { version = "0.2", optional = true }

Expand Down
43 changes: 17 additions & 26 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ extern crate cpp_demangle;
extern crate fallible_iterator;
extern crate gimli;
extern crate intervaltree;
extern crate lazy_init;
extern crate lazycell;
extern crate object;
#[cfg(feature = "rustc-demangle")]
extern crate rustc_demangle;
Expand All @@ -41,7 +41,7 @@ use std::u64;

use fallible_iterator::FallibleIterator;
use intervaltree::{Element, IntervalTree};
use lazy_init::Lazy;
use lazycell::LazyCell;
use object::Object;
use smallvec::SmallVec;

Expand All @@ -57,8 +57,7 @@ struct Lines<R: gimli::Reader> {

struct ResUnit<R>
where
R: gimli::Reader + Sync,
R::Offset: Sync,
R: gimli::Reader,
{
dw_unit: gimli::CompilationUnitHeader<R, R::Offset>,
abbrevs: gimli::Abbreviations,
Expand All @@ -67,8 +66,8 @@ where
comp_name: Option<R>,
lang: Option<gimli::DwLang>,
base_addr: u64,
lines: Lazy<Result<Lines<R>, Error>>,
funcs: Lazy<Result<IntervalTree<u64, Func<R::Offset>>, Error>>,
lines: LazyCell<Result<Lines<R>, Error>>,
funcs: LazyCell<Result<IntervalTree<u64, Func<R::Offset>>, Error>>,
}

/// The state necessary to perform address to line translation.
Expand All @@ -77,8 +76,7 @@ where
/// when performing lookups for many addresses in the same executable.
pub struct Context<R>
where
R: gimli::Reader + Sync,
R::Offset: Sync,
R: gimli::Reader,
{
unit_ranges: Vec<(gimli::Range, usize)>,
units: Vec<ResUnit<R>>,
Expand Down Expand Up @@ -205,8 +203,8 @@ impl<'a> Context<gimli::EndianSlice<'a, gimli::RunTimeEndian>> {
comp_name: dcn,
lang,
base_addr,
lines: Lazy::new(),
funcs: Lazy::new(),
lines: LazyCell::new(),
funcs: LazyCell::new(),
});
}

Expand Down Expand Up @@ -242,12 +240,11 @@ impl<'a> Context<gimli::EndianSlice<'a, gimli::RunTimeEndian>> {

impl<R> ResUnit<R>
where
R: gimli::Reader + Sync,
R::Offset: Sync,
R: gimli::Reader,
{
fn parse_lines(&self, sections: &DebugSections<R>) -> Result<&Lines<R>, Error> {
self.lines
.get_or_create(|| {
.borrow_with(|| {
let ilnp = sections.debug_line.program(
self.line_offset,
self.dw_unit.address_size(),
Expand All @@ -269,7 +266,7 @@ where
sections: &DebugSections<R>,
) -> Result<&IntervalTree<u64, Func<R::Offset>>, Error> {
self.funcs
.get_or_create(|| {
.borrow_with(|| {
let mut results = Vec::new();
let mut depth = 0;
let mut cursor = self.dw_unit.entries(&self.abbrevs);
Expand Down Expand Up @@ -322,8 +319,7 @@ struct DebugSections<R: gimli::Reader> {
/// An iterator over function frames.
pub struct FrameIter<'ctx, R>
where
R: gimli::Reader + Sync + 'ctx,
R::Offset: Sync,
R: gimli::Reader + 'ctx,
{
unit_id: usize,
units: &'ctx Vec<ResUnit<R>>,
Expand Down Expand Up @@ -426,8 +422,7 @@ pub struct Location {

impl<R> Context<R>
where
R: gimli::Reader + Sync,
R::Offset: Sync,
R: gimli::Reader,
{
fn find_unit(&self, probe: u64) -> Option<usize> {
let idx = self.unit_ranges.binary_search_by(|r| {
Expand Down Expand Up @@ -491,8 +486,7 @@ where

impl<R> ResUnit<R>
where
R: gimli::Reader + Sync,
R::Offset: Sync,
R: gimli::Reader,
{
fn find_location(
&self,
Expand Down Expand Up @@ -570,8 +564,7 @@ fn name_attr<'abbrev, 'unit, R>(
recursion_limit: usize,
) -> Result<Option<R>, Error>
where
R: gimli::Reader + Sync,
R::Offset: Sync,
R: gimli::Reader,
{
if recursion_limit == 0 {
return Ok(None);
Expand Down Expand Up @@ -625,8 +618,7 @@ where

impl<'ctx, R> FrameIter<'ctx, R>
where
R: gimli::Reader + Sync + 'ctx,
R::Offset: Sync,
R: gimli::Reader + 'ctx,
{
/// Advances the iterator and returns the next frame.
pub fn next(&mut self) -> Result<Option<Frame<R>>, Error> {
Expand Down Expand Up @@ -690,8 +682,7 @@ where

impl<'ctx, R> FallibleIterator for FrameIter<'ctx, R>
where
R: gimli::Reader + Sync + 'ctx,
R::Offset: Sync,
R: gimli::Reader + 'ctx,
{
type Item = Frame<R>;
type Error = Error;
Expand Down