Skip to content

Commit 913516e

Browse files
Swatinemjan-auer
andauthored
fix: Add a SymbolIterator and Lifetimes to ObjectLike trait (#277)
Co-authored-by: Jan Michael Auer <[email protected]>
1 parent dfd1836 commit 913516e

File tree

11 files changed

+205
-192
lines changed

11 files changed

+205
-192
lines changed

symbolic-debuginfo/src/base.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -625,13 +625,16 @@ pub trait DebugSession {
625625
}
626626

627627
/// An object containing debug information.
628-
pub trait ObjectLike {
628+
pub trait ObjectLike<'data, 'object> {
629629
/// Errors thrown when reading information from this object.
630630
type Error;
631631

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

635+
/// The iterator over the symbols in the public symbol table.
636+
type SymbolIterator: Iterator<Item = Symbol<'data>>;
637+
635638
/// The container format of this file.
636639
fn file_format(&self) -> FileFormat;
637640

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

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

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

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

679682
/// Determines whether this object contains stack unwinding information.
680683
fn has_unwind_info(&self) -> bool;

symbolic-debuginfo/src/breakpad.rs

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -734,21 +734,21 @@ impl<'d> Iterator for BreakpadStackRecords<'d> {
734734
/// > compactness.
735735
///
736736
/// The full documentation resides [here](https://chromium.googlesource.com/breakpad/breakpad/+/refs/heads/master/docs/symbol_files.md).
737-
pub struct BreakpadObject<'d> {
737+
pub struct BreakpadObject<'data> {
738738
id: DebugId,
739739
arch: Arch,
740-
module: BreakpadModuleRecord<'d>,
741-
data: &'d [u8],
740+
module: BreakpadModuleRecord<'data>,
741+
data: &'data [u8],
742742
}
743743

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

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

@@ -836,14 +836,14 @@ impl<'d> BreakpadObject<'d> {
836836
}
837837

838838
/// Returns an iterator over symbols in the public symbol table.
839-
pub fn symbols(&self) -> BreakpadSymbolIterator<'d> {
839+
pub fn symbols(&self) -> BreakpadSymbolIterator<'data> {
840840
BreakpadSymbolIterator {
841841
records: self.public_records(),
842842
}
843843
}
844844

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

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

881881
/// Returns an iterator over info records.
882-
pub fn info_records(&self) -> BreakpadInfoRecords<'d> {
882+
pub fn info_records(&self) -> BreakpadInfoRecords<'data> {
883883
BreakpadInfoRecords {
884884
lines: Lines::new(self.data),
885885
finished: false,
886886
}
887887
}
888888

889889
/// Returns an iterator over file records.
890-
pub fn file_records(&self) -> BreakpadFileRecords<'d> {
890+
pub fn file_records(&self) -> BreakpadFileRecords<'data> {
891891
BreakpadFileRecords {
892892
lines: Lines::new(self.data),
893893
finished: false,
894894
}
895895
}
896896

897897
/// Returns a map for file name lookups by id.
898-
pub fn file_map(&self) -> BreakpadFileMap<'d> {
898+
pub fn file_map(&self) -> BreakpadFileMap<'data> {
899899
self.file_records()
900900
.filter_map(Result::ok)
901901
.map(|file| (file.id, file.name))
902902
.collect()
903903
}
904904

905905
/// Returns an iterator over public symbol records.
906-
pub fn public_records(&self) -> BreakpadPublicRecords<'d> {
906+
pub fn public_records(&self) -> BreakpadPublicRecords<'data> {
907907
BreakpadPublicRecords {
908908
lines: Lines::new(self.data),
909909
finished: false,
910910
}
911911
}
912912

913913
/// Returns an iterator over function records.
914-
pub fn func_records(&self) -> BreakpadFuncRecords<'d> {
914+
pub fn func_records(&self) -> BreakpadFuncRecords<'data> {
915915
BreakpadFuncRecords {
916916
lines: Lines::new(self.data),
917917
finished: false,
918918
}
919919
}
920920

921921
/// Returns an iterator over stack frame records.
922-
pub fn stack_records(&self) -> BreakpadStackRecords<'d> {
922+
pub fn stack_records(&self) -> BreakpadStackRecords<'data> {
923923
BreakpadStackRecords {
924924
lines: Lines::new(self.data),
925925
finished: false,
926926
}
927927
}
928928

929929
/// Returns the raw data of the Breakpad file.
930-
pub fn data(&self) -> &'d [u8] {
930+
pub fn data(&self) -> &'data [u8] {
931931
self.data
932932
}
933933
}
@@ -946,29 +946,30 @@ impl fmt::Debug for BreakpadObject<'_> {
946946
}
947947
}
948948

949-
impl<'slf, 'd: 'slf> AsSelf<'slf> for BreakpadObject<'d> {
949+
impl<'slf, 'data: 'slf> AsSelf<'slf> for BreakpadObject<'data> {
950950
type Ref = BreakpadObject<'slf>;
951951

952952
fn as_self(&'slf self) -> &Self::Ref {
953953
self
954954
}
955955
}
956956

957-
impl<'d> Parse<'d> for BreakpadObject<'d> {
957+
impl<'data> Parse<'data> for BreakpadObject<'data> {
958958
type Error = BreakpadError;
959959

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

964-
fn parse(data: &'d [u8]) -> Result<Self, BreakpadError> {
964+
fn parse(data: &'data [u8]) -> Result<Self, BreakpadError> {
965965
Self::parse(data)
966966
}
967967
}
968968

969-
impl<'d> ObjectLike for BreakpadObject<'d> {
969+
impl<'data: 'object, 'object> ObjectLike<'data, 'object> for BreakpadObject<'data> {
970970
type Error = BreakpadError;
971-
type Session = BreakpadDebugSession<'d>;
971+
type Session = BreakpadDebugSession<'data>;
972+
type SymbolIterator = BreakpadSymbolIterator<'data>;
972973

973974
fn file_format(&self) -> FileFormat {
974975
self.file_format()
@@ -998,11 +999,11 @@ impl<'d> ObjectLike for BreakpadObject<'d> {
998999
self.has_symbols()
9991000
}
10001001

1001-
fn symbols(&self) -> DynIterator<'_, Symbol<'_>> {
1002-
Box::new(self.symbols())
1002+
fn symbols(&self) -> Self::SymbolIterator {
1003+
self.symbols()
10031004
}
10041005

1005-
fn symbol_map(&self) -> SymbolMap<'_> {
1006+
fn symbol_map(&self) -> SymbolMap<'data> {
10061007
self.symbol_map()
10071008
}
10081009

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

1033-
impl<'d> Iterator for BreakpadSymbolIterator<'d> {
1034-
type Item = Symbol<'d>;
1034+
impl<'data> Iterator for BreakpadSymbolIterator<'data> {
1035+
type Item = Symbol<'data>;
10351036

10361037
fn next(&mut self) -> Option<Self::Item> {
10371038
while let Some(result) = self.records.next() {

symbolic-debuginfo/src/dwarf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1161,7 +1161,7 @@ impl<'d> DwarfDebugSession<'d> {
11611161
}
11621162
}
11631163

1164-
impl<'d> DebugSession for DwarfDebugSession<'d> {
1164+
impl<'data> DebugSession for DwarfDebugSession<'data> {
11651165
type Error = DwarfError;
11661166

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

0 commit comments

Comments
 (0)