LLVM  4.0.0
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 //===----------------------------------------------------------------------===//
35 // DIEAbbrevData Implementation
36 //===----------------------------------------------------------------------===//
37 
38 /// Profile - Used to gather unique data for the abbreviation folding set.
39 ///
41  // Explicitly cast to an integer type for which FoldingSetNodeID has
42  // overloads. Otherwise MSVC 2010 thinks this call is ambiguous.
43  ID.AddInteger(unsigned(Attribute));
44  ID.AddInteger(unsigned(Form));
45 }
46 
47 //===----------------------------------------------------------------------===//
48 // DIEAbbrev Implementation
49 //===----------------------------------------------------------------------===//
50 
51 /// Profile - Used to gather unique data for the abbreviation folding set.
52 ///
54  ID.AddInteger(unsigned(Tag));
55  ID.AddInteger(unsigned(Children));
56 
57  // For each attribute description.
58  for (unsigned i = 0, N = Data.size(); i < N; ++i)
59  Data[i].Profile(ID);
60 }
61 
62 /// Emit - Print the abbreviation using the specified asm printer.
63 ///
64 void DIEAbbrev::Emit(const AsmPrinter *AP) const {
65  // Emit its Dwarf tag type.
66  AP->EmitULEB128(Tag, dwarf::TagString(Tag).data());
67 
68  // Emit whether it has children DIEs.
69  AP->EmitULEB128((unsigned)Children, dwarf::ChildrenString(Children).data());
70 
71  // For each attribute description.
72  for (unsigned i = 0, N = Data.size(); i < N; ++i) {
73  const DIEAbbrevData &AttrData = Data[i];
74 
75  // Emit attribute type.
76  AP->EmitULEB128(AttrData.getAttribute(),
77  dwarf::AttributeString(AttrData.getAttribute()).data());
78 
79  // Emit form type.
80  AP->EmitULEB128(AttrData.getForm(),
81  dwarf::FormEncodingString(AttrData.getForm()).data());
82 
83  // Emit value for DW_FORM_implicit_const.
84  if (AttrData.getForm() == dwarf::DW_FORM_implicit_const) {
85  assert(AP->getDwarfVersion() >= 5 &&
86  "DW_FORM_implicit_const is supported starting from DWARFv5");
87  AP->EmitSLEB128(AttrData.getValue());
88  }
89  }
90 
91  // Mark end of abbreviation.
92  AP->EmitULEB128(0, "EOM(1)");
93  AP->EmitULEB128(0, "EOM(2)");
94 }
95 
98  O << "Abbreviation @"
99  << format("0x%lx", (long)(intptr_t)this)
100  << " "
102  << " "
103  << dwarf::ChildrenString(Children)
104  << '\n';
105 
106  for (unsigned i = 0, N = Data.size(); i < N; ++i) {
107  O << " "
108  << dwarf::AttributeString(Data[i].getAttribute())
109  << " "
110  << dwarf::FormEncodingString(Data[i].getForm())
111  << '\n';
112  }
113 }
114 
116 void DIEAbbrev::dump() { print(dbgs()); }
117 
118 //===----------------------------------------------------------------------===//
119 // DIEAbbrevSet Implementation
120 //===----------------------------------------------------------------------===//
121 
123  for (DIEAbbrev *Abbrev : Abbreviations)
124  Abbrev->~DIEAbbrev();
125 }
126 
128 
130  DIEAbbrev Abbrev = Die.generateAbbrev();
131  Abbrev.Profile(ID);
132 
133  void *InsertPos;
134  if (DIEAbbrev *Existing =
135  AbbreviationsSet.FindNodeOrInsertPos(ID, InsertPos)) {
136  Die.setAbbrevNumber(Existing->getNumber());
137  return *Existing;
138  }
139 
140  // Move the abbreviation to the heap and assign a number.
141  DIEAbbrev *New = new (Alloc) DIEAbbrev(std::move(Abbrev));
142  Abbreviations.push_back(New);
143  New->setNumber(Abbreviations.size());
144  Die.setAbbrevNumber(Abbreviations.size());
145 
146  // Store it for lookup.
147  AbbreviationsSet.InsertNode(New, InsertPos);
148  return *New;
149 }
150 
152  if (!Abbreviations.empty()) {
153  // Start the debug abbrev section.
154  AP->OutStreamer->SwitchSection(Section);
155  AP->emitDwarfAbbrevs(Abbreviations);
156  }
157 }
158 
159 //===----------------------------------------------------------------------===//
160 // DIE Implementation
161 //===----------------------------------------------------------------------===//
162 
163 DIE *DIE::getParent() const {
164  return Owner.dyn_cast<DIE*>();
165 }
166 
168  DIEAbbrev Abbrev(Tag, hasChildren());
169  for (const DIEValue &V : values())
170  if (V.getForm() == dwarf::DW_FORM_implicit_const)
171  Abbrev.AddImplicitConstAttribute(V.getAttribute(),
172  V.getDIEInteger().getValue());
173  else
174  Abbrev.AddAttribute(V.getAttribute(), V.getForm());
175  return Abbrev;
176 }
177 
178 unsigned DIE::getDebugSectionOffset() const {
179  const DIEUnit *Unit = getUnit();
180  assert(Unit && "DIE must be owned by a DIEUnit to get its absolute offset");
181  return Unit->getDebugSectionOffset() + getOffset();
182 }
183 
184 const DIE *DIE::getUnitDie() const {
185  const DIE *p = this;
186  while (p) {
187  if (p->getTag() == dwarf::DW_TAG_compile_unit ||
188  p->getTag() == dwarf::DW_TAG_type_unit)
189  return p;
190  p = p->getParent();
191  }
192  return nullptr;
193 }
194 
195 const DIEUnit *DIE::getUnit() const {
196  const DIE *UnitDie = getUnitDie();
197  if (UnitDie)
198  return UnitDie->Owner.dyn_cast<DIEUnit*>();
199  return nullptr;
200 }
201 
203  // Iterate through all the attributes until we find the one we're
204  // looking for, if we can't find it return NULL.
205  for (const auto &V : values())
206  if (V.getAttribute() == Attribute)
207  return V;
208  return DIEValue();
209 }
210 
212 static void printValues(raw_ostream &O, const DIEValueList &Values,
213  StringRef Type, unsigned Size, unsigned IndentCount) {
214  O << Type << ": Size: " << Size << "\n";
215 
216  unsigned I = 0;
217  const std::string Indent(IndentCount, ' ');
218  for (const auto &V : Values.values()) {
219  O << Indent;
220  O << "Blk[" << I++ << "]";
221  O << " " << dwarf::FormEncodingString(V.getForm()) << " ";
222  V.print(O);
223  O << "\n";
224  }
225 }
226 
228 void DIE::print(raw_ostream &O, unsigned IndentCount) const {
229  const std::string Indent(IndentCount, ' ');
230  O << Indent << "Die: " << format("0x%lx", (long)(intptr_t) this)
231  << ", Offset: " << Offset << ", Size: " << Size << "\n";
232 
233  O << Indent << dwarf::TagString(getTag()) << " "
234  << dwarf::ChildrenString(hasChildren()) << "\n";
235 
236  IndentCount += 2;
237  for (const auto &V : values()) {
238  O << Indent;
239  O << dwarf::AttributeString(V.getAttribute());
240  O << " " << dwarf::FormEncodingString(V.getForm()) << " ";
241  V.print(O);
242  O << "\n";
243  }
244  IndentCount -= 2;
245 
246  for (const auto &Child : children())
247  Child.print(O, IndentCount + 4);
248 
249  O << "\n";
250 }
251 
253 void DIE::dump() {
254  print(dbgs());
255 }
256 
258  DIEAbbrevSet &AbbrevSet,
259  unsigned CUOffset) {
260  // Unique the abbreviation and fill in the abbreviation number so this DIE
261  // can be emitted.
262  const DIEAbbrev &Abbrev = AbbrevSet.uniqueAbbreviation(*this);
263 
264  // Set compile/type unit relative offset of this DIE.
265  setOffset(CUOffset);
266 
267  // Add the byte size of the abbreviation code.
268  CUOffset += getULEB128Size(getAbbrevNumber());
269 
270  // Add the byte size of all the DIE attribute values.
271  for (const auto &V : values())
272  CUOffset += V.SizeOf(AP);
273 
274  // Let the children compute their offsets and abbreviation numbers.
275  if (hasChildren()) {
276  (void)Abbrev;
277  assert(Abbrev.hasChildren() && "Children flag not set");
278 
279  for (auto &Child : children())
280  CUOffset = Child.computeOffsetsAndAbbrevs(AP, AbbrevSet, CUOffset);
281 
282  // Each child chain is terminated with a zero byte, adjust the offset.
283  CUOffset += sizeof(int8_t);
284  }
285 
286  // Compute the byte size of this DIE and all of its children correctly. This
287  // is needed so that top level DIE can help the compile unit set its length
288  // correctly.
289  setSize(CUOffset - getOffset());
290  return CUOffset;
291 }
292 
293 //===----------------------------------------------------------------------===//
294 // DIEUnit Implementation
295 //===----------------------------------------------------------------------===//
296 DIEUnit::DIEUnit(uint16_t V, uint8_t A, dwarf::Tag UnitTag)
297  : Die(UnitTag), Section(nullptr), Offset(0), Length(0), Version(V),
298  AddrSize(A)
299 {
300  Die.Owner = this;
301  assert((UnitTag == dwarf::DW_TAG_compile_unit ||
302  UnitTag == dwarf::DW_TAG_type_unit ||
303  UnitTag == dwarf::DW_TAG_partial_unit) && "expected a unit TAG");
304 }
305 
306 void DIEValue::EmitValue(const AsmPrinter *AP) const {
307  switch (Ty) {
308  case isNone:
309  llvm_unreachable("Expected valid DIEValue");
310 #define HANDLE_DIEVALUE(T) \
311  case is##T: \
312  getDIE##T().EmitValue(AP, Form); \
313  break;
314 #include "llvm/CodeGen/DIEValue.def"
315  }
316 }
317 
318 unsigned DIEValue::SizeOf(const AsmPrinter *AP) const {
319  switch (Ty) {
320  case isNone:
321  llvm_unreachable("Expected valid DIEValue");
322 #define HANDLE_DIEVALUE(T) \
323  case is##T: \
324  return getDIE##T().SizeOf(AP, Form);
325 #include "llvm/CodeGen/DIEValue.def"
326  }
327  llvm_unreachable("Unknown DIE kind");
328 }
329 
331 void DIEValue::print(raw_ostream &O) const {
332  switch (Ty) {
333  case isNone:
334  llvm_unreachable("Expected valid DIEValue");
335 #define HANDLE_DIEVALUE(T) \
336  case is##T: \
337  getDIE##T().print(O); \
338  break;
339 #include "llvm/CodeGen/DIEValue.def"
340  }
341 }
342 
344 void DIEValue::dump() const {
345  print(dbgs());
346 }
347 
348 //===----------------------------------------------------------------------===//
349 // DIEInteger Implementation
350 //===----------------------------------------------------------------------===//
351 
352 /// EmitValue - Emit integer of appropriate size.
353 ///
355  switch (Form) {
356  case dwarf::DW_FORM_implicit_const:
358  case dwarf::DW_FORM_flag_present:
359  // Emit something to keep the lines and comments in sync.
360  // FIXME: Is there a better way to do this?
361  Asm->OutStreamer->AddBlankLine();
362  return;
363  case dwarf::DW_FORM_flag:
365  case dwarf::DW_FORM_ref1:
367  case dwarf::DW_FORM_data1:
369  case dwarf::DW_FORM_ref2:
371  case dwarf::DW_FORM_data2:
373  case dwarf::DW_FORM_strp:
375  case dwarf::DW_FORM_ref4:
377  case dwarf::DW_FORM_data4:
379  case dwarf::DW_FORM_ref8:
381  case dwarf::DW_FORM_ref_sig8:
383  case dwarf::DW_FORM_data8:
385  case dwarf::DW_FORM_GNU_ref_alt:
387  case dwarf::DW_FORM_GNU_strp_alt:
389  case dwarf::DW_FORM_line_strp:
391  case dwarf::DW_FORM_sec_offset:
393  case dwarf::DW_FORM_strp_sup:
395  case dwarf::DW_FORM_ref_sup:
397  case dwarf::DW_FORM_addr:
399  case dwarf::DW_FORM_ref_addr:
400  Asm->OutStreamer->EmitIntValue(Integer, SizeOf(Asm, Form));
401  return;
402  case dwarf::DW_FORM_GNU_str_index:
404  case dwarf::DW_FORM_GNU_addr_index:
406  case dwarf::DW_FORM_ref_udata:
408  case dwarf::DW_FORM_udata:
409  Asm->EmitULEB128(Integer);
410  return;
411  case dwarf::DW_FORM_sdata:
412  Asm->EmitSLEB128(Integer);
413  return;
414  default: llvm_unreachable("DIE Value form not supported yet");
415  }
416 }
417 
418 /// SizeOf - Determine size of integer value in bytes.
419 ///
420 unsigned DIEInteger::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
421  switch (Form) {
422  case dwarf::DW_FORM_implicit_const: LLVM_FALLTHROUGH;
423  case dwarf::DW_FORM_flag_present: return 0;
424  case dwarf::DW_FORM_flag: LLVM_FALLTHROUGH;
425  case dwarf::DW_FORM_ref1: LLVM_FALLTHROUGH;
426  case dwarf::DW_FORM_data1: return sizeof(int8_t);
427  case dwarf::DW_FORM_ref2: LLVM_FALLTHROUGH;
428  case dwarf::DW_FORM_data2: return sizeof(int16_t);
429  case dwarf::DW_FORM_ref4: LLVM_FALLTHROUGH;
430  case dwarf::DW_FORM_data4: return sizeof(int32_t);
431  case dwarf::DW_FORM_ref8: LLVM_FALLTHROUGH;
432  case dwarf::DW_FORM_ref_sig8: LLVM_FALLTHROUGH;
433  case dwarf::DW_FORM_data8: return sizeof(int64_t);
434  case dwarf::DW_FORM_ref_addr:
435  if (AP->getDwarfVersion() == 2)
436  return AP->getPointerSize();
438  case dwarf::DW_FORM_strp:
440  case dwarf::DW_FORM_GNU_ref_alt:
442  case dwarf::DW_FORM_GNU_strp_alt:
444  case dwarf::DW_FORM_line_strp:
446  case dwarf::DW_FORM_sec_offset:
448  case dwarf::DW_FORM_strp_sup:
450  case dwarf::DW_FORM_ref_sup:
451  switch (AP->OutStreamer->getContext().getDwarfFormat()) {
452  case dwarf::DWARF32:
453  return 4;
454  case dwarf::DWARF64:
455  return 8;
456  }
457  llvm_unreachable("Invalid DWARF format");
458  case dwarf::DW_FORM_GNU_str_index:
460  case dwarf::DW_FORM_GNU_addr_index:
462  case dwarf::DW_FORM_ref_udata:
464  case dwarf::DW_FORM_udata:
465  return getULEB128Size(Integer);
466  case dwarf::DW_FORM_sdata:
467  return getSLEB128Size(Integer);
468  case dwarf::DW_FORM_addr:
469  return AP->getPointerSize();
470  default: llvm_unreachable("DIE Value form not supported yet");
471  }
472 }
473 
476  O << "Int: " << (int64_t)Integer << " 0x";
477  O.write_hex(Integer);
478 }
479 
480 //===----------------------------------------------------------------------===//
481 // DIEExpr Implementation
482 //===----------------------------------------------------------------------===//
483 
484 /// EmitValue - Emit expression value.
485 ///
487  AP->EmitDebugValue(Expr, SizeOf(AP, Form));
488 }
489 
490 /// SizeOf - Determine size of expression value in bytes.
491 ///
492 unsigned DIEExpr::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
493  if (Form == dwarf::DW_FORM_data4) return 4;
494  if (Form == dwarf::DW_FORM_sec_offset) return 4;
495  if (Form == dwarf::DW_FORM_strp) return 4;
496  return AP->getPointerSize();
497 }
498 
500 void DIEExpr::print(raw_ostream &O) const { O << "Expr: " << *Expr; }
501 
502 //===----------------------------------------------------------------------===//
503 // DIELabel Implementation
504 //===----------------------------------------------------------------------===//
505 
506 /// EmitValue - Emit label value.
507 ///
509  AP->EmitLabelReference(Label, SizeOf(AP, Form),
510  Form == dwarf::DW_FORM_strp ||
511  Form == dwarf::DW_FORM_sec_offset ||
512  Form == dwarf::DW_FORM_ref_addr ||
513  Form == dwarf::DW_FORM_data4);
514 }
515 
516 /// SizeOf - Determine size of label value in bytes.
517 ///
518 unsigned DIELabel::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
519  if (Form == dwarf::DW_FORM_data4) return 4;
520  if (Form == dwarf::DW_FORM_sec_offset) return 4;
521  if (Form == dwarf::DW_FORM_strp) return 4;
522  return AP->getPointerSize();
523 }
524 
526 void DIELabel::print(raw_ostream &O) const { O << "Lbl: " << Label->getName(); }
527 
528 //===----------------------------------------------------------------------===//
529 // DIEDelta Implementation
530 //===----------------------------------------------------------------------===//
531 
532 /// EmitValue - Emit delta value.
533 ///
535  AP->EmitLabelDifference(LabelHi, LabelLo, SizeOf(AP, Form));
536 }
537 
538 /// SizeOf - Determine size of delta value in bytes.
539 ///
540 unsigned DIEDelta::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
541  if (Form == dwarf::DW_FORM_data4) return 4;
542  if (Form == dwarf::DW_FORM_sec_offset) return 4;
543  if (Form == dwarf::DW_FORM_strp) return 4;
544  return AP->getPointerSize();
545 }
546 
548 void DIEDelta::print(raw_ostream &O) const {
549  O << "Del: " << LabelHi->getName() << "-" << LabelLo->getName();
550 }
551 
552 //===----------------------------------------------------------------------===//
553 // DIEString Implementation
554 //===----------------------------------------------------------------------===//
555 
556 /// EmitValue - Emit string value.
557 ///
559  assert(
560  (Form == dwarf::DW_FORM_strp || Form == dwarf::DW_FORM_GNU_str_index) &&
561  "Expected valid string form");
562 
563  // Index of string in symbol table.
564  if (Form == dwarf::DW_FORM_GNU_str_index) {
565  DIEInteger(S.getIndex()).EmitValue(AP, Form);
566  return;
567  }
568 
569  // Relocatable symbol.
570  assert(Form == dwarf::DW_FORM_strp);
572  DIELabel(S.getSymbol()).EmitValue(AP, Form);
573  return;
574  }
575 
576  // Offset into symbol table.
577  DIEInteger(S.getOffset()).EmitValue(AP, Form);
578 }
579 
580 /// SizeOf - Determine size of delta value in bytes.
581 ///
582 unsigned DIEString::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
583  assert(
584  (Form == dwarf::DW_FORM_strp || Form == dwarf::DW_FORM_GNU_str_index) &&
585  "Expected valid string form");
586 
587  // Index of string in symbol table.
588  if (Form == dwarf::DW_FORM_GNU_str_index)
589  return DIEInteger(S.getIndex()).SizeOf(AP, Form);
590 
591  // Relocatable symbol.
593  return DIELabel(S.getSymbol()).SizeOf(AP, Form);
594 
595  // Offset into symbol table.
596  return DIEInteger(S.getOffset()).SizeOf(AP, Form);
597 }
598 
601  O << "String: " << S.getString();
602 }
603 
604 //===----------------------------------------------------------------------===//
605 // DIEInlineString Implementation
606 //===----------------------------------------------------------------------===//
608  if (Form == dwarf::DW_FORM_string) {
609  for (char ch : S)
610  AP->EmitInt8(ch);
611  AP->EmitInt8(0);
612  return;
613  }
614  llvm_unreachable("Expected valid string form");
615 }
616 
618  // Emit string bytes + NULL byte.
619  return S.size() + 1;
620 }
621 
624  O << "InlineString: " << S;
625 }
626 
627 //===----------------------------------------------------------------------===//
628 // DIEEntry Implementation
629 //===----------------------------------------------------------------------===//
630 
631 /// EmitValue - Emit debug information entry offset.
632 ///
634 
635  switch (Form) {
636  case dwarf::DW_FORM_ref1:
637  case dwarf::DW_FORM_ref2:
638  case dwarf::DW_FORM_ref4:
639  case dwarf::DW_FORM_ref8:
640  AP->OutStreamer->EmitIntValue(Entry->getOffset(), SizeOf(AP, Form));
641  return;
642 
643  case dwarf::DW_FORM_ref_udata:
644  AP->EmitULEB128(Entry->getOffset());
645  return;
646 
647  case dwarf::DW_FORM_ref_addr: {
648  // Get the absolute offset for this DIE within the debug info/types section.
649  unsigned Addr = Entry->getDebugSectionOffset();
651  const DwarfDebug *DD = AP->getDwarfDebug();
652  if (DD)
653  assert(!DD->useSplitDwarf() &&
654  "TODO: dwo files can't have relocations.");
655  const DIEUnit *Unit = Entry->getUnit();
656  assert(Unit && "CUDie should belong to a CU.");
657  MCSection *Section = Unit->getSection();
658  if (Section) {
659  const MCSymbol *SectionSym = Section->getBeginSymbol();
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->getPointerSize();
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->getPointerSize();
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; }
DIEAbbrev generateAbbrev() const
Generate the abbreviation for this DIE.
Definition: DIE.cpp:167
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:40
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 debug information entry offset.
Definition: DIE.cpp:633
void setSize(unsigned S)
Definition: DIE.h:760
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
Definition: AsmPrinter.h:84
size_t i
void EmitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit string value.
Definition: DIE.cpp:558
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
Definition: Compiler.h:450
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:39
void EmitInt8(int Value) const
Emit a byte directive and value.
void EmitValue(const AsmPrinter *AP) const
Emit value via the Dwarf writer.
Definition: DIE.cpp:306
void print(raw_ostream &O) const
Definition: DIE.cpp:475
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...
Attribute
Attributes.
Definition: Dwarf.h:94
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...
child_range children()
Definition: DIE.h:704
Collects and handles dwarf debug information.
Definition: DwarfDebug.h:196
bool hasChildren() const
Definition: DIE.h:101
virtual void EmitDebugValue(const MCExpr *Value, unsigned Size) const
Emit the directive and value for debug thread local expression.
Definition: AsmPrinter.cpp:574
void EmitInt32(int Value) const
Emit a long directive and value.
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:440
void print(raw_ostream &O) const
Definition: DIE.cpp:526
void AddAttribute(dwarf::Attribute Attribute, dwarf::Form Form)
Adds another set of attribute information to the abbreviation.
Definition: DIE.h:108
void dump()
Definition: DIE.cpp:253
void Profile(FoldingSetNodeID &ID) const
Used to gather unique data for the abbreviation folding set.
Definition: DIE.cpp:53
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:184
Dwarf abbreviation data, describes one attribute of a Dwarf abbreviation.
Definition: DIE.h:48
void print(raw_ostream &O, unsigned IndentCount=0) const
Definition: DIE.cpp:228
dwarf::Form getForm() const
Definition: DIE.h:67
void AddImplicitConstAttribute(dwarf::Attribute Attribute, int64_t Value)
Adds attribute with DW_FORM_implicit_const value.
Definition: DIE.h:113
StringRef FormEncodingString(unsigned Encoding)
Definition: Dwarf.cpp:58
unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const
SizeOf - Determine size of delta value in bytes.
Definition: DIE.cpp:582
void AddInteger(signed I)
Definition: FoldingSet.cpp:61
uint16_t getDwarfVersion() const
const List & getList(size_t LI) const
void EmitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit location data.
Definition: DIE.cpp:722
unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const
Definition: DIE.cpp:672
StringRef AttributeString(unsigned Attribute)
Definition: Dwarf.cpp:47
void setNumber(unsigned N)
Definition: DIE.h:104
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:585
void emitDwarfSymbolReference(const MCSymbol *Label, bool ForceOffset=false) const
Emit a reference to a symbol for use in dwarf.
void EmitInt16(int Value) const
Emit a short directive and value.
unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const
Definition: DIE.cpp:617
void EmitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit expression value.
Definition: DIE.cpp:486
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
Definition: StringRef.h:135
dwarf::Tag getTag() const
Definition: DIE.h:692
void print(raw_ostream &O) const
Definition: DIE.cpp:824
Helps unique DIEAbbrev objects and assigns abbreviation numbers.
Definition: DIE.h:134
format_object< Ts...> format(const char *Fmt, const Ts &...Vals)
These are helper functions used to produce formatted output.
Definition: Format.h:124
void dump() const
Definition: DIE.cpp:344
FoldingSetNodeID - This class is used to gather all the unique data bits of a node.
Definition: FoldingSet.h:316
unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const
SizeOf - Determine size of label value in bytes.
Definition: DIE.cpp:518
bool useSplitDwarf() const
Returns whether or not to change the current debug info for the split dwarf proposal support...
Definition: DwarfDebug.h:516
bool hasChildren() const
Definition: DIE.h:696
unsigned getDebugSectionOffset() const
Get the absolute offset within the .debug_info or .debug_types section for this DIE.
Definition: DIE.cpp:178
const MCAsmInfo * MAI
Target Asm Printer information.
Definition: AsmPrinter.h:75
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
unsigned getAbbrevNumber() const
Definition: DIE.h:691
value_range values()
Definition: DIE.h:643
DIEValue findAttribute(dwarf::Attribute Attribute) const
Find a value in the DIE with the attribute given.
Definition: DIE.cpp:202
void EmitULEB128(uint64_t Value, const char *Desc=nullptr, unsigned PadTo=0) const
Emit the specified unsigned leb128 value.
DIE * getParent() const
Definition: DIE.cpp:163
A structured debug information entry.
Definition: DIE.h:655
void print(raw_ostream &O) const
Definition: DIE.cpp:600
void EmitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit delta value.
Definition: DIE.cpp:534
void Emit(const AsmPrinter *AP, MCSection *Section) const
Print all abbreviations using the specified asm printer.
Definition: DIE.cpp:151
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:67
unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const
SizeOf - Determine size of integer value in bytes.
Definition: DIE.cpp:420
unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const
SizeOf - Determine size of block data in bytes.
Definition: DIE.cpp:788
void print(raw_ostream &O) const
Definition: DIE.cpp:799
uint32_t Offset
static LLVM_DUMP_METHOD void printValues(raw_ostream &O, const DIEValueList &Values, StringRef Type, unsigned Size, unsigned IndentCount)
Definition: DIE.cpp:212
DwarfDebug * getDwarfDebug()
Definition: AsmPrinter.h:152
A label DIE.
Definition: DIE.h:216
void print(raw_ostream &O) const
Definition: DIE.cpp:701
void print(raw_ostream &O)
Definition: DIE.cpp:97
void dump()
Definition: DIE.cpp:116
int64_t getValue() const
Definition: DIE.h:68
#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:257
void print(raw_ostream &O) const
Definition: DIE.cpp:623
unsigned getULEB128Size(uint64_t Value)
Utility function to get the size of the ULEB128-encoded value.
Definition: LEB128.cpp:20
void EmitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit label value.
Definition: DIE.cpp:817
dwarf::Attribute getAttribute() const
Accessors.
Definition: DIE.h:66
unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const
SizeOf - Determine size of expression value in bytes.
Definition: DIE.cpp:492
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:195
unsigned getDebugSectionOffset() const
Definition: DIE.h:816
DIEUnit(uint16_t Version, uint8_t AddrSize, dwarf::Tag UnitTag)
The size in bytes of an address for this unit.
Definition: DIE.cpp:296
const DebugLocStream & getDebugLocs() const
Returns the entries for the .debug_loc section.
Definition: DwarfDebug.h:526
unsigned getOffset() const
Get the compile/type unit relative offset of this DIE.
Definition: DIE.h:694
Represents a compile or type unit.
Definition: DIE.h:782
void emitDwarfAbbrevs(const T &Abbrevs) const
Emit Dwarf abbreviation table.
Definition: AsmPrinter.h:497
MCSymbol * getBeginSymbol()
Definition: MCSection.h:106
void Profile(FoldingSetNodeID &ID) const
Used to gather unique data for the abbreviation folding set.
Definition: DIE.cpp:40
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:132
unsigned SizeOf(const AsmPrinter *AP) const
Return the size of a value in bytes.
Definition: DIE.cpp:318
void EmitValue(const AsmPrinter *AP, dwarf::Form Form) const
Definition: DIE.cpp:607
unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const
SizeOf - Determine size of location data in bytes.
Definition: DIE.cpp:739
DIEAbbrev & uniqueAbbreviation(DIE &Die)
Generate the abbreviation declaration for a DIE and return a pointer to the generated abbreviation...
Definition: DIE.cpp:127
An integer value DIE.
Definition: DIE.h:161
Dwarf abbreviation, describes the organization of a debug information object.
Definition: DIE.h:78
StringRef TagString(unsigned Tag)
Definition: Dwarf.cpp:21
StringRef getName() const
getName - Get the symbol name.
Definition: MCSymbol.h:199
void EmitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit integer of appropriate size.
Definition: DIE.cpp:354
void EmitSLEB128(int64_t Value, const char *Desc=nullptr) const
Emit the specified signed leb128 value.
void setOffset(unsigned O)
Definition: DIE.h:759
#define I(x, y, z)
Definition: MD5.cpp:54
#define N
unsigned getPointerSize() const
Return the pointer size from the TargetMachine.
Definition: AsmPrinter.cpp:154
unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const
Definition: DIE.cpp:807
void print(raw_ostream &O) const
Definition: DIE.cpp:548
unsigned getSLEB128Size(int64_t Value)
Utility function to get the size of the SLEB128-encoded value.
Definition: LEB128.cpp:30
void EmitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit label value.
Definition: DIE.cpp:508
StringRef ChildrenString(unsigned Children)
Definition: Dwarf.cpp:39
std::vector< uint8_t > Unit
Definition: FuzzerDefs.h:71
void print(raw_ostream &O) const
Definition: DIE.cpp:752
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
unsigned ComputeSize(const AsmPrinter *AP) const
ComputeSize - Calculate the size of the location expression.
Definition: DIE.cpp:762
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
Definition: Compiler.h:239
void setAbbrevNumber(unsigned I)
Set the abbreviation number for this DIE.
Definition: DIE.h:720
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44
unsigned ComputeSize(const AsmPrinter *AP) const
ComputeSize - Calculate the size of the location expression.
Definition: DIE.cpp:711
void Emit(const AsmPrinter *AP) const
Print the abbreviation using the specified asm printer.
Definition: DIE.cpp:64
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:47
void print(raw_ostream &O) const
Definition: DIE.cpp:500
void print(raw_ostream &O) const
Definition: DIE.cpp:331
static GCRegistry::Add< ErlangGC > A("erlang","erlang-compatible garbage collector")
const uint64_t Version
Definition: InstrProf.h:799
bool doesDwarfUseRelocationsAcrossSections() const
Definition: MCAsmInfo.h:558
unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const
SizeOf - Determine size of delta value in bytes.
Definition: DIE.cpp:540