LLVM  6.0.0svn
DIE.cpp
Go to the documentation of this file.
1 //===--- lib/CodeGen/DIE.cpp - DWARF Info Entries -------------------------===//
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 //
10 // Data structures for DWARF info entries.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "llvm/CodeGen/DIE.h"
15 #include "DwarfCompileUnit.h"
16 #include "DwarfDebug.h"
17 #include "DwarfUnit.h"
18 #include "llvm/ADT/Twine.h"
20 #include "llvm/IR/DataLayout.h"
21 #include "llvm/MC/MCAsmInfo.h"
22 #include "llvm/MC/MCContext.h"
23 #include "llvm/MC/MCStreamer.h"
24 #include "llvm/MC/MCSymbol.h"
25 #include "llvm/Support/Debug.h"
27 #include "llvm/Support/Format.h"
29 #include "llvm/Support/LEB128.h"
30 #include "llvm/Support/MD5.h"
32 using namespace llvm;
33 
34 #define DEBUG_TYPE "dwarfdebug"
35 
36 //===----------------------------------------------------------------------===//
37 // DIEAbbrevData Implementation
38 //===----------------------------------------------------------------------===//
39 
40 /// Profile - Used to gather unique data for the abbreviation folding set.
41 ///
43  // Explicitly cast to an integer type for which FoldingSetNodeID has
44  // overloads. Otherwise MSVC 2010 thinks this call is ambiguous.
45  ID.AddInteger(unsigned(Attribute));
46  ID.AddInteger(unsigned(Form));
47  if (Form == dwarf::DW_FORM_implicit_const)
48  ID.AddInteger(Value);
49 }
50 
51 //===----------------------------------------------------------------------===//
52 // DIEAbbrev Implementation
53 //===----------------------------------------------------------------------===//
54 
55 /// Profile - Used to gather unique data for the abbreviation folding set.
56 ///
58  ID.AddInteger(unsigned(Tag));
59  ID.AddInteger(unsigned(Children));
60 
61  // For each attribute description.
62  for (unsigned i = 0, N = Data.size(); i < N; ++i)
63  Data[i].Profile(ID);
64 }
65 
66 /// Emit - Print the abbreviation using the specified asm printer.
67 ///
68 void DIEAbbrev::Emit(const AsmPrinter *AP) const {
69  // Emit its Dwarf tag type.
70  AP->EmitULEB128(Tag, dwarf::TagString(Tag).data());
71 
72  // Emit whether it has children DIEs.
73  AP->EmitULEB128((unsigned)Children, dwarf::ChildrenString(Children).data());
74 
75  // For each attribute description.
76  for (unsigned i = 0, N = Data.size(); i < N; ++i) {
77  const DIEAbbrevData &AttrData = Data[i];
78 
79  // Emit attribute type.
80  AP->EmitULEB128(AttrData.getAttribute(),
81  dwarf::AttributeString(AttrData.getAttribute()).data());
82 
83  // Emit form type.
84 #ifndef NDEBUG
85  // Could be an assertion, but this way we can see the failing form code
86  // easily, which helps track down where it came from.
87  if (!dwarf::isValidFormForVersion(AttrData.getForm(),
88  AP->getDwarfVersion())) {
89  DEBUG(dbgs() << "Invalid form " << format("0x%x", AttrData.getForm())
90  << " for DWARF version " << AP->getDwarfVersion() << "\n");
91  llvm_unreachable("Invalid form for specified DWARF version");
92  }
93 #endif
94  AP->EmitULEB128(AttrData.getForm(),
95  dwarf::FormEncodingString(AttrData.getForm()).data());
96 
97  // Emit value for DW_FORM_implicit_const.
98  if (AttrData.getForm() == dwarf::DW_FORM_implicit_const)
99  AP->EmitSLEB128(AttrData.getValue());
100  }
101 
102  // Mark end of abbreviation.
103  AP->EmitULEB128(0, "EOM(1)");
104  AP->EmitULEB128(0, "EOM(2)");
105 }
106 
109  O << "Abbreviation @"
110  << format("0x%lx", (long)(intptr_t)this)
111  << " "
113  << " "
114  << dwarf::ChildrenString(Children)
115  << '\n';
116 
117  for (unsigned i = 0, N = Data.size(); i < N; ++i) {
118  O << " "
120  << " "
122 
123  if (Data[i].getForm() == dwarf::DW_FORM_implicit_const)
124  O << " " << Data[i].getValue();
125 
126  O << '\n';
127  }
128 }
129 
130 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
132  print(dbgs());
133 }
134 #endif
135 
136 //===----------------------------------------------------------------------===//
137 // DIEAbbrevSet Implementation
138 //===----------------------------------------------------------------------===//
139 
141  for (DIEAbbrev *Abbrev : Abbreviations)
142  Abbrev->~DIEAbbrev();
143 }
144 
146 
148  DIEAbbrev Abbrev = Die.generateAbbrev();
149  Abbrev.Profile(ID);
150 
151  void *InsertPos;
152  if (DIEAbbrev *Existing =
153  AbbreviationsSet.FindNodeOrInsertPos(ID, InsertPos)) {
154  Die.setAbbrevNumber(Existing->getNumber());
155  return *Existing;
156  }
157 
158  // Move the abbreviation to the heap and assign a number.
159  DIEAbbrev *New = new (Alloc) DIEAbbrev(std::move(Abbrev));
160  Abbreviations.push_back(New);
161  New->setNumber(Abbreviations.size());
162  Die.setAbbrevNumber(Abbreviations.size());
163 
164  // Store it for lookup.
165  AbbreviationsSet.InsertNode(New, InsertPos);
166  return *New;
167 }
168 
170  if (!Abbreviations.empty()) {
171  // Start the debug abbrev section.
172  AP->OutStreamer->SwitchSection(Section);
173  AP->emitDwarfAbbrevs(Abbreviations);
174  }
175 }
176 
177 //===----------------------------------------------------------------------===//
178 // DIE Implementation
179 //===----------------------------------------------------------------------===//
180 
181 DIE *DIE::getParent() const {
182  return Owner.dyn_cast<DIE*>();
183 }
184 
186  DIEAbbrev Abbrev(Tag, hasChildren());
187  for (const DIEValue &V : values())
188  if (V.getForm() == dwarf::DW_FORM_implicit_const)
189  Abbrev.AddImplicitConstAttribute(V.getAttribute(),
190  V.getDIEInteger().getValue());
191  else
192  Abbrev.AddAttribute(V.getAttribute(), V.getForm());
193  return Abbrev;
194 }
195 
196 unsigned DIE::getDebugSectionOffset() const {
197  const DIEUnit *Unit = getUnit();
198  assert(Unit && "DIE must be owned by a DIEUnit to get its absolute offset");
199  return Unit->getDebugSectionOffset() + getOffset();
200 }
201 
202 const DIE *DIE::getUnitDie() const {
203  const DIE *p = this;
204  while (p) {
205  if (p->getTag() == dwarf::DW_TAG_compile_unit ||
206  p->getTag() == dwarf::DW_TAG_type_unit)
207  return p;
208  p = p->getParent();
209  }
210  return nullptr;
211 }
212 
213 const DIEUnit *DIE::getUnit() const {
214  const DIE *UnitDie = getUnitDie();
215  if (UnitDie)
216  return UnitDie->Owner.dyn_cast<DIEUnit*>();
217  return nullptr;
218 }
219 
221  // Iterate through all the attributes until we find the one we're
222  // looking for, if we can't find it return NULL.
223  for (const auto &V : values())
224  if (V.getAttribute() == Attribute)
225  return V;
226  return DIEValue();
227 }
228 
230 static void printValues(raw_ostream &O, const DIEValueList &Values,
231  StringRef Type, unsigned Size, unsigned IndentCount) {
232  O << Type << ": Size: " << Size << "\n";
233 
234  unsigned I = 0;
235  const std::string Indent(IndentCount, ' ');
236  for (const auto &V : Values.values()) {
237  O << Indent;
238  O << "Blk[" << I++ << "]";
239  O << " " << dwarf::FormEncodingString(V.getForm()) << " ";
240  V.print(O);
241  O << "\n";
242  }
243 }
244 
246 void DIE::print(raw_ostream &O, unsigned IndentCount) const {
247  const std::string Indent(IndentCount, ' ');
248  O << Indent << "Die: " << format("0x%lx", (long)(intptr_t) this)
249  << ", Offset: " << Offset << ", Size: " << Size << "\n";
250 
251  O << Indent << dwarf::TagString(getTag()) << " "
252  << dwarf::ChildrenString(hasChildren()) << "\n";
253 
254  IndentCount += 2;
255  for (const auto &V : values()) {
256  O << Indent;
257  O << dwarf::AttributeString(V.getAttribute());
258  O << " " << dwarf::FormEncodingString(V.getForm()) << " ";
259  V.print(O);
260  O << "\n";
261  }
262  IndentCount -= 2;
263 
264  for (const auto &Child : children())
265  Child.print(O, IndentCount + 4);
266 
267  O << "\n";
268 }
269 
270 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
272  print(dbgs());
273 }
274 #endif
275 
277  DIEAbbrevSet &AbbrevSet,
278  unsigned CUOffset) {
279  // Unique the abbreviation and fill in the abbreviation number so this DIE
280  // can be emitted.
281  const DIEAbbrev &Abbrev = AbbrevSet.uniqueAbbreviation(*this);
282 
283  // Set compile/type unit relative offset of this DIE.
284  setOffset(CUOffset);
285 
286  // Add the byte size of the abbreviation code.
287  CUOffset += getULEB128Size(getAbbrevNumber());
288 
289  // Add the byte size of all the DIE attribute values.
290  for (const auto &V : values())
291  CUOffset += V.SizeOf(AP);
292 
293  // Let the children compute their offsets and abbreviation numbers.
294  if (hasChildren()) {
295  (void)Abbrev;
296  assert(Abbrev.hasChildren() && "Children flag not set");
297 
298  for (auto &Child : children())
299  CUOffset = Child.computeOffsetsAndAbbrevs(AP, AbbrevSet, CUOffset);
300 
301  // Each child chain is terminated with a zero byte, adjust the offset.
302  CUOffset += sizeof(int8_t);
303  }
304 
305  // Compute the byte size of this DIE and all of its children correctly. This
306  // is needed so that top level DIE can help the compile unit set its length
307  // correctly.
308  setSize(CUOffset - getOffset());
309  return CUOffset;
310 }
311 
312 //===----------------------------------------------------------------------===//
313 // DIEUnit Implementation
314 //===----------------------------------------------------------------------===//
315 DIEUnit::DIEUnit(uint16_t V, uint8_t A, dwarf::Tag UnitTag)
316  : Die(UnitTag), Section(nullptr), Offset(0), Length(0), Version(V),
317  AddrSize(A)
318 {
319  Die.Owner = this;
320  assert((UnitTag == dwarf::DW_TAG_compile_unit ||
321  UnitTag == dwarf::DW_TAG_type_unit ||
322  UnitTag == dwarf::DW_TAG_partial_unit) && "expected a unit TAG");
323 }
324 
325 void DIEValue::EmitValue(const AsmPrinter *AP) const {
326  switch (Ty) {
327  case isNone:
328  llvm_unreachable("Expected valid DIEValue");
329 #define HANDLE_DIEVALUE(T) \
330  case is##T: \
331  getDIE##T().EmitValue(AP, Form); \
332  break;
333 #include "llvm/CodeGen/DIEValue.def"
334  }
335 }
336 
337 unsigned DIEValue::SizeOf(const AsmPrinter *AP) const {
338  switch (Ty) {
339  case isNone:
340  llvm_unreachable("Expected valid DIEValue");
341 #define HANDLE_DIEVALUE(T) \
342  case is##T: \
343  return getDIE##T().SizeOf(AP, Form);
344 #include "llvm/CodeGen/DIEValue.def"
345  }
346  llvm_unreachable("Unknown DIE kind");
347 }
348 
350 void DIEValue::print(raw_ostream &O) const {
351  switch (Ty) {
352  case isNone:
353  llvm_unreachable("Expected valid DIEValue");
354 #define HANDLE_DIEVALUE(T) \
355  case is##T: \
356  getDIE##T().print(O); \
357  break;
358 #include "llvm/CodeGen/DIEValue.def"
359  }
360 }
361 
362 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
364  print(dbgs());
365 }
366 #endif
367 
368 //===----------------------------------------------------------------------===//
369 // DIEInteger Implementation
370 //===----------------------------------------------------------------------===//
371 
372 /// EmitValue - Emit integer of appropriate size.
373 ///
375  switch (Form) {
376  case dwarf::DW_FORM_implicit_const:
377  case dwarf::DW_FORM_flag_present:
378  // Emit something to keep the lines and comments in sync.
379  // FIXME: Is there a better way to do this?
380  Asm->OutStreamer->AddBlankLine();
381  return;
382  case dwarf::DW_FORM_flag:
383  case dwarf::DW_FORM_ref1:
384  case dwarf::DW_FORM_data1:
385  case dwarf::DW_FORM_strx1:
386  case dwarf::DW_FORM_addrx1:
387  case dwarf::DW_FORM_ref2:
388  case dwarf::DW_FORM_data2:
389  case dwarf::DW_FORM_strx2:
390  case dwarf::DW_FORM_addrx2:
391  case dwarf::DW_FORM_strp:
392  case dwarf::DW_FORM_ref4:
393  case dwarf::DW_FORM_data4:
394  case dwarf::DW_FORM_ref_sup4:
395  case dwarf::DW_FORM_strx4:
396  case dwarf::DW_FORM_addrx4:
397  case dwarf::DW_FORM_ref8:
398  case dwarf::DW_FORM_ref_sig8:
399  case dwarf::DW_FORM_data8:
400  case dwarf::DW_FORM_ref_sup8:
401  case dwarf::DW_FORM_GNU_ref_alt:
402  case dwarf::DW_FORM_GNU_strp_alt:
403  case dwarf::DW_FORM_line_strp:
404  case dwarf::DW_FORM_sec_offset:
405  case dwarf::DW_FORM_strp_sup:
406  case dwarf::DW_FORM_addr:
407  case dwarf::DW_FORM_ref_addr:
408  Asm->OutStreamer->EmitIntValue(Integer, SizeOf(Asm, Form));
409  return;
410  case dwarf::DW_FORM_GNU_str_index:
411  case dwarf::DW_FORM_GNU_addr_index:
412  case dwarf::DW_FORM_ref_udata:
413  case dwarf::DW_FORM_udata:
414  Asm->EmitULEB128(Integer);
415  return;
416  case dwarf::DW_FORM_sdata:
417  Asm->EmitSLEB128(Integer);
418  return;
419  default: llvm_unreachable("DIE Value form not supported yet");
420  }
421 }
422 
423 /// SizeOf - Determine size of integer value in bytes.
424 ///
425 unsigned DIEInteger::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
426  switch (Form) {
427  case dwarf::DW_FORM_implicit_const:
428  case dwarf::DW_FORM_flag_present:
429  return 0;
430  case dwarf::DW_FORM_flag:
431  case dwarf::DW_FORM_ref1:
432  case dwarf::DW_FORM_data1:
433  case dwarf::DW_FORM_strx1:
434  case dwarf::DW_FORM_addrx1:
435  return sizeof(int8_t);
436  case dwarf::DW_FORM_ref2:
437  case dwarf::DW_FORM_data2:
438  case dwarf::DW_FORM_strx2:
439  case dwarf::DW_FORM_addrx2:
440  return sizeof(int16_t);
441  case dwarf::DW_FORM_ref4:
442  case dwarf::DW_FORM_data4:
443  case dwarf::DW_FORM_ref_sup4:
444  case dwarf::DW_FORM_strx4:
445  case dwarf::DW_FORM_addrx4:
446  return sizeof(int32_t);
447  case dwarf::DW_FORM_ref8:
448  case dwarf::DW_FORM_ref_sig8:
449  case dwarf::DW_FORM_data8:
450  case dwarf::DW_FORM_ref_sup8:
451  return sizeof(int64_t);
452  case dwarf::DW_FORM_ref_addr:
453  if (AP->getDwarfVersion() == 2)
454  return AP->getPointerSize();
456  case dwarf::DW_FORM_strp:
457  case dwarf::DW_FORM_GNU_ref_alt:
458  case dwarf::DW_FORM_GNU_strp_alt:
459  case dwarf::DW_FORM_line_strp:
460  case dwarf::DW_FORM_sec_offset:
461  case dwarf::DW_FORM_strp_sup:
462  switch (AP->OutStreamer->getContext().getDwarfFormat()) {
463  case dwarf::DWARF32:
464  return 4;
465  case dwarf::DWARF64:
466  return 8;
467  }
468  llvm_unreachable("Invalid DWARF format");
469  case dwarf::DW_FORM_GNU_str_index:
470  case dwarf::DW_FORM_GNU_addr_index:
471  case dwarf::DW_FORM_ref_udata:
472  case dwarf::DW_FORM_udata:
473  return getULEB128Size(Integer);
474  case dwarf::DW_FORM_sdata:
475  return getSLEB128Size(Integer);
476  case dwarf::DW_FORM_addr:
477  return AP->getPointerSize();
478  default: llvm_unreachable("DIE Value form not supported yet");
479  }
480 }
481 
484  O << "Int: " << (int64_t)Integer << " 0x";
485  O.write_hex(Integer);
486 }
487 
488 //===----------------------------------------------------------------------===//
489 // DIEExpr Implementation
490 //===----------------------------------------------------------------------===//
491 
492 /// EmitValue - Emit expression value.
493 ///
495  AP->EmitDebugThreadLocal(Expr, SizeOf(AP, Form));
496 }
497 
498 /// SizeOf - Determine size of expression value in bytes.
499 ///
500 unsigned DIEExpr::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
501  if (Form == dwarf::DW_FORM_data4) return 4;
502  if (Form == dwarf::DW_FORM_sec_offset) return 4;
503  if (Form == dwarf::DW_FORM_strp) return 4;
504  return AP->getPointerSize();
505 }
506 
508 void DIEExpr::print(raw_ostream &O) const { O << "Expr: " << *Expr; }
509 
510 //===----------------------------------------------------------------------===//
511 // DIELabel Implementation
512 //===----------------------------------------------------------------------===//
513 
514 /// EmitValue - Emit label value.
515 ///
517  AP->EmitLabelReference(Label, SizeOf(AP, Form),
518  Form == dwarf::DW_FORM_strp ||
519  Form == dwarf::DW_FORM_sec_offset ||
520  Form == dwarf::DW_FORM_ref_addr ||
521  Form == dwarf::DW_FORM_data4);
522 }
523 
524 /// SizeOf - Determine size of label value in bytes.
525 ///
526 unsigned DIELabel::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
527  if (Form == dwarf::DW_FORM_data4) return 4;
528  if (Form == dwarf::DW_FORM_sec_offset) return 4;
529  if (Form == dwarf::DW_FORM_strp) return 4;
530  return AP->MAI->getCodePointerSize();
531 }
532 
534 void DIELabel::print(raw_ostream &O) const { O << "Lbl: " << Label->getName(); }
535 
536 //===----------------------------------------------------------------------===//
537 // DIEDelta Implementation
538 //===----------------------------------------------------------------------===//
539 
540 /// EmitValue - Emit delta value.
541 ///
543  AP->EmitLabelDifference(LabelHi, LabelLo, SizeOf(AP, Form));
544 }
545 
546 /// SizeOf - Determine size of delta value in bytes.
547 ///
548 unsigned DIEDelta::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
549  if (Form == dwarf::DW_FORM_data4) return 4;
550  if (Form == dwarf::DW_FORM_sec_offset) return 4;
551  if (Form == dwarf::DW_FORM_strp) return 4;
552  return AP->MAI->getCodePointerSize();
553 }
554 
556 void DIEDelta::print(raw_ostream &O) const {
557  O << "Del: " << LabelHi->getName() << "-" << LabelLo->getName();
558 }
559 
560 //===----------------------------------------------------------------------===//
561 // DIEString Implementation
562 //===----------------------------------------------------------------------===//
563 
564 /// EmitValue - Emit string value.
565 ///
567  assert(
568  (Form == dwarf::DW_FORM_strp || Form == dwarf::DW_FORM_GNU_str_index) &&
569  "Expected valid string form");
570 
571  // Index of string in symbol table.
572  if (Form == dwarf::DW_FORM_GNU_str_index) {
573  DIEInteger(S.getIndex()).EmitValue(AP, Form);
574  return;
575  }
576 
577  // Relocatable symbol.
578  assert(Form == dwarf::DW_FORM_strp);
580  DIELabel(S.getSymbol()).EmitValue(AP, Form);
581  return;
582  }
583 
584  // Offset into symbol table.
585  DIEInteger(S.getOffset()).EmitValue(AP, Form);
586 }
587 
588 /// SizeOf - Determine size of delta value in bytes.
589 ///
590 unsigned DIEString::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
591  assert(
592  (Form == dwarf::DW_FORM_strp || Form == dwarf::DW_FORM_GNU_str_index) &&
593  "Expected valid string form");
594 
595  // Index of string in symbol table.
596  if (Form == dwarf::DW_FORM_GNU_str_index)
597  return DIEInteger(S.getIndex()).SizeOf(AP, Form);
598 
599  // Relocatable symbol.
601  return DIELabel(S.getSymbol()).SizeOf(AP, Form);
602 
603  // Offset into symbol table.
604  return DIEInteger(S.getOffset()).SizeOf(AP, Form);
605 }
606 
609  O << "String: " << S.getString();
610 }
611 
612 //===----------------------------------------------------------------------===//
613 // DIEInlineString Implementation
614 //===----------------------------------------------------------------------===//
616  if (Form == dwarf::DW_FORM_string) {
617  for (char ch : S)
618  AP->EmitInt8(ch);
619  AP->EmitInt8(0);
620  return;
621  }
622  llvm_unreachable("Expected valid string form");
623 }
624 
626  // Emit string bytes + NULL byte.
627  return S.size() + 1;
628 }
629 
632  O << "InlineString: " << S;
633 }
634 
635 //===----------------------------------------------------------------------===//
636 // DIEEntry Implementation
637 //===----------------------------------------------------------------------===//
638 
639 /// EmitValue - Emit debug information entry offset.
640 ///
642 
643  switch (Form) {
644  case dwarf::DW_FORM_ref1:
645  case dwarf::DW_FORM_ref2:
646  case dwarf::DW_FORM_ref4:
647  case dwarf::DW_FORM_ref8:
648  AP->OutStreamer->EmitIntValue(Entry->getOffset(), SizeOf(AP, Form));
649  return;
650 
651  case dwarf::DW_FORM_ref_udata:
652  AP->EmitULEB128(Entry->getOffset());
653  return;
654 
655  case dwarf::DW_FORM_ref_addr: {
656  // Get the absolute offset for this DIE within the debug info/types section.
657  unsigned Addr = Entry->getDebugSectionOffset();
658  if (const MCSymbol *SectionSym =
659  Entry->getUnit()->getCrossSectionRelativeBaseAddress()) {
660  AP->EmitLabelPlusOffset(SectionSym, Addr, SizeOf(AP, Form), true);
661  return;
662  }
663 
664  AP->OutStreamer->EmitIntValue(Addr, SizeOf(AP, Form));
665  return;
666  }
667  default:
668  llvm_unreachable("Improper form for DIE reference");
669  }
670 }
671 
672 unsigned DIEEntry::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
673  switch (Form) {
674  case dwarf::DW_FORM_ref1:
675  return 1;
676  case dwarf::DW_FORM_ref2:
677  return 2;
678  case dwarf::DW_FORM_ref4:
679  return 4;
680  case dwarf::DW_FORM_ref8:
681  return 8;
682  case dwarf::DW_FORM_ref_udata:
683  return getULEB128Size(Entry->getOffset());
684  case dwarf::DW_FORM_ref_addr:
685  if (AP->getDwarfVersion() == 2)
686  return AP->MAI->getCodePointerSize();
687  switch (AP->OutStreamer->getContext().getDwarfFormat()) {
688  case dwarf::DWARF32:
689  return 4;
690  case dwarf::DWARF64:
691  return 8;
692  }
693  llvm_unreachable("Invalid DWARF format");
694 
695  default:
696  llvm_unreachable("Improper form for DIE reference");
697  }
698 }
699 
701 void DIEEntry::print(raw_ostream &O) const {
702  O << format("Die: 0x%lx", (long)(intptr_t)&Entry);
703 }
704 
705 //===----------------------------------------------------------------------===//
706 // DIELoc Implementation
707 //===----------------------------------------------------------------------===//
708 
709 /// ComputeSize - calculate the size of the location expression.
710 ///
711 unsigned DIELoc::ComputeSize(const AsmPrinter *AP) const {
712  if (!Size) {
713  for (const auto &V : values())
714  Size += V.SizeOf(AP);
715  }
716 
717  return Size;
718 }
719 
720 /// EmitValue - Emit location data.
721 ///
723  switch (Form) {
724  default: llvm_unreachable("Improper form for block");
725  case dwarf::DW_FORM_block1: Asm->EmitInt8(Size); break;
726  case dwarf::DW_FORM_block2: Asm->EmitInt16(Size); break;
727  case dwarf::DW_FORM_block4: Asm->EmitInt32(Size); break;
728  case dwarf::DW_FORM_block:
729  case dwarf::DW_FORM_exprloc:
730  Asm->EmitULEB128(Size); break;
731  }
732 
733  for (const auto &V : values())
734  V.EmitValue(Asm);
735 }
736 
737 /// SizeOf - Determine size of location data in bytes.
738 ///
739 unsigned DIELoc::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
740  switch (Form) {
741  case dwarf::DW_FORM_block1: return Size + sizeof(int8_t);
742  case dwarf::DW_FORM_block2: return Size + sizeof(int16_t);
743  case dwarf::DW_FORM_block4: return Size + sizeof(int32_t);
744  case dwarf::DW_FORM_block:
745  case dwarf::DW_FORM_exprloc:
746  return Size + getULEB128Size(Size);
747  default: llvm_unreachable("Improper form for block");
748  }
749 }
750 
752 void DIELoc::print(raw_ostream &O) const {
753  printValues(O, *this, "ExprLoc", Size, 5);
754 }
755 
756 //===----------------------------------------------------------------------===//
757 // DIEBlock Implementation
758 //===----------------------------------------------------------------------===//
759 
760 /// ComputeSize - calculate the size of the block.
761 ///
762 unsigned DIEBlock::ComputeSize(const AsmPrinter *AP) const {
763  if (!Size) {
764  for (const auto &V : values())
765  Size += V.SizeOf(AP);
766  }
767 
768  return Size;
769 }
770 
771 /// EmitValue - Emit block data.
772 ///
774  switch (Form) {
775  default: llvm_unreachable("Improper form for block");
776  case dwarf::DW_FORM_block1: Asm->EmitInt8(Size); break;
777  case dwarf::DW_FORM_block2: Asm->EmitInt16(Size); break;
778  case dwarf::DW_FORM_block4: Asm->EmitInt32(Size); break;
779  case dwarf::DW_FORM_block: Asm->EmitULEB128(Size); break;
780  }
781 
782  for (const auto &V : values())
783  V.EmitValue(Asm);
784 }
785 
786 /// SizeOf - Determine size of block data in bytes.
787 ///
788 unsigned DIEBlock::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
789  switch (Form) {
790  case dwarf::DW_FORM_block1: return Size + sizeof(int8_t);
791  case dwarf::DW_FORM_block2: return Size + sizeof(int16_t);
792  case dwarf::DW_FORM_block4: return Size + sizeof(int32_t);
793  case dwarf::DW_FORM_block: return Size + getULEB128Size(Size);
794  default: llvm_unreachable("Improper form for block");
795  }
796 }
797 
799 void DIEBlock::print(raw_ostream &O) const {
800  printValues(O, *this, "Blk", Size, 5);
801 }
802 
803 //===----------------------------------------------------------------------===//
804 // DIELocList Implementation
805 //===----------------------------------------------------------------------===//
806 
807 unsigned DIELocList::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
808  if (Form == dwarf::DW_FORM_data4)
809  return 4;
810  if (Form == dwarf::DW_FORM_sec_offset)
811  return 4;
812  return AP->MAI->getCodePointerSize();
813 }
814 
815 /// EmitValue - Emit label value.
816 ///
818  DwarfDebug *DD = AP->getDwarfDebug();
819  MCSymbol *Label = DD->getDebugLocs().getList(Index).Label;
820  AP->emitDwarfSymbolReference(Label, /*ForceOffset*/ DD->useSplitDwarf());
821 }
822 
824 void DIELocList::print(raw_ostream &O) const { O << "LocList: " << Index; }
void EmitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit debug information entry offset.
Definition: DIE.cpp:641
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:39
iterator_range< typename GraphTraits< GraphType >::ChildIteratorType > children(const typename GraphTraits< GraphType >::NodeRef &G)
Definition: GraphTraits.h:102
unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const
SizeOf - Determine size of location data in bytes.
Definition: DIE.cpp:739
void print(raw_ostream &O) const
Definition: DIE.cpp:631
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
Definition: AsmPrinter.h:93
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
void EmitInt8(int Value) const
Emit a byte directive and value.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:42
Attribute
Attributes.
Definition: Dwarf.h:105
const DebugLocStream & getDebugLocs() const
Returns the entries for the .debug_loc section.
Definition: DwarfDebug.h:531
uint16_t getDwarfVersion() const
Collects and handles dwarf debug information.
Definition: DwarfDebug.h:203
void EmitValue(const AsmPrinter *AP) const
Emit value via the Dwarf writer.
Definition: DIE.cpp:325
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
Definition: Format.h:124
unsigned getDebugSectionOffset() const
Definition: DIE.h:829
void emitDwarfSymbolReference(const MCSymbol *Label, bool ForceOffset=false) const
Emit a reference to a symbol for use in dwarf.
void AddAttribute(dwarf::Attribute Attribute, dwarf::Form Form)
Adds another set of attribute information to the abbreviation.
Definition: DIE.h:109
void print(raw_ostream &O) const
Definition: DIE.cpp:752
void dump() const
Definition: DIE.cpp:271
void print(raw_ostream &O) const
Definition: DIE.cpp:108
bool useSplitDwarf() const
Returns whether or not to change the current debug info for the split dwarf proposal support...
Definition: DwarfDebug.h:519
int64_t getValue() const
Definition: DIE.h:69
Dwarf abbreviation data, describes one attribute of a Dwarf abbreviation.
Definition: DIE.h:49
unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const
SizeOf - Determine size of delta value in bytes.
Definition: DIE.cpp:590
virtual void EmitDebugThreadLocal(const MCExpr *Value, unsigned Size) const
Emit the directive and value for debug thread local expression.
Definition: AsmPrinter.cpp:623
void Profile(FoldingSetNodeID &ID) const
Used to gather unique data for the abbreviation folding set.
Definition: DIE.cpp:57
void print(raw_ostream &O) const
Definition: DIE.cpp:534
void AddImplicitConstAttribute(dwarf::Attribute Attribute, int64_t Value)
Adds attribute with DW_FORM_implicit_const value.
Definition: DIE.h:114
const DIE * getUnitDie() const
Climb up the parent chain to get the compile unit or type unit DIE that this DIE belongs to...
Definition: DIE.cpp:202
StringRef FormEncodingString(unsigned Encoding)
Definition: Dwarf.cpp:105
void print(raw_ostream &O) const
Definition: DIE.cpp:483
dwarf::Form getForm() const
Definition: DIE.h:68
void AddInteger(signed I)
Definition: FoldingSet.cpp:61
unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const
Definition: DIE.cpp:807
DIEAbbrev generateAbbrev() const
Generate the abbreviation for this DIE.
Definition: DIE.cpp:185
void print(raw_ostream &O) const
Definition: DIE.cpp:799
unsigned getPointerSize() const
Return the pointer size from the TargetMachine.
Definition: AsmPrinter.cpp:202
StringRef AttributeString(unsigned Attribute)
Definition: Dwarf.cpp:72
void setNumber(unsigned N)
Definition: DIE.h:105
bool doesDwarfUseRelocationsAcrossSections() const
Definition: MCAsmInfo.h:574
raw_ostream & write_hex(unsigned long long N)
Output N in hexadecimal, without any prefix or padding.
A list of DIE values.
Definition: DIE.h:589
void EmitInt16(int Value) const
Emit a short directive and value.
static Error getOffset(const SymbolRef &Sym, SectionRef Sec, uint64_t &Result)
unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const
SizeOf - Determine size of block data in bytes.
Definition: DIE.cpp:788
unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const
Definition: DIE.cpp:672
Helps unique DIEAbbrev objects and assigns abbreviation numbers.
Definition: DIE.h:135
void EmitLabelPlusOffset(const MCSymbol *Label, uint64_t Offset, unsigned Size, bool IsSectionRelative=false) const
Emit something like ".long Label+Offset" where the size in bytes of the directive is specified by Siz...
void EmitInt32(int Value) const
Emit a long directive and value.
void Emit(const AsmPrinter *AP) const
Print the abbreviation using the specified asm printer.
Definition: DIE.cpp:68
FoldingSetNodeID - This class is used to gather all the unique data bits of a node.
Definition: FoldingSet.h:311
const DIEUnit * getUnit() const
Climb up the parent chain to get the compile unit or type unit that this DIE belongs to...
Definition: DIE.cpp:213
void EmitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit delta value.
Definition: DIE.cpp:542
void print(raw_ostream &O) const
Definition: DIE.cpp:350
const MCAsmInfo * MAI
Target Asm Printer information.
Definition: AsmPrinter.h:84
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
void print(raw_ostream &O) const
Definition: DIE.cpp:824
void EmitULEB128(uint64_t Value, const char *Desc=nullptr, unsigned PadTo=0) const
Emit the specified unsigned leb128 value.
void dump() const
Definition: DIE.cpp:131
value_range values()
Definition: DIE.h:650
ValuesClass values(OptsTy... Options)
Helper to build a ValuesClass by forwarding a variable number of arguments as an initializer list to ...
Definition: CommandLine.h:624
bool hasChildren() const
Definition: DIE.h:102
A structured debug information entry.
Definition: DIE.h:662
void Profile(FoldingSetNodeID &ID) const
Used to gather unique data for the abbreviation folding set.
Definition: DIE.cpp:42
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:76
void print(raw_ostream &O) const
Definition: DIE.cpp:508
void EmitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit string value.
Definition: DIE.cpp:566
dwarf::Attribute getAttribute() const
Accessors.
Definition: DIE.h:67
static LLVM_DUMP_METHOD void printValues(raw_ostream &O, const DIEValueList &Values, StringRef Type, unsigned Size, unsigned IndentCount)
Definition: DIE.cpp:230
DwarfDebug * getDwarfDebug()
Definition: AsmPrinter.h:181
A label DIE.
Definition: DIE.h:218
void EmitLabelReference(const MCSymbol *Label, unsigned Size, bool IsSectionRelative=false) const
Emit something like ".long Label" where the size in bytes of the directive is specified by Size and L...
Definition: AsmPrinter.h:471
void print(raw_ostream &O) const
Definition: DIE.cpp:556
DIE * getParent() const
Definition: DIE.cpp:181
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned computeOffsetsAndAbbrevs(const AsmPrinter *AP, DIEAbbrevSet &AbbrevSet, unsigned CUOffset)
Compute the offset of this DIE and all its children.
Definition: DIE.cpp:276
unsigned getULEB128Size(uint64_t Value)
Utility function to get the size of the ULEB128-encoded value.
Definition: LEB128.cpp:20
unsigned SizeOf(const AsmPrinter *AP) const
Return the size of a value in bytes.
Definition: DIE.cpp:337
unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const
SizeOf - Determine size of expression value in bytes.
Definition: DIE.cpp:500
void EmitSLEB128(int64_t Value, const char *Desc=nullptr) const
Emit the specified signed leb128 value.
unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const
SizeOf - Determine size of label value in bytes.
Definition: DIE.cpp:526
DIEUnit(uint16_t Version, uint8_t AddrSize, dwarf::Tag UnitTag)
Definition: DIE.cpp:315
void dump() const
Definition: DIE.cpp:363
Represents a compile or type unit.
Definition: DIE.h:788
const size_t N
void print(raw_ostream &O) const
Definition: DIE.cpp:608
static Optional< unsigned > getTag(const TargetRegisterInfo *TRI, const MachineInstr &MI, const LoadInfo &LI)
const List & getList(size_t LI) const
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:132
void emitDwarfAbbrevs(const T &Abbrevs) const
Emit Dwarf abbreviation table.
Definition: AsmPrinter.h:528
unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const
SizeOf - Determine size of delta value in bytes.
Definition: DIE.cpp:548
dwarf::Tag getTag() const
Definition: DIE.h:698
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
DIEAbbrev & uniqueAbbreviation(DIE &Die)
Generate the abbreviation declaration for a DIE and return a pointer to the generated abbreviation...
Definition: DIE.cpp:145
An integer value DIE.
Definition: DIE.h:163
Dwarf abbreviation, describes the organization of a debug information object.
Definition: DIE.h:79
void print(raw_ostream &O, unsigned IndentCount=0) const
Definition: DIE.cpp:246
StringRef TagString(unsigned Tag)
Definition: Dwarf.cpp:21
#define I(x, y, z)
Definition: MD5.cpp:58
void EmitLabelDifference(const MCSymbol *Hi, const MCSymbol *Lo, unsigned Size) const
Emit something like ".long Hi-Lo" where the size in bytes of the directive is specified by Size and H...
void EmitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit location data.
Definition: DIE.cpp:722
void EmitValue(const AsmPrinter *AP, dwarf::Form Form) const
Definition: DIE.cpp:615
unsigned getSLEB128Size(int64_t Value)
Utility function to get the size of the SLEB128-encoded value.
Definition: LEB128.cpp:30
StringRef ChildrenString(unsigned Children)
Definition: Dwarf.cpp:62
DIEValue findAttribute(dwarf::Attribute Attribute) const
Find a value in the DIE with the attribute given.
Definition: DIE.cpp:220
bool isValidFormForVersion(Form F, unsigned Version, bool ExtensionsOk=true)
Tells whether the specified form is defined in the specified version, or is an extension if extension...
Definition: Dwarf.cpp:570
std::vector< uint8_t > Unit
Definition: FuzzerDefs.h:105
unsigned getCodePointerSize() const
Get the code pointer size in bytes.
Definition: MCAsmInfo.h:382
void EmitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit block data.
Definition: DIE.cpp:773
void EmitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit expression value.
Definition: DIE.cpp:494
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
Definition: Value.h:73
unsigned ComputeSize(const AsmPrinter *AP) const
ComputeSize - Calculate the size of the location expression.
Definition: DIE.cpp:711
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
Definition: Compiler.h:235
unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const
SizeOf - Determine size of integer value in bytes.
Definition: DIE.cpp:425
void setAbbrevNumber(unsigned I)
Set the abbreviation number for this DIE.
Definition: DIE.h:726
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44
#define DEBUG(X)
Definition: Debug.h:118
unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const
Definition: DIE.cpp:625
unsigned getDebugSectionOffset() const
Get the absolute offset within the .debug_info or .debug_types section for this DIE.
Definition: DIE.cpp:196
void EmitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit label value.
Definition: DIE.cpp:817
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
void Emit(const AsmPrinter *AP, MCSection *Section) const
Print all abbreviations using the specified asm printer.
Definition: DIE.cpp:169
unsigned ComputeSize(const AsmPrinter *AP) const
ComputeSize - Calculate the size of the location expression.
Definition: DIE.cpp:762
const uint64_t Version
Definition: InstrProf.h:865
void print(raw_ostream &O) const
Definition: DIE.cpp:701
void EmitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit integer of appropriate size.
Definition: DIE.cpp:374
void EmitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit label value.
Definition: DIE.cpp:516