@@ -3,22 +3,32 @@ use std::error::Error;
3
3
use addr2line:: {
4
4
Context ,
5
5
LookupResult ,
6
- gimli:: { EndianRcSlice , RunTimeEndian } ,
7
- object:: { Object , ObjectSegment , ObjectSymbol , read:: File } ,
6
+ gimli:: { self , Dwarf , EndianSlice , LittleEndian , SectionId } ,
8
7
} ;
8
+ use object:: { Object , ObjectSection , ObjectSegment , ObjectSymbol , read:: File } ;
9
9
10
10
// Wrapper around addr2line that allows to look up function names and
11
11
// locations from a given address.
12
12
pub ( crate ) struct Symbols < ' sym > {
13
13
object : File < ' sym , & ' sym [ u8 ] > ,
14
- ctx : Context < EndianRcSlice < RunTimeEndian > > ,
14
+ ctx : Context < EndianSlice < ' sym , LittleEndian > > ,
15
15
}
16
16
17
17
impl < ' sym > Symbols < ' sym > {
18
18
/// Tries to create a new `Symbols` instance from the given ELF file bytes.
19
19
pub fn try_from ( bytes : & ' sym [ u8 ] ) -> Result < Self , Box < dyn Error > > {
20
20
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) ?;
22
32
23
33
Ok ( Self { object, ctx } )
24
34
}
0 commit comments