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