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