LLVM  7.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 "SyntaxHighlighting.h"
12 #include "llvm/ADT/None.h"
13 #include "llvm/ADT/Optional.h"
14 #include "llvm/ADT/StringRef.h"
22 #include "llvm/Object/ObjectFile.h"
24 #include "llvm/Support/Format.h"
27 #include <algorithm>
28 #include <cassert>
29 #include <cinttypes>
30 #include <cstdint>
31 #include <string>
32 #include <utility>
33 
34 using namespace llvm;
35 using namespace dwarf;
36 using namespace object;
37 using namespace syntax;
38 
39 static void dumpApplePropertyAttribute(raw_ostream &OS, uint64_t Val) {
40  OS << " (";
41  do {
42  uint64_t Shift = countTrailingZeros(Val);
43  assert(Shift < 64 && "undefined behavior");
44  uint64_t Bit = 1ULL << Shift;
45  auto PropName = ApplePropertyString(Bit);
46  if (!PropName.empty())
47  OS << PropName;
48  else
49  OS << format("DW_APPLE_PROPERTY_0x%" PRIx64, Bit);
50  if (!(Val ^= Bit))
51  break;
52  OS << ", ";
53  } while (true);
54  OS << ")";
55 }
56 
57 static void dumpRanges(const DWARFObject &Obj, raw_ostream &OS,
58  const DWARFAddressRangesVector &Ranges,
59  unsigned AddressSize, unsigned Indent,
60  const DIDumpOptions &DumpOpts) {
61  ArrayRef<SectionName> SectionNames;
62  if (DumpOpts.Verbose)
63  SectionNames = Obj.getSectionNames();
64 
65  for (const DWARFAddressRange &R : Ranges) {
66 
67  OS << '\n';
68  OS.indent(Indent);
69  R.dump(OS, AddressSize);
70 
71  if (SectionNames.empty() || R.SectionIndex == -1ULL)
72  continue;
73 
74  StringRef Name = SectionNames[R.SectionIndex].Name;
75  OS << " \"" << Name << '\"';
76 
77  // Print section index if name is not unique.
78  if (!SectionNames[R.SectionIndex].IsNameUnique)
79  OS << format(" [%" PRIu64 "]", R.SectionIndex);
80  }
81 }
82 
83 static void dumpLocation(raw_ostream &OS, DWARFFormValue &FormValue,
84  DWARFUnit *U, unsigned Indent,
85  DIDumpOptions DumpOpts) {
86  DWARFContext &Ctx = U->getContext();
87  const DWARFObject &Obj = Ctx.getDWARFObj();
88  const MCRegisterInfo *MRI = Ctx.getRegisterInfo();
89  if (FormValue.isFormClass(DWARFFormValue::FC_Block) ||
91  ArrayRef<uint8_t> Expr = *FormValue.getAsBlock();
92  DataExtractor Data(StringRef((const char *)Expr.data(), Expr.size()),
93  Ctx.isLittleEndian(), 0);
95  .print(OS, MRI);
96  return;
97  }
98 
99  FormValue.dump(OS, DumpOpts);
101  const DWARFSection &LocSection = Obj.getLocSection();
102  const DWARFSection &LocDWOSection = Obj.getLocDWOSection();
103  uint32_t Offset = *FormValue.getAsSectionOffset();
104 
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  LL->dump(OS, Ctx.isLittleEndian(), Obj.getAddressSize(), MRI, Indent);
112  else
113  OS << "error extracting location list.";
114  } else if (!LocDWOSection.Data.empty()) {
115  DataExtractor Data(LocDWOSection.Data, Ctx.isLittleEndian(), 0);
116  auto LL = DWARFDebugLocDWO::parseOneLocationList(Data, &Offset);
117  if (LL)
118  LL->dump(OS, Ctx.isLittleEndian(), Obj.getAddressSize(), MRI, Indent);
119  else
120  OS << "error extracting location list.";
121  }
122  }
123 }
124 
125 /// Dump the name encoded in the type tag.
127  StringRef TagStr = TagString(T);
128  if (!TagStr.startswith("DW_TAG_") || !TagStr.endswith("_type"))
129  return;
130  OS << TagStr.substr(7, TagStr.size() - 12) << " ";
131 }
132 
133 /// Recursively dump the DIE type name when applicable.
134 static void dumpTypeName(raw_ostream &OS, const DWARFDie &Die) {
135  DWARFDie D = Die.getAttributeValueAsReferencedDie(DW_AT_type);
136 
137  if (!D.isValid())
138  return;
139 
140  if (const char *Name = D.getName(DINameKind::LinkageName)) {
141  OS << Name;
142  return;
143  }
144 
145  // FIXME: We should have pretty printers per language. Currently we print
146  // everything as if it was C++ and fall back to the TAG type name.
147  const dwarf::Tag T = D.getTag();
148  switch (T) {
149  case DW_TAG_array_type:
150  case DW_TAG_pointer_type:
151  case DW_TAG_ptr_to_member_type:
152  case DW_TAG_reference_type:
153  case DW_TAG_rvalue_reference_type:
154  break;
155  default:
156  dumpTypeTagName(OS, T);
157  }
158 
159  // Follow the DW_AT_type if possible.
160  dumpTypeName(OS, D);
161 
162  switch (T) {
163  case DW_TAG_array_type:
164  OS << "[]";
165  break;
166  case DW_TAG_pointer_type:
167  OS << '*';
168  break;
169  case DW_TAG_ptr_to_member_type:
170  OS << '*';
171  break;
172  case DW_TAG_reference_type:
173  OS << '&';
174  break;
175  case DW_TAG_rvalue_reference_type:
176  OS << "&&";
177  break;
178  default:
179  break;
180  }
181 }
182 
183 static void dumpAttribute(raw_ostream &OS, const DWARFDie &Die,
184  uint32_t *OffsetPtr, dwarf::Attribute Attr,
185  dwarf::Form Form, unsigned Indent,
186  DIDumpOptions DumpOpts) {
187  if (!Die.isValid())
188  return;
189  const char BaseIndent[] = " ";
190  OS << BaseIndent;
191  OS.indent(Indent + 2);
192  auto attrString = AttributeString(Attr);
193  if (!attrString.empty())
194  WithColor(OS, syntax::Attribute) << attrString;
195  else
196  WithColor(OS, syntax::Attribute).get() << format("DW_AT_Unknown_%x", Attr);
197 
198  if (DumpOpts.Verbose || DumpOpts.ShowForm) {
199  auto formString = FormEncodingString(Form);
200  if (!formString.empty())
201  OS << " [" << formString << ']';
202  else
203  OS << format(" [DW_FORM_Unknown_%x]", Form);
204  }
205 
206  DWARFUnit *U = Die.getDwarfUnit();
207  DWARFFormValue formValue(Form);
208 
209  if (!formValue.extractValue(U->getDebugInfoExtractor(), OffsetPtr,
210  U->getFormParams(), U))
211  return;
212 
213  OS << "\t(";
214 
215  StringRef Name;
216  std::string File;
217  auto Color = syntax::Enumerator;
218  if (Attr == DW_AT_decl_file || Attr == DW_AT_call_file) {
220  if (const auto *LT = U->getContext().getLineTableForUnit(U))
221  if (LT->getFileNameByIndex(
222  formValue.getAsUnsignedConstant().getValue(),
223  U->getCompilationDir(),
225  File = '"' + File + '"';
226  Name = File;
227  }
228  } else if (Optional<uint64_t> Val = formValue.getAsUnsignedConstant())
229  Name = AttributeValueString(Attr, *Val);
230 
231  if (!Name.empty())
232  WithColor(OS, Color) << Name;
233  else if (Attr == DW_AT_decl_line || Attr == DW_AT_call_line)
234  OS << *formValue.getAsUnsignedConstant();
235  else if (Attr == DW_AT_high_pc && !DumpOpts.ShowForm && !DumpOpts.Verbose &&
236  formValue.getAsUnsignedConstant()) {
237  if (DumpOpts.ShowAddresses) {
238  // Print the actual address rather than the offset.
239  uint64_t LowPC, HighPC, Index;
240  if (Die.getLowAndHighPC(LowPC, HighPC, Index))
241  OS << format("0x%016" PRIx64, HighPC);
242  else
243  formValue.dump(OS, DumpOpts);
244  }
245  } else if (Attr == DW_AT_location || Attr == DW_AT_frame_base ||
246  Attr == DW_AT_data_member_location ||
247  Attr == DW_AT_GNU_call_site_value)
248  dumpLocation(OS, formValue, U, sizeof(BaseIndent) + Indent + 4, DumpOpts);
249  else
250  formValue.dump(OS, DumpOpts);
251 
252  // We have dumped the attribute raw value. For some attributes
253  // having both the raw value and the pretty-printed value is
254  // interesting. These attributes are handled below.
255  if (Attr == DW_AT_specification || Attr == DW_AT_abstract_origin) {
256  if (const char *Name = Die.getAttributeValueAsReferencedDie(Attr).getName(
258  OS << " \"" << Name << '\"';
259  } else if (Attr == DW_AT_type) {
260  OS << " \"";
261  dumpTypeName(OS, Die);
262  OS << '"';
263  } else if (Attr == DW_AT_APPLE_property_attribute) {
264  if (Optional<uint64_t> OptVal = formValue.getAsUnsignedConstant())
265  dumpApplePropertyAttribute(OS, *OptVal);
266  } else if (Attr == DW_AT_ranges) {
267  const DWARFObject &Obj = Die.getDwarfUnit()->getContext().getDWARFObj();
268  dumpRanges(Obj, OS, Die.getAddressRanges(), U->getAddressByteSize(),
269  sizeof(BaseIndent) + Indent + 4, DumpOpts);
270  }
271 
272  OS << ")\n";
273 }
274 
275 bool DWARFDie::isSubprogramDIE() const { return getTag() == DW_TAG_subprogram; }
276 
278  auto Tag = getTag();
279  return Tag == DW_TAG_subprogram || Tag == DW_TAG_inlined_subroutine;
280 }
281 
283  if (!isValid())
284  return None;
285  auto AbbrevDecl = getAbbreviationDeclarationPtr();
286  if (AbbrevDecl)
287  return AbbrevDecl->getAttributeValue(getOffset(), Attr, *U);
288  return None;
289 }
290 
293  if (!isValid())
294  return None;
295  auto AbbrevDecl = getAbbreviationDeclarationPtr();
296  if (AbbrevDecl) {
297  for (auto Attr : Attrs) {
298  if (auto Value = AbbrevDecl->getAttributeValue(getOffset(), Attr, *U))
299  return Value;
300  }
301  }
302  return None;
303 }
304 
307  if (!isValid())
308  return None;
309  if (auto Value = find(Attrs))
310  return Value;
311  if (auto Die = getAttributeValueAsReferencedDie(DW_AT_abstract_origin)) {
312  if (auto Value = Die.findRecursively(Attrs))
313  return Value;
314  }
315  if (auto Die = getAttributeValueAsReferencedDie(DW_AT_specification)) {
316  if (auto Value = Die.findRecursively(Attrs))
317  return Value;
318  }
319  return None;
320 }
321 
322 DWARFDie
324  if (auto SpecRef = toReference(find(Attr))) {
325  if (auto SpecUnit = U->getUnitSection().getUnitForOffset(*SpecRef))
326  return SpecUnit->getDIEForOffset(*SpecRef);
327  }
328  return DWARFDie();
329 }
330 
332  return toSectionOffset(find({DW_AT_rnglists_base, DW_AT_GNU_ranges_base}));
333 }
334 
336  if (auto FormValue = find(DW_AT_high_pc)) {
337  if (auto Address = FormValue->getAsAddress()) {
338  // High PC is an address.
339  return Address;
340  }
341  if (auto Offset = FormValue->getAsUnsignedConstant()) {
342  // High PC is an offset from LowPC.
343  return LowPC + *Offset;
344  }
345  }
346  return None;
347 }
348 
349 bool DWARFDie::getLowAndHighPC(uint64_t &LowPC, uint64_t &HighPC,
350  uint64_t &SectionIndex) const {
351  auto F = find(DW_AT_low_pc);
352  auto LowPcAddr = toAddress(F);
353  if (!LowPcAddr)
354  return false;
355  if (auto HighPcAddr = getHighPC(*LowPcAddr)) {
356  LowPC = *LowPcAddr;
357  HighPC = *HighPcAddr;
358  SectionIndex = F->getSectionIndex();
359  return true;
360  }
361  return false;
362 }
363 
365  if (isNULL())
366  return DWARFAddressRangesVector();
367  // Single range specified by low/high PC.
368  uint64_t LowPC, HighPC, Index;
369  if (getLowAndHighPC(LowPC, HighPC, Index))
370  return {{LowPC, HighPC, Index}};
371 
372  // Multiple ranges from .debug_ranges section.
373  auto RangesOffset = toSectionOffset(find(DW_AT_ranges));
374  if (RangesOffset) {
375  DWARFDebugRangeList RangeList;
376  if (U->extractRangeList(*RangesOffset, RangeList))
377  return RangeList.getAbsoluteRanges(U->getBaseAddress());
378  }
379  return DWARFAddressRangesVector();
380 }
381 
383  DWARFAddressRangesVector &Ranges) const {
384  if (isNULL())
385  return;
386  if (isSubprogramDIE()) {
387  const auto &DIERanges = getAddressRanges();
388  Ranges.insert(Ranges.end(), DIERanges.begin(), DIERanges.end());
389  }
390 
391  for (auto Child : children())
392  Child.collectChildrenAddressRanges(Ranges);
393 }
394 
395 bool DWARFDie::addressRangeContainsAddress(const uint64_t Address) const {
396  for (const auto &R : getAddressRanges()) {
397  if (R.LowPC <= Address && Address < R.HighPC)
398  return true;
399  }
400  return false;
401 }
402 
404  if (!isSubroutineDIE())
405  return nullptr;
406  return getName(Kind);
407 }
408 
409 const char *DWARFDie::getName(DINameKind Kind) const {
410  if (!isValid() || Kind == DINameKind::None)
411  return nullptr;
412  // Try to get mangled name only if it was asked for.
413  if (Kind == DINameKind::LinkageName) {
414  if (auto Name = dwarf::toString(
415  findRecursively({DW_AT_MIPS_linkage_name, DW_AT_linkage_name}),
416  nullptr))
417  return Name;
418  }
419  if (auto Name = dwarf::toString(findRecursively(DW_AT_name), nullptr))
420  return Name;
421  return nullptr;
422 }
423 
424 uint64_t DWARFDie::getDeclLine() const {
425  return toUnsigned(findRecursively(DW_AT_decl_line), 0);
426 }
427 
428 void DWARFDie::getCallerFrame(uint32_t &CallFile, uint32_t &CallLine,
429  uint32_t &CallColumn,
430  uint32_t &CallDiscriminator) const {
431  CallFile = toUnsigned(find(DW_AT_call_file), 0);
432  CallLine = toUnsigned(find(DW_AT_call_line), 0);
433  CallColumn = toUnsigned(find(DW_AT_call_column), 0);
434  CallDiscriminator = toUnsigned(find(DW_AT_GNU_discriminator), 0);
435 }
436 
437 /// Helper to dump a DIE with all of its parents, but no siblings.
438 static unsigned dumpParentChain(DWARFDie Die, raw_ostream &OS, unsigned Indent,
439  DIDumpOptions DumpOpts) {
440  if (!Die)
441  return Indent;
442  Indent = dumpParentChain(Die.getParent(), OS, Indent, DumpOpts);
443  Die.dump(OS, Indent, DumpOpts);
444  return Indent + 2;
445 }
446 
447 void DWARFDie::dump(raw_ostream &OS, unsigned Indent,
448  DIDumpOptions DumpOpts) const {
449  if (!isValid())
450  return;
451  DWARFDataExtractor debug_info_data = U->getDebugInfoExtractor();
452  const uint32_t Offset = getOffset();
453  uint32_t offset = Offset;
454  if (DumpOpts.ShowParents) {
455  DumpOpts.ShowParents = false;
456  Indent = dumpParentChain(getParent(), OS, Indent, DumpOpts);
457  }
458 
459  if (debug_info_data.isValidOffset(offset)) {
460  uint32_t abbrCode = debug_info_data.getULEB128(&offset);
461  if (DumpOpts.ShowAddresses)
462  WithColor(OS, syntax::Address).get() << format("\n0x%8.8x: ", Offset);
463 
464  if (abbrCode) {
465  auto AbbrevDecl = getAbbreviationDeclarationPtr();
466  if (AbbrevDecl) {
467  auto tagString = TagString(getTag());
468  if (!tagString.empty())
469  WithColor(OS, syntax::Tag).get().indent(Indent) << tagString;
470  else
471  WithColor(OS, syntax::Tag).get().indent(Indent)
472  << format("DW_TAG_Unknown_%x", getTag());
473 
474  if (DumpOpts.Verbose)
475  OS << format(" [%u] %c", abbrCode,
476  AbbrevDecl->hasChildren() ? '*' : ' ');
477  OS << '\n';
478 
479  // Dump all data in the DIE for the attributes.
480  for (const auto &AttrSpec : AbbrevDecl->attributes()) {
481  if (AttrSpec.Form == DW_FORM_implicit_const) {
482  // We are dumping .debug_info section ,
483  // implicit_const attribute values are not really stored here,
484  // but in .debug_abbrev section. So we just skip such attrs.
485  continue;
486  }
487  dumpAttribute(OS, *this, &offset, AttrSpec.Attr, AttrSpec.Form,
488  Indent, DumpOpts);
489  }
490 
491  DWARFDie child = getFirstChild();
492  if (DumpOpts.ShowChildren && DumpOpts.RecurseDepth > 0 && child) {
493  DumpOpts.RecurseDepth--;
494  while (child) {
495  child.dump(OS, Indent + 2, DumpOpts);
496  child = child.getSibling();
497  }
498  }
499  } else {
500  OS << "Abbreviation code not found in 'debug_abbrev' class for code: "
501  << abbrCode << '\n';
502  }
503  } else {
504  OS.indent(Indent) << "NULL\n";
505  }
506  }
507 }
508 
510 
512  if (isValid())
513  return U->getParent(Die);
514  return DWARFDie();
515 }
516 
518  if (isValid())
519  return U->getSibling(Die);
520  return DWARFDie();
521 }
522 
524  if (isValid())
525  return U->getFirstChild(Die);
526  return DWARFDie();
527 }
528 
530  return make_range(attribute_iterator(*this, false),
531  attribute_iterator(*this, true));
532 }
533 
535  : Die(D), AttrValue(0), Index(0) {
536  auto AbbrDecl = Die.getAbbreviationDeclarationPtr();
537  assert(AbbrDecl && "Must have abbreviation declaration");
538  if (End) {
539  // This is the end iterator so we set the index to the attribute count.
540  Index = AbbrDecl->getNumAttributes();
541  } else {
542  // This is the begin iterator so we extract the value for this->Index.
543  AttrValue.Offset = D.getOffset() + AbbrDecl->getCodeByteSize();
544  updateForIndex(*AbbrDecl, 0);
545  }
546 }
547 
548 void DWARFDie::attribute_iterator::updateForIndex(
549  const DWARFAbbreviationDeclaration &AbbrDecl, uint32_t I) {
550  Index = I;
551  // AbbrDecl must be valid before calling this function.
552  auto NumAttrs = AbbrDecl.getNumAttributes();
553  if (Index < NumAttrs) {
554  AttrValue.Attr = AbbrDecl.getAttrByIndex(Index);
555  // Add the previous byte size of any previous attribute value.
556  AttrValue.Offset += AttrValue.ByteSize;
557  AttrValue.Value.setForm(AbbrDecl.getFormByIndex(Index));
558  uint32_t ParseOffset = AttrValue.Offset;
559  auto U = Die.getDwarfUnit();
560  assert(U && "Die must have valid DWARF unit");
561  bool b = AttrValue.Value.extractValue(U->getDebugInfoExtractor(),
562  &ParseOffset, U->getFormParams(), U);
563  (void)b;
564  assert(b && "extractValue cannot fail on fully parsed DWARF");
565  AttrValue.ByteSize = ParseOffset - AttrValue.Offset;
566  } else {
567  assert(Index == NumAttrs && "Indexes should be [0, NumAttrs) only");
568  AttrValue.clear();
569  }
570 }
571 
573  if (auto AbbrDecl = Die.getAbbreviationDeclarationPtr())
574  updateForIndex(*AbbrDecl, Index + 1);
575  return *this;
576 }
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:115
StringRef ApplePropertyString(unsigned)
Definition: Dwarf.cpp:458
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
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
Definition: Compiler.h:449
bool isSubprogramDIE() const
Returns true if DIE represents a subprogram (not inlined).
Definition: DWARFDie.cpp:275
bool addressRangeContainsAddress(const uint64_t Address) const
Definition: DWARFDie.cpp:395
Attribute
Attributes.
Definition: Dwarf.h:107
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
Definition: StringRef.h:138
attribute_iterator & operator++()
Definition: DWARFDie.cpp:572
uint32_t ByteSize
The debug info/types section byte size of the data for this attribute.
const DWARFFormParams & getFormParams() const
Definition: DWARFUnit.h:318
void collectChildrenAddressRanges(DWARFAddressRangesVector &Ranges) const
Get all address ranges for any DW_TAG_subprogram DIEs in this DIE or any of its children.
Definition: DWARFDie.cpp:382
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:438
DWARFDie getAttributeValueAsReferencedDie(dwarf::Attribute Attr) const
Extract the specified attribute from this DIE as the referenced DIE.
Definition: DWARFDie.cpp:323
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:447
Optional< uint64_t > toAddress(const Optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract an address.
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:169
Optional< uint64_t > getRangesBaseAttribute() const
Extract the range base attribute from this DIE as absolute section offset.
Definition: DWARFDie.cpp:331
Optional< ArrayRef< uint8_t > > getAsBlock() const
StringRef FormEncodingString(unsigned Encoding)
Definition: Dwarf.cpp:105
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:183
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:428
static void dumpTypeName(raw_ostream &OS, const DWARFDie &Die)
Recursively dump the DIE type name when applicable.
Definition: DWARFDie.cpp:134
const MCRegisterInfo * getRegisterInfo() const
Definition: DWARFContext.h:297
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:321
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:39
dwarf::Form getFormByIndex(uint32_t idx) const
StringRef AttributeString(unsigned Attribute)
Definition: Dwarf.cpp:72
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:57
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:349
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
uint16_t getVersion() const
Definition: DWARFUnit.h:319
DWARFDie getSibling() const
Get the sibling of this DIE object.
Definition: DWARFDie.cpp:517
StringRef AttributeValueString(uint16_t Attr, unsigned Val)
Returns the symbolic string representing Val when used as a value for attribute Attr.
Definition: Dwarf.cpp:532
uint64_t getDeclLine() const
Returns the declaration line (start line) for a DIE, assuming it specifies a subprogram.
Definition: DWARFDie.cpp:424
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
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.
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:112
bool extractValue(const DWARFDataExtractor &Data, uint32_t *OffsetPtr, DWARFFormParams FormParams, const DWARFContext *Context=nullptr, const DWARFUnit *Unit=nullptr)
Extracts a value in Data at offset *OffsetPtr.
virtual uint8_t getAddressSize() const
Definition: DWARFObject.h:35
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:149
bool isSubroutineDIE() const
Returns true if DIE represents a subprogram or an inlined subroutine.
Definition: DWARFDie.cpp:277
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:306
static const unsigned End
Optional< uint64_t > getAsUnsignedConstant() const
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
DWARFContext & getContext() const
Definition: DWARFUnit.h:272
Optional< LocationList > parseOneLocationList(DWARFDataExtractor Data, uint32_t *Offset)
auto find(R &&Range, const T &Val) -> decltype(adl_begin(Range))
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:835
DWARFAddressRangesVector getAbsoluteRanges(llvm::Optional< BaseAddress > BaseAddr) const
getAbsoluteRanges - Returns absolute address ranges defined by this range list.
static Optional< LocationList > parseOneLocationList(DataExtractor Data, uint32_t *Offset)
const T * data() const
Definition: ArrayRef.h:146
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:409
Color
A "color", which is either even or odd.
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:529
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:64
unsigned RecurseDepth
Definition: DIContext.h:156
StringRef TagString(unsigned Tag)
Definition: Dwarf.cpp:21
LLVM_DUMP_METHOD void dump() const
Convenience zero-argument overload for debugging.
Definition: DWARFDie.cpp:509
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
bool isLittleEndian() const
Definition: DWARFContext.h:290
const DWARFObject & getDWARFObj() const
Definition: DWARFContext.h:124
Optional< uint64_t > getHighPC(uint64_t LowPC) const
Get the DW_AT_high_pc attribute value as an address.
Definition: DWARFDie.cpp:335
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())
Optional< DWARFFormValue > find(dwarf::Attribute Attr) const
Extract the specified attribute from this DIE.
Definition: DWARFDie.cpp:282
std::vector< DWARFAddressRange > DWARFAddressRangesVector
DWARFAddressRangesVector - represents a set of absolute address ranges.
LLVM Value Representation.
Definition: Value.h:73
DWARFDie getFirstChild() const
Get the first child of this DIE object.
Definition: DWARFDie.cpp:523
const DWARFDebugLine::LineTable * getLineTableForUnit(DWARFUnit *cu)
Get a pointer to a parsed line table corresponding to a compile unit.
static void dumpLocation(raw_ostream &OS, DWARFFormValue &FormValue, DWARFUnit *U, unsigned Indent, DIDumpOptions DumpOpts)
Definition: DWARFDie.cpp:83
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:44
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
Optional< uint64_t > getAsSectionOffset() const
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:403
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:126
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:511
DWARFAddressRangesVector getAddressRanges() const
Get the address ranges for this DIE.
Definition: DWARFDie.cpp:364