LLVM  8.0.0svn
DWARFDie.cpp
Go to the documentation of this file.
1 //===- DWARFDie.cpp -------------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
11 #include "llvm/ADT/None.h"
12 #include "llvm/ADT/Optional.h"
13 #include "llvm/ADT/SmallSet.h"
14 #include "llvm/ADT/StringRef.h"
22 #include "llvm/Object/ObjectFile.h"
24 #include "llvm/Support/Format.h"
27 #include "llvm/Support/WithColor.h"
29 #include <algorithm>
30 #include <cassert>
31 #include <cinttypes>
32 #include <cstdint>
33 #include <string>
34 #include <utility>
35 
36 using namespace llvm;
37 using namespace dwarf;
38 using namespace object;
39 
40 static void dumpApplePropertyAttribute(raw_ostream &OS, uint64_t Val) {
41  OS << " (";
42  do {
43  uint64_t Shift = countTrailingZeros(Val);
44  assert(Shift < 64 && "undefined behavior");
45  uint64_t Bit = 1ULL << Shift;
46  auto PropName = ApplePropertyString(Bit);
47  if (!PropName.empty())
48  OS << PropName;
49  else
50  OS << format("DW_APPLE_PROPERTY_0x%" PRIx64, Bit);
51  if (!(Val ^= Bit))
52  break;
53  OS << ", ";
54  } while (true);
55  OS << ")";
56 }
57 
58 static void dumpRanges(const DWARFObject &Obj, raw_ostream &OS,
59  const DWARFAddressRangesVector &Ranges,
60  unsigned AddressSize, unsigned Indent,
61  const DIDumpOptions &DumpOpts) {
62  ArrayRef<SectionName> SectionNames;
63  if (DumpOpts.Verbose)
64  SectionNames = Obj.getSectionNames();
65 
66  for (const DWARFAddressRange &R : Ranges) {
67 
68  OS << '\n';
69  OS.indent(Indent);
70  R.dump(OS, AddressSize);
71 
72  if (SectionNames.empty() || R.SectionIndex == -1ULL)
73  continue;
74 
75  StringRef Name = SectionNames[R.SectionIndex].Name;
76  OS << " \"" << Name << '\"';
77 
78  // Print section index if name is not unique.
79  if (!SectionNames[R.SectionIndex].IsNameUnique)
80  OS << format(" [%" PRIu64 "]", R.SectionIndex);
81  }
82 }
83 
84 static void dumpLocation(raw_ostream &OS, DWARFFormValue &FormValue,
85  DWARFUnit *U, unsigned Indent,
86  DIDumpOptions DumpOpts) {
87  DWARFContext &Ctx = U->getContext();
88  const DWARFObject &Obj = Ctx.getDWARFObj();
89  const MCRegisterInfo *MRI = Ctx.getRegisterInfo();
90  if (FormValue.isFormClass(DWARFFormValue::FC_Block) ||
92  ArrayRef<uint8_t> Expr = *FormValue.getAsBlock();
93  DataExtractor Data(StringRef((const char *)Expr.data(), Expr.size()),
94  Ctx.isLittleEndian(), 0);
96  .print(OS, MRI);
97  return;
98  }
99 
100  FormValue.dump(OS, DumpOpts);
102  const DWARFSection &LocSection = Obj.getLocSection();
103  const DWARFSection &LocDWOSection = Obj.getLocDWOSection();
104  uint32_t Offset = *FormValue.getAsSectionOffset();
105  if (!LocSection.Data.empty()) {
107  DWARFDataExtractor Data(Obj, LocSection, Ctx.isLittleEndian(),
108  Obj.getAddressSize());
109  auto LL = DebugLoc.parseOneLocationList(Data, &Offset);
110  if (LL) {
111  uint64_t BaseAddr = 0;
113  BaseAddr = BA->Address;
114  LL->dump(OS, Ctx.isLittleEndian(), Obj.getAddressSize(), MRI, BaseAddr,
115  Indent);
116  } else
117  OS << "error extracting location list.";
118  } else if (!LocDWOSection.Data.empty()) {
119  DataExtractor Data(LocDWOSection.Data, Ctx.isLittleEndian(), 0);
120  auto LL = DWARFDebugLocDWO::parseOneLocationList(Data, &Offset);
121  if (LL)
122  LL->dump(OS, Ctx.isLittleEndian(), Obj.getAddressSize(), MRI, Indent);
123  else
124  OS << "error extracting location list.";
125  }
126  }
127 }
128 
129 /// Dump the name encoded in the type tag.
131  StringRef TagStr = TagString(T);
132  if (!TagStr.startswith("DW_TAG_") || !TagStr.endswith("_type"))
133  return;
134  OS << TagStr.substr(7, TagStr.size() - 12) << " ";
135 }
136 
137 /// Recursively dump the DIE type name when applicable.
138 static void dumpTypeName(raw_ostream &OS, const DWARFDie &Die) {
139  DWARFDie D = Die.getAttributeValueAsReferencedDie(DW_AT_type);
140 
141  if (!D.isValid())
142  return;
143 
144  if (const char *Name = D.getName(DINameKind::LinkageName)) {
145  OS << Name;
146  return;
147  }
148 
149  // FIXME: We should have pretty printers per language. Currently we print
150  // everything as if it was C++ and fall back to the TAG type name.
151  const dwarf::Tag T = D.getTag();
152  switch (T) {
153  case DW_TAG_array_type:
154  case DW_TAG_pointer_type:
155  case DW_TAG_ptr_to_member_type:
156  case DW_TAG_reference_type:
157  case DW_TAG_rvalue_reference_type:
158  break;
159  default:
160  dumpTypeTagName(OS, T);
161  }
162 
163  // Follow the DW_AT_type if possible.
164  dumpTypeName(OS, D);
165 
166  switch (T) {
167  case DW_TAG_array_type:
168  OS << "[]";
169  break;
170  case DW_TAG_pointer_type:
171  OS << '*';
172  break;
173  case DW_TAG_ptr_to_member_type:
174  OS << '*';
175  break;
176  case DW_TAG_reference_type:
177  OS << '&';
178  break;
179  case DW_TAG_rvalue_reference_type:
180  OS << "&&";
181  break;
182  default:
183  break;
184  }
185 }
186 
187 static void dumpAttribute(raw_ostream &OS, const DWARFDie &Die,
188  uint32_t *OffsetPtr, dwarf::Attribute Attr,
189  dwarf::Form Form, unsigned Indent,
190  DIDumpOptions DumpOpts) {
191  if (!Die.isValid())
192  return;
193  const char BaseIndent[] = " ";
194  OS << BaseIndent;
195  OS.indent(Indent + 2);
196  WithColor(OS, HighlightColor::Attribute) << formatv("{0}", Attr);
197 
198  if (DumpOpts.Verbose || DumpOpts.ShowForm)
199  OS << formatv(" [{0}]", Form);
200 
201  DWARFUnit *U = Die.getDwarfUnit();
202  DWARFFormValue formValue(Form);
203 
204  if (!formValue.extractValue(U->getDebugInfoExtractor(), OffsetPtr,
205  U->getFormParams(), U))
206  return;
207 
208  OS << "\t(";
209 
210  StringRef Name;
211  std::string File;
213  if (Attr == DW_AT_decl_file || Attr == DW_AT_call_file) {
215  if (const auto *LT = U->getContext().getLineTableForUnit(U))
216  if (LT->getFileNameByIndex(
217  formValue.getAsUnsignedConstant().getValue(),
218  U->getCompilationDir(),
220  File = '"' + File + '"';
221  Name = File;
222  }
223  } else if (Optional<uint64_t> Val = formValue.getAsUnsignedConstant())
224  Name = AttributeValueString(Attr, *Val);
225 
226  if (!Name.empty())
227  WithColor(OS, Color) << Name;
228  else if (Attr == DW_AT_decl_line || Attr == DW_AT_call_line)
229  OS << *formValue.getAsUnsignedConstant();
230  else if (Attr == DW_AT_high_pc && !DumpOpts.ShowForm && !DumpOpts.Verbose &&
231  formValue.getAsUnsignedConstant()) {
232  if (DumpOpts.ShowAddresses) {
233  // Print the actual address rather than the offset.
234  uint64_t LowPC, HighPC, Index;
235  if (Die.getLowAndHighPC(LowPC, HighPC, Index))
236  OS << format("0x%016" PRIx64, HighPC);
237  else
238  formValue.dump(OS, DumpOpts);
239  }
240  } else if (Attr == DW_AT_location || Attr == DW_AT_frame_base ||
241  Attr == DW_AT_data_member_location ||
242  Attr == DW_AT_GNU_call_site_value)
243  dumpLocation(OS, formValue, U, sizeof(BaseIndent) + Indent + 4, DumpOpts);
244  else
245  formValue.dump(OS, DumpOpts);
246 
247  std::string Space = DumpOpts.ShowAddresses ? " " : "";
248 
249  // We have dumped the attribute raw value. For some attributes
250  // having both the raw value and the pretty-printed value is
251  // interesting. These attributes are handled below.
252  if (Attr == DW_AT_specification || Attr == DW_AT_abstract_origin) {
253  if (const char *Name = Die.getAttributeValueAsReferencedDie(Attr).getName(
255  OS << Space << "\"" << Name << '\"';
256  } else if (Attr == DW_AT_type) {
257  OS << Space << "\"";
258  dumpTypeName(OS, Die);
259  OS << '"';
260  } else if (Attr == DW_AT_APPLE_property_attribute) {
261  if (Optional<uint64_t> OptVal = formValue.getAsUnsignedConstant())
262  dumpApplePropertyAttribute(OS, *OptVal);
263  } else if (Attr == DW_AT_ranges) {
264  const DWARFObject &Obj = Die.getDwarfUnit()->getContext().getDWARFObj();
265  // For DW_FORM_rnglistx we need to dump the offset separately, since
266  // we have only dumped the index so far.
267  Optional<DWARFFormValue> Value = Die.find(DW_AT_ranges);
268  if (Value && Value->getForm() == DW_FORM_rnglistx)
269  if (auto RangeListOffset =
270  U->getRnglistOffset(*Value->getAsSectionOffset())) {
271  DWARFFormValue FV(dwarf::DW_FORM_sec_offset);
272  FV.setUValue(*RangeListOffset);
273  FV.dump(OS, DumpOpts);
274  }
275  if (auto RangesOrError = Die.getAddressRanges())
276  dumpRanges(Obj, OS, RangesOrError.get(), U->getAddressByteSize(),
277  sizeof(BaseIndent) + Indent + 4, DumpOpts);
278  else
279  WithColor::error() << "decoding address ranges: "
280  << toString(RangesOrError.takeError()) << '\n';
281  }
282 
283  OS << ")\n";
284 }
285 
286 bool DWARFDie::isSubprogramDIE() const { return getTag() == DW_TAG_subprogram; }
287 
289  auto Tag = getTag();
290  return Tag == DW_TAG_subprogram || Tag == DW_TAG_inlined_subroutine;
291 }
292 
294  if (!isValid())
295  return None;
296  auto AbbrevDecl = getAbbreviationDeclarationPtr();
297  if (AbbrevDecl)
298  return AbbrevDecl->getAttributeValue(getOffset(), Attr, *U);
299  return None;
300 }
301 
304  if (!isValid())
305  return None;
306  auto AbbrevDecl = getAbbreviationDeclarationPtr();
307  if (AbbrevDecl) {
308  for (auto Attr : Attrs) {
309  if (auto Value = AbbrevDecl->getAttributeValue(getOffset(), Attr, *U))
310  return Value;
311  }
312  }
313  return None;
314 }
315 
318  std::vector<DWARFDie> Worklist;
319  Worklist.push_back(*this);
320 
321  // Keep track if DIEs already seen to prevent infinite recursion.
322  // Empirically we rarely see a depth of more than 3 when dealing with valid
323  // DWARF. This corresponds to following the DW_AT_abstract_origin and
324  // DW_AT_specification just once.
326 
327  while (!Worklist.empty()) {
328  DWARFDie Die = Worklist.back();
329  Worklist.pop_back();
330 
331  if (!Die.isValid())
332  continue;
333 
334  if (Seen.count(Die))
335  continue;
336 
337  Seen.insert(Die);
338 
339  if (auto Value = Die.find(Attrs))
340  return Value;
341 
342  if (auto D = Die.getAttributeValueAsReferencedDie(DW_AT_abstract_origin))
343  Worklist.push_back(D);
344 
345  if (auto D = Die.getAttributeValueAsReferencedDie(DW_AT_specification))
346  Worklist.push_back(D);
347  }
348 
349  return None;
350 }
351 
352 DWARFDie
354  if (auto SpecRef = toReference(find(Attr))) {
355  if (auto SpecUnit = U->getUnitVector().getUnitForOffset(*SpecRef))
356  return SpecUnit->getDIEForOffset(*SpecRef);
357  }
358  return DWARFDie();
359 }
360 
362  return toSectionOffset(find({DW_AT_rnglists_base, DW_AT_GNU_ranges_base}));
363 }
364 
366  if (auto FormValue = find(DW_AT_high_pc)) {
367  if (auto Address = FormValue->getAsAddress()) {
368  // High PC is an address.
369  return Address;
370  }
371  if (auto Offset = FormValue->getAsUnsignedConstant()) {
372  // High PC is an offset from LowPC.
373  return LowPC + *Offset;
374  }
375  }
376  return None;
377 }
378 
379 bool DWARFDie::getLowAndHighPC(uint64_t &LowPC, uint64_t &HighPC,
380  uint64_t &SectionIndex) const {
381  auto F = find(DW_AT_low_pc);
382  auto LowPcAddr = toAddress(F);
383  if (!LowPcAddr)
384  return false;
385  if (auto HighPcAddr = getHighPC(*LowPcAddr)) {
386  LowPC = *LowPcAddr;
387  HighPC = *HighPcAddr;
388  SectionIndex = F->getSectionIndex();
389  return true;
390  }
391  return false;
392 }
393 
395  if (isNULL())
396  return DWARFAddressRangesVector();
397  // Single range specified by low/high PC.
398  uint64_t LowPC, HighPC, Index;
399  if (getLowAndHighPC(LowPC, HighPC, Index))
400  return DWARFAddressRangesVector{{LowPC, HighPC, Index}};
401 
402  Optional<DWARFFormValue> Value = find(DW_AT_ranges);
403  if (Value) {
404  if (Value->getForm() == DW_FORM_rnglistx)
405  return U->findRnglistFromIndex(*Value->getAsSectionOffset());
406  return U->findRnglistFromOffset(*Value->getAsSectionOffset());
407  }
408  return DWARFAddressRangesVector();
409 }
410 
412  DWARFAddressRangesVector &Ranges) const {
413  if (isNULL())
414  return;
415  if (isSubprogramDIE()) {
416  if (auto DIERangesOrError = getAddressRanges())
417  Ranges.insert(Ranges.end(), DIERangesOrError.get().begin(),
418  DIERangesOrError.get().end());
419  else
420  llvm::consumeError(DIERangesOrError.takeError());
421  }
422 
423  for (auto Child : children())
424  Child.collectChildrenAddressRanges(Ranges);
425 }
426 
427 bool DWARFDie::addressRangeContainsAddress(const uint64_t Address) const {
428  auto RangesOrError = getAddressRanges();
429  if (!RangesOrError) {
430  llvm::consumeError(RangesOrError.takeError());
431  return false;
432  }
433 
434  for (const auto &R : RangesOrError.get())
435  if (R.LowPC <= Address && Address < R.HighPC)
436  return true;
437  return false;
438 }
439 
441  if (!isSubroutineDIE())
442  return nullptr;
443  return getName(Kind);
444 }
445 
446 const char *DWARFDie::getName(DINameKind Kind) const {
447  if (!isValid() || Kind == DINameKind::None)
448  return nullptr;
449  // Try to get mangled name only if it was asked for.
450  if (Kind == DINameKind::LinkageName) {
451  if (auto Name = dwarf::toString(
452  findRecursively({DW_AT_MIPS_linkage_name, DW_AT_linkage_name}),
453  nullptr))
454  return Name;
455  }
456  if (auto Name = dwarf::toString(findRecursively(DW_AT_name), nullptr))
457  return Name;
458  return nullptr;
459 }
460 
461 uint64_t DWARFDie::getDeclLine() const {
462  return toUnsigned(findRecursively(DW_AT_decl_line), 0);
463 }
464 
465 void DWARFDie::getCallerFrame(uint32_t &CallFile, uint32_t &CallLine,
466  uint32_t &CallColumn,
467  uint32_t &CallDiscriminator) const {
468  CallFile = toUnsigned(find(DW_AT_call_file), 0);
469  CallLine = toUnsigned(find(DW_AT_call_line), 0);
470  CallColumn = toUnsigned(find(DW_AT_call_column), 0);
471  CallDiscriminator = toUnsigned(find(DW_AT_GNU_discriminator), 0);
472 }
473 
474 /// Helper to dump a DIE with all of its parents, but no siblings.
475 static unsigned dumpParentChain(DWARFDie Die, raw_ostream &OS, unsigned Indent,
476  DIDumpOptions DumpOpts) {
477  if (!Die)
478  return Indent;
479  Indent = dumpParentChain(Die.getParent(), OS, Indent, DumpOpts);
480  Die.dump(OS, Indent, DumpOpts);
481  return Indent + 2;
482 }
483 
484 void DWARFDie::dump(raw_ostream &OS, unsigned Indent,
485  DIDumpOptions DumpOpts) const {
486  if (!isValid())
487  return;
488  DWARFDataExtractor debug_info_data = U->getDebugInfoExtractor();
489  const uint32_t Offset = getOffset();
490  uint32_t offset = Offset;
491  if (DumpOpts.ShowParents) {
492  DIDumpOptions ParentDumpOpts = DumpOpts;
493  ParentDumpOpts.ShowParents = false;
494  ParentDumpOpts.ShowChildren = false;
495  Indent = dumpParentChain(getParent(), OS, Indent, ParentDumpOpts);
496  }
497 
498  if (debug_info_data.isValidOffset(offset)) {
499  uint32_t abbrCode = debug_info_data.getULEB128(&offset);
500  if (DumpOpts.ShowAddresses)
502  << format("\n0x%8.8x: ", Offset);
503 
504  if (abbrCode) {
505  auto AbbrevDecl = getAbbreviationDeclarationPtr();
506  if (AbbrevDecl) {
507  WithColor(OS, HighlightColor::Tag).get().indent(Indent)
508  << formatv("{0}", getTag());
509  if (DumpOpts.Verbose)
510  OS << format(" [%u] %c", abbrCode,
511  AbbrevDecl->hasChildren() ? '*' : ' ');
512  OS << '\n';
513 
514  // Dump all data in the DIE for the attributes.
515  for (const auto &AttrSpec : AbbrevDecl->attributes()) {
516  if (AttrSpec.Form == DW_FORM_implicit_const) {
517  // We are dumping .debug_info section ,
518  // implicit_const attribute values are not really stored here,
519  // but in .debug_abbrev section. So we just skip such attrs.
520  continue;
521  }
522  dumpAttribute(OS, *this, &offset, AttrSpec.Attr, AttrSpec.Form,
523  Indent, DumpOpts);
524  }
525 
526  DWARFDie child = getFirstChild();
527  if (DumpOpts.ShowChildren && DumpOpts.RecurseDepth > 0 && child) {
528  DumpOpts.RecurseDepth--;
529  DIDumpOptions ChildDumpOpts = DumpOpts;
530  ChildDumpOpts.ShowParents = false;
531  while (child) {
532  child.dump(OS, Indent + 2, ChildDumpOpts);
533  child = child.getSibling();
534  }
535  }
536  } else {
537  OS << "Abbreviation code not found in 'debug_abbrev' class for code: "
538  << abbrCode << '\n';
539  }
540  } else {
541  OS.indent(Indent) << "NULL\n";
542  }
543  }
544 }
545 
547 
549  if (isValid())
550  return U->getParent(Die);
551  return DWARFDie();
552 }
553 
555  if (isValid())
556  return U->getSibling(Die);
557  return DWARFDie();
558 }
559 
561  if (isValid())
562  return U->getPreviousSibling(Die);
563  return DWARFDie();
564 }
565 
567  if (isValid())
568  return U->getFirstChild(Die);
569  return DWARFDie();
570 }
571 
573  if (isValid())
574  return U->getLastChild(Die);
575  return DWARFDie();
576 }
577 
579  return make_range(attribute_iterator(*this, false),
580  attribute_iterator(*this, true));
581 }
582 
584  : Die(D), AttrValue(0), Index(0) {
585  auto AbbrDecl = Die.getAbbreviationDeclarationPtr();
586  assert(AbbrDecl && "Must have abbreviation declaration");
587  if (End) {
588  // This is the end iterator so we set the index to the attribute count.
589  Index = AbbrDecl->getNumAttributes();
590  } else {
591  // This is the begin iterator so we extract the value for this->Index.
592  AttrValue.Offset = D.getOffset() + AbbrDecl->getCodeByteSize();
593  updateForIndex(*AbbrDecl, 0);
594  }
595 }
596 
597 void DWARFDie::attribute_iterator::updateForIndex(
598  const DWARFAbbreviationDeclaration &AbbrDecl, uint32_t I) {
599  Index = I;
600  // AbbrDecl must be valid before calling this function.
601  auto NumAttrs = AbbrDecl.getNumAttributes();
602  if (Index < NumAttrs) {
603  AttrValue.Attr = AbbrDecl.getAttrByIndex(Index);
604  // Add the previous byte size of any previous attribute value.
605  AttrValue.Offset += AttrValue.ByteSize;
606  AttrValue.Value.setForm(AbbrDecl.getFormByIndex(Index));
607  uint32_t ParseOffset = AttrValue.Offset;
608  auto U = Die.getDwarfUnit();
609  assert(U && "Die must have valid DWARF unit");
610  bool b = AttrValue.Value.extractValue(U->getDebugInfoExtractor(),
611  &ParseOffset, U->getFormParams(), U);
612  (void)b;
613  assert(b && "extractValue cannot fail on fully parsed DWARF");
614  AttrValue.ByteSize = ParseOffset - AttrValue.Offset;
615  } else {
616  assert(Index == NumAttrs && "Indexes should be [0, NumAttrs) only");
617  AttrValue.clear();
618  }
619 }
620 
622  if (auto AbbrDecl = Die.getAbbreviationDeclarationPtr())
623  updateForIndex(*AbbrDecl, Index + 1);
624  return *this;
625 }
void dump(raw_ostream &OS, DIDumpOptions DumpOpts=DIDumpOptions()) const
const NoneType None
Definition: None.h:24
iterator_range< typename GraphTraits< GraphType >::ChildIteratorType > children(const typename GraphTraits< GraphType >::NodeRef &G)
Definition: GraphTraits.h:122
StringRef ApplePropertyString(unsigned)
Definition: Dwarf.cpp:469
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
DWARFUnit * getDwarfUnit() const
Definition: DWARFDie.h:54
bool isValid() const
Definition: DWARFDie.h:51
uint64_t getULEB128(uint32_t *offset_ptr) const
Extract a unsigned LEB128 value from *offset_ptr.
virtual const DWARFSection & getLocDWOSection() const
Definition: DWARFObject.h:60
dwarf::Attribute Attr
The attribute enumeration of this attribute.
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
bool isSubprogramDIE() const
Returns true if DIE represents a subprogram (not inlined).
Definition: DWARFDie.cpp:286
An RAII object that temporarily switches an output stream to a specific color.
Definition: WithColor.h:37
bool addressRangeContainsAddress(const uint64_t Address) const
Definition: DWARFDie.cpp:427
Attribute
Attributes.
Definition: Dwarf.h:114
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
Definition: StringRef.h:138
static raw_ostream & error()
Convenience method for printing "error: " to stderr.
Definition: WithColor.cpp:63
attribute_iterator & operator++()
Definition: DWARFDie.cpp:621
uint32_t ByteSize
The debug info/types section byte size of the data for this attribute.
void collectChildrenAddressRanges(DWARFAddressRangesVector &Ranges) const
Get all address ranges for any DW_TAG_subprogram DIEs in this DIE or any of its children.
Definition: DWARFDie.cpp:411
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
Definition: Format.h:124
const DWARFAbbreviationDeclaration * getAbbreviationDeclarationPtr() const
Get the abbreviation declaration for this DIE.
Definition: DWARFDie.h:59
raw_ostream & indent(unsigned NumSpaces)
indent - Insert &#39;NumSpaces&#39; spaces.
virtual const DWARFSection & getLocSection() const
Definition: DWARFObject.h:40
static unsigned dumpParentChain(DWARFDie Die, raw_ostream &OS, unsigned Indent, DIDumpOptions DumpOpts)
Helper to dump a DIE with all of its parents, but no siblings.
Definition: DWARFDie.cpp:475
void setUValue(uint64_t V)
auto formatv(const char *Fmt, Ts &&... Vals) -> formatv_object< decltype(std::make_tuple(detail::build_format_adapter(std::forward< Ts >(Vals))...))>
const DWARFDebugLine::LineTable * getLineTableForUnit(DWARFUnit *U)
Get a pointer to a parsed line table corresponding to a compile unit.
DWARFDie getAttributeValueAsReferencedDie(dwarf::Attribute Attr) const
Extract the specified attribute from this DIE as the referenced DIE.
Definition: DWARFDie.cpp:353
A debug info location.
Definition: DebugLoc.h:34
F(f)
DINameKind
A DINameKind is passed to name search methods to specify a preference regarding the type of name reso...
Definition: DIContext.h:114
bool isFormClass(FormClass FC) const
void dump(raw_ostream &OS, unsigned indent=0, DIDumpOptions DumpOpts=DIDumpOptions()) const
Dump the DIE and all of its attributes to the supplied stream.
Definition: DWARFDie.cpp:484
Optional< uint64_t > toAddress(const Optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract an address.
const dwarf::FormParams & getFormParams() const
Definition: DWARFUnit.h:272
dwarf::Form getForm() const
DWARFFormValue Value
The form and value for this attribute.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool endswith(StringRef Suffix) const
Check if this string ends with the given Suffix.
Definition: StringRef.h:279
const char * getCompilationDir()
Definition: DWARFUnit.cpp:315
Optional< uint64_t > getRangesBaseAttribute() const
Extract the range base attribute from this DIE as absolute section offset.
Definition: DWARFDie.cpp:361
Optional< ArrayRef< uint8_t > > getAsBlock() const
static void dumpAttribute(raw_ostream &OS, const DWARFDie &Die, uint32_t *OffsetPtr, dwarf::Attribute Attr, dwarf::Form Form, unsigned Indent, DIDumpOptions DumpOpts)
Definition: DWARFDie.cpp:187
static StringRef getName(Value *V)
void getCallerFrame(uint32_t &CallFile, uint32_t &CallLine, uint32_t &CallColumn, uint32_t &CallDiscriminator) const
Retrieves values of DW_AT_call_file, DW_AT_call_line and DW_AT_call_column from DIE (or zeroes if the...
Definition: DWARFDie.cpp:465
static void dumpTypeName(raw_ostream &OS, const DWARFDie &Die)
Recursively dump the DIE type name when applicable.
Definition: DWARFDie.cpp:138
Tagged union holding either a T or a Error.
Definition: CachePruning.h:23
#define LLVM_DUMP_METHOD
Definition: Compiler.h:74
const MCRegisterInfo * getRegisterInfo() const
Definition: DWARFContext.h:327
void setForm(dwarf::Form F)
uint32_t getOffset() const
Get the absolute offset into the debug info or types section.
Definition: DWARFDie.h:67
uint8_t getAddressByteSize() const
Definition: DWARFUnit.h:276
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition: StringRef.h:267
static void dumpApplePropertyAttribute(raw_ostream &OS, uint64_t Val)
Definition: DWARFDie.cpp:40
dwarf::Form getFormByIndex(uint32_t idx) const
const T & getValue() const LLVM_LVALUE_FUNCTION
Definition: Optional.h:179
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:133
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
static void dumpRanges(const DWARFObject &Obj, raw_ostream &OS, const DWARFAddressRangesVector &Ranges, unsigned AddressSize, unsigned Indent, const DIDumpOptions &DumpOpts)
Definition: DWARFDie.cpp:58
static Error getOffset(const SymbolRef &Sym, SectionRef Sec, uint64_t &Result)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition: StringRef.h:598
bool getLowAndHighPC(uint64_t &LowPC, uint64_t &HighPC, uint64_t &SectionIndex) const
Retrieves DW_AT_low_pc and DW_AT_high_pc from CU.
Definition: DWARFDie.cpp:379
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
uint16_t getVersion() const
Definition: DWARFUnit.h:275
DWARFDie getSibling() const
Get the sibling of this DIE object.
Definition: DWARFDie.cpp:554
StringRef AttributeValueString(uint16_t Attr, unsigned Val)
Returns the symbolic string representing Val when used as a value for attribute Attr.
Definition: Dwarf.cpp:543
uint64_t getDeclLine() const
Returns the declaration line (start line) for a DIE, assuming it specifies a subprogram.
Definition: DWARFDie.cpp:461
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
Container for dump options that control which debug information will be dumped.
Definition: DIContext.h:154
raw_ostream & get()
Definition: WithColor.h:47
Optional< uint64_t > toSectionOffset(const Optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract an section offset.
Utility class that carries the DWARF compile/type unit and the debug info entry in an object...
Definition: DWARFDie.h:43
Optional< uint64_t > toReference(const Optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract an reference.
DWARFDie getLastChild() const
Get the last child of this DIE object.
Definition: DWARFDie.cpp:572
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
unsigned const MachineRegisterInfo * MRI
std::size_t countTrailingZeros(T Val, ZeroBehavior ZB=ZB_Width)
Count number of 0&#39;s from the least significant bit to the most stopping at the first 1...
Definition: MathExtras.h:120
virtual uint8_t getAddressSize() const
Definition: DWARFObject.h:35
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:149
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
Definition: SmallSet.h:135
bool isSubroutineDIE() const
Returns true if DIE represents a subprogram or an inlined subroutine.
Definition: DWARFDie.cpp:288
Optional< DWARFFormValue > findRecursively(ArrayRef< dwarf::Attribute > Attrs) const
Extract the first value of any attribute in Attrs from this DIE and recurse into any DW_AT_specificat...
Definition: DWARFDie.cpp:317
Optional< uint64_t > getAsUnsignedConstant() const
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
DWARFContext & getContext() const
Definition: DWARFUnit.h:269
std::pair< NoneType, bool > insert(const T &V)
insert - Insert an element into the set if it isn&#39;t already there.
Definition: SmallSet.h:181
Optional< LocationList > parseOneLocationList(DWARFDataExtractor Data, uint32_t *Offset)
void consumeError(Error Err)
Consume a Error without doing anything.
Definition: Error.h:978
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:1063
static Optional< LocationList > parseOneLocationList(DataExtractor Data, uint32_t *Offset)
const T * data() const
Definition: ArrayRef.h:146
llvm::Optional< BaseAddress > getBaseAddress()
Definition: DWARFUnit.cpp:751
unsigned getTag(StringRef TagString)
Definition: Dwarf.cpp:32
A DataExtractor (typically for an in-memory copy of an object-file section) plus a relocation map for...
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
const char * getName(DINameKind Kind) const
Return the DIE name resolving DW_AT_sepcification or DW_AT_abstract_origin references if necessary...
Definition: DWARFDie.cpp:446
Color
A "color", which is either even or odd.
DWARFDie getPreviousSibling() const
Get the previous sibling of this DIE object.
Definition: DWARFDie.cpp:560
Definition: JSON.cpp:595
uint32_t Offset
The debug info/types offset for this attribute.
DWARFContext This data structure is the top level entity that deals with dwarf debug information pars...
Definition: DWARFContext.h:59
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
iterator_range< attribute_iterator > attributes() const
Get an iterator range to all attributes in the current DIE only.
Definition: DWARFDie.cpp:578
Optional< const char * > toString(const Optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract a string value from it.
A range adaptor for a pair of iterators.
This file contains constants used for implementing Dwarf debug support.
DWARFDataExtractor getDebugInfoExtractor() const
Definition: DWARFUnit.cpp:181
unsigned RecurseDepth
Definition: DIContext.h:156
bool extractValue(const DWARFDataExtractor &Data, uint32_t *OffsetPtr, dwarf::FormParams FormParams, const DWARFContext *Context=nullptr, const DWARFUnit *Unit=nullptr)
Extracts a value in Data at offset *OffsetPtr.
StringRef TagString(unsigned Tag)
Definition: Dwarf.cpp:21
LLVM_DUMP_METHOD void dump() const
Convenience zero-argument overload for debugging.
Definition: DWARFDie.cpp:546
dwarf::Tag getTag() const
Definition: DWARFDie.h:72
#define I(x, y, z)
Definition: MD5.cpp:58
virtual ArrayRef< SectionName > getSectionNames() const
Definition: DWARFObject.h:33
Expected< DWARFAddressRangesVector > getAddressRanges() const
Get the address ranges for this DIE.
Definition: DWARFDie.cpp:394
bool isLittleEndian() const
Definition: DWARFContext.h:320
const DWARFObject & getDWARFObj() const
Definition: DWARFContext.h:117
Optional< uint64_t > getHighPC(uint64_t LowPC) const
Get the DW_AT_high_pc attribute value as an address.
Definition: DWARFDie.cpp:365
bool isValidOffset(uint32_t offset) const
Test the validity of offset.
const unsigned Kind
dwarf::Attribute getAttrByIndex(uint32_t idx) const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Definition: JSON.cpp:592
Optional< DWARFFormValue > find(dwarf::Attribute Attr) const
Extract the specified attribute from this DIE.
Definition: DWARFDie.cpp:293
std::vector< DWARFAddressRange > DWARFAddressRangesVector
DWARFAddressRangesVector - represents a set of absolute address ranges.
LLVM Value Representation.
Definition: Value.h:73
DWARFDie getFirstChild() const
Get the first child of this DIE object.
Definition: DWARFDie.cpp:566
static void dumpLocation(raw_ostream &OS, DWARFFormValue &FormValue, DWARFUnit *U, unsigned Indent, DIDumpOptions DumpOpts)
Definition: DWARFDie.cpp:84
static const Function * getParent(const Value *V)
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:46
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
Optional< uint64_t > getAsSectionOffset() const
Optional< uint32_t > getRnglistOffset(uint32_t Index)
Return a rangelist&#39;s offset based on an index.
Definition: DWARFUnit.h:403
const char * getSubroutineName(DINameKind Kind) const
If a DIE represents a subprogram (or inlined subroutine), returns its mangled name (or short name...
Definition: DWARFDie.cpp:440
Optional< uint64_t > toUnsigned(const Optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract an unsigned constant.
static void dumpTypeTagName(raw_ostream &OS, dwarf::Tag T)
Dump the name encoded in the type tag.
Definition: DWARFDie.cpp:130
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:144
DWARFDie getParent() const
Get the parent of this DIE object.
Definition: DWARFDie.cpp:548
size_type count(const T &V) const
count - Return 1 if the element is in the set, 0 otherwise.
Definition: SmallSet.h:165