@@ -77,8 +77,10 @@ void ManualDWARFIndex::Index() {
77
77
lldb::eDescriptionLevelBrief);
78
78
79
79
// Include 2 passes per unit to index for extracting DIEs from the unit and
80
- // indexing the unit, and then 8 extra entries for finalizing each index set.
81
- const uint64_t total_progress = units_to_index.size () * 2 + 8 ;
80
+ // indexing the unit, and then extra entries for finalizing each index in the
81
+ // set.
82
+ const auto indices = IndexSet<NameToDIE>::Indices ();
83
+ const uint64_t total_progress = units_to_index.size () * 2 + indices.size ();
82
84
Progress progress (" Manually indexing DWARF" , module_desc.GetData (),
83
85
total_progress, /* debugger=*/ nullptr ,
84
86
Progress::kDefaultHighFrequencyReportTime );
@@ -122,37 +124,30 @@ void ManualDWARFIndex::Index() {
122
124
});
123
125
124
126
// Now index all DWARF unit in parallel.
125
- std::vector<IndexSet> sets (num_threads);
127
+ std::vector<IndexSet<NameToDIE> > sets (num_threads);
126
128
for_each_unit (
127
129
[this , dwp_dwarf, &sets](size_t worker_id, size_t , DWARFUnit *unit) {
128
130
IndexUnit (*unit, dwp_dwarf, sets[worker_id]);
129
131
});
130
132
131
133
// Merge partial indexes into a single index. Process each index in a set in
132
134
// parallel.
133
- auto finalize_fn = [this , &sets, &progress](NameToDIE (IndexSet::*index)) {
134
- NameToDIE &result = m_set.*index;
135
- for (auto &set : sets)
136
- result.Append (set.*index);
137
- result.Finalize ();
138
- progress.Increment ();
139
- };
140
-
141
- task_group.async (finalize_fn, &IndexSet::function_basenames);
142
- task_group.async (finalize_fn, &IndexSet::function_fullnames);
143
- task_group.async (finalize_fn, &IndexSet::function_methods);
144
- task_group.async (finalize_fn, &IndexSet::function_selectors);
145
- task_group.async (finalize_fn, &IndexSet::objc_class_selectors);
146
- task_group.async (finalize_fn, &IndexSet::globals);
147
- task_group.async (finalize_fn, &IndexSet::types);
148
- task_group.async (finalize_fn, &IndexSet::namespaces);
135
+ for (NameToDIE IndexSet<NameToDIE>::*index : indices) {
136
+ task_group.async ([this , &sets, index, &progress]() {
137
+ NameToDIE &result = m_set.*index;
138
+ for (auto &set : sets)
139
+ result.Append (set.*index);
140
+ result.Finalize ();
141
+ progress.Increment ();
142
+ });
143
+ }
149
144
task_group.wait ();
150
145
151
146
SaveToCache ();
152
147
}
153
148
154
149
void ManualDWARFIndex::IndexUnit (DWARFUnit &unit, SymbolFileDWARFDwo *dwp,
155
- IndexSet &set) {
150
+ IndexSet<NameToDIE> &set) {
156
151
Log *log = GetLog (DWARFLog::Lookups);
157
152
158
153
if (log) {
@@ -210,7 +205,7 @@ void ManualDWARFIndex::IndexUnit(DWARFUnit &unit, SymbolFileDWARFDwo *dwp,
210
205
211
206
void ManualDWARFIndex::IndexUnitImpl (DWARFUnit &unit,
212
207
const LanguageType cu_language,
213
- IndexSet &set) {
208
+ IndexSet<NameToDIE> &set) {
214
209
for (const DWARFDebugInfoEntry &die : unit.dies ()) {
215
210
const dw_tag_t tag = die.Tag ();
216
211
@@ -555,142 +550,6 @@ void ManualDWARFIndex::Dump(Stream &s) {
555
550
m_set.namespaces .Dump (&s);
556
551
}
557
552
558
- constexpr llvm::StringLiteral kIdentifierManualDWARFIndex (" DIDX" );
559
- // Define IDs for the different tables when encoding and decoding the
560
- // ManualDWARFIndex NameToDIE objects so we can avoid saving any empty maps.
561
- enum DataID {
562
- kDataIDFunctionBasenames = 1u ,
563
- kDataIDFunctionFullnames ,
564
- kDataIDFunctionMethods ,
565
- kDataIDFunctionSelectors ,
566
- kDataIDFunctionObjcClassSelectors ,
567
- kDataIDGlobals ,
568
- kDataIDTypes ,
569
- kDataIDNamespaces ,
570
- kDataIDEnd = 255u ,
571
-
572
- };
573
-
574
- // Version 2 changes the encoding of DIERef objects used in the DWARF manual
575
- // index name tables. See DIERef class for details.
576
- constexpr uint32_t CURRENT_CACHE_VERSION = 2 ;
577
-
578
- bool ManualDWARFIndex::IndexSet::Decode (const DataExtractor &data,
579
- lldb::offset_t *offset_ptr) {
580
- StringTableReader strtab;
581
- // We now decode the string table for all strings in the data cache file.
582
- if (!strtab.Decode (data, offset_ptr))
583
- return false ;
584
-
585
- llvm::StringRef identifier ((const char *)data.GetData (offset_ptr, 4 ), 4 );
586
- if (identifier != kIdentifierManualDWARFIndex )
587
- return false ;
588
- const uint32_t version = data.GetU32 (offset_ptr);
589
- if (version != CURRENT_CACHE_VERSION)
590
- return false ;
591
-
592
- bool done = false ;
593
- while (!done) {
594
- switch (data.GetU8 (offset_ptr)) {
595
- default :
596
- // If we got here, this is not expected, we expect the data IDs to match
597
- // one of the values from the DataID enumeration.
598
- return false ;
599
- case kDataIDFunctionBasenames :
600
- if (!function_basenames.Decode (data, offset_ptr, strtab))
601
- return false ;
602
- break ;
603
- case kDataIDFunctionFullnames :
604
- if (!function_fullnames.Decode (data, offset_ptr, strtab))
605
- return false ;
606
- break ;
607
- case kDataIDFunctionMethods :
608
- if (!function_methods.Decode (data, offset_ptr, strtab))
609
- return false ;
610
- break ;
611
- case kDataIDFunctionSelectors :
612
- if (!function_selectors.Decode (data, offset_ptr, strtab))
613
- return false ;
614
- break ;
615
- case kDataIDFunctionObjcClassSelectors :
616
- if (!objc_class_selectors.Decode (data, offset_ptr, strtab))
617
- return false ;
618
- break ;
619
- case kDataIDGlobals :
620
- if (!globals.Decode (data, offset_ptr, strtab))
621
- return false ;
622
- break ;
623
- case kDataIDTypes :
624
- if (!types.Decode (data, offset_ptr, strtab))
625
- return false ;
626
- break ;
627
- case kDataIDNamespaces :
628
- if (!namespaces.Decode (data, offset_ptr, strtab))
629
- return false ;
630
- break ;
631
- case kDataIDEnd :
632
- // We got to the end of our NameToDIE encodings.
633
- done = true ;
634
- break ;
635
- }
636
- }
637
- // Success!
638
- return true ;
639
- }
640
-
641
- void ManualDWARFIndex::IndexSet::Encode (DataEncoder &encoder) const {
642
- ConstStringTable strtab;
643
-
644
- // Encoder the DWARF index into a separate encoder first. This allows us
645
- // gather all of the strings we willl need in "strtab" as we will need to
646
- // write the string table out before the symbol table.
647
- DataEncoder index_encoder (encoder.GetByteOrder (),
648
- encoder.GetAddressByteSize ());
649
-
650
- index_encoder.AppendData (kIdentifierManualDWARFIndex );
651
- // Encode the data version.
652
- index_encoder.AppendU32 (CURRENT_CACHE_VERSION);
653
-
654
- if (!function_basenames.IsEmpty ()) {
655
- index_encoder.AppendU8 (kDataIDFunctionBasenames );
656
- function_basenames.Encode (index_encoder, strtab);
657
- }
658
- if (!function_fullnames.IsEmpty ()) {
659
- index_encoder.AppendU8 (kDataIDFunctionFullnames );
660
- function_fullnames.Encode (index_encoder, strtab);
661
- }
662
- if (!function_methods.IsEmpty ()) {
663
- index_encoder.AppendU8 (kDataIDFunctionMethods );
664
- function_methods.Encode (index_encoder, strtab);
665
- }
666
- if (!function_selectors.IsEmpty ()) {
667
- index_encoder.AppendU8 (kDataIDFunctionSelectors );
668
- function_selectors.Encode (index_encoder, strtab);
669
- }
670
- if (!objc_class_selectors.IsEmpty ()) {
671
- index_encoder.AppendU8 (kDataIDFunctionObjcClassSelectors );
672
- objc_class_selectors.Encode (index_encoder, strtab);
673
- }
674
- if (!globals.IsEmpty ()) {
675
- index_encoder.AppendU8 (kDataIDGlobals );
676
- globals.Encode (index_encoder, strtab);
677
- }
678
- if (!types.IsEmpty ()) {
679
- index_encoder.AppendU8 (kDataIDTypes );
680
- types.Encode (index_encoder, strtab);
681
- }
682
- if (!namespaces.IsEmpty ()) {
683
- index_encoder.AppendU8 (kDataIDNamespaces );
684
- namespaces.Encode (index_encoder, strtab);
685
- }
686
- index_encoder.AppendU8 (kDataIDEnd );
687
-
688
- // Now that all strings have been gathered, we will emit the string table.
689
- strtab.Encode (encoder);
690
- // Followed by the symbol table data.
691
- encoder.AppendData (index_encoder.GetData ());
692
- }
693
-
694
553
bool ManualDWARFIndex::Decode (const DataExtractor &data,
695
554
lldb::offset_t *offset_ptr,
696
555
bool &signature_mismatch) {
@@ -702,18 +561,18 @@ bool ManualDWARFIndex::Decode(const DataExtractor &data,
702
561
signature_mismatch = true ;
703
562
return false ;
704
563
}
705
- IndexSet set;
706
- if (!set. Decode (data, offset_ptr) )
564
+ std::optional< IndexSet<NameToDIE>> set = DecodeIndexSet (data, offset_ptr) ;
565
+ if (!set)
707
566
return false ;
708
- m_set = std::move (set);
567
+ m_set = std::move (* set);
709
568
return true ;
710
569
}
711
570
712
571
bool ManualDWARFIndex::Encode (DataEncoder &encoder) const {
713
572
CacheSignature signature (m_dwarf->GetObjectFile ());
714
573
if (!signature.Encode (encoder))
715
574
return false ;
716
- m_set. Encode ( encoder);
575
+ EncodeIndexSet (m_set, encoder);
717
576
return true ;
718
577
}
719
578
0 commit comments