1 //===- DWARFUnit.cpp ------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "llvm/DebugInfo/DWARF/DWARFUnit.h"
11 #include "llvm/ADT/SmallString.h"
12 #include "llvm/ADT/StringRef.h"
13 #include "llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h"
14 #include "llvm/DebugInfo/DWARF/DWARFContext.h"
15 #include "llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h"
16 #include "llvm/DebugInfo/DWARF/DWARFDebugInfoEntry.h"
17 #include "llvm/DebugInfo/DWARF/DWARFDie.h"
18 #include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
19 #include "llvm/Support/DataExtractor.h"
20 #include "llvm/Support/Path.h"
21 #include <algorithm>
22 #include <cassert>
23 #include <cstddef>
24 #include <cstdint>
25 #include <cstdio>
26 #include <utility>
27 #include <vector>
28 
29 using namespace llvm;
30 using namespace dwarf;
31 
32 void DWARFUnitSectionBase::parse(DWARFContext &C, const DWARFSection &Section) {
33   const DWARFObject &D = C.getDWARFObj();
34   parseImpl(C, D, Section, C.getDebugAbbrev(), &D.getRangeSection(),
35             D.getStringSection(), D.getStringOffsetSection(),
36             &D.getAddrSection(), D.getLineSection(), D.isLittleEndian(), false,
37             false);
38 }
39 
40 void DWARFUnitSectionBase::parseDWO(DWARFContext &C,
41                                     const DWARFSection &DWOSection, bool Lazy) {
42   const DWARFObject &D = C.getDWARFObj();
43   parseImpl(C, D, DWOSection, C.getDebugAbbrevDWO(), &D.getRangeDWOSection(),
44             D.getStringDWOSection(), D.getStringOffsetDWOSection(),
45             &D.getAddrSection(), D.getLineDWOSection(), C.isLittleEndian(),
46             true, Lazy);
47 }
48 
49 DWARFUnit::DWARFUnit(DWARFContext &DC, const DWARFSection &Section,
50                      const DWARFDebugAbbrev *DA, const DWARFSection *RS,
51                      StringRef SS, const DWARFSection &SOS,
52                      const DWARFSection *AOS, const DWARFSection &LS, bool LE,
53                      bool IsDWO, const DWARFUnitSectionBase &UnitSection,
54                      const DWARFUnitIndex::Entry *IndexEntry)
55     : Context(DC), InfoSection(Section), Abbrev(DA), RangeSection(RS),
56       LineSection(LS), StringSection(SS), StringOffsetSection(SOS),
57       AddrOffsetSection(AOS), isLittleEndian(LE), isDWO(IsDWO),
58       UnitSection(UnitSection), IndexEntry(IndexEntry) {
59   clear();
60 }
61 
62 DWARFUnit::~DWARFUnit() = default;
63 
64 DWARFDataExtractor DWARFUnit::getDebugInfoExtractor() const {
65   return DWARFDataExtractor(Context.getDWARFObj(), InfoSection, isLittleEndian,
66                             getAddressByteSize());
67 }
68 
69 bool DWARFUnit::getAddrOffsetSectionItem(uint32_t Index,
70                                                 uint64_t &Result) const {
71   uint32_t Offset = AddrOffsetSectionBase + Index * getAddressByteSize();
72   if (AddrOffsetSection->Data.size() < Offset + getAddressByteSize())
73     return false;
74   DWARFDataExtractor DA(Context.getDWARFObj(), *AddrOffsetSection,
75                         isLittleEndian, getAddressByteSize());
76   Result = DA.getRelocatedAddress(&Offset);
77   return true;
78 }
79 
80 bool DWARFUnit::getStringOffsetSectionItem(uint32_t Index,
81                                            uint64_t &Result) const {
82   if (!StringOffsetsTableContribution)
83     return false;
84   unsigned ItemSize = getDwarfStringOffsetsByteSize();
85   uint32_t Offset = getStringOffsetsBase() + Index * ItemSize;
86   if (StringOffsetSection.Data.size() < Offset + ItemSize)
87     return false;
88   DWARFDataExtractor DA(Context.getDWARFObj(), StringOffsetSection,
89                         isLittleEndian, 0);
90   Result = DA.getRelocatedValue(ItemSize, &Offset);
91   return true;
92 }
93 
94 bool DWARFUnit::extractImpl(const DWARFDataExtractor &debug_info,
95                             uint32_t *offset_ptr) {
96   Length = debug_info.getU32(offset_ptr);
97   // FIXME: Support DWARF64.
98   FormParams.Format = DWARF32;
99   FormParams.Version = debug_info.getU16(offset_ptr);
100   if (FormParams.Version >= 5) {
101     UnitType = debug_info.getU8(offset_ptr);
102     FormParams.AddrSize = debug_info.getU8(offset_ptr);
103     AbbrOffset = debug_info.getU32(offset_ptr);
104   } else {
105     AbbrOffset = debug_info.getRelocatedValue(4, offset_ptr);
106     FormParams.AddrSize = debug_info.getU8(offset_ptr);
107   }
108   if (IndexEntry) {
109     if (AbbrOffset)
110       return false;
111     auto *UnitContrib = IndexEntry->getOffset();
112     if (!UnitContrib || UnitContrib->Length != (Length + 4))
113       return false;
114     auto *AbbrEntry = IndexEntry->getOffset(DW_SECT_ABBREV);
115     if (!AbbrEntry)
116       return false;
117     AbbrOffset = AbbrEntry->Offset;
118   }
119 
120   bool LengthOK = debug_info.isValidOffset(getNextUnitOffset() - 1);
121   bool VersionOK = DWARFContext::isSupportedVersion(getVersion());
122   bool AddrSizeOK = getAddressByteSize() == 4 || getAddressByteSize() == 8;
123 
124   if (!LengthOK || !VersionOK || !AddrSizeOK)
125     return false;
126 
127   // Keep track of the highest DWARF version we encounter across all units.
128   Context.setMaxVersionIfGreater(getVersion());
129   return true;
130 }
131 
132 bool DWARFUnit::extract(const DWARFDataExtractor &debug_info,
133                         uint32_t *offset_ptr) {
134   clear();
135 
136   Offset = *offset_ptr;
137 
138   if (debug_info.isValidOffset(*offset_ptr)) {
139     if (extractImpl(debug_info, offset_ptr))
140       return true;
141 
142     // reset the offset to where we tried to parse from if anything went wrong
143     *offset_ptr = Offset;
144   }
145 
146   return false;
147 }
148 
149 bool DWARFUnit::extractRangeList(uint32_t RangeListOffset,
150                                  DWARFDebugRangeList &RangeList) const {
151   // Require that compile unit is extracted.
152   assert(!DieArray.empty());
153   DWARFDataExtractor RangesData(Context.getDWARFObj(), *RangeSection,
154                                 isLittleEndian, getAddressByteSize());
155   uint32_t ActualRangeListOffset = RangeSectionBase + RangeListOffset;
156   return RangeList.extract(RangesData, &ActualRangeListOffset);
157 }
158 
159 void DWARFUnit::clear() {
160   Offset = 0;
161   Length = 0;
162   Abbrevs = nullptr;
163   FormParams = dwarf::FormParams({0, 0, DWARF32});
164   BaseAddr.reset();
165   RangeSectionBase = 0;
166   AddrOffsetSectionBase = 0;
167   clearDIEs(false);
168   DWO.reset();
169 }
170 
171 const char *DWARFUnit::getCompilationDir() {
172   return dwarf::toString(getUnitDIE().find(DW_AT_comp_dir), nullptr);
173 }
174 
175 Optional<uint64_t> DWARFUnit::getDWOId() {
176   return toUnsigned(getUnitDIE().find(DW_AT_GNU_dwo_id));
177 }
178 
179 void DWARFUnit::extractDIEsToVector(
180     bool AppendCUDie, bool AppendNonCUDies,
181     std::vector<DWARFDebugInfoEntry> &Dies) const {
182   if (!AppendCUDie && !AppendNonCUDies)
183     return;
184 
185   // Set the offset to that of the first DIE and calculate the start of the
186   // next compilation unit header.
187   uint32_t DIEOffset = Offset + getHeaderSize();
188   uint32_t NextCUOffset = getNextUnitOffset();
189   DWARFDebugInfoEntry DIE;
190   DWARFDataExtractor DebugInfoData = getDebugInfoExtractor();
191   uint32_t Depth = 0;
192   bool IsCUDie = true;
193 
194   while (DIE.extractFast(*this, &DIEOffset, DebugInfoData, NextCUOffset,
195                          Depth)) {
196     if (IsCUDie) {
197       if (AppendCUDie)
198         Dies.push_back(DIE);
199       if (!AppendNonCUDies)
200         break;
201       // The average bytes per DIE entry has been seen to be
202       // around 14-20 so let's pre-reserve the needed memory for
203       // our DIE entries accordingly.
204       Dies.reserve(Dies.size() + getDebugInfoSize() / 14);
205       IsCUDie = false;
206     } else {
207       Dies.push_back(DIE);
208     }
209 
210     if (const DWARFAbbreviationDeclaration *AbbrDecl =
211             DIE.getAbbreviationDeclarationPtr()) {
212       // Normal DIE
213       if (AbbrDecl->hasChildren())
214         ++Depth;
215     } else {
216       // NULL DIE.
217       if (Depth > 0)
218         --Depth;
219       if (Depth == 0)
220         break;  // We are done with this compile unit!
221     }
222   }
223 
224   // Give a little bit of info if we encounter corrupt DWARF (our offset
225   // should always terminate at or before the start of the next compilation
226   // unit header).
227   if (DIEOffset > NextCUOffset)
228     fprintf(stderr, "warning: DWARF compile unit extends beyond its "
229                     "bounds cu 0x%8.8x at 0x%8.8x'\n", getOffset(), DIEOffset);
230 }
231 
232 size_t DWARFUnit::extractDIEsIfNeeded(bool CUDieOnly) {
233   if ((CUDieOnly && !DieArray.empty()) ||
234       DieArray.size() > 1)
235     return 0; // Already parsed.
236 
237   bool HasCUDie = !DieArray.empty();
238   extractDIEsToVector(!HasCUDie, !CUDieOnly, DieArray);
239 
240   if (DieArray.empty())
241     return 0;
242 
243   // If CU DIE was just parsed, copy several attribute values from it.
244   if (!HasCUDie) {
245     DWARFDie UnitDie = getUnitDIE();
246     Optional<DWARFFormValue> PC = UnitDie.find({DW_AT_low_pc, DW_AT_entry_pc});
247     if (Optional<uint64_t> Addr = toAddress(PC))
248         setBaseAddress({*Addr, PC->getSectionIndex()});
249 
250     if (!isDWO) {
251       assert(AddrOffsetSectionBase == 0);
252       assert(RangeSectionBase == 0);
253       AddrOffsetSectionBase =
254           toSectionOffset(UnitDie.find(DW_AT_GNU_addr_base), 0);
255       RangeSectionBase = toSectionOffset(UnitDie.find(DW_AT_rnglists_base), 0);
256     }
257 
258     // In general, in DWARF v5 and beyond we derive the start of the unit's
259     // contribution to the string offsets table from the unit DIE's
260     // DW_AT_str_offsets_base attribute. Split DWARF units do not use this
261     // attribute, so we assume that there is a contribution to the string
262     // offsets table starting at offset 0 of the debug_str_offsets.dwo section.
263     // In both cases we need to determine the format of the contribution,
264     // which may differ from the unit's format.
265     uint64_t StringOffsetsContributionBase =
266         isDWO ? 0 : toSectionOffset(UnitDie.find(DW_AT_str_offsets_base), 0);
267     if (IndexEntry)
268       if (const auto *C = IndexEntry->getOffset(DW_SECT_STR_OFFSETS))
269         StringOffsetsContributionBase += C->Offset;
270 
271     DWARFDataExtractor DA(Context.getDWARFObj(), StringOffsetSection,
272                           isLittleEndian, 0);
273     if (isDWO)
274       StringOffsetsTableContribution =
275           determineStringOffsetsTableContributionDWO(
276               DA, StringOffsetsContributionBase);
277     else if (getVersion() >= 5)
278       StringOffsetsTableContribution = determineStringOffsetsTableContribution(
279           DA, StringOffsetsContributionBase);
280 
281     // Don't fall back to DW_AT_GNU_ranges_base: it should be ignored for
282     // skeleton CU DIE, so that DWARF users not aware of it are not broken.
283   }
284 
285   return DieArray.size();
286 }
287 
288 bool DWARFUnit::parseDWO() {
289   if (isDWO)
290     return false;
291   if (DWO.get())
292     return false;
293   DWARFDie UnitDie = getUnitDIE();
294   if (!UnitDie)
295     return false;
296   auto DWOFileName = dwarf::toString(UnitDie.find(DW_AT_GNU_dwo_name));
297   if (!DWOFileName)
298     return false;
299   auto CompilationDir = dwarf::toString(UnitDie.find(DW_AT_comp_dir));
300   SmallString<16> AbsolutePath;
301   if (sys::path::is_relative(*DWOFileName) && CompilationDir &&
302       *CompilationDir) {
303     sys::path::append(AbsolutePath, *CompilationDir);
304   }
305   sys::path::append(AbsolutePath, *DWOFileName);
306   auto DWOId = getDWOId();
307   if (!DWOId)
308     return false;
309   auto DWOContext = Context.getDWOContext(AbsolutePath);
310   if (!DWOContext)
311     return false;
312 
313   DWARFCompileUnit *DWOCU = DWOContext->getDWOCompileUnitForHash(*DWOId);
314   if (!DWOCU)
315     return false;
316   DWO = std::shared_ptr<DWARFCompileUnit>(std::move(DWOContext), DWOCU);
317   // Share .debug_addr and .debug_ranges section with compile unit in .dwo
318   DWO->setAddrOffsetSection(AddrOffsetSection, AddrOffsetSectionBase);
319   auto DWORangesBase = UnitDie.getRangesBaseAttribute();
320   DWO->setRangesSection(RangeSection, DWORangesBase ? *DWORangesBase : 0);
321   return true;
322 }
323 
324 void DWARFUnit::clearDIEs(bool KeepCUDie) {
325   if (DieArray.size() > (unsigned)KeepCUDie) {
326     DieArray.resize((unsigned)KeepCUDie);
327     DieArray.shrink_to_fit();
328   }
329 }
330 
331 void DWARFUnit::collectAddressRanges(DWARFAddressRangesVector &CURanges) {
332   DWARFDie UnitDie = getUnitDIE();
333   if (!UnitDie)
334     return;
335   // First, check if unit DIE describes address ranges for the whole unit.
336   const auto &CUDIERanges = UnitDie.getAddressRanges();
337   if (!CUDIERanges.empty()) {
338     CURanges.insert(CURanges.end(), CUDIERanges.begin(), CUDIERanges.end());
339     return;
340   }
341 
342   // This function is usually called if there in no .debug_aranges section
343   // in order to produce a compile unit level set of address ranges that
344   // is accurate. If the DIEs weren't parsed, then we don't want all dies for
345   // all compile units to stay loaded when they weren't needed. So we can end
346   // up parsing the DWARF and then throwing them all away to keep memory usage
347   // down.
348   const bool ClearDIEs = extractDIEsIfNeeded(false) > 1;
349   getUnitDIE().collectChildrenAddressRanges(CURanges);
350 
351   // Collect address ranges from DIEs in .dwo if necessary.
352   bool DWOCreated = parseDWO();
353   if (DWO)
354     DWO->collectAddressRanges(CURanges);
355   if (DWOCreated)
356     DWO.reset();
357 
358   // Keep memory down by clearing DIEs if this generate function
359   // caused them to be parsed.
360   if (ClearDIEs)
361     clearDIEs(true);
362 }
363 
364 void DWARFUnit::updateAddressDieMap(DWARFDie Die) {
365   if (Die.isSubroutineDIE()) {
366     for (const auto &R : Die.getAddressRanges()) {
367       // Ignore 0-sized ranges.
368       if (R.LowPC == R.HighPC)
369         continue;
370       auto B = AddrDieMap.upper_bound(R.LowPC);
371       if (B != AddrDieMap.begin() && R.LowPC < (--B)->second.first) {
372         // The range is a sub-range of existing ranges, we need to split the
373         // existing range.
374         if (R.HighPC < B->second.first)
375           AddrDieMap[R.HighPC] = B->second;
376         if (R.LowPC > B->first)
377           AddrDieMap[B->first].first = R.LowPC;
378       }
379       AddrDieMap[R.LowPC] = std::make_pair(R.HighPC, Die);
380     }
381   }
382   // Parent DIEs are added to the AddrDieMap prior to the Children DIEs to
383   // simplify the logic to update AddrDieMap. The child's range will always
384   // be equal or smaller than the parent's range. With this assumption, when
385   // adding one range into the map, it will at most split a range into 3
386   // sub-ranges.
387   for (DWARFDie Child = Die.getFirstChild(); Child; Child = Child.getSibling())
388     updateAddressDieMap(Child);
389 }
390 
391 DWARFDie DWARFUnit::getSubroutineForAddress(uint64_t Address) {
392   extractDIEsIfNeeded(false);
393   if (AddrDieMap.empty())
394     updateAddressDieMap(getUnitDIE());
395   auto R = AddrDieMap.upper_bound(Address);
396   if (R == AddrDieMap.begin())
397     return DWARFDie();
398   // upper_bound's previous item contains Address.
399   --R;
400   if (Address >= R->second.first)
401     return DWARFDie();
402   return R->second.second;
403 }
404 
405 void
406 DWARFUnit::getInlinedChainForAddress(uint64_t Address,
407                                      SmallVectorImpl<DWARFDie> &InlinedChain) {
408   assert(InlinedChain.empty());
409   // Try to look for subprogram DIEs in the DWO file.
410   parseDWO();
411   // First, find the subroutine that contains the given address (the leaf
412   // of inlined chain).
413   DWARFDie SubroutineDIE =
414       (DWO ? DWO.get() : this)->getSubroutineForAddress(Address);
415 
416   while (SubroutineDIE) {
417     if (SubroutineDIE.isSubroutineDIE())
418       InlinedChain.push_back(SubroutineDIE);
419     SubroutineDIE  = SubroutineDIE.getParent();
420   }
421 }
422 
423 const DWARFUnitIndex &llvm::getDWARFUnitIndex(DWARFContext &Context,
424                                               DWARFSectionKind Kind) {
425   if (Kind == DW_SECT_INFO)
426     return Context.getCUIndex();
427   assert(Kind == DW_SECT_TYPES);
428   return Context.getTUIndex();
429 }
430 
431 DWARFDie DWARFUnit::getParent(const DWARFDebugInfoEntry *Die) {
432   if (!Die)
433     return DWARFDie();
434   const uint32_t Depth = Die->getDepth();
435   // Unit DIEs always have a depth of zero and never have parents.
436   if (Depth == 0)
437     return DWARFDie();
438   // Depth of 1 always means parent is the compile/type unit.
439   if (Depth == 1)
440     return getUnitDIE();
441   // Look for previous DIE with a depth that is one less than the Die's depth.
442   const uint32_t ParentDepth = Depth - 1;
443   for (uint32_t I = getDIEIndex(Die) - 1; I > 0; --I) {
444     if (DieArray[I].getDepth() == ParentDepth)
445       return DWARFDie(this, &DieArray[I]);
446   }
447   return DWARFDie();
448 }
449 
450 DWARFDie DWARFUnit::getSibling(const DWARFDebugInfoEntry *Die) {
451   if (!Die)
452     return DWARFDie();
453   uint32_t Depth = Die->getDepth();
454   // Unit DIEs always have a depth of zero and never have siblings.
455   if (Depth == 0)
456     return DWARFDie();
457   // NULL DIEs don't have siblings.
458   if (Die->getAbbreviationDeclarationPtr() == nullptr)
459     return DWARFDie();
460 
461   // Find the next DIE whose depth is the same as the Die's depth.
462   for (size_t I = getDIEIndex(Die) + 1, EndIdx = DieArray.size(); I < EndIdx;
463        ++I) {
464     if (DieArray[I].getDepth() == Depth)
465       return DWARFDie(this, &DieArray[I]);
466   }
467   return DWARFDie();
468 }
469 
470 DWARFDie DWARFUnit::getFirstChild(const DWARFDebugInfoEntry *Die) {
471   if (!Die->hasChildren())
472     return DWARFDie();
473 
474   // We do not want access out of bounds when parsing corrupted debug data.
475   size_t I = getDIEIndex(Die) + 1;
476   if (I >= DieArray.size())
477     return DWARFDie();
478   return DWARFDie(this, &DieArray[I]);
479 }
480 
481 const DWARFAbbreviationDeclarationSet *DWARFUnit::getAbbreviations() const {
482   if (!Abbrevs)
483     Abbrevs = Abbrev->getAbbreviationDeclarationSet(AbbrOffset);
484   return Abbrevs;
485 }
486 
487 Optional<StrOffsetsContributionDescriptor>
488 StrOffsetsContributionDescriptor::validateContributionSize(
489     DWARFDataExtractor &DA) {
490   uint8_t EntrySize = getDwarfOffsetByteSize();
491   // In order to ensure that we don't read a partial record at the end of
492   // the section we validate for a multiple of the entry size.
493   uint64_t ValidationSize = alignTo(Size, EntrySize);
494   // Guard against overflow.
495   if (ValidationSize >= Size)
496     if (DA.isValidOffsetForDataOfSize((uint32_t)Base, ValidationSize))
497       return *this;
498   return Optional<StrOffsetsContributionDescriptor>();
499 }
500 
501 // Look for a DWARF64-formatted contribution to the string offsets table
502 // starting at a given offset and record it in a descriptor.
503 static Optional<StrOffsetsContributionDescriptor>
504 parseDWARF64StringOffsetsTableHeader(DWARFDataExtractor &DA, uint32_t Offset) {
505   if (!DA.isValidOffsetForDataOfSize(Offset, 16))
506     return Optional<StrOffsetsContributionDescriptor>();
507 
508   if (DA.getU32(&Offset) != 0xffffffff)
509     return Optional<StrOffsetsContributionDescriptor>();
510 
511   uint64_t Size = DA.getU64(&Offset);
512   uint8_t Version = DA.getU16(&Offset);
513   (void)DA.getU16(&Offset); // padding
514   return StrOffsetsContributionDescriptor(Offset, Size, Version, DWARF64);
515   //return Optional<StrOffsetsContributionDescriptor>(Descriptor);
516 }
517 
518 // Look for a DWARF32-formatted contribution to the string offsets table
519 // starting at a given offset and record it in a descriptor.
520 static Optional<StrOffsetsContributionDescriptor>
521 parseDWARF32StringOffsetsTableHeader(DWARFDataExtractor &DA, uint32_t Offset) {
522   if (!DA.isValidOffsetForDataOfSize(Offset, 8))
523     return Optional<StrOffsetsContributionDescriptor>();
524   uint32_t ContributionSize = DA.getU32(&Offset);
525   if (ContributionSize >= 0xfffffff0)
526     return Optional<StrOffsetsContributionDescriptor>();
527   uint8_t Version = DA.getU16(&Offset);
528   (void)DA.getU16(&Offset); // padding
529   return StrOffsetsContributionDescriptor(Offset, ContributionSize, Version, DWARF32);
530   //return Optional<StrOffsetsContributionDescriptor>(Descriptor);
531 }
532 
533 Optional<StrOffsetsContributionDescriptor>
534 DWARFUnit::determineStringOffsetsTableContribution(DWARFDataExtractor &DA,
535                                                    uint64_t Offset) {
536   Optional<StrOffsetsContributionDescriptor> Descriptor;
537   // Attempt to find a DWARF64 contribution 16 bytes before the base.
538   if (Offset >= 16)
539     Descriptor =
540         parseDWARF64StringOffsetsTableHeader(DA, (uint32_t)Offset - 16);
541   // Try to find a DWARF32 contribution 8 bytes before the base.
542   if (!Descriptor && Offset >= 8)
543     Descriptor = parseDWARF32StringOffsetsTableHeader(DA, (uint32_t)Offset - 8);
544   return Descriptor ? Descriptor->validateContributionSize(DA) : Descriptor;
545 }
546 
547 Optional<StrOffsetsContributionDescriptor>
548 DWARFUnit::determineStringOffsetsTableContributionDWO(DWARFDataExtractor &DA,
549                                                       uint64_t Offset) {
550   if (getVersion() >= 5) {
551     // Look for a valid contribution at the given offset.
552     auto Descriptor =
553         parseDWARF64StringOffsetsTableHeader(DA, (uint32_t)Offset);
554     if (!Descriptor)
555       Descriptor = parseDWARF32StringOffsetsTableHeader(DA, (uint32_t)Offset);
556     return Descriptor ? Descriptor->validateContributionSize(DA) : Descriptor;
557   }
558   // Prior to DWARF v5, we derive the contribution size from the
559   // index table (in a package file). In a .dwo file it is simply
560   // the length of the string offsets section.
561   uint64_t Size = 0;
562   if (!IndexEntry)
563     Size = StringOffsetSection.Data.size();
564   else if (const auto *C = IndexEntry->getOffset(DW_SECT_STR_OFFSETS))
565     Size = C->Length;
566   // Return a descriptor with the given offset as base, version 4 and
567   // DWARF32 format.
568   //return Optional<StrOffsetsContributionDescriptor>(
569       //StrOffsetsContributionDescriptor(Offset, Size, 4, DWARF32));
570   return StrOffsetsContributionDescriptor(Offset, Size, 4, DWARF32);
571 }
572