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 None;
220  unsigned ItemSize = getDwarfStringOffsetsByteSize();
221  uint64_t Offset = getStringOffsetsBase() + Index * ItemSize;
222  if (StringOffsetSection.Data.size() < Offset + ItemSize)
223  return None;
224  DWARFDataExtractor DA(Context.getDWARFObj(), StringOffsetSection,
225  isLittleEndian, 0);
226  return DA.getRelocatedValue(ItemSize, &Offset);
227 }
228 
230  const DWARFDataExtractor &debug_info,
231  uint64_t *offset_ptr,
233  Offset = *offset_ptr;
234  Error Err = Error::success();
235  IndexEntry = nullptr;
236  std::tie(Length, FormParams.Format) =
237  debug_info.getInitialLength(offset_ptr, &Err);
238  FormParams.Version = debug_info.getU16(offset_ptr, &Err);
239  if (FormParams.Version >= 5) {
240  UnitType = debug_info.getU8(offset_ptr, &Err);
241  FormParams.AddrSize = debug_info.getU8(offset_ptr, &Err);
242  AbbrOffset = debug_info.getRelocatedValue(
243  FormParams.getDwarfOffsetByteSize(), offset_ptr, nullptr, &Err);
244  } else {
245  AbbrOffset = debug_info.getRelocatedValue(
246  FormParams.getDwarfOffsetByteSize(), offset_ptr, nullptr, &Err);
247  FormParams.AddrSize = debug_info.getU8(offset_ptr, &Err);
248  // Fake a unit type based on the section type. This isn't perfect,
249  // but distinguishing compile and type units is generally enough.
251  UnitType = DW_UT_type;
252  else
253  UnitType = DW_UT_compile;
254  }
255  if (isTypeUnit()) {
256  TypeHash = debug_info.getU64(offset_ptr, &Err);
257  TypeOffset = debug_info.getUnsigned(
258  offset_ptr, FormParams.getDwarfOffsetByteSize(), &Err);
259  } else if (UnitType == DW_UT_split_compile || UnitType == DW_UT_skeleton)
260  DWOId = debug_info.getU64(offset_ptr, &Err);
261 
262  if (Err) {
263  Context.getWarningHandler()(joinErrors(
266  "DWARF unit at 0x%8.8" PRIx64 " cannot be parsed:", Offset),
267  std::move(Err)));
268  return false;
269  }
270 
271  // Header fields all parsed, capture the size of this unit header.
272  assert(*offset_ptr - Offset <= 255 && "unexpected header size");
273  Size = uint8_t(*offset_ptr - Offset);
274  uint64_t NextCUOffset = Offset + getUnitLengthFieldByteSize() + getLength();
275 
276  if (!debug_info.isValidOffset(getNextUnitOffset() - 1)) {
277  Context.getWarningHandler()(
279  "DWARF unit from offset 0x%8.8" PRIx64 " incl. "
280  "to offset 0x%8.8" PRIx64 " excl. "
281  "extends past section size 0x%8.8zx",
282  Offset, NextCUOffset, debug_info.size()));
283  return false;
284  }
285 
287  Context.getWarningHandler()(createStringError(
289  "DWARF unit at offset 0x%8.8" PRIx64 " "
290  "has unsupported version %" PRIu16 ", supported are 2-%u",
292  return false;
293  }
294 
295  // Type offset is unit-relative; should be after the header and before
296  // the end of the current unit.
297  if (isTypeUnit() && TypeOffset < Size) {
298  Context.getWarningHandler()(
300  "DWARF type unit at offset "
301  "0x%8.8" PRIx64 " "
302  "has its relocated type_offset 0x%8.8" PRIx64 " "
303  "pointing inside the header",
304  Offset, Offset + TypeOffset));
305  return false;
306  }
307  if (isTypeUnit() &&
308  TypeOffset >= getUnitLengthFieldByteSize() + getLength()) {
309  Context.getWarningHandler()(createStringError(
311  "DWARF type unit from offset 0x%8.8" PRIx64 " incl. "
312  "to offset 0x%8.8" PRIx64 " excl. has its "
313  "relocated type_offset 0x%8.8" PRIx64 " pointing past the unit end",
314  Offset, NextCUOffset, Offset + TypeOffset));
315  return false;
316  }
317 
320  for (auto Size : DWARFContext::getSupportedAddressSizes())
321  Sizes.push_back(std::to_string(Size));
322  Context.getWarningHandler()(createStringError(
324  "DWARF unit at offset 0x%8.8" PRIx64 " "
325  "has unsupported address size %" PRIu8 ", supported are %s",
326  Offset, getAddressByteSize(), llvm::join(Sizes, ", ").c_str()));
327  return false;
328  }
329 
330  // Keep track of the highest DWARF version we encounter across all units.
331  Context.setMaxVersionIfGreater(getVersion());
332  return true;
333 }
334 
336  assert(Entry);
337  assert(!IndexEntry);
338  IndexEntry = Entry;
339  if (AbbrOffset)
340  return false;
341  auto *UnitContrib = IndexEntry->getContribution();
342  if (!UnitContrib ||
343  UnitContrib->Length != (getLength() + getUnitLengthFieldByteSize()))
344  return false;
345  auto *AbbrEntry = IndexEntry->getContribution(DW_SECT_ABBREV);
346  if (!AbbrEntry)
347  return false;
348  AbbrOffset = AbbrEntry->Offset;
349  return true;
350 }
351 
353  DWARFDebugRangeList &RangeList) const {
354  // Require that compile unit is extracted.
355  assert(!DieArray.empty());
356  DWARFDataExtractor RangesData(Context.getDWARFObj(), *RangeSection,
357  isLittleEndian, getAddressByteSize());
358  uint64_t ActualRangeListOffset = RangeSectionBase + RangeListOffset;
359  return RangeList.extract(RangesData, &ActualRangeListOffset);
360 }
361 
363  Abbrevs = nullptr;
364  BaseAddr.reset();
365  RangeSectionBase = 0;
366  LocSectionBase = 0;
367  AddrOffsetSectionBase = None;
368  SU = nullptr;
369  clearDIEs(false);
370  DWO.reset();
371 }
372 
374  return dwarf::toString(getUnitDIE().find(DW_AT_comp_dir), nullptr);
375 }
376 
377 void DWARFUnit::extractDIEsToVector(
378  bool AppendCUDie, bool AppendNonCUDies,
379  std::vector<DWARFDebugInfoEntry> &Dies) const {
380  if (!AppendCUDie && !AppendNonCUDies)
381  return;
382 
383  // Set the offset to that of the first DIE and calculate the start of the
384  // next compilation unit header.
385  uint64_t DIEOffset = getOffset() + getHeaderSize();
386  uint64_t NextCUOffset = getNextUnitOffset();
388  DWARFDataExtractor DebugInfoData = getDebugInfoExtractor();
389  // The end offset has been already checked by DWARFUnitHeader::extract.
390  assert(DebugInfoData.isValidOffset(NextCUOffset - 1));
391  uint32_t Depth = 0;
392  bool IsCUDie = true;
393 
394  while (DIE.extractFast(*this, &DIEOffset, DebugInfoData, NextCUOffset,
395  Depth)) {
396  if (IsCUDie) {
397  if (AppendCUDie)
398  Dies.push_back(DIE);
399  if (!AppendNonCUDies)
400  break;
401  // The average bytes per DIE entry has been seen to be
402  // around 14-20 so let's pre-reserve the needed memory for
403  // our DIE entries accordingly.
404  Dies.reserve(Dies.size() + getDebugInfoSize() / 14);
405  IsCUDie = false;
406  } else {
407  Dies.push_back(DIE);
408  }
409 
410  if (const DWARFAbbreviationDeclaration *AbbrDecl =
411  DIE.getAbbreviationDeclarationPtr()) {
412  // Normal DIE
413  if (AbbrDecl->hasChildren())
414  ++Depth;
415  else if (Depth == 0)
416  break; // This unit has a single DIE with no children.
417  } else {
418  // NULL DIE.
419  if (Depth > 0)
420  --Depth;
421  if (Depth == 0)
422  break; // We are done with this compile unit!
423  }
424  }
425 }
426 
427 void DWARFUnit::extractDIEsIfNeeded(bool CUDieOnly) {
428  if (Error e = tryExtractDIEsIfNeeded(CUDieOnly))
429  Context.getRecoverableErrorHandler()(std::move(e));
430 }
431 
433  if ((CUDieOnly && !DieArray.empty()) ||
434  DieArray.size() > 1)
435  return Error::success(); // Already parsed.
436 
437  bool HasCUDie = !DieArray.empty();
438  extractDIEsToVector(!HasCUDie, !CUDieOnly, DieArray);
439 
440  if (DieArray.empty())
441  return Error::success();
442 
443  // If CU DIE was just parsed, copy several attribute values from it.
444  if (HasCUDie)
445  return Error::success();
446 
447  DWARFDie UnitDie(this, &DieArray[0]);
448  if (Optional<uint64_t> DWOId = toUnsigned(UnitDie.find(DW_AT_GNU_dwo_id)))
449  Header.setDWOId(*DWOId);
450  if (!IsDWO) {
451  assert(AddrOffsetSectionBase == None);
452  assert(RangeSectionBase == 0);
453  assert(LocSectionBase == 0);
454  AddrOffsetSectionBase = toSectionOffset(UnitDie.find(DW_AT_addr_base));
455  if (!AddrOffsetSectionBase)
456  AddrOffsetSectionBase =
457  toSectionOffset(UnitDie.find(DW_AT_GNU_addr_base));
458  RangeSectionBase = toSectionOffset(UnitDie.find(DW_AT_rnglists_base), 0);
459  LocSectionBase = toSectionOffset(UnitDie.find(DW_AT_loclists_base), 0);
460  }
461 
462  // In general, in DWARF v5 and beyond we derive the start of the unit's
463  // contribution to the string offsets table from the unit DIE's
464  // DW_AT_str_offsets_base attribute. Split DWARF units do not use this
465  // attribute, so we assume that there is a contribution to the string
466  // offsets table starting at offset 0 of the debug_str_offsets.dwo section.
467  // In both cases we need to determine the format of the contribution,
468  // which may differ from the unit's format.
469  DWARFDataExtractor DA(Context.getDWARFObj(), StringOffsetSection,
470  isLittleEndian, 0);
471  if (IsDWO || getVersion() >= 5) {
472  auto StringOffsetOrError =
475  if (!StringOffsetOrError)
477  "invalid reference to or invalid content in "
478  ".debug_str_offsets[.dwo]: " +
479  toString(StringOffsetOrError.takeError()));
480 
481  StringOffsetsTableContribution = *StringOffsetOrError;
482  }
483 
484  // DWARF v5 uses the .debug_rnglists and .debug_rnglists.dwo sections to
485  // describe address ranges.
486  if (getVersion() >= 5) {
487  // In case of DWP, the base offset from the index has to be added.
488  if (IsDWO) {
489  uint64_t ContributionBaseOffset = 0;
490  if (auto *IndexEntry = Header.getIndexEntry())
491  if (auto *Contrib = IndexEntry->getContribution(DW_SECT_RNGLISTS))
492  ContributionBaseOffset = Contrib->Offset;
494  &Context.getDWARFObj().getRnglistsDWOSection(),
495  ContributionBaseOffset +
497  } else
498  setRangesSection(&Context.getDWARFObj().getRnglistsSection(),
499  toSectionOffset(UnitDie.find(DW_AT_rnglists_base),
501  Header.getFormat())));
502  }
503 
504  if (IsDWO) {
505  // If we are reading a package file, we need to adjust the location list
506  // data based on the index entries.
507  StringRef Data = Header.getVersion() >= 5
508  ? Context.getDWARFObj().getLoclistsDWOSection().Data
509  : Context.getDWARFObj().getLocDWOSection().Data;
510  if (auto *IndexEntry = Header.getIndexEntry())
511  if (const auto *C = IndexEntry->getContribution(
512  Header.getVersion() >= 5 ? DW_SECT_LOCLISTS : DW_SECT_EXT_LOC))
513  Data = Data.substr(C->Offset, C->Length);
514 
515  DWARFDataExtractor DWARFData(Data, isLittleEndian, getAddressByteSize());
516  LocTable =
517  std::make_unique<DWARFDebugLoclists>(DWARFData, Header.getVersion());
518  LocSectionBase = DWARFListTableHeader::getHeaderSize(Header.getFormat());
519  } else if (getVersion() >= 5) {
520  LocTable = std::make_unique<DWARFDebugLoclists>(
521  DWARFDataExtractor(Context.getDWARFObj(),
522  Context.getDWARFObj().getLoclistsSection(),
523  isLittleEndian, getAddressByteSize()),
524  getVersion());
525  } else {
526  LocTable = std::make_unique<DWARFDebugLoc>(DWARFDataExtractor(
527  Context.getDWARFObj(), Context.getDWARFObj().getLocSection(),
528  isLittleEndian, getAddressByteSize()));
529  }
530 
531  // Don't fall back to DW_AT_GNU_ranges_base: it should be ignored for
532  // skeleton CU DIE, so that DWARF users not aware of it are not broken.
533  return Error::success();
534 }
535 
536 bool DWARFUnit::parseDWO() {
537  if (IsDWO)
538  return false;
539  if (DWO.get())
540  return false;
541  DWARFDie UnitDie = getUnitDIE();
542  if (!UnitDie)
543  return false;
544  auto DWOFileName = getVersion() >= 5
545  ? dwarf::toString(UnitDie.find(DW_AT_dwo_name))
546  : dwarf::toString(UnitDie.find(DW_AT_GNU_dwo_name));
547  if (!DWOFileName)
548  return false;
549  auto CompilationDir = dwarf::toString(UnitDie.find(DW_AT_comp_dir));
550  SmallString<16> AbsolutePath;
551  if (sys::path::is_relative(*DWOFileName) && CompilationDir &&
552  *CompilationDir) {
553  sys::path::append(AbsolutePath, *CompilationDir);
554  }
555  sys::path::append(AbsolutePath, *DWOFileName);
556  auto DWOId = getDWOId();
557  if (!DWOId)
558  return false;
559  auto DWOContext = Context.getDWOContext(AbsolutePath);
560  if (!DWOContext)
561  return false;
562 
563  DWARFCompileUnit *DWOCU = DWOContext->getDWOCompileUnitForHash(*DWOId);
564  if (!DWOCU)
565  return false;
566  DWO = std::shared_ptr<DWARFCompileUnit>(std::move(DWOContext), DWOCU);
567  DWO->setSkeletonUnit(this);
568  // Share .debug_addr and .debug_ranges section with compile unit in .dwo
569  if (AddrOffsetSectionBase)
570  DWO->setAddrOffsetSection(AddrOffsetSection, *AddrOffsetSectionBase);
571  if (getVersion() == 4) {
572  auto DWORangesBase = UnitDie.getRangesBaseAttribute();
573  DWO->setRangesSection(RangeSection, DWORangesBase ? *DWORangesBase : 0);
574  }
575 
576  return true;
577 }
578 
579 void DWARFUnit::clearDIEs(bool KeepCUDie) {
580  // Do not use resize() + shrink_to_fit() to free memory occupied by dies.
581  // shrink_to_fit() is a *non-binding* request to reduce capacity() to size().
582  // It depends on the implementation whether the request is fulfilled.
583  // Create a new vector with a small capacity and assign it to the DieArray to
584  // have previous contents freed.
585  DieArray = (KeepCUDie && !DieArray.empty())
586  ? std::vector<DWARFDebugInfoEntry>({DieArray[0]})
587  : std::vector<DWARFDebugInfoEntry>();
588 }
589 
592  if (getVersion() <= 4) {
593  DWARFDebugRangeList RangeList;
594  if (Error E = extractRangeList(Offset, RangeList))
595  return std::move(E);
596  return RangeList.getAbsoluteRanges(getBaseAddress());
597  }
598  DWARFDataExtractor RangesData(Context.getDWARFObj(), *RangeSection,
599  isLittleEndian, Header.getAddressByteSize());
600  DWARFDebugRnglistTable RnglistTable;
601  auto RangeListOrError = RnglistTable.findList(RangesData, Offset);
602  if (RangeListOrError)
603  return RangeListOrError.get().getAbsoluteRanges(getBaseAddress(), *this);
604  return RangeListOrError.takeError();
605 }
606 
609  if (auto Offset = getRnglistOffset(Index))
610  return findRnglistFromOffset(*Offset);
611 
613  "invalid range list table index %d (possibly "
614  "missing the entire range list table)",
615  Index);
616 }
617 
619  DWARFDie UnitDie = getUnitDIE();
620  if (!UnitDie)
621  return createStringError(errc::invalid_argument, "No unit DIE");
622 
623  // First, check if unit DIE describes address ranges for the whole unit.
624  auto CUDIERangesOrError = UnitDie.getAddressRanges();
625  if (!CUDIERangesOrError)
627  "decoding address ranges: %s",
628  toString(CUDIERangesOrError.takeError()).c_str());
629  return *CUDIERangesOrError;
630 }
631 
635 
636  Error InterpretationError = Error::success();
637 
640  [this](uint32_t Index) { return getAddrOffsetSectionItem(Index); },
642  if (L)
643  Result.push_back(std::move(*L));
644  else
645  InterpretationError =
646  joinErrors(L.takeError(), std::move(InterpretationError));
647  return !InterpretationError;
648  });
649 
650  if (ParseError || InterpretationError)
651  return joinErrors(std::move(ParseError), std::move(InterpretationError));
652 
653  return Result;
654 }
655 
657  if (Die.isSubroutineDIE()) {
658  auto DIERangesOrError = Die.getAddressRanges();
659  if (DIERangesOrError) {
660  for (const auto &R : DIERangesOrError.get()) {
661  // Ignore 0-sized ranges.
662  if (R.LowPC == R.HighPC)
663  continue;
664  auto B = AddrDieMap.upper_bound(R.LowPC);
665  if (B != AddrDieMap.begin() && R.LowPC < (--B)->second.first) {
666  // The range is a sub-range of existing ranges, we need to split the
667  // existing range.
668  if (R.HighPC < B->second.first)
669  AddrDieMap[R.HighPC] = B->second;
670  if (R.LowPC > B->first)
671  AddrDieMap[B->first].first = R.LowPC;
672  }
673  AddrDieMap[R.LowPC] = std::make_pair(R.HighPC, Die);
674  }
675  } else
676  llvm::consumeError(DIERangesOrError.takeError());
677  }
678  // Parent DIEs are added to the AddrDieMap prior to the Children DIEs to
679  // simplify the logic to update AddrDieMap. The child's range will always
680  // be equal or smaller than the parent's range. With this assumption, when
681  // adding one range into the map, it will at most split a range into 3
682  // sub-ranges.
683  for (DWARFDie Child = Die.getFirstChild(); Child; Child = Child.getSibling())
684  updateAddressDieMap(Child);
685 }
686 
688  extractDIEsIfNeeded(false);
689  if (AddrDieMap.empty())
691  auto R = AddrDieMap.upper_bound(Address);
692  if (R == AddrDieMap.begin())
693  return DWARFDie();
694  // upper_bound's previous item contains Address.
695  --R;
696  if (Address >= R->second.first)
697  return DWARFDie();
698  return R->second.second;
699 }
700 
701 void
703  SmallVectorImpl<DWARFDie> &InlinedChain) {
704  assert(InlinedChain.empty());
705  // Try to look for subprogram DIEs in the DWO file.
706  parseDWO();
707  // First, find the subroutine that contains the given address (the leaf
708  // of inlined chain).
709  DWARFDie SubroutineDIE =
710  (DWO ? *DWO : *this).getSubroutineForAddress(Address);
711 
712  while (SubroutineDIE) {
713  if (SubroutineDIE.isSubprogramDIE()) {
714  InlinedChain.push_back(SubroutineDIE);
715  return;
716  }
717  if (SubroutineDIE.getTag() == DW_TAG_inlined_subroutine)
718  InlinedChain.push_back(SubroutineDIE);
719  SubroutineDIE = SubroutineDIE.getParent();
720  }
721 }
722 
725  if (Kind == DW_SECT_INFO)
726  return Context.getCUIndex();
728  return Context.getTUIndex();
729 }
730 
732  if (!Die)
733  return DWARFDie();
734  const uint32_t Depth = Die->getDepth();
735  // Unit DIEs always have a depth of zero and never have parents.
736  if (Depth == 0)
737  return DWARFDie();
738  // Depth of 1 always means parent is the compile/type unit.
739  if (Depth == 1)
740  return getUnitDIE();
741  // Look for previous DIE with a depth that is one less than the Die's depth.
742  const uint32_t ParentDepth = Depth - 1;
743  for (uint32_t I = getDIEIndex(Die) - 1; I > 0; --I) {
744  if (DieArray[I].getDepth() == ParentDepth)
745  return DWARFDie(this, &DieArray[I]);
746  }
747  return DWARFDie();
748 }
749 
751  if (!Die)
752  return DWARFDie();
753  uint32_t Depth = Die->getDepth();
754  // Unit DIEs always have a depth of zero and never have siblings.
755  if (Depth == 0)
756  return DWARFDie();
757  // NULL DIEs don't have siblings.
758  if (Die->getAbbreviationDeclarationPtr() == nullptr)
759  return DWARFDie();
760 
761  // Find the next DIE whose depth is the same as the Die's depth.
762  for (size_t I = getDIEIndex(Die) + 1, EndIdx = DieArray.size(); I < EndIdx;
763  ++I) {
764  if (DieArray[I].getDepth() == Depth)
765  return DWARFDie(this, &DieArray[I]);
766  }
767  return DWARFDie();
768 }
769 
771  if (!Die)
772  return DWARFDie();
773  uint32_t Depth = Die->getDepth();
774  // Unit DIEs always have a depth of zero and never have siblings.
775  if (Depth == 0)
776  return DWARFDie();
777 
778  // Find the previous DIE whose depth is the same as the Die's depth.
779  for (size_t I = getDIEIndex(Die); I > 0;) {
780  --I;
781  if (DieArray[I].getDepth() == Depth - 1)
782  return DWARFDie();
783  if (DieArray[I].getDepth() == Depth)
784  return DWARFDie(this, &DieArray[I]);
785  }
786  return DWARFDie();
787 }
788 
790  if (!Die->hasChildren())
791  return DWARFDie();
792 
793  // We do not want access out of bounds when parsing corrupted debug data.
794  size_t I = getDIEIndex(Die) + 1;
795  if (I >= DieArray.size())
796  return DWARFDie();
797  return DWARFDie(this, &DieArray[I]);
798 }
799 
801  if (!Die->hasChildren())
802  return DWARFDie();
803 
804  uint32_t Depth = Die->getDepth();
805  for (size_t I = getDIEIndex(Die) + 1, EndIdx = DieArray.size(); I < EndIdx;
806  ++I) {
807  if (DieArray[I].getDepth() == Depth + 1 &&
808  DieArray[I].getTag() == dwarf::DW_TAG_null)
809  return DWARFDie(this, &DieArray[I]);
810  assert(DieArray[I].getDepth() > Depth && "Not processing children?");
811  }
812  return DWARFDie();
813 }
814 
816  if (!Abbrevs)
818  return Abbrevs;
819 }
820 
822  if (BaseAddr)
823  return BaseAddr;
824 
825  DWARFDie UnitDie = getUnitDIE();
826  Optional<DWARFFormValue> PC = UnitDie.find({DW_AT_low_pc, DW_AT_entry_pc});
827  BaseAddr = toSectionedAddress(PC);
828  return BaseAddr;
829 }
830 
834  uint8_t EntrySize = getDwarfOffsetByteSize();
835  // In order to ensure that we don't read a partial record at the end of
836  // the section we validate for a multiple of the entry size.
837  uint64_t ValidationSize = alignTo(Size, EntrySize);
838  // Guard against overflow.
839  if (ValidationSize >= Size)
840  if (DA.isValidOffsetForDataOfSize((uint32_t)Base, ValidationSize))
841  return *this;
842  return createStringError(errc::invalid_argument, "length exceeds section size");
843 }
844 
845 // Look for a DWARF64-formatted contribution to the string offsets table
846 // starting at a given offset and record it in a descriptor.
849  if (!DA.isValidOffsetForDataOfSize(Offset, 16))
850  return createStringError(errc::invalid_argument, "section offset exceeds section size");
851 
852  if (DA.getU32(&Offset) != dwarf::DW_LENGTH_DWARF64)
853  return createStringError(errc::invalid_argument, "32 bit contribution referenced from a 64 bit unit");
854 
855  uint64_t Size = DA.getU64(&Offset);
856  uint8_t Version = DA.getU16(&Offset);
857  (void)DA.getU16(&Offset); // padding
858  // The encoded length includes the 2-byte version field and the 2-byte
859  // padding, so we need to subtract them out when we populate the descriptor.
861 }
862 
863 // Look for a DWARF32-formatted contribution to the string offsets table
864 // starting at a given offset and record it in a descriptor.
867  if (!DA.isValidOffsetForDataOfSize(Offset, 8))
868  return createStringError(errc::invalid_argument, "section offset exceeds section size");
869 
870  uint32_t ContributionSize = DA.getU32(&Offset);
871  if (ContributionSize >= dwarf::DW_LENGTH_lo_reserved)
872  return createStringError(errc::invalid_argument, "invalid length");
873 
874  uint8_t Version = DA.getU16(&Offset);
875  (void)DA.getU16(&Offset); // padding
876  // The encoded length includes the 2-byte version field and the 2-byte
877  // padding, so we need to subtract them out when we populate the descriptor.
878  return StrOffsetsContributionDescriptor(Offset, ContributionSize - 4, Version,
879  DWARF32);
880 }
881 
885  uint64_t Offset) {
887  switch (Format) {
889  if (Offset < 16)
890  return createStringError(errc::invalid_argument, "insufficient space for 64 bit header prefix");
891  auto DescOrError = parseDWARF64StringOffsetsTableHeader(DA, Offset - 16);
892  if (!DescOrError)
893  return DescOrError.takeError();
894  Desc = *DescOrError;
895  break;
896  }
898  if (Offset < 8)
899  return createStringError(errc::invalid_argument, "insufficient space for 32 bit header prefix");
900  auto DescOrError = parseDWARF32StringOffsetsTableHeader(DA, Offset - 8);
901  if (!DescOrError)
902  return DescOrError.takeError();
903  Desc = *DescOrError;
904  break;
905  }
906  }
907  return Desc.validateContributionSize(DA);
908 }
909 
912  assert(!IsDWO);
913  auto OptOffset = toSectionOffset(getUnitDIE().find(DW_AT_str_offsets_base));
914  if (!OptOffset)
915  return None;
916  auto DescOrError =
917  parseDWARFStringOffsetsTableHeader(DA, Header.getFormat(), *OptOffset);
918  if (!DescOrError)
919  return DescOrError.takeError();
920  return *DescOrError;
921 }
922 
925  assert(IsDWO);
926  uint64_t Offset = 0;
927  auto IndexEntry = Header.getIndexEntry();
928  const auto *C =
929  IndexEntry ? IndexEntry->getContribution(DW_SECT_STR_OFFSETS) : nullptr;
930  if (C)
931  Offset = C->Offset;
932  if (getVersion() >= 5) {
933  if (DA.getData().data() == nullptr)
934  return None;
935  Offset += Header.getFormat() == dwarf::DwarfFormat::DWARF32 ? 8 : 16;
936  // Look for a valid contribution at the given offset.
937  auto DescOrError = parseDWARFStringOffsetsTableHeader(DA, Header.getFormat(), Offset);
938  if (!DescOrError)
939  return DescOrError.takeError();
940  return *DescOrError;
941  }
942  // Prior to DWARF v5, we derive the contribution size from the
943  // index table (in a package file). In a .dwo file it is simply
944  // the length of the string offsets section.
946  if (C)
947  Desc = StrOffsetsContributionDescriptor(C->Offset, C->Length, 4,
948  Header.getFormat());
949  else if (!IndexEntry && !StringOffsetSection.Data.empty())
950  Desc = StrOffsetsContributionDescriptor(0, StringOffsetSection.Data.size(),
951  4, Header.getFormat());
952  else
953  return None;
954  auto DescOrError = Desc.validateContributionSize(DA);
955  if (!DescOrError)
956  return DescOrError.takeError();
957  return *DescOrError;
958 }
959 
961  DataExtractor RangesData(RangeSection->Data, isLittleEndian,
963  DWARFDataExtractor RangesDA(Context.getDWARFObj(), *RangeSection,
964  isLittleEndian, 0);
966  RangesData, RangeSectionBase, getFormat(), Index))
967  return *Off + RangeSectionBase;
968  return None;
969 }
970 
973  LocTable->getData(), LocSectionBase, getFormat(), Index))
974  return *Off + LocSectionBase;
975  return None;
976 }
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:815
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:608
llvm::DWARFUnit::getFirstChild
DWARFDie getFirstChild(const DWARFDebugInfoEntry *Die)
Definition: DWARFUnit.cpp:789
llvm
---------------------— PointerInfo ------------------------------------—
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:893
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:1674
DWARFCompileUnit.h
llvm::StringRef::empty
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:153
llvm::DWARFUnit::getRnglistOffset
Optional< uint64_t > getRnglistOffset(uint32_t Index)
Return a rangelist's offset based on an index.
Definition: DWARFUnit.cpp:960
StringRef.h
llvm::toString
std::string toString(Error E)
Write all error messages (if any) in E to a string.
Definition: Error.h:1020
parseDWARF64StringOffsetsTableHeader
static Expected< StrOffsetsContributionDescriptor > parseDWARF64StringOffsetsTableHeader(DWARFDataExtractor &DA, uint64_t Offset)
Definition: DWARFUnit.cpp:848
llvm::SmallVector< std::string, 3 >
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:282
llvm::dwarf::DW_LENGTH_DWARF64
@ DW_LENGTH_DWARF64
Indicator of 64-bit DWARF format.
Definition: Dwarf.h:56
llvm::Depth
@ Depth
Definition: SIMachineScheduler.h:36
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:832
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:233
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:224
llvm::DWARFContext::getSupportedAddressSizes
static SmallVector< uint8_t, 3 > getSupportedAddressSizes()
Definition: DWARFContext.h:372
llvm::Optional
Definition: APInt.h:33
Offset
uint64_t Offset
Definition: ELFObjHandler.cpp:81
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::getAbbreviationDeclarationPtr
const DWARFAbbreviationDeclaration * getAbbreviationDeclarationPtr() const
Definition: DWARFDebugInfoEntry.h:58
llvm::DWARFDebugInfoEntry
DWARFDebugInfoEntry - A DIE with only the minimum required data.
Definition: DWARFDebugInfoEntry.h:23
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:1035
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:971
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:454
Context
LLVMContext & Context
Definition: NVVMIntrRange.cpp:66
llvm::DWARFUnit::getUnitDIE
DWARFDie getUnitDIE(bool ExtractUnitDIEOnly=true)
Definition: DWARFUnit.h:390
llvm::ARMBuildAttrs::Section
@ Section
Legacy Tags.
Definition: ARMBuildAttributes.h:78
llvm::DWARFUnit::getStringOffsetSectionItem
Optional< uint64_t > getStringOffsetSectionItem(uint32_t Index) const
Definition: DWARFUnit.cpp:217
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:814
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:911
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:303
llvm::dwarf::DW_LENGTH_lo_reserved
@ DW_LENGTH_lo_reserved
Special values for an initial length field.
Definition: Dwarf.h:55
llvm::M68kBeads::DA
@ DA
Definition: M68kBaseInfo.h:59
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::IndexedInstrProf::Version
const uint64_t Version
Definition: InstrProf.h:991
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:656
llvm::DWARFUnit::getParent
DWARFDie getParent(const DWARFDebugInfoEntry *Die)
Definition: DWARFUnit.cpp:731
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:687
llvm::DWARFDebugRangeList::extract
Error extract(const DWARFDataExtractor &data, uint64_t *offset_ptr)
Definition: DWARFDebugRangeList.cpp:25
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:618
llvm::DWARFUnit::findLoclistFromOffset
Expected< DWARFLocationExpressionsVector > findLoclistFromOffset(uint64_t Offset)
Definition: DWARFUnit.cpp:633
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:170
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:1571
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:933
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:59
DWARFUnit.h
llvm::DWARFUnit::getSibling
DWARFDie getSibling(const DWARFDebugInfoEntry *Die)
Definition: DWARFUnit.cpp:750
llvm::DWARFDie::find
Optional< DWARFFormValue > find(dwarf::Attribute Attr) const
Extract the specified attribute from this DIE.
Definition: DWARFDie.cpp:819
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::DWARFContext::isAddressSizeSupported
static bool isAddressSizeSupported(unsigned AddressSize)
Definition: DWARFContext.h:375
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:663
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:362
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::hasSingleElement
bool hasSingleElement(ContainerTy &&C)
Returns true if the given container only contains a single element.
Definition: STLExtras.h:259
llvm::DWARFUnit::getCompilationDir
const char * getCompilationDir()
Definition: DWARFUnit.cpp:373
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:58
llvm::DWARFDebugRangeList::getAbsoluteRanges
DWARFAddressRangesVector getAbsoluteRanges(llvm::Optional< object::SectionedAddress > BaseAddr) const
getAbsoluteRanges - Returns absolute address ranges defined by this range list.
Definition: DWARFDebugRangeList.cpp:70
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:229
llvm::DWARFDie::getSibling
DWARFDie getSibling() const
Get the sibling of this DIE object.
Definition: DWARFDie.cpp:1122
llvm::DWARFUnitHeader::getNextUnitOffset
uint64_t getNextUnitOffset() const
Definition: DWARFUnit.h:108
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::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:591
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:352
parseDWARFStringOffsetsTableHeader
static Expected< StrOffsetsContributionDescriptor > parseDWARFStringOffsetsTableHeader(DWARFDataExtractor &DA, llvm::dwarf::DwarfFormat Format, uint64_t Offset)
Definition: DWARFUnit.cpp:883
llvm::DWARFDie::getParent
DWARFDie getParent() const
Get the parent of this DIE object.
Definition: DWARFDie.cpp:1116
llvm::DWARFUnit::getAddressByteSize
uint8_t getAddressByteSize() const
Definition: DWARFUnit.h:286
llvm::DWARFUnit::getLastChild
DWARFDie getLastChild(const DWARFDebugInfoEntry *Die)
Definition: DWARFUnit.cpp:800
llvm::createStringError
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition: Error.h:1231
llvm::SectionKind
SectionKind - This is a simple POD value that classifies the properties of a section.
Definition: SectionKind.h:22
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:770
llvm::DWARFUnit::tryExtractDIEsIfNeeded
Error tryExtractDIEsIfNeeded(bool CUDieOnly)
Definition: DWARFUnit.cpp:432
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
llvm::c_str
SmallVectorImpl< T >::const_pointer c_str(SmallVectorImpl< T > &str)
Definition: WindowsSupport.h:193
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:702
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:210
parseDWARF32StringOffsetsTableHeader
static Expected< StrOffsetsContributionDescriptor > parseDWARF32StringOffsetsTableHeader(DWARFDataExtractor &DA, uint64_t Offset)
Definition: DWARFUnit.cpp:866
llvm::dwarf::FormParams::Version
uint16_t Version
Definition: Dwarf.h:649
llvm::DWARFUnit::getAbbreviationsOffset
uint64_t getAbbreviationsOffset() const
Definition: DWARFUnit.h:367
llvm::X86AS::SS
@ SS
Definition: X86.h:189
llvm::DataExtractor
Definition: DataExtractor.h:41
llvm::DWARFDie::getTag
dwarf::Tag getTag() const
Definition: DWARFDie.h:72
llvm::DWARFUnitHeader::getUnitLengthFieldByteSize
uint8_t getUnitLengthFieldByteSize() const
Definition: DWARFUnit.h:105
llvm::DWARFUnitHeader::applyIndexEntry
bool applyIndexEntry(const DWARFUnitIndex::Entry *Entry)
Definition: DWARFUnit.cpp:335
llvm::DWARFUnit::getBaseAddress
llvm::Optional< object::SectionedAddress > getBaseAddress()
Definition: DWARFUnit.cpp:821
llvm::to_string
std::string to_string(const T &Value)
Definition: ScopedPrinter.h:63
llvm::SmallVectorImpl
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:43
llvm::getDWARFUnitIndex
const DWARFUnitIndex & getDWARFUnitIndex(DWARFContext &Context, DWARFSectionKind Kind)
Definition: DWARFUnit.cpp:723
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:812
llvm::DWARFDebugInfoEntry::hasChildren
bool hasChildren() const
Definition: DWARFDebugInfoEntry.h:56
llvm::DWARFUnit::getLocationTable
const DWARFLocationTable & getLocationTable()
Definition: DWARFUnit.h:342
llvm::StringRef::size
LLVM_NODISCARD size_t size() const
size - Get the string size.
Definition: StringRef.h:157
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:924
llvm::DWARFContext::isSupportedVersion
static bool isSupportedVersion(unsigned version)
Definition: DWARFContext.h:368
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:698
CU
Definition: AArch64AsmBackend.cpp:501
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:1134
llvm::DWARFContext::getMaxSupportedVersion
static unsigned getMaxSupportedVersion()
Definition: DWARFContext.h:367
llvm::dwarf::DWARF32
@ DWARF32
Definition: Dwarf.h:92
llvm::DWARFDebugInfoEntry::getDepth
uint32_t getDepth() const
Definition: DWARFDebugInfoEntry.h:50
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