Skip to content

fix: Add a SymbolIterator and Lifetimes to ObjectLike trait #277

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

Merged
merged 5 commits into from
Oct 9, 2020
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
11 changes: 7 additions & 4 deletions symbolic-debuginfo/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -625,13 +625,16 @@ pub trait DebugSession {
}

/// An object containing debug information.
pub trait ObjectLike {
pub trait ObjectLike<'data, 'object> {
/// Errors thrown when reading information from this object.
type Error;

/// A session that allows optimized access to debugging information.
type Session: DebugSession<Error = Self::Error>;

/// The iterator over the symbols in the public symbol table.
type SymbolIterator: Iterator<Item = Symbol<'data>>;

/// The container format of this file.
fn file_format(&self) -> FileFormat;

Expand All @@ -657,10 +660,10 @@ pub trait ObjectLike {
fn has_symbols(&self) -> bool;

/// Returns an iterator over symbols in the public symbol table.
fn symbols(&self) -> DynIterator<'_, Symbol<'_>>;
fn symbols(&'object self) -> Self::SymbolIterator;

/// Returns an ordered map of symbols in the symbol table.
fn symbol_map(&self) -> SymbolMap<'_>;
fn symbol_map(&self) -> SymbolMap<'data>;

/// Determines whether this object contains debug information.
fn has_debug_info(&self) -> bool;
Expand All @@ -674,7 +677,7 @@ pub trait ObjectLike {
/// Constructing this session will also work if the object does not contain debugging
/// information, in which case the session will be a no-op. This can be checked via
/// [`has_debug_info`](trait.ObjectLike.html#tymethod.has_debug_info).
fn debug_session(&self) -> Result<Self::Session, Self::Error>;
fn debug_session(&'object self) -> Result<Self::Session, Self::Error>;

/// Determines whether this object contains stack unwinding information.
fn has_unwind_info(&self) -> bool;
Expand Down
57 changes: 29 additions & 28 deletions symbolic-debuginfo/src/breakpad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -734,21 +734,21 @@ impl<'d> Iterator for BreakpadStackRecords<'d> {
/// > compactness.
///
/// The full documentation resides [here](https://chromium.googlesource.com/breakpad/breakpad/+/refs/heads/master/docs/symbol_files.md).
pub struct BreakpadObject<'d> {
pub struct BreakpadObject<'data> {
id: DebugId,
arch: Arch,
module: BreakpadModuleRecord<'d>,
data: &'d [u8],
module: BreakpadModuleRecord<'data>,
data: &'data [u8],
}

impl<'d> BreakpadObject<'d> {
impl<'data> BreakpadObject<'data> {
/// Tests whether the buffer could contain a Breakpad object.
pub fn test(data: &[u8]) -> bool {
data.starts_with(b"MODULE ")
}

/// Tries to parse a Breakpad object from the given slice.
pub fn parse(data: &'d [u8]) -> Result<Self, BreakpadError> {
pub fn parse(data: &'data [u8]) -> Result<Self, BreakpadError> {
// Ensure that we do not read the entire file at once.
let header = if data.len() > BREAKPAD_HEADER_CAP {
match str::from_utf8(&data[..BREAKPAD_HEADER_CAP]) {
Expand Down Expand Up @@ -813,7 +813,7 @@ impl<'d> BreakpadObject<'d> {
/// This is the name of the original debug file that was used to create the Breakpad file. On
/// Windows, this will have a `.pdb` extension, on other platforms that name is likely
/// equivalent to the name of the code file (shared library or executable).
pub fn name(&self) -> &'d str {
pub fn name(&self) -> &'data str {
self.module.name
}

Expand All @@ -836,14 +836,14 @@ impl<'d> BreakpadObject<'d> {
}

/// Returns an iterator over symbols in the public symbol table.
pub fn symbols(&self) -> BreakpadSymbolIterator<'d> {
pub fn symbols(&self) -> BreakpadSymbolIterator<'data> {
BreakpadSymbolIterator {
records: self.public_records(),
}
}

/// Returns an ordered map of symbols in the symbol table.
pub fn symbol_map(&self) -> SymbolMap<'d> {
pub fn symbol_map(&self) -> SymbolMap<'data> {
self.symbols().collect()
}

Expand All @@ -861,7 +861,7 @@ impl<'d> BreakpadObject<'d> {
/// Constructing this session will also work if the object does not contain debugging
/// information, in which case the session will be a no-op. This can be checked via
/// [`has_debug_info`](struct.BreakpadObject.html#method.has_debug_info).
pub fn debug_session(&self) -> Result<BreakpadDebugSession<'d>, BreakpadError> {
pub fn debug_session(&self) -> Result<BreakpadDebugSession<'data>, BreakpadError> {
Ok(BreakpadDebugSession {
file_map: self.file_map(),
func_records: self.func_records(),
Expand All @@ -879,55 +879,55 @@ impl<'d> BreakpadObject<'d> {
}

/// Returns an iterator over info records.
pub fn info_records(&self) -> BreakpadInfoRecords<'d> {
pub fn info_records(&self) -> BreakpadInfoRecords<'data> {
BreakpadInfoRecords {
lines: Lines::new(self.data),
finished: false,
}
}

/// Returns an iterator over file records.
pub fn file_records(&self) -> BreakpadFileRecords<'d> {
pub fn file_records(&self) -> BreakpadFileRecords<'data> {
BreakpadFileRecords {
lines: Lines::new(self.data),
finished: false,
}
}

/// Returns a map for file name lookups by id.
pub fn file_map(&self) -> BreakpadFileMap<'d> {
pub fn file_map(&self) -> BreakpadFileMap<'data> {
self.file_records()
.filter_map(Result::ok)
.map(|file| (file.id, file.name))
.collect()
}

/// Returns an iterator over public symbol records.
pub fn public_records(&self) -> BreakpadPublicRecords<'d> {
pub fn public_records(&self) -> BreakpadPublicRecords<'data> {
BreakpadPublicRecords {
lines: Lines::new(self.data),
finished: false,
}
}

/// Returns an iterator over function records.
pub fn func_records(&self) -> BreakpadFuncRecords<'d> {
pub fn func_records(&self) -> BreakpadFuncRecords<'data> {
BreakpadFuncRecords {
lines: Lines::new(self.data),
finished: false,
}
}

/// Returns an iterator over stack frame records.
pub fn stack_records(&self) -> BreakpadStackRecords<'d> {
pub fn stack_records(&self) -> BreakpadStackRecords<'data> {
BreakpadStackRecords {
lines: Lines::new(self.data),
finished: false,
}
}

/// Returns the raw data of the Breakpad file.
pub fn data(&self) -> &'d [u8] {
pub fn data(&self) -> &'data [u8] {
self.data
}
}
Expand All @@ -946,29 +946,30 @@ impl fmt::Debug for BreakpadObject<'_> {
}
}

impl<'slf, 'd: 'slf> AsSelf<'slf> for BreakpadObject<'d> {
impl<'slf, 'data: 'slf> AsSelf<'slf> for BreakpadObject<'data> {
type Ref = BreakpadObject<'slf>;

fn as_self(&'slf self) -> &Self::Ref {
self
}
}

impl<'d> Parse<'d> for BreakpadObject<'d> {
impl<'data> Parse<'data> for BreakpadObject<'data> {
type Error = BreakpadError;

fn test(data: &[u8]) -> bool {
Self::test(data)
}

fn parse(data: &'d [u8]) -> Result<Self, BreakpadError> {
fn parse(data: &'data [u8]) -> Result<Self, BreakpadError> {
Self::parse(data)
}
}

impl<'d> ObjectLike for BreakpadObject<'d> {
impl<'data: 'object, 'object> ObjectLike<'data, 'object> for BreakpadObject<'data> {
type Error = BreakpadError;
type Session = BreakpadDebugSession<'d>;
type Session = BreakpadDebugSession<'data>;
type SymbolIterator = BreakpadSymbolIterator<'data>;

fn file_format(&self) -> FileFormat {
self.file_format()
Expand Down Expand Up @@ -998,11 +999,11 @@ impl<'d> ObjectLike for BreakpadObject<'d> {
self.has_symbols()
}

fn symbols(&self) -> DynIterator<'_, Symbol<'_>> {
Box::new(self.symbols())
fn symbols(&self) -> Self::SymbolIterator {
self.symbols()
}

fn symbol_map(&self) -> SymbolMap<'_> {
fn symbol_map(&self) -> SymbolMap<'data> {
self.symbol_map()
}

Expand All @@ -1026,12 +1027,12 @@ impl<'d> ObjectLike for BreakpadObject<'d> {
/// An iterator over symbols in the Breakpad object.
///
/// Returned by [`BreakpadObject::symbols`](struct.BreakpadObject.html#method.symbols).
pub struct BreakpadSymbolIterator<'d> {
records: BreakpadPublicRecords<'d>,
pub struct BreakpadSymbolIterator<'data> {
records: BreakpadPublicRecords<'data>,
}

impl<'d> Iterator for BreakpadSymbolIterator<'d> {
type Item = Symbol<'d>;
impl<'data> Iterator for BreakpadSymbolIterator<'data> {
type Item = Symbol<'data>;

fn next(&mut self) -> Option<Self::Item> {
while let Some(result) = self.records.next() {
Expand Down
2 changes: 1 addition & 1 deletion symbolic-debuginfo/src/dwarf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1161,7 +1161,7 @@ impl<'d> DwarfDebugSession<'d> {
}
}

impl<'d> DebugSession for DwarfDebugSession<'d> {
impl<'data> DebugSession for DwarfDebugSession<'data> {
type Error = DwarfError;

fn functions(&self) -> DynIterator<'_, Result<Function<'_>, Self::Error>> {
Expand Down
Loading