LLVM  7.0.0svn
DWARFUnit.cpp
Go to the documentation of this file.
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 
11 #include "llvm/ADT/SmallString.h"
12 #include "llvm/ADT/StringRef.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 
33  const DWARFObject &D = C.getDWARFObj();
34  parseImpl(C, Section, C.getDebugAbbrev(), &D.getRangeSection(),
36  &D.getAddrSection(), D.getLineSection(), D.isLittleEndian(), false,
37  false);
38 }
39 
41  const DWARFSection &DWOSection, bool Lazy) {
42  const DWARFObject &D = C.getDWARFObj();
43  parseImpl(C, DWOSection, C.getDebugAbbrevDWO(), &D.getRangeDWOSection(),
46  true, Lazy);
47 }
48 
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 
65  return DWARFDataExtractor(Context.getDWARFObj(), InfoSection, isLittleEndian,
67 }
68 
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 
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.
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 
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 
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 
170  return dwarf::toString(getUnitDIE().find(DW_AT_comp_dir), nullptr);
171 }
172 
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();
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 =
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 =
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 
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;
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 
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 
390  extractDIEsIfNeeded(false);
391  if (AddrDieMap.empty())
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
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 
423  if (Kind == DW_SECT_INFO)
424  return Context.getCUIndex();
425  assert(Kind == DW_SECT_TYPES);
426  return Context.getTUIndex();
427 }
428 
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 
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 
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 
480  if (!Abbrevs)
481  Abbrevs = Abbrev->getAbbreviationDeclarationSet(AbbrOffset);
482  return Abbrevs;
483 }
484 
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;
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.
503  if (!DA.isValidOffsetForDataOfSize(Offset, 16))
505 
506  if (DA.getU32(&Offset) != 0xffffffff)
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.
520  if (!DA.isValidOffsetForDataOfSize(Offset, 8))
522  uint32_t ContributionSize = DA.getU32(&Offset);
523  if (ContributionSize >= 0xfffffff0)
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 
533  uint64_t Offset) {
535  // Attempt to find a DWARF64 contribution 16 bytes before the base.
536  if (Offset >= 16)
537  Descriptor =
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 
547  uint64_t Offset) {
548  if (getVersion() >= 5) {
549  // Look for a valid contribution at the given offset.
550  auto Descriptor =
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 }
const DWARFAbbreviationDeclarationSet * getAbbreviations() const
Definition: DWARFUnit.cpp:479
const DWARFUnitIndex & getTUIndex()
uint64_t CallInst * C
void getInlinedChainForAddress(uint64_t Address, SmallVectorImpl< DWARFDie > &InlinedChain)
getInlinedChainForAddress - fetches inlined chain for a given address.
Definition: DWARFUnit.cpp:404
virtual ~DWARFUnit()
virtual const DWARFSection & getAddrSection() const
Definition: DWARFObject.h:66
LLVMContext & Context
bool extractRangeList(uint32_t RangeListOffset, DWARFDebugRangeList &RangeList) const
extractRangeList - extracts the range list referenced by this compile unit from .debug_ranges section...
Definition: DWARFUnit.cpp:147
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
Represents a unit&#39;s contribution to the string offsets table.
Definition: DWARFUnit.h:169
uint64_t getSectionIndex() const
std::shared_ptr< DWARFContext > getDWOContext(StringRef AbsolutePath)
void collectAddressRanges(DWARFAddressRangesVector &CURanges)
Definition: DWARFUnit.cpp:329
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
Definition: StringRef.h:138
void collectChildrenAddressRanges(DWARFAddressRangesVector &Ranges) const
Get all address ranges for any DW_TAG_subprogram DIEs in this DIE or any of its children.
Definition: DWARFDie.cpp:382
void parseDWO(DWARFContext &C, const DWARFSection &DWOSection, bool Lazy=false)
Definition: DWARFUnit.cpp:40
void setBaseAddress(BaseAddress BaseAddr)
Definition: DWARFUnit.h:380
DWARFDie getSibling(const DWARFDebugInfoEntry *Die)
Definition: DWARFUnit.cpp:448
uint64_t getRelocatedAddress(uint32_t *Off, uint64_t *SecIx=nullptr) const
Extracts an address-sized value and applies a relocation to the result if one exists for the given of...
unsigned second
static Optional< StrOffsetsContributionDescriptor > parseDWARF64StringOffsetsTableHeader(DWARFDataExtractor &DA, uint32_t Offset)
Definition: DWARFUnit.cpp:502
Optional< StrOffsetsContributionDescriptor > validateContributionSize(DWARFDataExtractor &DA)
Determine whether a contribution to the string offsets table is consistent with the relevant section ...
Definition: DWARFUnit.cpp:486
uint64_t alignTo(uint64_t Value, uint64_t Align, uint64_t Skew=0)
Returns the next integer (mod 2**64) that is greater than or equal to Value and is a multiple of Alig...
Definition: MathExtras.h:677
Optional< StrOffsetsContributionDescriptor > determineStringOffsetsTableContribution(DWARFDataExtractor &DA, uint64_t Offset)
Find the unit&#39;s contribution to the string offsets table and determine its length and form...
Definition: DWARFUnit.cpp:532
const DWARFDebugAbbrev * getDebugAbbrevDWO()
Get a pointer to the parsed dwo abbreviations object.
uint8_t getDwarfStringOffsetsByteSize() const
Definition: DWARFUnit.h:327
uint16_t getU16(uint32_t *offset_ptr) const
Extract a uint16_t value from *offset_ptr.
dwarf::DwarfFormat Format
Optional< uint64_t > toAddress(const Optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract an address.
DWARFDie getSubroutineForAddress(uint64_t Address)
Returns subprogram DIE with address range encompassing the provided address.
Definition: DWARFUnit.cpp:389
static Optional< StrOffsetsContributionDescriptor > parseDWARF32StringOffsetsTableHeader(DWARFDataExtractor &DA, uint32_t Offset)
Definition: DWARFUnit.cpp:519
virtual bool isLittleEndian() const =0
uint32_t getNextUnitOffset() const
Definition: DWARFUnit.h:311
bool getAddrOffsetSectionItem(uint32_t Index, uint64_t &Result) const
Definition: DWARFUnit.cpp:69
void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
Definition: Path.cpp:466
DWARFUnit(DWARFContext &Context, const DWARFSection &Section, const DWARFDebugAbbrev *DA, const DWARFSection *RS, StringRef SS, const DWARFSection &SOS, const DWARFSection *AOS, const DWARFSection &LS, bool LE, bool IsDWO, const DWARFUnitSectionBase &UnitSection, const DWARFUnitIndex::Entry *IndexEntry=nullptr)
Definition: DWARFUnit.cpp:49
uint32_t getU32(uint32_t *offset_ptr) const
Extract a uint32_t value from *offset_ptr.
static ManagedStatic< DebugCounter > DC
const char * getCompilationDir()
Definition: DWARFUnit.cpp:169
Optional< uint64_t > getRangesBaseAttribute() const
Extract the range base attribute from this DIE as absolute section offset.
Definition: DWARFDie.cpp:331
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:42
virtual uint32_t getHeaderSize() const
Size in bytes of the unit header.
Definition: DWARFUnit.h:245
virtual const DWARFSection & getStringOffsetDWOSection() const
Definition: DWARFObject.h:62
uint8_t getAddressByteSize() const
Definition: DWARFUnit.h:321
void parse(DWARFContext &C, const DWARFSection &Section)
Definition: DWARFUnit.cpp:32
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition: SmallString.h:26
const DWARFDebugAbbrev * getDebugAbbrev()
Get a pointer to the parsed DebugAbbrev object.
uint16_t getVersion() const
Definition: DWARFUnit.h:319
DWARFDie getSibling() const
Get the sibling of this DIE object.
Definition: DWARFDie.cpp:517
DWARFDie getFirstChild(const DWARFDebugInfoEntry *Die)
Definition: DWARFUnit.cpp:468
Optional< uint64_t > toSectionOffset(const Optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract an section offset.
bool isValidOffsetForDataOfSize(uint32_t offset, uint32_t length) const
Test the availability of length bytes of data from offset.
Utility class that carries the DWARF compile/type unit and the debug info entry in an object...
Definition: DWARFDie.h:43
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
virtual const DWARFSection & getStringOffsetSection() const
Definition: DWARFObject.h:54
DWARFSectionKind
A structured debug information entry.
Definition: DIE.h:662
bool isSubroutineDIE() const
Returns true if DIE represents a subprogram or an inlined subroutine.
Definition: DWARFDie.cpp:277
bool extractFast(const DWARFUnit &U, uint32_t *OffsetPtr)
Extracts a debug info entry, which is a child of a given unit, starting at a given offset...
const DWARFAbbreviationDeclarationSet * getAbbreviationDeclarationSet(uint64_t CUAbbrOffset) const
DWARFDie getParent(const DWARFDebugInfoEntry *Die)
Definition: DWARFUnit.cpp:429
virtual const DWARFSection & getLineDWOSection() const
Definition: DWARFObject.h:59
uint8_t getU8(uint32_t *offset_ptr) const
Extract a uint8_t value from *offset_ptr.
virtual StringRef getStringSection() const
Definition: DWARFObject.h:46
virtual StringRef getStringDWOSection() const
Definition: DWARFObject.h:61
uint64_t getU64(uint32_t *offset_ptr) const
Extract a uint64_t value from *offset_ptr.
const DWARFUnitIndex & getDWARFUnitIndex(DWARFContext &Context, DWARFSectionKind Kind)
Definition: DWARFUnit.cpp:421
auto find(R &&Range, const T &Val) -> decltype(adl_begin(Range))
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:835
uint64_t getRelocatedValue(uint32_t Size, uint32_t *Off, uint64_t *SectionIndex=nullptr) const
Extracts a value and applies a relocation to the result if one exists for the given offset...
UnitType
Constants for unit types in DWARF v5.
Definition: Dwarf.h:321
A DataExtractor (typically for an in-memory copy of an object-file section) plus a relocation map for...
uint64_t getStringOffsetsBase() const
Definition: DWARFUnit.h:332
DWARFDie getUnitDIE(bool ExtractUnitDIEOnly=true)
Definition: DWARFUnit.h:382
const DWARFAbbreviationDeclaration * getAbbreviationDeclarationPtr() const
bool extract(DataExtractor debug_info, uint32_t *offset_ptr)
Definition: DWARFUnit.cpp:131
DWARFContext This data structure is the top level entity that deals with dwarf debug information pars...
Definition: DWARFContext.h:59
A helper struct for DWARFFormValue methods, providing information that allows it to know the byte siz...
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
Optional< const char * > toString(const Optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract a string value from it.
DWARFDataExtractor getDebugInfoExtractor() const
Definition: DWARFUnit.cpp:64
virtual const DWARFSection & getLineSection() const
Definition: DWARFObject.h:44
static bool isSupportedVersion(unsigned version)
Definition: DWARFContext.h:291
virtual const DWARFSection & getRangeDWOSection() const
Definition: DWARFObject.h:65
bool getStringOffsetSectionItem(uint32_t Index, uint64_t &Result) const
Definition: DWARFUnit.cpp:80
LLVM_NODISCARD bool empty() const
Definition: SmallVector.h:61
virtual bool extractImpl(DataExtractor debug_info, uint32_t *offset_ptr)
Definition: DWARFUnit.cpp:94
Optional< uint64_t > getDWOId()
Definition: DWARFUnit.cpp:173
#define I(x, y, z)
Definition: MD5.cpp:58
bool is_relative(const Twine &path, Style style=Style::native)
Is path relative?
Definition: Path.cpp:685
uint32_t getOffset() const
Definition: DWARFUnit.h:310
void updateAddressDieMap(DWARFDie Die)
Recursively update address to Die map.
Definition: DWARFUnit.cpp:362
bool isLittleEndian() const
Definition: DWARFContext.h:290
const DWARFObject & getDWARFObj() const
Definition: DWARFContext.h:124
bool isValidOffset(uint32_t offset) const
Test the validity of offset.
const DWARFUnitIndex & getCUIndex()
virtual const DWARFSection & getRangeSection() const
Definition: DWARFObject.h:47
const unsigned Kind
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Base class for all DWARFUnitSection classes.
Definition: DWARFUnit.h:45
Optional< DWARFFormValue > find(dwarf::Attribute Attr) const
Extract the specified attribute from this DIE.
Definition: DWARFDie.cpp:282
std::vector< DWARFAddressRange > DWARFAddressRangesVector
DWARFAddressRangesVector - represents a set of absolute address ranges.
DWARFDebugInfoEntry - A DIE with only the minimum required data.
DWARFDie getFirstChild() const
Get the first child of this DIE object.
Definition: DWARFDie.cpp:523
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
const SectionContribution * getOffset(DWARFSectionKind Sec) const
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
const uint64_t Version
Definition: InstrProf.h:867
bool extract(const DWARFDataExtractor &data, uint32_t *offset_ptr)
uint8_t getDwarfOffsetByteSize() const
Definition: DWARFUnit.h:323
void setMaxVersionIfGreater(unsigned Version)
Definition: DWARFContext.h:213
Optional< uint64_t > toUnsigned(const Optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract an unsigned constant.
DWARFDie getParent() const
Get the parent of this DIE object.
Definition: DWARFDie.cpp:511
Optional< StrOffsetsContributionDescriptor > determineStringOffsetsTableContributionDWO(DWARFDataExtractor &DA, uint64_t Offset)
Find the unit&#39;s contribution to the string offsets table and determine its length and form...
Definition: DWARFUnit.cpp:546
DWARFAddressRangesVector getAddressRanges() const
Get the address ranges for this DIE.
Definition: DWARFDie.cpp:364