@@ -3,22 +3,32 @@ use std::error::Error;
33use addr2line:: {
44 Context ,
55 LookupResult ,
6- gimli:: { EndianRcSlice , RunTimeEndian } ,
7- object:: { Object , ObjectSegment , ObjectSymbol , read:: File } ,
6+ gimli:: { self , Dwarf , EndianSlice , LittleEndian , SectionId } ,
87} ;
8+ use object:: { Object , ObjectSection , ObjectSegment , ObjectSymbol , read:: File } ;
99
1010// Wrapper around addr2line that allows to look up function names and
1111// locations from a given address.
1212pub ( crate ) struct Symbols < ' sym > {
1313 object : File < ' sym , & ' sym [ u8 ] > ,
14- ctx : Context < EndianRcSlice < RunTimeEndian > > ,
14+ ctx : Context < EndianSlice < ' sym , LittleEndian > > ,
1515}
1616
1717impl < ' sym > Symbols < ' sym > {
1818 /// Tries to create a new `Symbols` instance from the given ELF file bytes.
1919 pub fn try_from ( bytes : & ' sym [ u8 ] ) -> Result < Self , Box < dyn Error > > {
2020 let object = File :: parse ( bytes) ?;
21- let ctx = Context :: new ( & object) ?;
21+ let dwarf = Dwarf :: load (
22+ |id : SectionId | -> Result < EndianSlice < ' sym , LittleEndian > , gimli:: Error > {
23+ let data = object
24+ . section_by_name ( id. name ( ) )
25+ . and_then ( |section| section. data ( ) . ok ( ) )
26+ . unwrap_or ( & [ ] [ ..] ) ;
27+ Ok ( EndianSlice :: new ( data, LittleEndian ) )
28+ } ,
29+ ) ?;
30+
31+ let ctx = Context :: from_dwarf ( dwarf) ?;
2232
2333 Ok ( Self { object, ctx } )
2434 }
0 commit comments