@@ -129,7 +129,7 @@ pub struct UnitIndex<R: Reader> {
129129 hash_ids : R ,
130130 hash_rows : R ,
131131 // Only `section_count` values are valid.
132- sections : [ SectionId ; SECTION_COUNT_MAX as usize ] ,
132+ sections : [ IndexSectionId ; SECTION_COUNT_MAX as usize ] ,
133133 offsets : R ,
134134 sizes : R ,
135135}
@@ -144,7 +144,7 @@ impl<R: Reader> UnitIndex<R> {
144144 slot_count : 0 ,
145145 hash_ids : input. clone ( ) ,
146146 hash_rows : input. clone ( ) ,
147- sections : [ SectionId :: DebugAbbrev ; SECTION_COUNT_MAX as usize ] ,
147+ sections : [ IndexSectionId :: DebugAbbrev ; SECTION_COUNT_MAX as usize ] ,
148148 offsets : input. clone ( ) ,
149149 sizes : input. clone ( ) ,
150150 } ) ;
@@ -173,33 +173,33 @@ impl<R: Reader> UnitIndex<R> {
173173 let hash_ids = input. split ( R :: Offset :: from_u64 ( u64:: from ( slot_count) * 8 ) ?) ?;
174174 let hash_rows = input. split ( R :: Offset :: from_u64 ( u64:: from ( slot_count) * 4 ) ?) ?;
175175
176- let mut sections = [ SectionId :: DebugAbbrev ; SECTION_COUNT_MAX as usize ] ;
176+ let mut sections = [ IndexSectionId :: DebugAbbrev ; SECTION_COUNT_MAX as usize ] ;
177177 if section_count > SECTION_COUNT_MAX . into ( ) {
178178 return Err ( Error :: InvalidIndexSectionCount ) ;
179179 }
180180 for i in 0 ..section_count {
181181 let section = input. read_u32 ( ) ?;
182182 sections[ i as usize ] = if version == 2 {
183183 match constants:: DwSectV2 ( section) {
184- constants:: DW_SECT_V2_INFO => SectionId :: DebugInfo ,
185- constants:: DW_SECT_V2_TYPES => SectionId :: DebugTypes ,
186- constants:: DW_SECT_V2_ABBREV => SectionId :: DebugAbbrev ,
187- constants:: DW_SECT_V2_LINE => SectionId :: DebugLine ,
188- constants:: DW_SECT_V2_LOC => SectionId :: DebugLoc ,
189- constants:: DW_SECT_V2_STR_OFFSETS => SectionId :: DebugStrOffsets ,
190- constants:: DW_SECT_V2_MACINFO => SectionId :: DebugMacinfo ,
191- constants:: DW_SECT_V2_MACRO => SectionId :: DebugMacro ,
184+ constants:: DW_SECT_V2_INFO => IndexSectionId :: DebugInfo ,
185+ constants:: DW_SECT_V2_TYPES => IndexSectionId :: DebugTypes ,
186+ constants:: DW_SECT_V2_ABBREV => IndexSectionId :: DebugAbbrev ,
187+ constants:: DW_SECT_V2_LINE => IndexSectionId :: DebugLine ,
188+ constants:: DW_SECT_V2_LOC => IndexSectionId :: DebugLoc ,
189+ constants:: DW_SECT_V2_STR_OFFSETS => IndexSectionId :: DebugStrOffsets ,
190+ constants:: DW_SECT_V2_MACINFO => IndexSectionId :: DebugMacinfo ,
191+ constants:: DW_SECT_V2_MACRO => IndexSectionId :: DebugMacro ,
192192 section => return Err ( Error :: UnknownIndexSectionV2 ( section) ) ,
193193 }
194194 } else {
195195 match constants:: DwSect ( section) {
196- constants:: DW_SECT_INFO => SectionId :: DebugInfo ,
197- constants:: DW_SECT_ABBREV => SectionId :: DebugAbbrev ,
198- constants:: DW_SECT_LINE => SectionId :: DebugLine ,
199- constants:: DW_SECT_LOCLISTS => SectionId :: DebugLocLists ,
200- constants:: DW_SECT_STR_OFFSETS => SectionId :: DebugStrOffsets ,
201- constants:: DW_SECT_MACRO => SectionId :: DebugMacro ,
202- constants:: DW_SECT_RNGLISTS => SectionId :: DebugRngLists ,
196+ constants:: DW_SECT_INFO => IndexSectionId :: DebugInfo ,
197+ constants:: DW_SECT_ABBREV => IndexSectionId :: DebugAbbrev ,
198+ constants:: DW_SECT_LINE => IndexSectionId :: DebugLine ,
199+ constants:: DW_SECT_LOCLISTS => IndexSectionId :: DebugLocLists ,
200+ constants:: DW_SECT_STR_OFFSETS => IndexSectionId :: DebugStrOffsets ,
201+ constants:: DW_SECT_MACRO => IndexSectionId :: DebugMacro ,
202+ constants:: DW_SECT_RNGLISTS => IndexSectionId :: DebugRngLists ,
203203 section => return Err ( Error :: UnknownIndexSection ( section) ) ,
204204 }
205205 } ;
@@ -305,7 +305,7 @@ impl<R: Reader> UnitIndex<R> {
305305/// An iterator over the section offsets and sizes for a row in a `UnitIndex`.
306306#[ derive( Debug , Clone ) ]
307307pub struct UnitIndexSectionIterator < ' index , R : Reader > {
308- sections : slice:: Iter < ' index , SectionId > ,
308+ sections : slice:: Iter < ' index , IndexSectionId > ,
309309 offsets : R ,
310310 sizes : R ,
311311}
@@ -330,13 +330,57 @@ impl<'index, R: Reader> Iterator for UnitIndexSectionIterator<'index, R> {
330330#[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
331331pub struct UnitIndexSection {
332332 /// The section kind.
333- pub section : SectionId ,
333+ pub section : IndexSectionId ,
334334 /// The base offset of the unit's contribution to the section.
335335 pub offset : u32 ,
336336 /// The size of the unit's contribution to the section.
337337 pub size : u32 ,
338338}
339339
340+ /// Section kinds which are permitted in a `.dwp` index.
341+ #[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
342+ pub enum IndexSectionId {
343+ /// The `.debug_abbrev.dwo` section.
344+ DebugAbbrev ,
345+ /// The `.debug_info.dwo` section.
346+ DebugInfo ,
347+ /// The `.debug_line.dwo` section.
348+ DebugLine ,
349+ /// The `.debug_loc.dwo` section.
350+ DebugLoc ,
351+ /// The `.debug_loclists.dwo` section.
352+ DebugLocLists ,
353+ /// The `.debug_macinfo.dwo` section.
354+ DebugMacinfo ,
355+ /// The `.debug_macro.dwo` section.
356+ DebugMacro ,
357+ /// The `.debug_rnglists.dwo` section.
358+ DebugRngLists ,
359+ /// The `.debug_str_offsets.dwo` section.
360+ DebugStrOffsets ,
361+ /// The `.debug_types.dwo` section.
362+ DebugTypes ,
363+ }
364+
365+ impl IndexSectionId {
366+ /// Returns the ELF section name for this kind, when found in a .dwo or .dwp file.
367+ pub fn dwo_name ( self ) -> & ' static str {
368+ let section_id = match self {
369+ IndexSectionId :: DebugAbbrev => SectionId :: DebugAbbrev ,
370+ IndexSectionId :: DebugInfo => SectionId :: DebugInfo ,
371+ IndexSectionId :: DebugLine => SectionId :: DebugLine ,
372+ IndexSectionId :: DebugLoc => SectionId :: DebugLoc ,
373+ IndexSectionId :: DebugLocLists => SectionId :: DebugLocLists ,
374+ IndexSectionId :: DebugMacro => SectionId :: DebugMacro ,
375+ IndexSectionId :: DebugMacinfo => SectionId :: DebugMacinfo ,
376+ IndexSectionId :: DebugRngLists => SectionId :: DebugRngLists ,
377+ IndexSectionId :: DebugStrOffsets => SectionId :: DebugStrOffsets ,
378+ IndexSectionId :: DebugTypes => SectionId :: DebugTypes ,
379+ } ;
380+ section_id. dwo_name ( ) . unwrap ( )
381+ }
382+ }
383+
340384#[ cfg( test) ]
341385mod tests {
342386 use super :: * ;
@@ -437,26 +481,26 @@ mod tests {
437481 assert_eq ! (
438482 index. sections,
439483 [
440- SectionId :: DebugInfo ,
441- SectionId :: DebugTypes ,
442- SectionId :: DebugAbbrev ,
443- SectionId :: DebugLine ,
444- SectionId :: DebugLoc ,
445- SectionId :: DebugStrOffsets ,
446- SectionId :: DebugMacinfo ,
447- SectionId :: DebugMacro ,
484+ IndexSectionId :: DebugInfo ,
485+ IndexSectionId :: DebugTypes ,
486+ IndexSectionId :: DebugAbbrev ,
487+ IndexSectionId :: DebugLine ,
488+ IndexSectionId :: DebugLoc ,
489+ IndexSectionId :: DebugStrOffsets ,
490+ IndexSectionId :: DebugMacinfo ,
491+ IndexSectionId :: DebugMacro ,
448492 ]
449493 ) ;
450494 #[ rustfmt:: skip]
451495 let expect = [
452- UnitIndexSection { section : SectionId :: DebugInfo , offset : 11 , size : 21 } ,
453- UnitIndexSection { section : SectionId :: DebugTypes , offset : 12 , size : 22 } ,
454- UnitIndexSection { section : SectionId :: DebugAbbrev , offset : 13 , size : 23 } ,
455- UnitIndexSection { section : SectionId :: DebugLine , offset : 14 , size : 24 } ,
456- UnitIndexSection { section : SectionId :: DebugLoc , offset : 15 , size : 25 } ,
457- UnitIndexSection { section : SectionId :: DebugStrOffsets , offset : 16 , size : 26 } ,
458- UnitIndexSection { section : SectionId :: DebugMacinfo , offset : 17 , size : 27 } ,
459- UnitIndexSection { section : SectionId :: DebugMacro , offset : 18 , size : 28 } ,
496+ UnitIndexSection { section : IndexSectionId :: DebugInfo , offset : 11 , size : 21 } ,
497+ UnitIndexSection { section : IndexSectionId :: DebugTypes , offset : 12 , size : 22 } ,
498+ UnitIndexSection { section : IndexSectionId :: DebugAbbrev , offset : 13 , size : 23 } ,
499+ UnitIndexSection { section : IndexSectionId :: DebugLine , offset : 14 , size : 24 } ,
500+ UnitIndexSection { section : IndexSectionId :: DebugLoc , offset : 15 , size : 25 } ,
501+ UnitIndexSection { section : IndexSectionId :: DebugStrOffsets , offset : 16 , size : 26 } ,
502+ UnitIndexSection { section : IndexSectionId :: DebugMacinfo , offset : 17 , size : 27 } ,
503+ UnitIndexSection { section : IndexSectionId :: DebugMacro , offset : 18 , size : 28 } ,
460504 ] ;
461505 let mut sections = index. sections ( 1 ) . unwrap ( ) ;
462506 for section in & expect {
@@ -492,24 +536,24 @@ mod tests {
492536 assert_eq ! (
493537 index. sections[ ..7 ] ,
494538 [
495- SectionId :: DebugInfo ,
496- SectionId :: DebugAbbrev ,
497- SectionId :: DebugLine ,
498- SectionId :: DebugLocLists ,
499- SectionId :: DebugStrOffsets ,
500- SectionId :: DebugMacro ,
501- SectionId :: DebugRngLists ,
539+ IndexSectionId :: DebugInfo ,
540+ IndexSectionId :: DebugAbbrev ,
541+ IndexSectionId :: DebugLine ,
542+ IndexSectionId :: DebugLocLists ,
543+ IndexSectionId :: DebugStrOffsets ,
544+ IndexSectionId :: DebugMacro ,
545+ IndexSectionId :: DebugRngLists ,
502546 ]
503547 ) ;
504548 #[ rustfmt:: skip]
505549 let expect = [
506- UnitIndexSection { section : SectionId :: DebugInfo , offset : 11 , size : 21 } ,
507- UnitIndexSection { section : SectionId :: DebugAbbrev , offset : 12 , size : 22 } ,
508- UnitIndexSection { section : SectionId :: DebugLine , offset : 13 , size : 23 } ,
509- UnitIndexSection { section : SectionId :: DebugLocLists , offset : 14 , size : 24 } ,
510- UnitIndexSection { section : SectionId :: DebugStrOffsets , offset : 15 , size : 25 } ,
511- UnitIndexSection { section : SectionId :: DebugMacro , offset : 16 , size : 26 } ,
512- UnitIndexSection { section : SectionId :: DebugRngLists , offset : 17 , size : 27 } ,
550+ UnitIndexSection { section : IndexSectionId :: DebugInfo , offset : 11 , size : 21 } ,
551+ UnitIndexSection { section : IndexSectionId :: DebugAbbrev , offset : 12 , size : 22 } ,
552+ UnitIndexSection { section : IndexSectionId :: DebugLine , offset : 13 , size : 23 } ,
553+ UnitIndexSection { section : IndexSectionId :: DebugLocLists , offset : 14 , size : 24 } ,
554+ UnitIndexSection { section : IndexSectionId :: DebugStrOffsets , offset : 15 , size : 25 } ,
555+ UnitIndexSection { section : IndexSectionId :: DebugMacro , offset : 16 , size : 26 } ,
556+ UnitIndexSection { section : IndexSectionId :: DebugRngLists , offset : 17 , size : 27 } ,
513557 ] ;
514558 let mut sections = index. sections ( 1 ) . unwrap ( ) ;
515559 for section in & expect {
0 commit comments