@@ -3,8 +3,8 @@ use alloc::string::String;
33use crate :: common:: {
44 DebugAddrBase , DebugAddrIndex , DebugInfoOffset , DebugLineStrOffset , DebugLocListsBase ,
55 DebugLocListsIndex , DebugRngListsBase , DebugRngListsIndex , DebugStrOffset , DebugStrOffsetsBase ,
6- DebugStrOffsetsIndex , DebugTypesOffset , Encoding , LocationListsOffset , RangeListsOffset ,
7- SectionId , UnitSectionOffset ,
6+ DebugStrOffsetsIndex , DebugTypesOffset , DwarfFileType , Encoding , LocationListsOffset ,
7+ RangeListsOffset , SectionId , UnitSectionOffset ,
88} ;
99use crate :: constants;
1010use crate :: read:: {
@@ -50,6 +50,9 @@ pub struct Dwarf<R> {
5050
5151 /// The range lists in the `.debug_ranges` and `.debug_rnglists` sections.
5252 pub ranges : RangeLists < R > ,
53+
54+ /// The type of this file.
55+ pub file_type : DwarfFileType ,
5356}
5457
5558impl < T > Dwarf < T > {
@@ -84,6 +87,7 @@ impl<T> Dwarf<T> {
8487 debug_types : Section :: load ( & mut section) ?,
8588 locations : LocationLists :: new ( debug_loc, debug_loclists) ,
8689 ranges : RangeLists :: new ( debug_ranges, debug_rnglists) ,
90+ file_type : DwarfFileType :: Main ,
8791 } )
8892 }
8993
@@ -129,6 +133,7 @@ impl<T> Dwarf<T> {
129133 debug_types : self . debug_types . borrow ( & mut borrow) ,
130134 locations : self . locations . borrow ( & mut borrow) ,
131135 ranges : self . ranges . borrow ( & mut borrow) ,
136+ file_type : self . file_type ,
132137 }
133138 }
134139}
@@ -376,13 +381,22 @@ impl<R: Reader> Dwarf<R> {
376381 unit : & Unit < R > ,
377382 offset : LocationListsOffset < R :: Offset > ,
378383 ) -> Result < LocListIter < R > > {
379- self . locations . locations (
380- offset,
381- unit. encoding ( ) ,
382- unit. low_pc ,
383- & self . debug_addr ,
384- unit. addr_base ,
385- )
384+ match self . file_type {
385+ DwarfFileType :: Main => self . locations . locations (
386+ offset,
387+ unit. encoding ( ) ,
388+ unit. low_pc ,
389+ & self . debug_addr ,
390+ unit. addr_base ,
391+ ) ,
392+ DwarfFileType :: Dwo => self . locations . locations_dwo (
393+ offset,
394+ unit. encoding ( ) ,
395+ unit. low_pc ,
396+ & self . debug_addr ,
397+ unit. addr_base ,
398+ ) ,
399+ }
386400 }
387401
388402 /// Try to return an attribute value as a location list offset.
@@ -519,17 +533,26 @@ impl<R: Reader> Unit<R> {
519533 pub fn new ( dwarf : & Dwarf < R > , header : UnitHeader < R > ) -> Result < Self > {
520534 let abbreviations = header. abbreviations ( & dwarf. debug_abbrev ) ?;
521535 let mut unit = Unit {
522- header,
523536 abbreviations,
524537 name : None ,
525538 comp_dir : None ,
526539 low_pc : 0 ,
527- // Defaults to 0 for GNU extensions.
528- str_offsets_base : DebugStrOffsetsBase ( R :: Offset :: from_u8 ( 0 ) ) ,
540+ str_offsets_base : DebugStrOffsetsBase :: default_for_encoding_and_file (
541+ header. encoding ( ) ,
542+ dwarf. file_type ,
543+ ) ,
544+ // NB: Because the .debug_addr section never lives in a .dwo, we can assume its base is always 0 or provided.
529545 addr_base : DebugAddrBase ( R :: Offset :: from_u8 ( 0 ) ) ,
530- loclists_base : DebugLocListsBase ( R :: Offset :: from_u8 ( 0 ) ) ,
531- rnglists_base : DebugRngListsBase ( R :: Offset :: from_u8 ( 0 ) ) ,
546+ loclists_base : DebugLocListsBase :: default_for_encoding_and_file (
547+ header. encoding ( ) ,
548+ dwarf. file_type ,
549+ ) ,
550+ rnglists_base : DebugRngListsBase :: default_for_encoding_and_file (
551+ header. encoding ( ) ,
552+ dwarf. file_type ,
553+ ) ,
532554 line_program : None ,
555+ header,
533556 } ;
534557 let mut name = None ;
535558 let mut comp_dir = None ;
@@ -646,7 +669,9 @@ impl<R: Reader> Unit<R> {
646669 pub fn copy_relocated_attributes ( & mut self , other : & Unit < R > ) {
647670 self . low_pc = other. low_pc ;
648671 self . addr_base = other. addr_base ;
649- self . rnglists_base = other. rnglists_base ;
672+ if self . header . version ( ) < 5 {
673+ self . rnglists_base = other. rnglists_base ;
674+ }
650675 }
651676}
652677
0 commit comments