LLVM  14.0.0git
DWARFUnit.cpp
Go to the documentation of this file.
1 //===- DWARFUnit.cpp ------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
10 #include "llvm/ADT/SmallString.h"
11 #include "llvm/ADT/StringRef.h"
22 #include "llvm/Support/Errc.h"
23 #include "llvm/Support/Path.h"
24 #include <algorithm>
25 #include <cassert>
26 #include <cstddef>
27 #include <cstdint>
28 #include <cstdio>
29 #include <utility>
30 #include <vector>
31 
32 using namespace llvm;
33 using namespace dwarf;
34 
36  const DWARFSection &Section,
38  const DWARFObject &D = C.getDWARFObj();
39  addUnitsImpl(C, D, Section, C.getDebugAbbrev(), &D.getRangesSection(),
40  &D.getLocSection(), D.getStrSection(),
41  D.getStrOffsetsSection(), &D.getAddrSection(),
42  D.getLineSection(), D.isLittleEndian(), false, false,
43  SectionKind);
44 }
45 
47  const DWARFSection &DWOSection,
49  bool Lazy) {
50  const DWARFObject &D = C.getDWARFObj();
51  addUnitsImpl(C, D, DWOSection, C.getDebugAbbrevDWO(), &D.getRangesDWOSection(),
52  &D.getLocDWOSection(), D.getStrDWOSection(),
53  D.getStrOffsetsDWOSection(), &D.getAddrSection(),
54  D.getLineDWOSection(), C.isLittleEndian(), true, Lazy,
55  SectionKind);
56 }
57 
58 void DWARFUnitVector::addUnitsImpl(
60  const DWARFDebugAbbrev *DA, const DWARFSection *RS,
61  const DWARFSection *LocSection, StringRef SS, const DWARFSection &SOS,
62  const DWARFSection *AOS, const DWARFSection &LS, bool LE, bool IsDWO,
63  bool Lazy, DWARFSectionKind SectionKind) {
65  // Lazy initialization of Parser, now that we have all section info.
66  if (!Parser) {
67  Parser = [=, &Context, &Obj, &Section, &SOS,
69  const DWARFSection *CurSection,
70  const DWARFUnitIndex::Entry *IndexEntry)
71  -> std::unique_ptr<DWARFUnit> {
72  const DWARFSection &InfoSection = CurSection ? *CurSection : Section;
73  DWARFDataExtractor Data(Obj, InfoSection, LE, 0);
74  if (!Data.isValidOffset(Offset))
75  return nullptr;
76  DWARFUnitHeader Header;
77  if (!Header.extract(Context, Data, &Offset, SectionKind))
78  return nullptr;
79  if (!IndexEntry && IsDWO) {
81  Context, Header.isTypeUnit() ? DW_SECT_EXT_TYPES : DW_SECT_INFO);
82  IndexEntry = Index.getFromOffset(Header.getOffset());
83  }
84  if (IndexEntry && !Header.applyIndexEntry(IndexEntry))
85  return nullptr;
86  std::unique_ptr<DWARFUnit> U;
87  if (Header.isTypeUnit())
88  U = std::make_unique<DWARFTypeUnit>(Context, InfoSection, Header, DA,
89  RS, LocSection, SS, SOS, AOS, LS,
90  LE, IsDWO, *this);
91  else
92  U = std::make_unique<DWARFCompileUnit>(Context, InfoSection, Header,
93  DA, RS, LocSection, SS, SOS,
94  AOS, LS, LE, IsDWO, *this);
95  return U;
96  };
97  }
98  if (Lazy)
99  return;
100  // Find a reasonable insertion point within the vector. We skip over
101  // (a) units from a different section, (b) units from the same section
102  // but with lower offset-within-section. This keeps units in order
103  // within a section, although not necessarily within the object file,
104  // even if we do lazy parsing.
105  auto I = this->begin();
106  uint64_t Offset = 0;
107  while (Data.isValidOffset(Offset)) {
108  if (I != this->end() &&
109  (&(*I)->getInfoSection() != &Section || (*I)->getOffset() == Offset)) {
110  ++I;
111  continue;
112  }
113  auto U = Parser(Offset, SectionKind, &Section, nullptr);
114  // If parsing failed, we're done with this section.
115  if (!U)
116  break;
117  Offset = U->getNextUnitOffset();
118  I = std::next(this->insert(I, std::move(U)));
119  }
120 }
121 
122 DWARFUnit *DWARFUnitVector::addUnit(std::unique_ptr<DWARFUnit> Unit) {
123  auto I = std::upper_bound(begin(), end(), Unit,
124  [](const std::unique_ptr<DWARFUnit> &LHS,
125  const std::unique_ptr<DWARFUnit> &RHS) {
126  return LHS->getOffset() < RHS->getOffset();
127  });
128  return this->insert(I, std::move(Unit))->get();
129 }
130 
132  auto end = begin() + getNumInfoUnits();
133  auto *CU =
135  [](uint64_t LHS, const std::unique_ptr<DWARFUnit> &RHS) {
136  return LHS < RHS->getNextUnitOffset();
137  });
138  if (CU != end && (*CU)->getOffset() <= Offset)
139  return CU->get();
140  return nullptr;
141 }
142 
143 DWARFUnit *
145  const auto *CUOff = E.getContribution(DW_SECT_INFO);
146  if (!CUOff)
147  return nullptr;
148 
149  auto Offset = CUOff->Offset;
150  auto end = begin() + getNumInfoUnits();
151 
152  auto *CU =
153  std::upper_bound(begin(), end, CUOff->Offset,
154  [](uint64_t LHS, const std::unique_ptr<DWARFUnit> &RHS) {
155  return LHS < RHS->getNextUnitOffset();
156  });
157  if (CU != end && (*CU)->getOffset() <= Offset)
158  return CU->get();
159 
160  if (!Parser)
161  return nullptr;
162 
163  auto U = Parser(Offset, DW_SECT_INFO, nullptr, &E);
164  if (!U)
165  U = nullptr;
166 
167  auto *NewCU = U.get();
168  this->insert(CU, std::move(U));
169  ++NumInfoUnits;
170  return NewCU;
171 }
172 
174  const DWARFUnitHeader &Header, const DWARFDebugAbbrev *DA,
175  const DWARFSection *RS, const DWARFSection *LocSection,
176  StringRef SS, const DWARFSection &SOS,
177  const DWARFSection *AOS, const DWARFSection &LS, bool LE,
178  bool IsDWO, const DWARFUnitVector &UnitVector)
179  : Context(DC), InfoSection(Section), Header(Header), Abbrev(DA),
180  RangeSection(RS), LineSection(LS), StringSection(SS),
181  StringOffsetSection(SOS), AddrOffsetSection(AOS), isLittleEndian(LE),
182  IsDWO(IsDWO), UnitVector(UnitVector) {
183  clear();
184 }
185 
186 DWARFUnit::~DWARFUnit() = default;
187 
189  return DWARFDataExtractor(Context.getDWARFObj(), InfoSection, isLittleEndian,
191 }
192 
195  if (!AddrOffsetSectionBase) {
196  auto R = Context.info_section_units();
197  // Surprising if a DWO file has more than one skeleton unit in it - this
198  // probably shouldn't be valid, but if a use case is found, here's where to
199  // support it (probably have to linearly search for the matching skeleton CU
200  // here)
201  if (IsDWO && hasSingleElement(R))
202  return (*R.begin())->getAddrOffsetSectionItem(Index);
203 
204  return None;
205  }
206 
207  uint64_t Offset = *AddrOffsetSectionBase + Index * getAddressByteSize();
208  if (AddrOffsetSection->Data.size() < Offset + getAddressByteSize())
209  return None;
210  DWARFDataExtractor DA(Context.getDWARFObj(), *AddrOffsetSection,
211  isLittleEndian, getAddressByteSize());
213  uint64_t Address = DA.getRelocatedAddress(&Offset, &Section);
214  return {{Address, Section}};
215 }
216 
218  if (!StringOffsetsTableContribution)
219  return make_error<StringError>(
220  "DW_FORM_strx used without a valid string offsets table",
222  unsigned ItemSize = getDwarfStringOffsetsByteSize();
223  uint64_t Offset = getStringOffsetsBase() + Index * ItemSize;
224  if (StringOffsetSection.Data.size() < Offset + ItemSize)
225  return make_error<StringError>("DW_FORM_strx uses index " + Twine(Index) +
226  ", which is too large",
228  DWARFDataExtractor DA(Context.getDWARFObj(), StringOffsetSection,
229  isLittleEndian, 0);
230  return DA.getRelocatedValue(ItemSize, &Offset);
231 }
232 
234  const DWARFDataExtractor &debug_info,
235  uint64_t *offset_ptr,
237  Offset = *offset_ptr;
238  Error Err = Error::success();
239  IndexEntry = nullptr;
240  std::tie(Length, FormParams.Format) =
241  debug_info.getInitialLength(offset_ptr, &Err);
242  FormParams.Version = debug_info.getU16(offset_ptr, &Err);
243  if (FormParams.Version >= 5) {
244  UnitType = debug_info.getU8(offset_ptr, &Err);
245  FormParams.AddrSize = debug_info.getU8(offset_ptr, &Err);
246  AbbrOffset = debug_info.getRelocatedValue(
247  FormParams.getDwarfOffsetByteSize(), offset_ptr, nullptr, &Err);
248  } else {
249  AbbrOffset = debug_info.getRelocatedValue(
250  FormParams.getDwarfOffsetByteSize(), offset_ptr, nullptr, &Err);
251  FormParams.AddrSize = debug_info.getU8(offset_ptr, &Err);
252  // Fake a unit type based on the section type. This isn't perfect,
253  // but distinguishing compile and type units is generally enough.
255  UnitType = DW_UT_type;
256  else
257  UnitType = DW_UT_compile;
258  }
259  if (isTypeUnit()) {
260  TypeHash = debug_info.getU64(offset_ptr, &Err);
261  TypeOffset = debug_info.getUnsigned(
262  offset_ptr, FormParams.getDwarfOffsetByteSize(), &Err);
263  } else if (UnitType == DW_UT_split_compile || UnitType == DW_UT_skeleton)
264  DWOId = debug_info.getU64(offset_ptr, &Err);
265 
266  if (Err) {
267  Context.getWarningHandler()(joinErrors(
270  "DWARF unit at 0x%8.8" PRIx64 " cannot be parsed:", Offset),
271  std::move(Err)));
272  return false;
273  }
274 
275  // Header fields all parsed, capture the size of this unit header.
276  assert(*offset_ptr - Offset <= 255 && "unexpected header size");
277  Size = uint8_t(*offset_ptr - Offset);
278  uint64_t NextCUOffset = Offset + getUnitLengthFieldByteSize() + getLength();
279 
280  if (!debug_info.isValidOffset(getNextUnitOffset() - 1)) {
281  Context.getWarningHandler()(
283  "DWARF unit from offset 0x%8.8" PRIx64 " incl. "
284  "to offset 0x%8.8" PRIx64 " excl. "
285  "extends past section size 0x%8.8zx",
286  Offset, NextCUOffset, debug_info.size()));
287  return false;
288  }
289 
291  Context.getWarningHandler()(createStringError(
293  "DWARF unit at offset 0x%8.8" PRIx64 " "
294  "has unsupported version %" PRIu16 ", supported are 2-%u",
296  return false;
297  }
298 
299  // Type offset is unit-relative; should be after the header and before
300  // the end of the current unit.
301  if (isTypeUnit() && TypeOffset < Size) {
302  Context.getWarningHandler()(
304  "DWARF type unit at offset "
305  "0x%8.8" PRIx64 " "
306  "has its relocated type_offset 0x%8.8" PRIx64 " "
307  "pointing inside the header",
308  Offset, Offset + TypeOffset));
309  return false;
310  }
311  if (isTypeUnit() &&
312  TypeOffset >= getUnitLengthFieldByteSize() + getLength()) {
313  Context.getWarningHandler()(createStringError(
315  "DWARF type unit from offset 0x%8.8" PRIx64 " incl. "
316  "to offset 0x%8.8" PRIx64 " excl. has its "
317  "relocated type_offset 0x%8.8" PRIx64 " pointing past the unit end",
318  Offset, NextCUOffset, Offset + TypeOffset));
319  return false;
320  }
321 
324  "DWARF unit at offset 0x%8.8" PRIx64, Offset)) {
325  Context.getWarningHandler()(std::move(SizeErr));
326  return false;
327  }
328 
329  // Keep track of the highest DWARF version we encounter across all units.
330  Context.setMaxVersionIfGreater(getVersion());
331  return true;
332 }
333 
335  assert(Entry);
336  assert(!IndexEntry);
337  IndexEntry = Entry;
338  if (AbbrOffset)
339  return false;
340  auto *UnitContrib = IndexEntry->getContribution();
341  if (!UnitContrib ||
342  UnitContrib->Length != (getLength() + getUnitLengthFieldByteSize()))
343  return false;
344  auto *AbbrEntry = IndexEntry->getContribution(DW_SECT_ABBREV);
345  if (!AbbrEntry)
346  return false;
347  AbbrOffset = AbbrEntry->Offset;
348  return true;
349 }
350 
352  DWARFDebugRangeList &RangeList) const {
353  // Require that compile unit is extracted.
354  assert(!DieArray.empty());
355  DWARFDataExtractor RangesData(Context.getDWARFObj(), *RangeSection,
356  isLittleEndian, getAddressByteSize());
357  uint64_t ActualRangeListOffset = RangeSectionBase + RangeListOffset;
358  return RangeList.extract(RangesData, &ActualRangeListOffset);
359 }
360 
362  Abbrevs = nullptr;
363  BaseAddr.reset();
364  RangeSectionBase = 0;
365  LocSectionBase = 0;
366  AddrOffsetSectionBase = None;
367  SU = nullptr;
368  clearDIEs(false);
369  DWO.reset();
370 }
371 
373  return dwarf::toString(getUnitDIE().find(DW_AT_comp_dir), nullptr);
374 }
375 
376 void DWARFUnit::extractDIEsToVector(
377  bool AppendCUDie, bool AppendNonCUDies,
378  std::vector<DWARFDebugInfoEntry> &Dies) const {
379  if (!AppendCUDie && !AppendNonCUDies)
380  return;
381 
382  // Set the offset to that of the first DIE and calculate the start of the
383  // next compilation unit header.
384  uint64_t DIEOffset = getOffset() + getHeaderSize();
385  uint64_t NextCUOffset = getNextUnitOffset();
387  DWARFDataExtractor DebugInfoData = getDebugInfoExtractor();
388  // The end offset has been already checked by DWARFUnitHeader::extract.
389  assert(DebugInfoData.isValidOffset(NextCUOffset - 1));
390  std::vector<uint32_t> Parents;
391  std::vector<uint32_t> PrevSiblings;
392  bool IsCUDie = true;
393 
394  assert(
395  ((AppendCUDie && Dies.empty()) || (!AppendCUDie && Dies.size() == 1)) &&
396  "Dies array is not empty");
397 
398  // Fill Parents and Siblings stacks with initial value.
399  Parents.push_back(UINT32_MAX);
400  if (!AppendCUDie)
401  Parents.push_back(0);
402  PrevSiblings.push_back(0);
403 
404  // Start to extract dies.
405  do {
406  assert(Parents.size() > 0 && "Empty parents stack");
407  assert((Parents.back() == UINT32_MAX || Parents.back() <= Dies.size()) &&
408  "Wrong parent index");
409 
410  // Extract die. Stop if any error occured.
411  if (!DIE.extractFast(*this, &DIEOffset, DebugInfoData, NextCUOffset,
412  Parents.back()))
413  break;
414 
415  // If previous sibling is remembered then update it`s SiblingIdx field.
416  if (PrevSiblings.back() > 0) {
417  assert(PrevSiblings.back() < Dies.size() &&
418  "Previous sibling index is out of Dies boundaries");
419  Dies[PrevSiblings.back()].setSiblingIdx(Dies.size());
420  }
421 
422  // Store die into the Dies vector.
423  if (IsCUDie) {
424  if (AppendCUDie)
425  Dies.push_back(DIE);
426  if (!AppendNonCUDies)
427  break;
428  // The average bytes per DIE entry has been seen to be
429  // around 14-20 so let's pre-reserve the needed memory for
430  // our DIE entries accordingly.
431  Dies.reserve(Dies.size() + getDebugInfoSize() / 14);
432  } else {
433  // Remember last previous sibling.
434  PrevSiblings.back() = Dies.size();
435 
436  Dies.push_back(DIE);
437  }
438 
439  // Check for new children scope.
440  if (const DWARFAbbreviationDeclaration *AbbrDecl =
441  DIE.getAbbreviationDeclarationPtr()) {
442  if (AbbrDecl->hasChildren()) {
443  if (AppendCUDie || !IsCUDie) {
444  assert(Dies.size() > 0 && "Dies does not contain any die");
445  Parents.push_back(Dies.size() - 1);
446  PrevSiblings.push_back(0);
447  }
448  } else if (IsCUDie)
449  // Stop if we have single compile unit die w/o children.
450  break;
451  } else {
452  // NULL DIE: finishes current children scope.
453  Parents.pop_back();
454  PrevSiblings.pop_back();
455  }
456 
457  if (IsCUDie)
458  IsCUDie = false;
459 
460  // Stop when compile unit die is removed from the parents stack.
461  } while (Parents.size() > 1);
462 }
463 
464 void DWARFUnit::extractDIEsIfNeeded(bool CUDieOnly) {
465  if (Error e = tryExtractDIEsIfNeeded(CUDieOnly))
466  Context.getRecoverableErrorHandler()(std::move(e));
467 }
468 
470  if ((CUDieOnly && !DieArray.empty()) ||
471  DieArray.size() > 1)
472  return Error::success(); // Already parsed.
473 
474  bool HasCUDie = !DieArray.empty();
475  extractDIEsToVector(!HasCUDie, !CUDieOnly, DieArray);
476 
477  if (DieArray.empty())
478  return Error::success();
479 
480  // If CU DIE was just parsed, copy several attribute values from it.
481  if (HasCUDie)
482  return Error::success();
483 
484  DWARFDie UnitDie(this, &DieArray[0]);
485  if (Optional<uint64_t> DWOId = toUnsigned(UnitDie.find(DW_AT_GNU_dwo_id)))
486  Header.setDWOId(*DWOId);
487  if (!IsDWO) {
488  assert(AddrOffsetSectionBase == None);
489  assert(RangeSectionBase == 0);
490  assert(LocSectionBase == 0);
491  AddrOffsetSectionBase = toSectionOffset(UnitDie.find(DW_AT_addr_base));
492  if (!AddrOffsetSectionBase)
493  AddrOffsetSectionBase =
494  toSectionOffset(UnitDie.find(DW_AT_GNU_addr_base));
495  RangeSectionBase = toSectionOffset(UnitDie.find(DW_AT_rnglists_base), 0);
496  LocSectionBase = toSectionOffset(UnitDie.find(DW_AT_loclists_base), 0);
497  }
498 
499  // In general, in DWARF v5 and beyond we derive the start of the unit's
500  // contribution to the string offsets table from the unit DIE's
501  // DW_AT_str_offsets_base attribute. Split DWARF units do not use this
502  // attribute, so we assume that there is a contribution to the string
503  // offsets table starting at offset 0 of the debug_str_offsets.dwo section.
504  // In both cases we need to determine the format of the contribution,
505  // which may differ from the unit's format.
506  DWARFDataExtractor DA(Context.getDWARFObj(), StringOffsetSection,
507  isLittleEndian, 0);
508  if (IsDWO || getVersion() >= 5) {
509  auto StringOffsetOrError =
512  if (!StringOffsetOrError)
514  "invalid reference to or invalid content in "
515  ".debug_str_offsets[.dwo]: " +
516  toString(StringOffsetOrError.takeError()));
517 
518  StringOffsetsTableContribution = *StringOffsetOrError;
519  }
520 
521  // DWARF v5 uses the .debug_rnglists and .debug_rnglists.dwo sections to
522  // describe address ranges.
523  if (getVersion() >= 5) {
524  // In case of DWP, the base offset from the index has to be added.
525  if (IsDWO) {
526  uint64_t ContributionBaseOffset = 0;
527  if (auto *IndexEntry = Header.getIndexEntry())
528  if (auto *Contrib = IndexEntry->getContribution(DW_SECT_RNGLISTS))
529  ContributionBaseOffset = Contrib->Offset;
531  &Context.getDWARFObj().getRnglistsDWOSection(),
532  ContributionBaseOffset +
534  } else
535  setRangesSection(&Context.getDWARFObj().getRnglistsSection(),
536  toSectionOffset(UnitDie.find(DW_AT_rnglists_base),
538  Header.getFormat())));
539  }
540 
541  if (IsDWO) {
542  // If we are reading a package file, we need to adjust the location list
543  // data based on the index entries.
544  StringRef Data = Header.getVersion() >= 5
545  ? Context.getDWARFObj().getLoclistsDWOSection().Data
546  : Context.getDWARFObj().getLocDWOSection().Data;
547  if (auto *IndexEntry = Header.getIndexEntry())
548  if (const auto *C = IndexEntry->getContribution(
549  Header.getVersion() >= 5 ? DW_SECT_LOCLISTS : DW_SECT_EXT_LOC))
550  Data = Data.substr(C->Offset, C->Length);
551 
552  DWARFDataExtractor DWARFData(Data, isLittleEndian, getAddressByteSize());
553  LocTable =
554  std::make_unique<DWARFDebugLoclists>(DWARFData, Header.getVersion());
555  LocSectionBase = DWARFListTableHeader::getHeaderSize(Header.getFormat());
556  } else if (getVersion() >= 5) {
557  LocTable = std::make_unique<DWARFDebugLoclists>(
558  DWARFDataExtractor(Context.getDWARFObj(),
559  Context.getDWARFObj().getLoclistsSection(),
560  isLittleEndian, getAddressByteSize()),
561  getVersion());
562  } else {
563  LocTable = std::make_unique<DWARFDebugLoc>(DWARFDataExtractor(
564  Context.getDWARFObj(), Context.getDWARFObj().getLocSection(),
565  isLittleEndian, getAddressByteSize()));
566  }
567 
568  // Don't fall back to DW_AT_GNU_ranges_base: it should be ignored for
569  // skeleton CU DIE, so that DWARF users not aware of it are not broken.
570  return Error::success();
571 }
572 
573 bool DWARFUnit::parseDWO() {
574  if (IsDWO)
575  return false;
576  if (DWO.get())
577  return false;
578  DWARFDie UnitDie = getUnitDIE();
579  if (!UnitDie)
580  return false;
581  auto DWOFileName = getVersion() >= 5
582  ? dwarf::toString(UnitDie.find(DW_AT_dwo_name))
583  : dwarf::toString(UnitDie.find(DW_AT_GNU_dwo_name));
584  if (!DWOFileName)
585  return false;
586  auto CompilationDir = dwarf::toString(UnitDie.find(DW_AT_comp_dir));
587  SmallString<16> AbsolutePath;
588  if (sys::path::is_relative(*DWOFileName) && CompilationDir &&
589  *CompilationDir) {
590  sys::path::append(AbsolutePath, *CompilationDir);
591  }
592  sys::path::append(AbsolutePath, *DWOFileName);
593  auto DWOId = getDWOId();
594  if (!DWOId)
595  return false;
596  auto DWOContext = Context.getDWOContext(AbsolutePath);
597  if (!DWOContext)
598  return false;
599 
600  DWARFCompileUnit *DWOCU = DWOContext->getDWOCompileUnitForHash(*DWOId);
601  if (!DWOCU)
602  return false;
603  DWO = std::shared_ptr<DWARFCompileUnit>(std::move(DWOContext), DWOCU);
604  DWO->setSkeletonUnit(this);
605  // Share .debug_addr and .debug_ranges section with compile unit in .dwo
606  if (AddrOffsetSectionBase)
607  DWO->setAddrOffsetSection(AddrOffsetSection, *AddrOffsetSectionBase);
608  if (getVersion() == 4) {
609  auto DWORangesBase = UnitDie.getRangesBaseAttribute();
610  DWO->setRangesSection(RangeSection, DWORangesBase.getValueOr(0));
611  }
612 
613  return true;
614 }
615 
616 void DWARFUnit::clearDIEs(bool KeepCUDie) {
617  // Do not use resize() + shrink_to_fit() to free memory occupied by dies.
618  // shrink_to_fit() is a *non-binding* request to reduce capacity() to size().
619  // It depends on the implementation whether the request is fulfilled.
620  // Create a new vector with a small capacity and assign it to the DieArray to
621  // have previous contents freed.
622  DieArray = (KeepCUDie && !DieArray.empty())
623  ? std::vector<DWARFDebugInfoEntry>({DieArray[0]})
624  : std::vector<DWARFDebugInfoEntry>();
625 }
626 
629  if (getVersion() <= 4) {
630  DWARFDebugRangeList RangeList;
631  if (Error E = extractRangeList(Offset, RangeList))
632  return std::move(E);
633  return RangeList.getAbsoluteRanges(getBaseAddress());
634  }
635  DWARFDataExtractor RangesData(Context.getDWARFObj(), *RangeSection,
636  isLittleEndian, Header.getAddressByteSize());
637  DWARFDebugRnglistTable RnglistTable;
638  auto RangeListOrError = RnglistTable.findList(RangesData, Offset);
639  if (RangeListOrError)
640  return RangeListOrError.get().getAbsoluteRanges(getBaseAddress(), *this);
641  return RangeListOrError.takeError();
642 }
643 
646  if (auto Offset = getRnglistOffset(Index))
647  return findRnglistFromOffset(*Offset);
648 
650  "invalid range list table index %d (possibly "
651  "missing the entire range list table)",
652  Index);
653 }
654 
656  DWARFDie UnitDie = getUnitDIE();
657  if (!UnitDie)
658  return createStringError(errc::invalid_argument, "No unit DIE");
659 
660  // First, check if unit DIE describes address ranges for the whole unit.
661  auto CUDIERangesOrError = UnitDie.getAddressRanges();
662  if (!CUDIERangesOrError)
664  "decoding address ranges: %s",
665  toString(CUDIERangesOrError.takeError()).c_str());
666  return *CUDIERangesOrError;
667 }
668 
672 
673  Error InterpretationError = Error::success();
674 
677  [this](uint32_t Index) { return getAddrOffsetSectionItem(Index); },
679  if (L)
680  Result.push_back(std::move(*L));
681  else
682  InterpretationError =
683  joinErrors(L.takeError(), std::move(InterpretationError));
684  return !InterpretationError;
685  });
686 
687  if (ParseError || InterpretationError)
688  return joinErrors(std::move(ParseError), std::move(InterpretationError));
689 
690  return Result;
691 }
692 
694  if (Die.isSubroutineDIE()) {
695  auto DIERangesOrError = Die.getAddressRanges();
696  if (DIERangesOrError) {
697  for (const auto &R : DIERangesOrError.get()) {
698  // Ignore 0-sized ranges.
699  if (R.LowPC == R.HighPC)
700  continue;
701  auto B = AddrDieMap.upper_bound(R.LowPC);
702  if (B != AddrDieMap.begin() && R.LowPC < (--B)->second.first) {
703  // The range is a sub-range of existing ranges, we need to split the
704  // existing range.
705  if (R.HighPC < B->second.first)
706  AddrDieMap[R.HighPC] = B->second;
707  if (R.LowPC > B->first)
708  AddrDieMap[B->first].first = R.LowPC;
709  }
710  AddrDieMap[R.LowPC] = std::make_pair(R.HighPC, Die);
711  }
712  } else
713  llvm::consumeError(DIERangesOrError.takeError());
714  }
715  // Parent DIEs are added to the AddrDieMap prior to the Children DIEs to
716  // simplify the logic to update AddrDieMap. The child's range will always
717  // be equal or smaller than the parent's range. With this assumption, when
718  // adding one range into the map, it will at most split a range into 3
719  // sub-ranges.
720  for (DWARFDie Child = Die.getFirstChild(); Child; Child = Child.getSibling())
721  updateAddressDieMap(Child);
722 }
723 
725  extractDIEsIfNeeded(false);
726  if (AddrDieMap.empty())
728  auto R = AddrDieMap.upper_bound(Address);
729  if (R == AddrDieMap.begin())
730  return DWARFDie();
731  // upper_bound's previous item contains Address.
732  --R;
733  if (Address >= R->second.first)
734  return DWARFDie();
735  return R->second.second;
736 }
737 
738 void
740  SmallVectorImpl<DWARFDie> &InlinedChain) {
741  assert(InlinedChain.empty());
742  // Try to look for subprogram DIEs in the DWO file.
743  parseDWO();
744  // First, find the subroutine that contains the given address (the leaf
745  // of inlined chain).
746  DWARFDie SubroutineDIE =
747  (DWO ? *DWO : *this).getSubroutineForAddress(Address);
748 
749  while (SubroutineDIE) {
750  if (SubroutineDIE.isSubprogramDIE()) {
751  InlinedChain.push_back(SubroutineDIE);
752  return;
753  }
754  if (SubroutineDIE.getTag() == DW_TAG_inlined_subroutine)
755  InlinedChain.push_back(SubroutineDIE);
756  SubroutineDIE = SubroutineDIE.getParent();
757  }
758 }
759 
762  if (Kind == DW_SECT_INFO)
763  return Context.getCUIndex();
765  return Context.getTUIndex();
766 }
767 
769  if (!Die)
770  return DWARFDie();
771 
772  if (Optional<uint32_t> ParentIdx = Die->getParentIdx()) {
773  assert(*ParentIdx < DieArray.size() &&
774  "ParentIdx is out of DieArray boundaries");
775  return DWARFDie(this, &DieArray[*ParentIdx]);
776  }
777 
778  return DWARFDie();
779 }
780 
782  if (!Die)
783  return DWARFDie();
784 
785  if (Optional<uint32_t> SiblingIdx = Die->getSiblingIdx()) {
786  assert(*SiblingIdx < DieArray.size() &&
787  "SiblingIdx is out of DieArray boundaries");
788  return DWARFDie(this, &DieArray[*SiblingIdx]);
789  }
790 
791  return DWARFDie();
792 }
793 
795  if (!Die)
796  return DWARFDie();
797 
798  Optional<uint32_t> ParentIdx = Die->getParentIdx();
799  if (!ParentIdx)
800  // Die is a root die, there is no previous sibling.
801  return DWARFDie();
802 
803  assert(*ParentIdx < DieArray.size() &&
804  "ParentIdx is out of DieArray boundaries");
805  assert(getDIEIndex(Die) > 0 && "Die is a root die");
806 
807  uint32_t PrevDieIdx = getDIEIndex(Die) - 1;
808  if (PrevDieIdx == *ParentIdx)
809  // Immediately previous node is parent, there is no previous sibling.
810  return DWARFDie();
811 
812  while (DieArray[PrevDieIdx].getParentIdx() != *ParentIdx) {
813  PrevDieIdx = *DieArray[PrevDieIdx].getParentIdx();
814 
815  assert(PrevDieIdx < DieArray.size() &&
816  "PrevDieIdx is out of DieArray boundaries");
817  assert(PrevDieIdx >= *ParentIdx &&
818  "PrevDieIdx is not a child of parent of Die");
819  }
820 
821  return DWARFDie(this, &DieArray[PrevDieIdx]);
822 }
823 
825  if (!Die->hasChildren())
826  return DWARFDie();
827 
828  // TODO: Instead of checking here for invalid die we might reject
829  // invalid dies at parsing stage(DWARFUnit::extractDIEsToVector).
830  // We do not want access out of bounds when parsing corrupted debug data.
831  size_t I = getDIEIndex(Die) + 1;
832  if (I >= DieArray.size())
833  return DWARFDie();
834  return DWARFDie(this, &DieArray[I]);
835 }
836 
838  if (!Die->hasChildren())
839  return DWARFDie();
840 
841  if (Optional<uint32_t> SiblingIdx = Die->getSiblingIdx()) {
842  assert(*SiblingIdx < DieArray.size() &&
843  "SiblingIdx is out of DieArray boundaries");
844  assert(DieArray[*SiblingIdx - 1].getTag() == dwarf::DW_TAG_null &&
845  "Bad end of children marker");
846  return DWARFDie(this, &DieArray[*SiblingIdx - 1]);
847  }
848 
849  // If SiblingIdx is set for non-root dies we could be sure that DWARF is
850  // correct and "end of children marker" must be found. For root die we do not
851  // have such a guarantee(parsing root die might be stopped if "end of children
852  // marker" is missing, SiblingIdx is always zero for root die). That is why we
853  // do not use assertion for checking for "end of children marker" for root
854  // die.
855 
856  // TODO: Instead of checking here for invalid die we might reject
857  // invalid dies at parsing stage(DWARFUnit::extractDIEsToVector).
858  if (getDIEIndex(Die) == 0 && DieArray.size() > 1 &&
859  DieArray.back().getTag() == dwarf::DW_TAG_null) {
860  // For the unit die we might take last item from DieArray.
861  assert(getDIEIndex(Die) == getDIEIndex(getUnitDIE()) && "Bad unit die");
862  return DWARFDie(this, &DieArray.back());
863  }
864 
865  return DWARFDie();
866 }
867 
869  if (!Abbrevs)
871  return Abbrevs;
872 }
873 
875  if (BaseAddr)
876  return BaseAddr;
877 
878  DWARFDie UnitDie = getUnitDIE();
879  Optional<DWARFFormValue> PC = UnitDie.find({DW_AT_low_pc, DW_AT_entry_pc});
880  BaseAddr = toSectionedAddress(PC);
881  return BaseAddr;
882 }
883 
887  uint8_t EntrySize = getDwarfOffsetByteSize();
888  // In order to ensure that we don't read a partial record at the end of
889  // the section we validate for a multiple of the entry size.
890  uint64_t ValidationSize = alignTo(Size, EntrySize);
891  // Guard against overflow.
892  if (ValidationSize >= Size)
893  if (DA.isValidOffsetForDataOfSize((uint32_t)Base, ValidationSize))
894  return *this;
895  return createStringError(errc::invalid_argument, "length exceeds section size");
896 }
897 
898 // Look for a DWARF64-formatted contribution to the string offsets table
899 // starting at a given offset and record it in a descriptor.
902  if (!DA.isValidOffsetForDataOfSize(Offset, 16))
903  return createStringError(errc::invalid_argument, "section offset exceeds section size");
904 
905  if (DA.getU32(&Offset) != dwarf::DW_LENGTH_DWARF64)
906  return createStringError(errc::invalid_argument, "32 bit contribution referenced from a 64 bit unit");
907 
908  uint64_t Size = DA.getU64(&Offset);
909  uint8_t Version = DA.getU16(&Offset);
910  (void)DA.getU16(&Offset); // padding
911  // The encoded length includes the 2-byte version field and the 2-byte
912  // padding, so we need to subtract them out when we populate the descriptor.
914 }
915 
916 // Look for a DWARF32-formatted contribution to the string offsets table
917 // starting at a given offset and record it in a descriptor.
920  if (!DA.isValidOffsetForDataOfSize(Offset, 8))
921  return createStringError(errc::invalid_argument, "section offset exceeds section size");
922 
923  uint32_t ContributionSize = DA.getU32(&Offset);
924  if (ContributionSize >= dwarf::DW_LENGTH_lo_reserved)
925  return createStringError(errc::invalid_argument, "invalid length");
926 
927  uint8_t Version = DA.getU16(&Offset);
928  (void)DA.getU16(&Offset); // padding
929  // The encoded length includes the 2-byte version field and the 2-byte
930  // padding, so we need to subtract them out when we populate the descriptor.
931  return StrOffsetsContributionDescriptor(Offset, ContributionSize - 4, Version,
932  DWARF32);
933 }
934 
938  uint64_t Offset) {
940  switch (Format) {
942  if (Offset < 16)
943  return createStringError(errc::invalid_argument, "insufficient space for 64 bit header prefix");
944  auto DescOrError = parseDWARF64StringOffsetsTableHeader(DA, Offset - 16);
945  if (!DescOrError)
946  return DescOrError.takeError();
947  Desc = *DescOrError;
948  break;
949  }
951  if (Offset < 8)
952  return createStringError(errc::invalid_argument, "insufficient space for 32 bit header prefix");
953  auto DescOrError = parseDWARF32StringOffsetsTableHeader(DA, Offset - 8);
954  if (!DescOrError)
955  return DescOrError.takeError();
956  Desc = *DescOrError;
957  break;
958  }
959  }
960  return Desc.validateContributionSize(DA);
961 }
962 
965  assert(!IsDWO);
966  auto OptOffset = toSectionOffset(getUnitDIE().find(DW_AT_str_offsets_base));
967  if (!OptOffset)
968  return None;
969  auto DescOrError =
970  parseDWARFStringOffsetsTableHeader(DA, Header.getFormat(), *OptOffset);
971  if (!DescOrError)
972  return DescOrError.takeError();
973  return *DescOrError;
974 }
975 
978  assert(IsDWO);
979  uint64_t Offset = 0;
980  auto IndexEntry = Header.getIndexEntry();
981  const auto *C =
982  IndexEntry ? IndexEntry->getContribution(DW_SECT_STR_OFFSETS) : nullptr;
983  if (C)
984  Offset = C->Offset;
985  if (getVersion() >= 5) {
986  if (DA.getData().data() == nullptr)
987  return None;
988  Offset += Header.getFormat() == dwarf::DwarfFormat::DWARF32 ? 8 : 16;
989  // Look for a valid contribution at the given offset.
990  auto DescOrError = parseDWARFStringOffsetsTableHeader(DA, Header.getFormat(), Offset);
991  if (!DescOrError)
992  return DescOrError.takeError();
993  return *DescOrError;
994  }
995  // Prior to DWARF v5, we derive the contribution size from the
996  // index table (in a package file). In a .dwo file it is simply
997  // the length of the string offsets section.
999  if (C)
1000  Desc = StrOffsetsContributionDescriptor(C->Offset, C->Length, 4,
1001  Header.getFormat());
1002  else if (!IndexEntry && !StringOffsetSection.Data.empty())
1003  Desc = StrOffsetsContributionDescriptor(0, StringOffsetSection.Data.size(),
1004  4, Header.getFormat());
1005  else
1006  return None;
1007  auto DescOrError = Desc.validateContributionSize(DA);
1008  if (!DescOrError)
1009  return DescOrError.takeError();
1010  return *DescOrError;
1011 }
1012 
1014  DataExtractor RangesData(RangeSection->Data, isLittleEndian,
1015  getAddressByteSize());
1016  DWARFDataExtractor RangesDA(Context.getDWARFObj(), *RangeSection,
1017  isLittleEndian, 0);
1019  RangesData, RangeSectionBase, getFormat(), Index))
1020  return *Off + RangeSectionBase;
1021  return None;
1022 }
1023 
1026  LocTable->getData(), LocSectionBase, getFormat(), Index))
1027  return *Off + LocSectionBase;
1028  return None;
1029 }
llvm::Check::Size
@ Size
Definition: FileCheck.h:73
llvm::DWARFLocationExpressionsVector
std::vector< DWARFLocationExpression > DWARFLocationExpressionsVector
Represents a set of absolute location expressions.
Definition: DWARFLocationExpression.h:45
llvm::DWARFDebugRangeList
Definition: DWARFDebugRangeList.h:22
llvm::alignTo
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition: Alignment.h:148
llvm::DWARFSection
Definition: DWARFSection.h:16
DWARFFormValue.h
llvm::DWARFUnit::getAbbreviations
const DWARFAbbreviationDeclarationSet * getAbbreviations() const
Definition: DWARFUnit.cpp:868
llvm::errc::invalid_argument
@ invalid_argument
llvm::DWARFUnit::findRnglistFromIndex
Expected< DWARFAddressRangesVector > findRnglistFromIndex(uint32_t Index)
Return a vector of address ranges retrieved from an encoded range list whose offset is found via a ta...
Definition: DWARFUnit.cpp:645
llvm::DWARFUnit::getFirstChild
DWARFDie getFirstChild(const DWARFDebugInfoEntry *Die)
Definition: DWARFUnit.cpp:824
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
llvm::DWARFUnitHeader::getLength
uint64_t getLength() const
Definition: DWARFUnit.h:90
llvm::DWARFDie::getRangesBaseAttribute
Optional< uint64_t > getRangesBaseAttribute() const
Extract the range base attribute from this DIE as absolute section offset.
Definition: DWARFDie.cpp:909
llvm::upper_bound
auto upper_bound(R &&Range, T &&Value)
Provide wrappers to std::upper_bound which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:1772
DWARFCompileUnit.h
llvm::DWARFUnit::getRnglistOffset
Optional< uint64_t > getRnglistOffset(uint32_t Index)
Return a rangelist's offset based on an index.
Definition: DWARFUnit.cpp:1013
StringRef.h
llvm::toString
std::string toString(Error E)
Write all error messages (if any) in E to a string.
Definition: Error.h:1030
parseDWARF64StringOffsetsTableHeader
static Expected< StrOffsetsContributionDescriptor > parseDWARF64StringOffsetsTableHeader(DWARFDataExtractor &DA, uint64_t Offset)
Definition: DWARFUnit.cpp:901
Path.h
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition: Error.h:331
DWARFContext.h
llvm::dwarf::toSectionedAddress
Optional< object::SectionedAddress > toSectionedAddress(const Optional< DWARFFormValue > &V)
Definition: DWARFFormValue.h:295
llvm::dwarf::DW_LENGTH_DWARF64
@ DW_LENGTH_DWARF64
Indicator of 64-bit DWARF format.
Definition: Dwarf.h:56
Errc.h
llvm::DWARFUnitVector::addUnitsForSection
void addUnitsForSection(DWARFContext &C, const DWARFSection &Section, DWARFSectionKind SectionKind)
Read units from a .debug_info or .debug_types section.
Definition: DWARFUnit.cpp:35
llvm::DWARFUnitVector::addUnitsForDWOSection
void addUnitsForDWOSection(DWARFContext &C, const DWARFSection &DWOSection, DWARFSectionKind SectionKind, bool Lazy=false)
Read units from a .debug_info.dwo or .debug_types.dwo section.
Definition: DWARFUnit.cpp:46
llvm::DWARFContext
DWARFContext This data structure is the top level entity that deals with dwarf debug information pars...
Definition: DWARFContext.h:53
llvm::StrOffsetsContributionDescriptor::validateContributionSize
Expected< StrOffsetsContributionDescriptor > validateContributionSize(DWARFDataExtractor &DA)
Determine whether a contribution to the string offsets table is consistent with the relevant section ...
Definition: DWARFUnit.cpp:885
llvm::StrOffsetsContributionDescriptor::Base
uint64_t Base
Definition: DWARFUnit.h:180
llvm::sys::path::end
const_iterator end(StringRef path)
Get end iterator over path.
Definition: Path.cpp:236
llvm::dwarf::FormParams::AddrSize
uint8_t AddrSize
Definition: Dwarf.h:650
llvm::DWARFUnitIndex::Entry
Definition: DWARFUnitIndex.h:92
llvm::sys::path::begin
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
Definition: Path.cpp:227
llvm::Optional
Definition: APInt.h:33
Offset
uint64_t Offset
Definition: ELFObjHandler.cpp:80
llvm::DIE
A structured debug information entry.
Definition: DIE.h:739
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:42
llvm::DWARFDebugInfoEntry
DWARFDebugInfoEntry - A DIE with only the minimum required data.
Definition: DWARFDebugInfoEntry.h:22
RHS
Value * RHS
Definition: X86PartialReduction.cpp:74
llvm::DataExtractor::getU64
uint64_t getU64(uint64_t *offset_ptr, Error *Err=nullptr) const
Extract a uint64_t value from *offset_ptr.
Definition: DataExtractor.cpp:117
llvm::DWARFDataExtractor
A DataExtractor (typically for an in-memory copy of an object-file section) plus a relocation map for...
Definition: DWARFDataExtractor.h:21
llvm::StrOffsetsContributionDescriptor::Size
uint64_t Size
The contribution size not including the header.
Definition: DWARFUnit.h:182
llvm::dwarf::FormParams::Format
DwarfFormat Format
Definition: Dwarf.h:651
getTag
static Optional< unsigned > getTag(const TargetRegisterInfo *TRI, const MachineInstr &MI, const LoadInfo &LI)
Definition: AArch64FalkorHWPFFix.cpp:659
llvm::consumeError
void consumeError(Error Err)
Consume a Error without doing anything.
Definition: Error.h:1045
llvm::Data
@ Data
Definition: SIMachineScheduler.h:55
llvm::DWARFUnitHeader::getFormat
dwarf::DwarfFormat getFormat() const
Definition: DWARFUnit.h:84
llvm::DWARFUnit::getAddrOffsetSectionItem
Optional< object::SectionedAddress > getAddrOffsetSectionItem(uint32_t Index) const
Definition: DWARFUnit.cpp:194
llvm::DWARFUnit::getLoclistOffset
Optional< uint64_t > getLoclistOffset(uint32_t Index)
Definition: DWARFUnit.cpp:1024
Context
ManagedStatic< detail::RecordContext > Context
Definition: Record.cpp:96
llvm::sys::path::append
void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
Definition: Path.cpp:457
llvm::DWARFUnit::getUnitDIE
DWARFDie getUnitDIE(bool ExtractUnitDIEOnly=true)
Definition: DWARFUnit.h:390
llvm::ARMBuildAttrs::Section
@ Section
Legacy Tags.
Definition: ARMBuildAttributes.h:82
LHS
Value * LHS
Definition: X86PartialReduction.cpp:73
llvm::DWARFUnit::getDWOId
Optional< uint64_t > getDWOId()
Definition: DWARFUnit.h:405
llvm::DWARFDataExtractor::getRelocatedValue
uint64_t getRelocatedValue(uint32_t Size, uint64_t *Off, uint64_t *SectionIndex=nullptr, Error *Err=nullptr) const
Extracts a value and applies a relocation to the result if one exists for the given offset.
Definition: DWARFDataExtractor.cpp:46
SmallString.h
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::DWARFDie::isSubroutineDIE
bool isSubroutineDIE() const
Returns true if DIE represents a subprogram or an inlined subroutine.
Definition: DWARFDie.cpp:816
llvm::DWARFUnit::determineStringOffsetsTableContribution
Expected< Optional< StrOffsetsContributionDescriptor > > determineStringOffsetsTableContribution(DWARFDataExtractor &DA)
Find the unit's contribution to the string offsets table and determine its length and form.
Definition: DWARFUnit.cpp:964
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::DWARFDebugAbbrev
Definition: DWARFDebugAbbrev.h:56
llvm::StrOffsetsContributionDescriptor
Represents base address of the CU.
Definition: DWARFUnit.h:179
llvm::DWARFSectionKind
DWARFSectionKind
The enum of section identifiers to be used in internal interfaces.
Definition: DWARFUnitIndex.h:56
llvm::DWARFUnitIndex
Definition: DWARFUnitIndex.h:80
DWARFDie.h
llvm::dwarf::Index
Index
Definition: Dwarf.h:467
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
llvm::DWARFUnitHeader::setDWOId
void setDWOId(uint64_t Id)
Definition: DWARFUnit.h:93
llvm::DWARFUnitHeader::isTypeUnit
bool isTypeUnit() const
Definition: DWARFUnit.h:101
llvm::dwarf::toSectionOffset
Optional< uint64_t > toSectionOffset(const Optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract an section offset.
Definition: DWARFFormValue.h:316
llvm::dwarf::DW_LENGTH_lo_reserved
@ DW_LENGTH_lo_reserved
Special values for an initial length field.
Definition: Dwarf.h:55
llvm::DWARFContext::checkAddressSizeSupported
static Error checkAddressSizeSupported(unsigned AddressSize, std::error_code EC, char const *Fmt, const Ts &...Vals)
Definition: DWARFContext.h:392
llvm::DW_SECT_EXT_TYPES
@ DW_SECT_EXT_TYPES
Definition: DWARFUnitIndex.h:62
llvm::DWARFObject
Definition: DWARFObject.h:25
llvm::AArch64CC::LE
@ LE
Definition: AArch64BaseInfo.h:268
llvm::dwarf::DwarfFormat
DwarfFormat
Constants that define the DWARF format as 32 or 64 bit.
Definition: Dwarf.h:92
llvm::None
const NoneType None
Definition: None.h:23
llvm::lltok::Kind
Kind
Definition: LLToken.h:18
llvm::DWARFUnit::updateAddressDieMap
void updateAddressDieMap(DWARFDie Die)
Recursively update address to Die map.
Definition: DWARFUnit.cpp:693
llvm::DWARFUnit::getParent
DWARFDie getParent(const DWARFDebugInfoEntry *Die)
Definition: DWARFUnit.cpp:768
llvm::SmallString< 16 >
llvm::DWARFCompileUnit
Definition: DWARFCompileUnit.h:17
llvm::DWARFUnit::getSubroutineForAddress
DWARFDie getSubroutineForAddress(uint64_t Address)
Returns subprogram DIE with address range encompassing the provided address.
Definition: DWARFUnit.cpp:724
llvm::DWARFDebugRangeList::extract
Error extract(const DWARFDataExtractor &data, uint64_t *offset_ptr)
Definition: DWARFDebugRangeList.cpp:31
llvm::DataExtractor::size
size_t size() const
Return the number of bytes in the underlying buffer.
Definition: DataExtractor.h:688
llvm::DWARFAbbreviationDeclarationSet
Definition: DWARFDebugAbbrev.h:22
llvm::DWARFUnit::~DWARFUnit
virtual ~DWARFUnit()
llvm::DWARFUnit::getDebugInfoExtractor
DWARFDataExtractor getDebugInfoExtractor() const
Definition: DWARFUnit.cpp:188
llvm::DWARFUnit::collectAddressRanges
Expected< DWARFAddressRangesVector > collectAddressRanges()
Definition: DWARFUnit.cpp:655
llvm::DWARFUnit::findLoclistFromOffset
Expected< DWARFLocationExpressionsVector > findLoclistFromOffset(uint64_t Offset)
Definition: DWARFUnit.cpp:670
llvm::StringRef::empty
constexpr LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:152
llvm::DWARFListTableHeader::getHeaderSize
static uint8_t getHeaderSize(dwarf::DwarfFormat Format)
Return the size of the table header including the length but not including the offsets.
Definition: DWARFListTable.h:104
llvm::DWARFLocationTable::visitAbsoluteLocationList
Error visitAbsoluteLocationList(uint64_t Offset, Optional< object::SectionedAddress > BaseAddr, std::function< Optional< object::SectionedAddress >(uint32_t)> LookupAddr, function_ref< bool(Expected< DWARFLocationExpression >)> Callback) const
Definition: DWARFDebugLoc.cpp:168
llvm::DWARFDebugRnglistTable
Definition: DWARFDebugRnglists.h:60
uint64_t
D
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
llvm::find
auto find(R &&Range, const T &Val)
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1669
llvm::DWARFUnitHeader
Base class describing the header of any kind of "unit." Some information is specific to certain unit ...
Definition: DWARFUnit.h:47
llvm::DW_SECT_EXT_LOC
@ DW_SECT_EXT_LOC
Definition: DWARFUnitIndex.h:63
llvm::DWARFDie::getAddressRanges
Expected< DWARFAddressRangesVector > getAddressRanges() const
Get the address ranges for this DIE.
Definition: DWARFDie.cpp:949
llvm::DWARFListTableHeader::getOffsetEntry
Optional< uint64_t > getOffsetEntry(DataExtractor Data, uint32_t Index) const
Definition: DWARFListTable.h:116
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::numbers::e
constexpr double e
Definition: MathExtras.h:57
llvm::DWARFUnitIndex::Entry::getContribution
const SectionContribution * getContribution(DWARFSectionKind Sec) const
Definition: DWARFUnitIndex.cpp:247
I
#define I(x, y, z)
Definition: MD5.cpp:58
DWARFUnit.h
llvm::DWARFUnit::getSibling
DWARFDie getSibling(const DWARFDebugInfoEntry *Die)
Definition: DWARFUnit.cpp:781
llvm::DWARFDie::find
Optional< DWARFFormValue > find(dwarf::Attribute Attr) const
Extract the specified attribute from this DIE.
Definition: DWARFDie.cpp:821
llvm::DWARFUnit::getDwarfStringOffsetsByteSize
uint8_t getDwarfStringOffsetsByteSize() const
Definition: DWARFUnit.h:357
llvm::joinErrors
Error joinErrors(Error E1, Error E2)
Concatenate errors.
Definition: Error.h:428
DWARFDebugRnglists.h
llvm::dwarf::FormParams
A helper struct providing information about the byte size of DW_FORM values that vary in size dependi...
Definition: Dwarf.h:648
llvm::HighlightColor::Address
@ Address
llvm::DWARFUnit::DWARFUnit
DWARFUnit(DWARFContext &Context, const DWARFSection &Section, const DWARFUnitHeader &Header, const DWARFDebugAbbrev *DA, const DWARFSection *RS, const DWARFSection *LocSection, StringRef SS, const DWARFSection &SOS, const DWARFSection *AOS, const DWARFSection &LS, bool LE, bool IsDWO, const DWARFUnitVector &UnitVector)
Definition: DWARFUnit.cpp:173
llvm::dwarf::UnitType
UnitType
Constants for unit types in DWARF v5.
Definition: Dwarf.h:460
llvm::DataExtractor::getUnsigned
uint64_t getUnsigned(uint64_t *offset_ptr, uint32_t byte_size, Error *Err=nullptr) const
Extract an unsigned integer of size byte_size from *offset_ptr.
Definition: DataExtractor.cpp:126
llvm::DataExtractor::isValidOffset
bool isValidOffset(uint64_t offset) const
Test the validity of offset.
Definition: DataExtractor.h:665
DWARFAbbreviationDeclaration.h
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::DWARFDataExtractor::getInitialLength
std::pair< uint64_t, dwarf::DwarfFormat > getInitialLength(uint64_t *Off, Error *Err=nullptr) const
Extracts the DWARF "initial length" field, which can either be a 32-bit value smaller than 0xfffffff0...
Definition: DWARFDataExtractor.cpp:15
llvm::DWARFUnit::getFormat
dwarf::DwarfFormat getFormat() const
Definition: DWARFUnit.h:294
llvm::dwarf::FormParams::getDwarfOffsetByteSize
uint8_t getDwarfOffsetByteSize() const
The size of a reference is determined by the DWARF 32/64-bit format.
Definition: Dwarf.h:666
llvm::DWARFUnitHeader::getIndexEntry
const DWARFUnitIndex::Entry * getIndexEntry() const
Definition: DWARFUnit.h:97
llvm::DWARFUnit::getNextUnitOffset
uint64_t getNextUnitOffset() const
Definition: DWARFUnit.h:298
llvm::DWARFUnit::clear
void clear()
Definition: DWARFUnit.cpp:361
llvm::DWARFDebugAbbrev::getAbbreviationDeclarationSet
const DWARFAbbreviationDeclarationSet * getAbbreviationDeclarationSet(uint64_t CUAbbrOffset) const
Definition: DWARFDebugAbbrev.cpp:143
llvm::dwarf::toString
Optional< const char * > toString(const Optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract a string value from it.
Definition: DWARFFormValue.h:175
llvm::DWARFUnitVector::getUnitForIndexEntry
DWARFUnit * getUnitForIndexEntry(const DWARFUnitIndex::Entry &E)
Definition: DWARFUnit.cpp:144
llvm::DWARFDebugInfoEntry::getParentIdx
Optional< uint32_t > getParentIdx() const
Returns index of the parent die.
Definition: DWARFDebugInfoEntry.h:48
llvm::hasSingleElement
bool hasSingleElement(ContainerTy &&C)
Returns true if the given container only contains a single element.
Definition: STLExtras.h:314
llvm::DWARFUnit::getCompilationDir
const char * getCompilationDir()
Definition: DWARFUnit.cpp:372
llvm::DWARFUnitVector::addUnit
DWARFUnit * addUnit(std::unique_ptr< DWARFUnit > Unit)
Add an existing DWARFUnit to this UnitVector.
Definition: DWARFUnit.cpp:122
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
llvm::DWARFDebugRangeList::getAbsoluteRanges
DWARFAddressRangesVector getAbsoluteRanges(llvm::Optional< object::SectionedAddress > BaseAddr) const
getAbsoluteRanges - Returns absolute address ranges defined by this range list.
Definition: DWARFDebugRangeList.cpp:87
llvm::DWARFUnitHeader::getAddressByteSize
uint8_t getAddressByteSize() const
Definition: DWARFUnit.h:85
llvm::DWARFUnitVector::getUnitForOffset
DWARFUnit * getUnitForOffset(uint64_t Offset) const
Definition: DWARFUnit.cpp:131
uint32_t
DWARFDebugInfoEntry.h
DC
static ManagedStatic< DebugCounter > DC
Definition: DebugCounter.cpp:70
llvm::DWARFUnitHeader::extract
bool extract(DWARFContext &Context, const DWARFDataExtractor &debug_info, uint64_t *offset_ptr, DWARFSectionKind SectionKind)
Parse a unit header from debug_info starting at offset_ptr.
Definition: DWARFUnit.cpp:233
llvm::DWARFDie::getSibling
DWARFDie getSibling() const
Get the sibling of this DIE object.
Definition: DWARFDie.cpp:1142
llvm::DWARFUnitHeader::getNextUnitOffset
uint64_t getNextUnitOffset() const
Definition: DWARFUnit.h:108
llvm::DWARFDebugInfoEntry::getSiblingIdx
Optional< uint32_t > getSiblingIdx() const
Returns index of the sibling die.
Definition: DWARFDebugInfoEntry.h:56
llvm::DataExtractor::getU8
uint8_t getU8(uint64_t *offset_ptr, Error *Err=nullptr) const
Extract a uint8_t value from *offset_ptr.
Definition: DataExtractor.cpp:80
llvm::DWARFUnit::getStringOffsetSectionItem
Expected< uint64_t > getStringOffsetSectionItem(uint32_t Index) const
Definition: DWARFUnit.cpp:217
llvm::DWARFUnit::findRnglistFromOffset
Expected< DWARFAddressRangesVector > findRnglistFromOffset(uint64_t Offset)
Return a vector of address ranges resulting from a (possibly encoded) range list starting at a given ...
Definition: DWARFUnit.cpp:628
llvm::DWARFUnitHeader::getVersion
uint16_t getVersion() const
Definition: DWARFUnit.h:83
llvm::DWARFUnit::extractRangeList
Error extractRangeList(uint64_t RangeListOffset, DWARFDebugRangeList &RangeList) const
Extract the range list referenced by this compile unit from the .debug_ranges section.
Definition: DWARFUnit.cpp:351
llvm::StringRef::size
constexpr LLVM_NODISCARD size_t size() const
size - Get the string size.
Definition: StringRef.h:156
parseDWARFStringOffsetsTableHeader
static Expected< StrOffsetsContributionDescriptor > parseDWARFStringOffsetsTableHeader(DWARFDataExtractor &DA, llvm::dwarf::DwarfFormat Format, uint64_t Offset)
Definition: DWARFUnit.cpp:936
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:83
llvm::DWARFDie::getParent
DWARFDie getParent() const
Get the parent of this DIE object.
Definition: DWARFDie.cpp:1136
llvm::DWARFUnit::getAddressByteSize
uint8_t getAddressByteSize() const
Definition: DWARFUnit.h:286
llvm::DWARFUnit::getLastChild
DWARFDie getLastChild(const DWARFDebugInfoEntry *Die)
Definition: DWARFUnit.cpp:837
llvm::createStringError
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition: Error.h:1241
llvm::SectionKind
SectionKind - This is a simple POD value that classifies the properties of a section.
Definition: SectionKind.h:22
llvm::inconvertibleErrorCode
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Definition: Error.cpp:77
DWARFDebugAbbrev.h
llvm::DWARFAbbreviationDeclaration
Definition: DWARFAbbreviationDeclaration.h:27
llvm::DWARFUnit
Definition: DWARFUnit.h:203
llvm::DWARFUnit::setRangesSection
void setRangesSection(const DWARFSection *RS, uint64_t Base)
Definition: DWARFUnit.h:323
llvm::DWARFUnit::getHeaderSize
uint32_t getHeaderSize() const
Size in bytes of the parsed unit header.
Definition: DWARFUnit.h:292
llvm::DWARFUnit::getPreviousSibling
DWARFDie getPreviousSibling(const DWARFDebugInfoEntry *Die)
Definition: DWARFUnit.cpp:794
llvm::DWARFUnit::tryExtractDIEsIfNeeded
Error tryExtractDIEsIfNeeded(bool CUDieOnly)
Definition: DWARFUnit.cpp:469
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
llvm::DWARFUnitHeader::getOffset
uint64_t getOffset() const
Definition: DWARFUnit.h:81
llvm::AArch64CC::LS
@ LS
Definition: AArch64BaseInfo.h:264
DataExtractor.h
llvm::DWARFListTableBase::findList
Expected< DWARFListType > findList(DWARFDataExtractor Data, uint64_t Offset) const
Look up a list based on a given offset.
Definition: DWARFListTable.h:280
llvm::DWARFUnit::getOffset
uint64_t getOffset() const
Definition: DWARFUnit.h:281
DWARFTypeUnit.h
llvm::StrOffsetsContributionDescriptor::getDwarfOffsetByteSize
uint8_t getDwarfOffsetByteSize() const
Definition: DWARFUnit.h:193
llvm::DWARFUnit::getInlinedChainForAddress
void getInlinedChainForAddress(uint64_t Address, SmallVectorImpl< DWARFDie > &InlinedChain)
getInlinedChainForAddress - fetches inlined chain for a given address.
Definition: DWARFUnit.cpp:739
llvm::dwarf::toUnsigned
Optional< uint64_t > toUnsigned(const Optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract an unsigned constant.
Definition: DWARFFormValue.h:223
parseDWARF32StringOffsetsTableHeader
static Expected< StrOffsetsContributionDescriptor > parseDWARF32StringOffsetsTableHeader(DWARFDataExtractor &DA, uint64_t Offset)
Definition: DWARFUnit.cpp:919
llvm::dwarf::FormParams::Version
uint16_t Version
Definition: Dwarf.h:649
llvm::DWARFUnit::getAbbreviationsOffset
uint64_t getAbbreviationsOffset() const
Definition: DWARFUnit.h:367
llvm::DataExtractor
Definition: DataExtractor.h:41
llvm::DWARFDie::getTag
dwarf::Tag getTag() const
Definition: DWARFDie.h:72
Version
uint64_t Version
Definition: RawMemProfReader.cpp:25
llvm::DWARFUnitHeader::getUnitLengthFieldByteSize
uint8_t getUnitLengthFieldByteSize() const
Definition: DWARFUnit.h:105
llvm::DWARFUnitHeader::applyIndexEntry
bool applyIndexEntry(const DWARFUnitIndex::Entry *Entry)
Definition: DWARFUnit.cpp:334
llvm::DWARFUnit::getBaseAddress
llvm::Optional< object::SectionedAddress > getBaseAddress()
Definition: DWARFUnit.cpp:874
llvm::SmallVectorImpl
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:43
llvm::X86AS::SS
@ SS
Definition: X86.h:189
llvm::getDWARFUnitIndex
const DWARFUnitIndex & getDWARFUnitIndex(DWARFContext &Context, DWARFSectionKind Kind)
Definition: DWARFUnit.cpp:760
llvm::dwarf::DWARF64
@ DWARF64
Definition: Dwarf.h:92
llvm::DWARFDie
Utility class that carries the DWARF compile/type unit and the debug info entry in an object.
Definition: DWARFDie.h:43
llvm::DWARFDie::isSubprogramDIE
bool isSubprogramDIE() const
Returns true if DIE represents a subprogram (not inlined).
Definition: DWARFDie.cpp:814
llvm::M68kBeads::DA
@ DA
Definition: M68kBaseInfo.h:59
llvm::DWARFDebugInfoEntry::hasChildren
bool hasChildren() const
Definition: DWARFDebugInfoEntry.h:70
llvm::DWARFUnit::getLocationTable
const DWARFLocationTable & getLocationTable()
Definition: DWARFUnit.h:342
llvm::DWARFUnit::determineStringOffsetsTableContributionDWO
Expected< Optional< StrOffsetsContributionDescriptor > > determineStringOffsetsTableContributionDWO(DWARFDataExtractor &DA)
Find the unit's contribution to the string offsets table and determine its length and form.
Definition: DWARFUnit.cpp:977
llvm::DWARFContext::isSupportedVersion
static bool isSupportedVersion(unsigned version)
Definition: DWARFContext.h:381
llvm::DWARFSection::Data
StringRef Data
Definition: DWARFSection.h:17
llvm::sys::path::is_relative
bool is_relative(const Twine &path, Style style=Style::native)
Is path relative?
Definition: Path.cpp:700
CU
Definition: AArch64AsmBackend.cpp:504
llvm::DWARFUnit::getStringOffsetsBase
uint64_t getStringOffsetsBase() const
Definition: DWARFUnit.h:362
llvm::DWARFUnit::getVersion
uint16_t getVersion() const
Definition: DWARFUnit.h:285
llvm::DWARFDie::getFirstChild
DWARFDie getFirstChild() const
Get the first child of this DIE object.
Definition: DWARFDie.cpp:1154
llvm::DWARFContext::getMaxSupportedVersion
static unsigned getMaxSupportedVersion()
Definition: DWARFContext.h:380
llvm::dwarf::DWARF32
@ DWARF32
Definition: Dwarf.h:92
llvm::DataExtractor::getU16
uint16_t getU16(uint64_t *offset_ptr, Error *Err=nullptr) const
Extract a uint16_t value from *offset_ptr.
Definition: DataExtractor.cpp:93
llvm::DWARFUnitVector
Describe a collection of units.
Definition: DWARFUnit.h:120