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