LLVM  10.0.0svn
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 "llvm/Support/WithColor.h"
25 #include <algorithm>
26 #include <cassert>
27 #include <cstddef>
28 #include <cstdint>
29 #include <cstdio>
30 #include <utility>
31 #include <vector>
32 
33 using namespace llvm;
34 using namespace dwarf;
35 
37  const DWARFSection &Section,
39  const DWARFObject &D = C.getDWARFObj();
40  addUnitsImpl(C, D, Section, C.getDebugAbbrev(), &D.getRangesSection(),
41  &D.getLocSection(), D.getStrSection(),
43  D.getLineSection(), D.isLittleEndian(), false, false,
44  SectionKind);
45 }
46 
48  const DWARFSection &DWOSection,
50  bool Lazy) {
51  const DWARFObject &D = C.getDWARFObj();
52  addUnitsImpl(C, D, DWOSection, C.getDebugAbbrevDWO(), &D.getRangesDWOSection(),
55  D.getLineDWOSection(), C.isLittleEndian(), true, Lazy,
56  SectionKind);
57 }
58 
59 void DWARFUnitVector::addUnitsImpl(
61  const DWARFDebugAbbrev *DA, const DWARFSection *RS,
62  const DWARFSection *LocSection, StringRef SS, const DWARFSection &SOS,
63  const DWARFSection *AOS, const DWARFSection &LS, bool LE, bool IsDWO,
64  bool Lazy, DWARFSectionKind SectionKind) {
65  DWARFDataExtractor Data(Obj, Section, LE, 0);
66  // Lazy initialization of Parser, now that we have all section info.
67  if (!Parser) {
68  Parser = [=, &Context, &Obj, &Section, &SOS,
69  &LS](uint64_t Offset, DWARFSectionKind SectionKind,
70  const DWARFSection *CurSection,
71  const DWARFUnitIndex::Entry *IndexEntry)
72  -> std::unique_ptr<DWARFUnit> {
73  const DWARFSection &InfoSection = CurSection ? *CurSection : Section;
74  DWARFDataExtractor Data(Obj, InfoSection, LE, 0);
75  if (!Data.isValidOffset(Offset))
76  return nullptr;
77  const DWARFUnitIndex *Index = nullptr;
78  if (IsDWO)
79  Index = &getDWARFUnitIndex(Context, SectionKind);
80  DWARFUnitHeader Header;
81  if (!Header.extract(Context, Data, &Offset, SectionKind, Index,
82  IndexEntry))
83  return nullptr;
84  std::unique_ptr<DWARFUnit> U;
85  if (Header.isTypeUnit())
86  U = std::make_unique<DWARFTypeUnit>(Context, InfoSection, Header, DA,
87  RS, LocSection, SS, SOS, AOS, LS,
88  LE, IsDWO, *this);
89  else
90  U = std::make_unique<DWARFCompileUnit>(Context, InfoSection, Header,
91  DA, RS, LocSection, SS, SOS,
92  AOS, LS, LE, IsDWO, *this);
93  return U;
94  };
95  }
96  if (Lazy)
97  return;
98  // Find a reasonable insertion point within the vector. We skip over
99  // (a) units from a different section, (b) units from the same section
100  // but with lower offset-within-section. This keeps units in order
101  // within a section, although not necessarily within the object file,
102  // even if we do lazy parsing.
103  auto I = this->begin();
104  uint64_t Offset = 0;
105  while (Data.isValidOffset(Offset)) {
106  if (I != this->end() &&
107  (&(*I)->getInfoSection() != &Section || (*I)->getOffset() == Offset)) {
108  ++I;
109  continue;
110  }
111  auto U = Parser(Offset, SectionKind, &Section, nullptr);
112  // If parsing failed, we're done with this section.
113  if (!U)
114  break;
115  Offset = U->getNextUnitOffset();
116  I = std::next(this->insert(I, std::move(U)));
117  }
118 }
119 
120 DWARFUnit *DWARFUnitVector::addUnit(std::unique_ptr<DWARFUnit> Unit) {
121  auto I = std::upper_bound(begin(), end(), Unit,
122  [](const std::unique_ptr<DWARFUnit> &LHS,
123  const std::unique_ptr<DWARFUnit> &RHS) {
124  return LHS->getOffset() < RHS->getOffset();
125  });
126  return this->insert(I, std::move(Unit))->get();
127 }
128 
130  auto end = begin() + getNumInfoUnits();
131  auto *CU =
132  std::upper_bound(begin(), end, Offset,
133  [](uint64_t LHS, const std::unique_ptr<DWARFUnit> &RHS) {
134  return LHS < RHS->getNextUnitOffset();
135  });
136  if (CU != end && (*CU)->getOffset() <= Offset)
137  return CU->get();
138  return nullptr;
139 }
140 
141 DWARFUnit *
143  const auto *CUOff = E.getOffset(DW_SECT_INFO);
144  if (!CUOff)
145  return nullptr;
146 
147  auto Offset = CUOff->Offset;
148  auto end = begin() + getNumInfoUnits();
149 
150  auto *CU =
151  std::upper_bound(begin(), end, CUOff->Offset,
152  [](uint64_t LHS, const std::unique_ptr<DWARFUnit> &RHS) {
153  return LHS < RHS->getNextUnitOffset();
154  });
155  if (CU != end && (*CU)->getOffset() <= Offset)
156  return CU->get();
157 
158  if (!Parser)
159  return nullptr;
160 
161  auto U = Parser(Offset, DW_SECT_INFO, nullptr, &E);
162  if (!U)
163  U = nullptr;
164 
165  auto *NewCU = U.get();
166  this->insert(CU, std::move(U));
167  ++NumInfoUnits;
168  return NewCU;
169 }
170 
172  const DWARFUnitHeader &Header, const DWARFDebugAbbrev *DA,
173  const DWARFSection *RS, const DWARFSection *LocSection,
174  StringRef SS, const DWARFSection &SOS,
175  const DWARFSection *AOS, const DWARFSection &LS, bool LE,
176  bool IsDWO, const DWARFUnitVector &UnitVector)
177  : Context(DC), InfoSection(Section), Header(Header), Abbrev(DA),
178  RangeSection(RS), LocSection(LocSection), LineSection(LS),
179  StringSection(SS), StringOffsetSection(SOS), AddrOffsetSection(AOS),
180  isLittleEndian(LE), IsDWO(IsDWO), UnitVector(UnitVector) {
181  clear();
182  // For split DWARF we only need to keep track of the location list section's
183  // data (no relocations), and if we are reading a package file, we need to
184  // adjust the location list data based on the index entries.
185  if (IsDWO) {
186  LocSectionData = LocSection->Data;
187  if (auto *IndexEntry = Header.getIndexEntry())
188  if (const auto *C = IndexEntry->getOffset(DW_SECT_LOC))
189  LocSectionData = LocSectionData.substr(C->Offset, C->Length);
190  }
191 }
192 
193 DWARFUnit::~DWARFUnit() = default;
194 
196  return DWARFDataExtractor(Context.getDWARFObj(), InfoSection, isLittleEndian,
198 }
199 
202  if (IsDWO) {
203  auto R = Context.info_section_units();
204  auto I = R.begin();
205  // Surprising if a DWO file has more than one skeleton unit in it - this
206  // probably shouldn't be valid, but if a use case is found, here's where to
207  // support it (probably have to linearly search for the matching skeleton CU
208  // here)
209  if (I != R.end() && std::next(I) == R.end())
210  return (*I)->getAddrOffsetSectionItem(Index);
211  }
212  uint64_t Offset = AddrOffsetSectionBase + Index * getAddressByteSize();
213  if (AddrOffsetSection->Data.size() < Offset + getAddressByteSize())
214  return None;
215  DWARFDataExtractor DA(Context.getDWARFObj(), *AddrOffsetSection,
216  isLittleEndian, getAddressByteSize());
217  uint64_t Section;
218  uint64_t Address = DA.getRelocatedAddress(&Offset, &Section);
219  return {{Address, Section}};
220 }
221 
223  if (!StringOffsetsTableContribution)
224  return None;
225  unsigned ItemSize = getDwarfStringOffsetsByteSize();
226  uint64_t Offset = getStringOffsetsBase() + Index * ItemSize;
227  if (StringOffsetSection.Data.size() < Offset + ItemSize)
228  return None;
229  DWARFDataExtractor DA(Context.getDWARFObj(), StringOffsetSection,
230  isLittleEndian, 0);
231  return DA.getRelocatedValue(ItemSize, &Offset);
232 }
233 
235  const DWARFDataExtractor &debug_info,
236  uint64_t *offset_ptr,
238  const DWARFUnitIndex *Index,
239  const DWARFUnitIndex::Entry *Entry) {
240  Offset = *offset_ptr;
241  IndexEntry = Entry;
242  if (!IndexEntry && Index)
243  IndexEntry = Index->getFromOffset(*offset_ptr);
244  Length = debug_info.getRelocatedValue(4, offset_ptr);
246  if (Length == dwarf::DW_LENGTH_DWARF64) {
247  Length = debug_info.getU64(offset_ptr);
249  }
250  FormParams.Version = debug_info.getU16(offset_ptr);
251  if (FormParams.Version >= 5) {
252  UnitType = debug_info.getU8(offset_ptr);
253  FormParams.AddrSize = debug_info.getU8(offset_ptr);
254  AbbrOffset = debug_info.getRelocatedValue(FormParams.getDwarfOffsetByteSize(), offset_ptr);
255  } else {
256  AbbrOffset = debug_info.getRelocatedValue(FormParams.getDwarfOffsetByteSize(), offset_ptr);
257  FormParams.AddrSize = debug_info.getU8(offset_ptr);
258  // Fake a unit type based on the section type. This isn't perfect,
259  // but distinguishing compile and type units is generally enough.
260  if (SectionKind == DW_SECT_TYPES)
261  UnitType = DW_UT_type;
262  else
263  UnitType = DW_UT_compile;
264  }
265  if (IndexEntry) {
266  if (AbbrOffset)
267  return false;
268  auto *UnitContrib = IndexEntry->getOffset();
269  if (!UnitContrib || UnitContrib->Length != (Length + 4))
270  return false;
271  auto *AbbrEntry = IndexEntry->getOffset(DW_SECT_ABBREV);
272  if (!AbbrEntry)
273  return false;
274  AbbrOffset = AbbrEntry->Offset;
275  }
276  if (isTypeUnit()) {
277  TypeHash = debug_info.getU64(offset_ptr);
278  TypeOffset =
279  debug_info.getUnsigned(offset_ptr, FormParams.getDwarfOffsetByteSize());
280  } else if (UnitType == DW_UT_split_compile || UnitType == DW_UT_skeleton)
281  DWOId = debug_info.getU64(offset_ptr);
282 
283  // Header fields all parsed, capture the size of this unit header.
284  assert(*offset_ptr - Offset <= 255 && "unexpected header size");
285  Size = uint8_t(*offset_ptr - Offset);
286 
287  // Type offset is unit-relative; should be after the header and before
288  // the end of the current unit.
289  bool TypeOffsetOK =
290  !isTypeUnit()
291  ? true
292  : TypeOffset >= Size &&
293  TypeOffset < getLength() + getUnitLengthFieldByteSize();
294  bool LengthOK = debug_info.isValidOffset(getNextUnitOffset() - 1);
295  bool VersionOK = DWARFContext::isSupportedVersion(getVersion());
296  bool AddrSizeOK = getAddressByteSize() == 4 || getAddressByteSize() == 8;
297 
298  if (!LengthOK || !VersionOK || !AddrSizeOK || !TypeOffsetOK)
299  return false;
300 
301  // Keep track of the highest DWARF version we encounter across all units.
303  return true;
304 }
305 
306 // Parse the rangelist table header, including the optional array of offsets
307 // following it (DWARF v5 and later).
311  // We are expected to be called with Offset 0 or pointing just past the table
312  // header. Correct Offset in the latter case so that it points to the start
313  // of the header.
314  if (Offset > 0) {
316  if (Offset < HeaderSize)
317  return createStringError(errc::invalid_argument, "Did not detect a valid"
318  " range list table with base = 0x%" PRIx64 "\n",
319  Offset);
320  Offset -= HeaderSize;
321  }
323  if (Error E = Table.extractHeaderAndOffsets(DA, &Offset))
324  return std::move(E);
325  return Table;
326 }
327 
328 Error DWARFUnit::extractRangeList(uint64_t RangeListOffset,
329  DWARFDebugRangeList &RangeList) const {
330  // Require that compile unit is extracted.
331  assert(!DieArray.empty());
332  DWARFDataExtractor RangesData(Context.getDWARFObj(), *RangeSection,
333  isLittleEndian, getAddressByteSize());
334  uint64_t ActualRangeListOffset = RangeSectionBase + RangeListOffset;
335  return RangeList.extract(RangesData, &ActualRangeListOffset);
336 }
337 
339  Abbrevs = nullptr;
340  BaseAddr.reset();
341  RangeSectionBase = 0;
342  AddrOffsetSectionBase = 0;
343  clearDIEs(false);
344  DWO.reset();
345 }
346 
348  return dwarf::toString(getUnitDIE().find(DW_AT_comp_dir), nullptr);
349 }
350 
351 void DWARFUnit::extractDIEsToVector(
352  bool AppendCUDie, bool AppendNonCUDies,
353  std::vector<DWARFDebugInfoEntry> &Dies) const {
354  if (!AppendCUDie && !AppendNonCUDies)
355  return;
356 
357  // Set the offset to that of the first DIE and calculate the start of the
358  // next compilation unit header.
359  uint64_t DIEOffset = getOffset() + getHeaderSize();
360  uint64_t NextCUOffset = getNextUnitOffset();
362  DWARFDataExtractor DebugInfoData = getDebugInfoExtractor();
363  uint32_t Depth = 0;
364  bool IsCUDie = true;
365 
366  while (DIE.extractFast(*this, &DIEOffset, DebugInfoData, NextCUOffset,
367  Depth)) {
368  if (IsCUDie) {
369  if (AppendCUDie)
370  Dies.push_back(DIE);
371  if (!AppendNonCUDies)
372  break;
373  // The average bytes per DIE entry has been seen to be
374  // around 14-20 so let's pre-reserve the needed memory for
375  // our DIE entries accordingly.
376  Dies.reserve(Dies.size() + getDebugInfoSize() / 14);
377  IsCUDie = false;
378  } else {
379  Dies.push_back(DIE);
380  }
381 
382  if (const DWARFAbbreviationDeclaration *AbbrDecl =
384  // Normal DIE
385  if (AbbrDecl->hasChildren())
386  ++Depth;
387  } else {
388  // NULL DIE.
389  if (Depth > 0)
390  --Depth;
391  if (Depth == 0)
392  break; // We are done with this compile unit!
393  }
394  }
395 
396  // Give a little bit of info if we encounter corrupt DWARF (our offset
397  // should always terminate at or before the start of the next compilation
398  // unit header).
399  if (DIEOffset > NextCUOffset)
400  WithColor::warning() << format("DWARF compile unit extends beyond its "
401  "bounds cu 0x%8.8" PRIx64 " "
402  "at 0x%8.8" PRIx64 "\n",
403  getOffset(), DIEOffset);
404 }
405 
406 void DWARFUnit::extractDIEsIfNeeded(bool CUDieOnly) {
407  if (Error e = tryExtractDIEsIfNeeded(CUDieOnly))
408  WithColor::error() << toString(std::move(e));
409 }
410 
412  if ((CUDieOnly && !DieArray.empty()) ||
413  DieArray.size() > 1)
414  return Error::success(); // Already parsed.
415 
416  bool HasCUDie = !DieArray.empty();
417  extractDIEsToVector(!HasCUDie, !CUDieOnly, DieArray);
418 
419  if (DieArray.empty())
420  return Error::success();
421 
422  // If CU DIE was just parsed, copy several attribute values from it.
423  if (HasCUDie)
424  return Error::success();
425 
426  DWARFDie UnitDie(this, &DieArray[0]);
427  if (Optional<uint64_t> DWOId = toUnsigned(UnitDie.find(DW_AT_GNU_dwo_id)))
428  Header.setDWOId(*DWOId);
429  if (!IsDWO) {
430  assert(AddrOffsetSectionBase == 0);
431  assert(RangeSectionBase == 0);
432  AddrOffsetSectionBase = toSectionOffset(UnitDie.find(DW_AT_addr_base), 0);
433  if (!AddrOffsetSectionBase)
434  AddrOffsetSectionBase =
435  toSectionOffset(UnitDie.find(DW_AT_GNU_addr_base), 0);
436  RangeSectionBase = toSectionOffset(UnitDie.find(DW_AT_rnglists_base), 0);
437  }
438 
439  // In general, in DWARF v5 and beyond we derive the start of the unit's
440  // contribution to the string offsets table from the unit DIE's
441  // DW_AT_str_offsets_base attribute. Split DWARF units do not use this
442  // attribute, so we assume that there is a contribution to the string
443  // offsets table starting at offset 0 of the debug_str_offsets.dwo section.
444  // In both cases we need to determine the format of the contribution,
445  // which may differ from the unit's format.
446  DWARFDataExtractor DA(Context.getDWARFObj(), StringOffsetSection,
447  isLittleEndian, 0);
448  if (IsDWO || getVersion() >= 5) {
449  auto StringOffsetOrError =
452  if (!StringOffsetOrError)
454  "invalid reference to or invalid content in "
455  ".debug_str_offsets[.dwo]: " +
456  toString(StringOffsetOrError.takeError()));
457 
458  StringOffsetsTableContribution = *StringOffsetOrError;
459  }
460 
461  // DWARF v5 uses the .debug_rnglists and .debug_rnglists.dwo sections to
462  // describe address ranges.
463  if (getVersion() >= 5) {
464  if (IsDWO)
466  else
468  toSectionOffset(UnitDie.find(DW_AT_rnglists_base), 0));
469  if (RangeSection->Data.size()) {
470  // Parse the range list table header. Individual range lists are
471  // extracted lazily.
472  DWARFDataExtractor RangesDA(Context.getDWARFObj(), *RangeSection,
473  isLittleEndian, 0);
474  auto TableOrError = parseRngListTableHeader(RangesDA, RangeSectionBase,
475  Header.getFormat());
476  if (!TableOrError)
478  "parsing a range list table: " +
479  toString(TableOrError.takeError()));
480 
481  RngListTable = TableOrError.get();
482 
483  // In a split dwarf unit, there is no DW_AT_rnglists_base attribute.
484  // Adjust RangeSectionBase to point past the table header.
485  if (IsDWO && RngListTable)
486  RangeSectionBase = RngListTable->getHeaderSize();
487  }
488  }
489 
490  // Don't fall back to DW_AT_GNU_ranges_base: it should be ignored for
491  // skeleton CU DIE, so that DWARF users not aware of it are not broken.
492  return Error::success();
493 }
494 
495 bool DWARFUnit::parseDWO() {
496  if (IsDWO)
497  return false;
498  if (DWO.get())
499  return false;
500  DWARFDie UnitDie = getUnitDIE();
501  if (!UnitDie)
502  return false;
503  auto DWOFileName = dwarf::toString(UnitDie.find(DW_AT_GNU_dwo_name));
504  if (!DWOFileName)
505  return false;
506  auto CompilationDir = dwarf::toString(UnitDie.find(DW_AT_comp_dir));
507  SmallString<16> AbsolutePath;
508  if (sys::path::is_relative(*DWOFileName) && CompilationDir &&
509  *CompilationDir) {
510  sys::path::append(AbsolutePath, *CompilationDir);
511  }
512  sys::path::append(AbsolutePath, *DWOFileName);
513  auto DWOId = getDWOId();
514  if (!DWOId)
515  return false;
516  auto DWOContext = Context.getDWOContext(AbsolutePath);
517  if (!DWOContext)
518  return false;
519 
520  DWARFCompileUnit *DWOCU = DWOContext->getDWOCompileUnitForHash(*DWOId);
521  if (!DWOCU)
522  return false;
523  DWO = std::shared_ptr<DWARFCompileUnit>(std::move(DWOContext), DWOCU);
524  // Share .debug_addr and .debug_ranges section with compile unit in .dwo
525  DWO->setAddrOffsetSection(AddrOffsetSection, AddrOffsetSectionBase);
526  if (getVersion() >= 5) {
527  DWO->setRangesSection(&Context.getDWARFObj().getRnglistsDWOSection(), 0);
528  DWARFDataExtractor RangesDA(Context.getDWARFObj(), *RangeSection,
529  isLittleEndian, 0);
530  if (auto TableOrError = parseRngListTableHeader(RangesDA, RangeSectionBase,
531  Header.getFormat()))
532  DWO->RngListTable = TableOrError.get();
533  else
534  WithColor::error() << "parsing a range list table: "
535  << toString(TableOrError.takeError())
536  << '\n';
537  if (DWO->RngListTable)
538  DWO->RangeSectionBase = DWO->RngListTable->getHeaderSize();
539  } else {
540  auto DWORangesBase = UnitDie.getRangesBaseAttribute();
541  DWO->setRangesSection(RangeSection, DWORangesBase ? *DWORangesBase : 0);
542  }
543 
544  return true;
545 }
546 
547 void DWARFUnit::clearDIEs(bool KeepCUDie) {
548  if (DieArray.size() > (unsigned)KeepCUDie) {
549  DieArray.resize((unsigned)KeepCUDie);
550  DieArray.shrink_to_fit();
551  }
552 }
553 
556  if (getVersion() <= 4) {
557  DWARFDebugRangeList RangeList;
558  if (Error E = extractRangeList(Offset, RangeList))
559  return std::move(E);
560  return RangeList.getAbsoluteRanges(getBaseAddress());
561  }
562  if (RngListTable) {
563  DWARFDataExtractor RangesData(Context.getDWARFObj(), *RangeSection,
564  isLittleEndian, RngListTable->getAddrSize());
565  auto RangeListOrError = RngListTable->findList(RangesData, Offset);
566  if (RangeListOrError)
567  return RangeListOrError.get().getAbsoluteRanges(getBaseAddress(), *this);
568  return RangeListOrError.takeError();
569  }
570 
572  "missing or invalid range list table");
573 }
574 
577  if (auto Offset = getRnglistOffset(Index))
578  return findRnglistFromOffset(*Offset + RangeSectionBase);
579 
580  if (RngListTable)
582  "invalid range list table index %d", Index);
583 
585  "missing or invalid range list table");
586 }
587 
589  DWARFDie UnitDie = getUnitDIE();
590  if (!UnitDie)
591  return createStringError(errc::invalid_argument, "No unit DIE");
592 
593  // First, check if unit DIE describes address ranges for the whole unit.
594  auto CUDIERangesOrError = UnitDie.getAddressRanges();
595  if (!CUDIERangesOrError)
597  "decoding address ranges: %s",
598  toString(CUDIERangesOrError.takeError()).c_str());
599  return *CUDIERangesOrError;
600 }
601 
603  if (Die.isSubroutineDIE()) {
604  auto DIERangesOrError = Die.getAddressRanges();
605  if (DIERangesOrError) {
606  for (const auto &R : DIERangesOrError.get()) {
607  // Ignore 0-sized ranges.
608  if (R.LowPC == R.HighPC)
609  continue;
610  auto B = AddrDieMap.upper_bound(R.LowPC);
611  if (B != AddrDieMap.begin() && R.LowPC < (--B)->second.first) {
612  // The range is a sub-range of existing ranges, we need to split the
613  // existing range.
614  if (R.HighPC < B->second.first)
615  AddrDieMap[R.HighPC] = B->second;
616  if (R.LowPC > B->first)
617  AddrDieMap[B->first].first = R.LowPC;
618  }
619  AddrDieMap[R.LowPC] = std::make_pair(R.HighPC, Die);
620  }
621  } else
622  llvm::consumeError(DIERangesOrError.takeError());
623  }
624  // Parent DIEs are added to the AddrDieMap prior to the Children DIEs to
625  // simplify the logic to update AddrDieMap. The child's range will always
626  // be equal or smaller than the parent's range. With this assumption, when
627  // adding one range into the map, it will at most split a range into 3
628  // sub-ranges.
629  for (DWARFDie Child = Die.getFirstChild(); Child; Child = Child.getSibling())
630  updateAddressDieMap(Child);
631 }
632 
634  extractDIEsIfNeeded(false);
635  if (AddrDieMap.empty())
637  auto R = AddrDieMap.upper_bound(Address);
638  if (R == AddrDieMap.begin())
639  return DWARFDie();
640  // upper_bound's previous item contains Address.
641  --R;
642  if (Address >= R->second.first)
643  return DWARFDie();
644  return R->second.second;
645 }
646 
647 void
649  SmallVectorImpl<DWARFDie> &InlinedChain) {
650  assert(InlinedChain.empty());
651  // Try to look for subprogram DIEs in the DWO file.
652  parseDWO();
653  // First, find the subroutine that contains the given address (the leaf
654  // of inlined chain).
655  DWARFDie SubroutineDIE =
656  (DWO ? *DWO : *this).getSubroutineForAddress(Address);
657 
658  if (!SubroutineDIE)
659  return;
660 
661  while (!SubroutineDIE.isSubprogramDIE()) {
662  if (SubroutineDIE.getTag() == DW_TAG_inlined_subroutine)
663  InlinedChain.push_back(SubroutineDIE);
664  SubroutineDIE = SubroutineDIE.getParent();
665  }
666  InlinedChain.push_back(SubroutineDIE);
667 }
668 
671  if (Kind == DW_SECT_INFO)
672  return Context.getCUIndex();
673  assert(Kind == DW_SECT_TYPES);
674  return Context.getTUIndex();
675 }
676 
678  if (!Die)
679  return DWARFDie();
680  const uint32_t Depth = Die->getDepth();
681  // Unit DIEs always have a depth of zero and never have parents.
682  if (Depth == 0)
683  return DWARFDie();
684  // Depth of 1 always means parent is the compile/type unit.
685  if (Depth == 1)
686  return getUnitDIE();
687  // Look for previous DIE with a depth that is one less than the Die's depth.
688  const uint32_t ParentDepth = Depth - 1;
689  for (uint32_t I = getDIEIndex(Die) - 1; I > 0; --I) {
690  if (DieArray[I].getDepth() == ParentDepth)
691  return DWARFDie(this, &DieArray[I]);
692  }
693  return DWARFDie();
694 }
695 
697  if (!Die)
698  return DWARFDie();
699  uint32_t Depth = Die->getDepth();
700  // Unit DIEs always have a depth of zero and never have siblings.
701  if (Depth == 0)
702  return DWARFDie();
703  // NULL DIEs don't have siblings.
704  if (Die->getAbbreviationDeclarationPtr() == nullptr)
705  return DWARFDie();
706 
707  // Find the next DIE whose depth is the same as the Die's depth.
708  for (size_t I = getDIEIndex(Die) + 1, EndIdx = DieArray.size(); I < EndIdx;
709  ++I) {
710  if (DieArray[I].getDepth() == Depth)
711  return DWARFDie(this, &DieArray[I]);
712  }
713  return DWARFDie();
714 }
715 
717  if (!Die)
718  return DWARFDie();
719  uint32_t Depth = Die->getDepth();
720  // Unit DIEs always have a depth of zero and never have siblings.
721  if (Depth == 0)
722  return DWARFDie();
723 
724  // Find the previous DIE whose depth is the same as the Die's depth.
725  for (size_t I = getDIEIndex(Die); I > 0;) {
726  --I;
727  if (DieArray[I].getDepth() == Depth - 1)
728  return DWARFDie();
729  if (DieArray[I].getDepth() == Depth)
730  return DWARFDie(this, &DieArray[I]);
731  }
732  return DWARFDie();
733 }
734 
736  if (!Die->hasChildren())
737  return DWARFDie();
738 
739  // We do not want access out of bounds when parsing corrupted debug data.
740  size_t I = getDIEIndex(Die) + 1;
741  if (I >= DieArray.size())
742  return DWARFDie();
743  return DWARFDie(this, &DieArray[I]);
744 }
745 
747  if (!Die->hasChildren())
748  return DWARFDie();
749 
750  uint32_t Depth = Die->getDepth();
751  for (size_t I = getDIEIndex(Die) + 1, EndIdx = DieArray.size(); I < EndIdx;
752  ++I) {
753  if (DieArray[I].getDepth() == Depth + 1 &&
754  DieArray[I].getTag() == dwarf::DW_TAG_null)
755  return DWARFDie(this, &DieArray[I]);
756  assert(DieArray[I].getDepth() > Depth && "Not processing children?");
757  }
758  return DWARFDie();
759 }
760 
762  if (!Abbrevs)
763  Abbrevs = Abbrev->getAbbreviationDeclarationSet(Header.getAbbrOffset());
764  return Abbrevs;
765 }
766 
768  if (BaseAddr)
769  return BaseAddr;
770 
771  DWARFDie UnitDie = getUnitDIE();
772  Optional<DWARFFormValue> PC = UnitDie.find({DW_AT_low_pc, DW_AT_entry_pc});
773  BaseAddr = toSectionedAddress(PC);
774  return BaseAddr;
775 }
776 
779  DWARFDataExtractor &DA) {
780  uint8_t EntrySize = getDwarfOffsetByteSize();
781  // In order to ensure that we don't read a partial record at the end of
782  // the section we validate for a multiple of the entry size.
783  uint64_t ValidationSize = alignTo(Size, EntrySize);
784  // Guard against overflow.
785  if (ValidationSize >= Size)
786  if (DA.isValidOffsetForDataOfSize((uint32_t)Base, ValidationSize))
787  return *this;
788  return createStringError(errc::invalid_argument, "length exceeds section size");
789 }
790 
791 // Look for a DWARF64-formatted contribution to the string offsets table
792 // starting at a given offset and record it in a descriptor.
795  if (!DA.isValidOffsetForDataOfSize(Offset, 16))
796  return createStringError(errc::invalid_argument, "section offset exceeds section size");
797 
798  if (DA.getU32(&Offset) != dwarf::DW_LENGTH_DWARF64)
799  return createStringError(errc::invalid_argument, "32 bit contribution referenced from a 64 bit unit");
800 
801  uint64_t Size = DA.getU64(&Offset);
802  uint8_t Version = DA.getU16(&Offset);
803  (void)DA.getU16(&Offset); // padding
804  // The encoded length includes the 2-byte version field and the 2-byte
805  // padding, so we need to subtract them out when we populate the descriptor.
806  return StrOffsetsContributionDescriptor(Offset, Size - 4, Version, DWARF64);
807 }
808 
809 // Look for a DWARF32-formatted contribution to the string offsets table
810 // starting at a given offset and record it in a descriptor.
813  if (!DA.isValidOffsetForDataOfSize(Offset, 8))
814  return createStringError(errc::invalid_argument, "section offset exceeds section size");
815 
816  uint32_t ContributionSize = DA.getU32(&Offset);
817  if (ContributionSize >= dwarf::DW_LENGTH_lo_reserved)
818  return createStringError(errc::invalid_argument, "invalid length");
819 
820  uint8_t Version = DA.getU16(&Offset);
821  (void)DA.getU16(&Offset); // padding
822  // The encoded length includes the 2-byte version field and the 2-byte
823  // padding, so we need to subtract them out when we populate the descriptor.
824  return StrOffsetsContributionDescriptor(Offset, ContributionSize - 4, Version,
825  DWARF32);
826 }
827 
831  uint64_t Offset) {
833  switch (Format) {
835  if (Offset < 16)
836  return createStringError(errc::invalid_argument, "insufficient space for 64 bit header prefix");
837  auto DescOrError = parseDWARF64StringOffsetsTableHeader(DA, Offset - 16);
838  if (!DescOrError)
839  return DescOrError.takeError();
840  Desc = *DescOrError;
841  break;
842  }
844  if (Offset < 8)
845  return createStringError(errc::invalid_argument, "insufficient space for 32 bit header prefix");
846  auto DescOrError = parseDWARF32StringOffsetsTableHeader(DA, Offset - 8);
847  if (!DescOrError)
848  return DescOrError.takeError();
849  Desc = *DescOrError;
850  break;
851  }
852  }
853  return Desc.validateContributionSize(DA);
854 }
855 
858  uint64_t Offset;
859  if (IsDWO) {
860  Offset = 0;
861  if (DA.getData().data() == nullptr)
862  return None;
863  } else {
864  auto OptOffset = toSectionOffset(getUnitDIE().find(DW_AT_str_offsets_base));
865  if (!OptOffset)
866  return None;
867  Offset = *OptOffset;
868  }
869  auto DescOrError = parseDWARFStringOffsetsTableHeader(DA, Header.getFormat(), Offset);
870  if (!DescOrError)
871  return DescOrError.takeError();
872  return *DescOrError;
873 }
874 
877  uint64_t Offset = 0;
878  auto IndexEntry = Header.getIndexEntry();
879  const auto *C =
880  IndexEntry ? IndexEntry->getOffset(DW_SECT_STR_OFFSETS) : nullptr;
881  if (C)
882  Offset = C->Offset;
883  if (getVersion() >= 5) {
884  if (DA.getData().data() == nullptr)
885  return None;
886  Offset += Header.getFormat() == dwarf::DwarfFormat::DWARF32 ? 8 : 16;
887  // Look for a valid contribution at the given offset.
888  auto DescOrError = parseDWARFStringOffsetsTableHeader(DA, Header.getFormat(), Offset);
889  if (!DescOrError)
890  return DescOrError.takeError();
891  return *DescOrError;
892  }
893  // Prior to DWARF v5, we derive the contribution size from the
894  // index table (in a package file). In a .dwo file it is simply
895  // the length of the string offsets section.
896  if (!IndexEntry)
897  return {
899  {0, StringOffsetSection.Data.size(), 4, DWARF32})};
900  if (C)
902  {C->Offset, C->Length, 4, DWARF32})};
903  return None;
904 }
const DWARFAbbreviationDeclarationSet * getAbbreviations() const
Definition: DWARFUnit.cpp:761
const DWARFUnitIndex & getTUIndex()
uint64_t CallInst * C
uint8_t getU8(uint64_t *offset_ptr, Error *Err=nullptr) const
Extract a uint8_t value from *offset_ptr.
void getInlinedChainForAddress(uint64_t Address, SmallVectorImpl< DWARFDie > &InlinedChain)
getInlinedChainForAddress - fetches inlined chain for a given address.
Definition: DWARFUnit.cpp:648
virtual ~DWARFUnit()
const_iterator end(StringRef path)
Get end iterator over path.
Definition: Path.cpp:233
uint64_t getNextUnitOffset() const
Definition: DWARFUnit.h:292
virtual const DWARFSection & getAddrSection() const
Definition: DWARFObject.h:69
static Expected< StrOffsetsContributionDescriptor > parseDWARFStringOffsetsTableHeader(DWARFDataExtractor &DA, llvm::dwarf::DwarfFormat Format, uint64_t Offset)
Definition: DWARFUnit.cpp:829
A helper struct providing information about the byte size of DW_FORM values that vary in size dependi...
Definition: Dwarf.h:488
virtual StringRef getStrSection() const
Definition: DWARFObject.h:47
LLVMContext & Context
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
Definition: Path.cpp:224
DWARFUnit * getUnitForOffset(uint64_t Offset) const
Definition: DWARFUnit.cpp:129
uint16_t getU16(uint64_t *offset_ptr, Error *Err=nullptr) const
Extract a uint16_t value from *offset_ptr.
virtual const DWARFSection & getLocDWOSection() const
Definition: DWARFObject.h:62
Expected< Optional< StrOffsetsContributionDescriptor > > determineStringOffsetsTableContributionDWO(DWARFDataExtractor &DA)
Find the unit&#39;s contribution to the string offsets table and determine its length and form...
Definition: DWARFUnit.cpp:876
This class represents lattice values for constants.
Definition: AllocatorList.h:23
Represents base address of the CU.
Definition: DWARFUnit.h:169
bool isSubprogramDIE() const
Returns true if DIE represents a subprogram (not inlined).
Definition: DWARFDie.cpp:356
static Expected< StrOffsetsContributionDescriptor > parseDWARF32StringOffsetsTableHeader(DWARFDataExtractor &DA, uint64_t Offset)
Definition: DWARFUnit.cpp:812
bool isTypeUnit() const
Definition: DWARFUnit.h:291
bool extract(DWARFContext &Context, const DWARFDataExtractor &debug_info, uint64_t *offset_ptr, DWARFSectionKind Kind=DW_SECT_INFO, const DWARFUnitIndex *Index=nullptr, const DWARFUnitIndex::Entry *Entry=nullptr)
Parse a unit header from debug_info starting at offset_ptr.
Definition: DWARFUnit.cpp:234
std::shared_ptr< DWARFContext > getDWOContext(StringRef AbsolutePath)
static raw_ostream & error()
Convenience method for printing "error: " to stderr.
Definition: WithColor.cpp:60
static uint8_t getHeaderSize(dwarf::DwarfFormat Format)
Return the size of the table header including the length but not including the offsets.
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
Definition: Format.h:124
virtual StringRef getStrDWOSection() const
Definition: DWARFObject.h:63
virtual const DWARFSection & getLocSection() const
Definition: DWARFObject.h:40
DWARFDie getSibling(const DWARFDebugInfoEntry *Die)
Definition: DWARFUnit.cpp:696
uint32_t getU32(uint64_t *offset_ptr, Error *Err=nullptr) const
Extract a uint32_t value from *offset_ptr.
unsigned second
static raw_ostream & warning()
Convenience method for printing "warning: " to stderr.
Definition: WithColor.cpp:62
StringRef getData() const
Get the data pointed to by this extractor.
Definition: DataExtractor.h:92
virtual const DWARFSection & getRnglistsDWOSection() const
Definition: DWARFObject.h:68
block Block Frequency true
bool extractFast(const DWARFUnit &U, uint64_t *OffsetPtr)
Extracts a debug info entry, which is a child of a given unit, starting at a given offset...
Expected< StrOffsetsContributionDescriptor > validateContributionSize(DWARFDataExtractor &DA)
Determine whether a contribution to the string offsets table is consistent with the relevant section ...
Definition: DWARFUnit.cpp:778
const DWARFDebugAbbrev * getDebugAbbrevDWO()
Get a pointer to the parsed dwo abbreviations object.
uint8_t getDwarfStringOffsetsByteSize() const
Definition: DWARFUnit.h:335
void addUnitsForSection(DWARFContext &C, const DWARFSection &Section, DWARFSectionKind SectionKind)
Read units from a .debug_info or .debug_types section.
Definition: DWARFUnit.cpp:36
DWARFDie getSubroutineForAddress(uint64_t Address)
Returns subprogram DIE with address range encompassing the provided address.
Definition: DWARFUnit.cpp:633
virtual bool isLittleEndian() const =0
void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
Definition: Path.cpp:455
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:171
virtual const DWARFSection & getRangesSection() const
Definition: DWARFObject.h:48
std::string toString(Error E)
Write all error messages (if any) in E to a string.
Definition: Error.h:966
static ManagedStatic< DebugCounter > DC
DwarfFormat
Constants that define the DWARF format as 32 or 64 bit.
Definition: Dwarf.h:70
const char * getCompilationDir()
Definition: DWARFUnit.cpp:347
Optional< uint64_t > getRangesBaseAttribute() const
Extract the range base attribute from this DIE as absolute section offset.
Definition: DWARFDie.cpp:438
uint64_t getAbbrOffset() const
Definition: DWARFUnit.h:86
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:41
DWARFUnit * addUnit(std::unique_ptr< DWARFUnit > Unit)
Add an existing DWARFUnit to this UnitVector.
Definition: DWARFUnit.cpp:120
Tagged union holding either a T or a Error.
Definition: yaml2obj.h:21
LLVM_NODISCARD StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition: StringRef.h:592
bool isTypeUnit() const
Definition: DWARFUnit.h:96
uint8_t getAddressByteSize() const
Definition: DWARFUnit.h:284
Optional< object::SectionedAddress > toSectionedAddress(const Optional< DWARFFormValue > &V)
DWARFAddressRangesVector getAbsoluteRanges(llvm::Optional< object::SectionedAddress > BaseAddr) const
getAbsoluteRanges - Returns absolute address ranges defined by this range list.
virtual const DWARFSection & getStrOffsetsSection() const
Definition: DWARFObject.h:55
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...
LLVM_NODISCARD size_t size() const
size - Get the string size.
Definition: StringRef.h:144
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition: SmallString.h:25
llvm::Optional< object::SectionedAddress > getBaseAddress()
Definition: DWARFUnit.cpp:767
const DWARFDebugAbbrev * getDebugAbbrev()
Get a pointer to the parsed DebugAbbrev object.
virtual const DWARFSection & getStrOffsetsDWOSection() const
Definition: DWARFObject.h:64
DWARFDie getLastChild(const DWARFDebugInfoEntry *Die)
Definition: DWARFUnit.cpp:746
uint16_t getVersion() const
Definition: DWARFUnit.h:283
uint8_t getUnitLengthFieldByteSize(DwarfFormat Format)
Get the byte size of the unit length field depending on the DWARF format.
Definition: Dwarf.h:517
DWARFDie getSibling() const
Get the sibling of this DIE object.
Definition: DWARFDie.cpp:633
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:576
DWARFDie getFirstChild(const DWARFDebugInfoEntry *Die)
Definition: DWARFUnit.cpp:735
unit_iterator_range info_section_units()
Get units from .debug_info in this context.
Definition: DWARFContext.h:137
Optional< uint64_t > toSectionOffset(const Optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract an section offset.
virtual const DWARFSection & getRangesDWOSection() const
Definition: DWARFObject.h:67
Utility class that carries the DWARF compile/type unit and the debug info entry in an object...
Definition: DWARFDie.h:42
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
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.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
DWARFSectionKind
A structured debug information entry.
Definition: DIE.h:700
bool isSubroutineDIE() const
Returns true if DIE represents a subprogram or an inlined subroutine.
Definition: DWARFDie.cpp:358
Optional< uint64_t > getDWOId()
Definition: DWARFUnit.h:401
Expected< DWARFAddressRangesVector > collectAddressRanges()
Definition: DWARFUnit.cpp:588
Error tryExtractDIEsIfNeeded(bool CUDieOnly)
Definition: DWARFUnit.cpp:411
const DWARFAbbreviationDeclarationSet * getAbbreviationDeclarationSet(uint64_t CUAbbrOffset) const
Error extractHeaderAndOffsets(DWARFDataExtractor Data, uint64_t *OffsetPtr)
Extract the table header and the array of offsets.
DWARFDie getParent(const DWARFDebugInfoEntry *Die)
Definition: DWARFUnit.cpp:677
virtual const DWARFSection & getLineDWOSection() const
Definition: DWARFObject.h:61
SectionKind - This is a simple POD value that classifies the properties of a section.
Definition: SectionKind.h:22
Error extract(const DWARFDataExtractor &data, uint64_t *offset_ptr)
uint32_t getHeaderSize() const
Size in bytes of the parsed unit header.
Definition: DWARFUnit.h:249
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:328
void consumeError(Error Err)
Consume a Error without doing anything.
Definition: Error.h:981
const DWARFUnitIndex & getDWARFUnitIndex(DWARFContext &Context, DWARFSectionKind Kind)
Definition: DWARFUnit.cpp:669
auto find(R &&Range, const T &Val) -> decltype(adl_begin(Range))
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:1186
static Expected< DWARFDebugRnglistTable > parseRngListTableHeader(DWARFDataExtractor &DA, uint64_t Offset, DwarfFormat Format)
Definition: DWARFUnit.cpp:309
Base class describing the header of any kind of "unit." Some information is specific to certain unit ...
Definition: DWARFUnit.h:46
dwarf::DwarfFormat getFormat() const
Definition: DWARFUnit.h:79
UnitType
Constants for unit types in DWARF v5.
Definition: Dwarf.h:319
DWARFUnit * getUnitForIndexEntry(const DWARFUnitIndex::Entry &E)
Definition: DWARFUnit.cpp:142
A DataExtractor (typically for an in-memory copy of an object-file section) plus a relocation map for...
uint64_t getStringOffsetsBase() const
Definition: DWARFUnit.h:340
uint64_t getOffset() const
Definition: DWARFUnit.h:279
DWARFDie getUnitDIE(bool ExtractUnitDIEOnly=true)
Definition: DWARFUnit.h:386
const DWARFAbbreviationDeclaration * getAbbreviationDeclarationPtr() const
static ErrorSuccess success()
Create a success value.
Definition: Error.h:326
void setDWOId(uint64_t Id)
Definition: DWARFUnit.h:88
SmallVectorImpl< T >::const_pointer c_str(SmallVectorImpl< T > &str)
const DWARFUnitIndex::Entry * getIndexEntry() const
Definition: DWARFUnit.h:92
bool isValidOffsetForDataOfSize(uint64_t offset, uint64_t length) const
Test the availability of length bytes of data from offset.
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:555
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:47
static unsigned getDepth(const SmallVectorImpl< const MachineBasicBlock *> &Stack, const MachineBasicBlock *MBB)
DWARFContext This data structure is the top level entity that deals with dwarf debug information pars...
Definition: DWARFContext.h:58
Expected< Optional< StrOffsetsContributionDescriptor > > determineStringOffsetsTableContribution(DWARFDataExtractor &DA)
Find the unit&#39;s contribution to the string offsets table and determine its length and form...
Definition: DWARFUnit.cpp:857
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
Describe a collection of units.
Definition: DWARFUnit.h:113
Optional< const char * > toString(const Optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract a string value from it.
bool isValidOffset(uint64_t offset) const
Test the validity of offset.
virtual const DWARFSection & getRnglistsSection() const
Definition: DWARFObject.h:49
DWARFDataExtractor getDebugInfoExtractor() const
Definition: DWARFUnit.cpp:195
static Expected< StrOffsetsContributionDescriptor > parseDWARF64StringOffsetsTableHeader(DWARFDataExtractor &DA, uint64_t Offset)
Definition: DWARFUnit.cpp:794
virtual const DWARFSection & getLineSection() const
Definition: DWARFObject.h:45
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition: Alignment.h:133
static bool isSupportedVersion(unsigned version)
Definition: DWARFContext.h:338
dwarf::Tag getTag() const
Definition: DWARFDie.h:71
LLVM_NODISCARD bool empty() const
Definition: SmallVector.h:55
#define I(x, y, z)
Definition: MD5.cpp:58
bool is_relative(const Twine &path, Style style=Style::native)
Is path relative?
Definition: Path.cpp:674
Expected< DWARFAddressRangesVector > getAddressRanges() const
Get the address ranges for this DIE.
Definition: DWARFDie.cpp:471
DWARFDie getPreviousSibling(const DWARFDebugInfoEntry *Die)
Definition: DWARFUnit.cpp:716
uint32_t Size
Definition: Profile.cpp:46
void updateAddressDieMap(DWARFDie Die)
Recursively update address to Die map.
Definition: DWARFUnit.cpp:602
Optional< uint64_t > getRnglistOffset(uint32_t Index)
Return a rangelist&#39;s offset based on an index.
Definition: DWARFUnit.h:419
void setRangesSection(const DWARFSection *RS, uint64_t Base)
Definition: DWARFUnit.h:307
bool isLittleEndian() const
Definition: DWARFContext.h:337
const DWARFObject & getDWARFObj() const
Definition: DWARFContext.h:116
const DWARFUnitIndex & getCUIndex()
LLVM_NODISCARD const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Definition: StringRef.h:136
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
DwarfFormat Format
Definition: Dwarf.h:491
Optional< DWARFFormValue > find(dwarf::Attribute Attr) const
Extract the specified attribute from this DIE.
Definition: DWARFDie.cpp:363
DWARFDebugInfoEntry - A DIE with only the minimum required data.
DWARFDie getFirstChild() const
Get the first child of this DIE object.
Definition: DWARFDie.cpp:645
uint64_t getLength() const
Definition: DWARFUnit.h:289
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
const Entry * getFromOffset(uint32_t Offset) const
const SectionContribution * getOffset(DWARFSectionKind Sec) const
uint64_t getU64(uint64_t *offset_ptr, Error *Err=nullptr) const
Extract a uint64_t value from *offset_ptr.
Optional< object::SectionedAddress > getAddrOffsetSectionItem(uint32_t Index) const
Definition: DWARFUnit.cpp:201
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
uint8_t getDwarfOffsetByteSize() const
The size of a reference is determined by the DWARF 32/64-bit format.
Definition: Dwarf.h:503
const uint64_t Version
Definition: InstrProf.h:984
uint8_t getDwarfOffsetByteSize() const
Definition: DWARFUnit.h:286
void setMaxVersionIfGreater(unsigned Version)
Definition: DWARFContext.h:245
StringRef LocSectionData
Definition: DWARFUnit.h:206
Optional< uint64_t > toUnsigned(const Optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract an unsigned constant.
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition: Error.h:1177
Optional< uint64_t > getStringOffsetSectionItem(uint32_t Index) const
Definition: DWARFUnit.cpp:222
DWARFDie getParent() const
Get the parent of this DIE object.
Definition: DWARFDie.cpp:627
auto upper_bound(R &&Range, T &&Value) -> decltype(adl_begin(Range))
Provide wrappers to std::upper_bound which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:1276