]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/CodeGen/AsmPrinter/DIE.cpp
Update lldb to trunk r290819 and resolve conflicts.
[FreeBSD/FreeBSD.git] / contrib / llvm / lib / CodeGen / AsmPrinter / DIE.cpp
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"
19 #include "llvm/CodeGen/AsmPrinter.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"
26 #include "llvm/Support/ErrorHandling.h"
27 #include "llvm/Support/Format.h"
28 #include "llvm/Support/FormattedStream.h"
29 #include "llvm/Support/LEB128.h"
30 #include "llvm/Support/MD5.h"
31 #include "llvm/Support/raw_ostream.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 ///
40 void DIEAbbrevData::Profile(FoldingSetNodeID &ID) const {
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 ///
53 void DIEAbbrev::Profile(FoldingSetNodeID &ID) const {
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
84   // Mark end of abbreviation.
85   AP->EmitULEB128(0, "EOM(1)");
86   AP->EmitULEB128(0, "EOM(2)");
87 }
88
89 LLVM_DUMP_METHOD
90 void DIEAbbrev::print(raw_ostream &O) {
91   O << "Abbreviation @"
92     << format("0x%lx", (long)(intptr_t)this)
93     << "  "
94     << dwarf::TagString(Tag)
95     << " "
96     << dwarf::ChildrenString(Children)
97     << '\n';
98
99   for (unsigned i = 0, N = Data.size(); i < N; ++i) {
100     O << "  "
101       << dwarf::AttributeString(Data[i].getAttribute())
102       << "  "
103       << dwarf::FormEncodingString(Data[i].getForm())
104       << '\n';
105   }
106 }
107
108 LLVM_DUMP_METHOD
109 void DIEAbbrev::dump() { print(dbgs()); }
110
111 //===----------------------------------------------------------------------===//
112 // DIEAbbrevSet Implementation
113 //===----------------------------------------------------------------------===//
114
115 DIEAbbrevSet::~DIEAbbrevSet() {
116   for (DIEAbbrev *Abbrev : Abbreviations)
117     Abbrev->~DIEAbbrev();
118 }
119
120 DIEAbbrev &DIEAbbrevSet::uniqueAbbreviation(DIE &Die) {
121
122   FoldingSetNodeID ID;
123   DIEAbbrev Abbrev = Die.generateAbbrev();
124   Abbrev.Profile(ID);
125
126   void *InsertPos;
127   if (DIEAbbrev *Existing =
128           AbbreviationsSet.FindNodeOrInsertPos(ID, InsertPos)) {
129     Die.setAbbrevNumber(Existing->getNumber());
130     return *Existing;
131   }
132
133   // Move the abbreviation to the heap and assign a number.
134   DIEAbbrev *New = new (Alloc) DIEAbbrev(std::move(Abbrev));
135   Abbreviations.push_back(New);
136   New->setNumber(Abbreviations.size());
137   Die.setAbbrevNumber(Abbreviations.size());
138
139   // Store it for lookup.
140   AbbreviationsSet.InsertNode(New, InsertPos);
141   return *New;
142 }
143
144 void DIEAbbrevSet::Emit(const AsmPrinter *AP, MCSection *Section) const {
145   if (!Abbreviations.empty()) {
146     // Start the debug abbrev section.
147     AP->OutStreamer->SwitchSection(Section);
148     AP->emitDwarfAbbrevs(Abbreviations);
149   }
150 }
151
152 //===----------------------------------------------------------------------===//
153 // DIE Implementation
154 //===----------------------------------------------------------------------===//
155
156 DIE *DIE::getParent() const {
157   return Owner.dyn_cast<DIE*>();
158 }
159
160 DIEAbbrev DIE::generateAbbrev() const {
161   DIEAbbrev Abbrev(Tag, hasChildren());
162   for (const DIEValue &V : values())
163     Abbrev.AddAttribute(V.getAttribute(), V.getForm());
164   return Abbrev;
165 }
166
167 unsigned DIE::getDebugSectionOffset() const {
168   const DIEUnit *Unit = getUnit();
169   assert(Unit && "DIE must be owned by a DIEUnit to get its absolute offset");
170   return Unit->getDebugSectionOffset() + getOffset();
171 }
172
173 const DIE *DIE::getUnitDie() const {
174   const DIE *p = this;
175   while (p) {
176     if (p->getTag() == dwarf::DW_TAG_compile_unit ||
177         p->getTag() == dwarf::DW_TAG_type_unit)
178       return p;
179     p = p->getParent();
180   }
181   return nullptr;
182 }
183
184 const DIEUnit *DIE::getUnit() const {
185   const DIE *UnitDie = getUnitDie();
186   if (UnitDie)
187     return UnitDie->Owner.dyn_cast<DIEUnit*>();
188   return nullptr;
189 }
190
191 DIEValue DIE::findAttribute(dwarf::Attribute Attribute) const {
192   // Iterate through all the attributes until we find the one we're
193   // looking for, if we can't find it return NULL.
194   for (const auto &V : values())
195     if (V.getAttribute() == Attribute)
196       return V;
197   return DIEValue();
198 }
199
200 LLVM_DUMP_METHOD
201 static void printValues(raw_ostream &O, const DIEValueList &Values,
202                         StringRef Type, unsigned Size, unsigned IndentCount) {
203   O << Type << ": Size: " << Size << "\n";
204
205   unsigned I = 0;
206   const std::string Indent(IndentCount, ' ');
207   for (const auto &V : Values.values()) {
208     O << Indent;
209     O << "Blk[" << I++ << "]";
210     O << "  " << dwarf::FormEncodingString(V.getForm()) << " ";
211     V.print(O);
212     O << "\n";
213   }
214 }
215
216 LLVM_DUMP_METHOD
217 void DIE::print(raw_ostream &O, unsigned IndentCount) const {
218   const std::string Indent(IndentCount, ' ');
219   O << Indent << "Die: " << format("0x%lx", (long)(intptr_t) this)
220     << ", Offset: " << Offset << ", Size: " << Size << "\n";
221
222   O << Indent << dwarf::TagString(getTag()) << " "
223     << dwarf::ChildrenString(hasChildren()) << "\n";
224
225   IndentCount += 2;
226   for (const auto &V : values()) {
227     O << Indent;
228     O << dwarf::AttributeString(V.getAttribute());
229     O << "  " << dwarf::FormEncodingString(V.getForm()) << " ";
230     V.print(O);
231     O << "\n";
232   }
233   IndentCount -= 2;
234
235   for (const auto &Child : children())
236     Child.print(O, IndentCount + 4);
237
238   O << "\n";
239 }
240
241 LLVM_DUMP_METHOD
242 void DIE::dump() {
243   print(dbgs());
244 }
245
246 unsigned DIE::computeOffsetsAndAbbrevs(const AsmPrinter *AP,
247                                        DIEAbbrevSet &AbbrevSet,
248                                        unsigned CUOffset) {
249   // Unique the abbreviation and fill in the abbreviation number so this DIE
250   // can be emitted.
251   const DIEAbbrev &Abbrev = AbbrevSet.uniqueAbbreviation(*this);
252
253   // Set compile/type unit relative offset of this DIE.
254   setOffset(CUOffset);
255
256   // Add the byte size of the abbreviation code.
257   CUOffset += getULEB128Size(getAbbrevNumber());
258
259   // Add the byte size of all the DIE attribute values.
260   for (const auto &V : values())
261     CUOffset += V.SizeOf(AP);
262
263   // Let the children compute their offsets and abbreviation numbers.
264   if (hasChildren()) {
265     (void)Abbrev;
266     assert(Abbrev.hasChildren() && "Children flag not set");
267
268     for (auto &Child : children())
269       CUOffset = Child.computeOffsetsAndAbbrevs(AP, AbbrevSet, CUOffset);
270
271     // Each child chain is terminated with a zero byte, adjust the offset.
272     CUOffset += sizeof(int8_t);
273   }
274
275   // Compute the byte size of this DIE and all of its children correctly. This
276   // is needed so that top level DIE can help the compile unit set its length
277   // correctly.
278   setSize(CUOffset - getOffset());
279   return CUOffset;
280 }
281
282 //===----------------------------------------------------------------------===//
283 // DIEUnit Implementation
284 //===----------------------------------------------------------------------===//
285 DIEUnit::DIEUnit(uint16_t V, uint8_t A, dwarf::Tag UnitTag)
286     : Die(UnitTag), Section(nullptr), Offset(0), Length(0), Version(V),
287       AddrSize(A)
288 {
289   Die.Owner = this;
290   assert((UnitTag == dwarf::DW_TAG_compile_unit ||
291           UnitTag == dwarf::DW_TAG_type_unit ||
292           UnitTag == dwarf::DW_TAG_partial_unit) && "expected a unit TAG");
293 }
294
295 void DIEValue::EmitValue(const AsmPrinter *AP) const {
296   switch (Ty) {
297   case isNone:
298     llvm_unreachable("Expected valid DIEValue");
299 #define HANDLE_DIEVALUE(T)                                                     \
300   case is##T:                                                                  \
301     getDIE##T().EmitValue(AP, Form);                                           \
302     break;
303 #include "llvm/CodeGen/DIEValue.def"
304   }
305 }
306
307 unsigned DIEValue::SizeOf(const AsmPrinter *AP) const {
308   switch (Ty) {
309   case isNone:
310     llvm_unreachable("Expected valid DIEValue");
311 #define HANDLE_DIEVALUE(T)                                                     \
312   case is##T:                                                                  \
313     return getDIE##T().SizeOf(AP, Form);
314 #include "llvm/CodeGen/DIEValue.def"
315   }
316   llvm_unreachable("Unknown DIE kind");
317 }
318
319 LLVM_DUMP_METHOD
320 void DIEValue::print(raw_ostream &O) const {
321   switch (Ty) {
322   case isNone:
323     llvm_unreachable("Expected valid DIEValue");
324 #define HANDLE_DIEVALUE(T)                                                     \
325   case is##T:                                                                  \
326     getDIE##T().print(O);                                                      \
327     break;
328 #include "llvm/CodeGen/DIEValue.def"
329   }
330 }
331
332 LLVM_DUMP_METHOD
333 void DIEValue::dump() const {
334   print(dbgs());
335 }
336
337 //===----------------------------------------------------------------------===//
338 // DIEInteger Implementation
339 //===----------------------------------------------------------------------===//
340
341 /// EmitValue - Emit integer of appropriate size.
342 ///
343 void DIEInteger::EmitValue(const AsmPrinter *Asm, dwarf::Form Form) const {
344   switch (Form) {
345   case dwarf::DW_FORM_flag_present:
346     // Emit something to keep the lines and comments in sync.
347     // FIXME: Is there a better way to do this?
348     Asm->OutStreamer->AddBlankLine();
349     return;
350   case dwarf::DW_FORM_flag:
351     LLVM_FALLTHROUGH;
352   case dwarf::DW_FORM_ref1:
353     LLVM_FALLTHROUGH;
354   case dwarf::DW_FORM_data1:
355     LLVM_FALLTHROUGH;
356   case dwarf::DW_FORM_ref2:
357     LLVM_FALLTHROUGH;
358   case dwarf::DW_FORM_data2:
359     LLVM_FALLTHROUGH;
360   case dwarf::DW_FORM_strp:
361     LLVM_FALLTHROUGH;
362   case dwarf::DW_FORM_ref4:
363     LLVM_FALLTHROUGH;
364   case dwarf::DW_FORM_data4:
365     LLVM_FALLTHROUGH;
366   case dwarf::DW_FORM_ref8:
367     LLVM_FALLTHROUGH;
368   case dwarf::DW_FORM_ref_sig8:
369     LLVM_FALLTHROUGH;
370   case dwarf::DW_FORM_data8:
371     LLVM_FALLTHROUGH;
372   case dwarf::DW_FORM_GNU_ref_alt:
373     LLVM_FALLTHROUGH;
374   case dwarf::DW_FORM_GNU_strp_alt:
375     LLVM_FALLTHROUGH;
376   case dwarf::DW_FORM_line_strp:
377     LLVM_FALLTHROUGH;
378   case dwarf::DW_FORM_sec_offset:
379     LLVM_FALLTHROUGH;
380   case dwarf::DW_FORM_strp_sup:
381     LLVM_FALLTHROUGH;
382   case dwarf::DW_FORM_ref_sup:
383     LLVM_FALLTHROUGH;
384   case dwarf::DW_FORM_addr:
385     LLVM_FALLTHROUGH;
386   case dwarf::DW_FORM_ref_addr:
387     Asm->OutStreamer->EmitIntValue(Integer, SizeOf(Asm, Form));
388     return;
389   case dwarf::DW_FORM_GNU_str_index:
390     LLVM_FALLTHROUGH;
391   case dwarf::DW_FORM_GNU_addr_index:
392     LLVM_FALLTHROUGH;
393   case dwarf::DW_FORM_ref_udata:
394     LLVM_FALLTHROUGH;
395   case dwarf::DW_FORM_udata:
396     Asm->EmitULEB128(Integer);
397     return;
398   case dwarf::DW_FORM_sdata:
399     Asm->EmitSLEB128(Integer);
400     return;
401   default: llvm_unreachable("DIE Value form not supported yet");
402   }
403 }
404
405 /// SizeOf - Determine size of integer value in bytes.
406 ///
407 unsigned DIEInteger::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
408   switch (Form) {
409   case dwarf::DW_FORM_flag_present: return 0;
410   case dwarf::DW_FORM_flag:  LLVM_FALLTHROUGH;
411   case dwarf::DW_FORM_ref1:  LLVM_FALLTHROUGH;
412   case dwarf::DW_FORM_data1: return sizeof(int8_t);
413   case dwarf::DW_FORM_ref2:  LLVM_FALLTHROUGH;
414   case dwarf::DW_FORM_data2: return sizeof(int16_t);
415   case dwarf::DW_FORM_ref4:  LLVM_FALLTHROUGH;
416   case dwarf::DW_FORM_data4: return sizeof(int32_t);
417   case dwarf::DW_FORM_ref8:  LLVM_FALLTHROUGH;
418   case dwarf::DW_FORM_ref_sig8:  LLVM_FALLTHROUGH;
419   case dwarf::DW_FORM_data8: return sizeof(int64_t);
420   case dwarf::DW_FORM_ref_addr:
421     if (AP->getDwarfVersion() == 2)
422       return AP->getPointerSize();
423     LLVM_FALLTHROUGH;
424   case dwarf::DW_FORM_strp:
425     LLVM_FALLTHROUGH;
426   case dwarf::DW_FORM_GNU_ref_alt:
427     LLVM_FALLTHROUGH;
428   case dwarf::DW_FORM_GNU_strp_alt:
429     LLVM_FALLTHROUGH;
430   case dwarf::DW_FORM_line_strp:
431     LLVM_FALLTHROUGH;
432   case dwarf::DW_FORM_sec_offset:
433     LLVM_FALLTHROUGH;
434   case dwarf::DW_FORM_strp_sup:
435     LLVM_FALLTHROUGH;
436   case dwarf::DW_FORM_ref_sup:
437     switch (AP->OutStreamer->getContext().getDwarfFormat()) {
438     case dwarf::DWARF32:
439       return 4;
440     case dwarf::DWARF64:
441       return 8;
442     }
443     llvm_unreachable("Invalid DWARF format");
444   case dwarf::DW_FORM_GNU_str_index:
445     LLVM_FALLTHROUGH;
446   case dwarf::DW_FORM_GNU_addr_index:
447     LLVM_FALLTHROUGH;
448   case dwarf::DW_FORM_ref_udata:
449     LLVM_FALLTHROUGH;
450   case dwarf::DW_FORM_udata:
451     return getULEB128Size(Integer);
452   case dwarf::DW_FORM_sdata:
453     return getSLEB128Size(Integer);
454   case dwarf::DW_FORM_addr:
455     return AP->getPointerSize();
456   default: llvm_unreachable("DIE Value form not supported yet");
457   }
458 }
459
460 LLVM_DUMP_METHOD
461 void DIEInteger::print(raw_ostream &O) const {
462   O << "Int: " << (int64_t)Integer << "  0x";
463   O.write_hex(Integer);
464 }
465
466 //===----------------------------------------------------------------------===//
467 // DIEExpr Implementation
468 //===----------------------------------------------------------------------===//
469
470 /// EmitValue - Emit expression value.
471 ///
472 void DIEExpr::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
473   AP->OutStreamer->EmitValue(Expr, SizeOf(AP, Form));
474 }
475
476 /// SizeOf - Determine size of expression value in bytes.
477 ///
478 unsigned DIEExpr::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
479   if (Form == dwarf::DW_FORM_data4) return 4;
480   if (Form == dwarf::DW_FORM_sec_offset) return 4;
481   if (Form == dwarf::DW_FORM_strp) return 4;
482   return AP->getPointerSize();
483 }
484
485 LLVM_DUMP_METHOD
486 void DIEExpr::print(raw_ostream &O) const { O << "Expr: " << *Expr; }
487
488 //===----------------------------------------------------------------------===//
489 // DIELabel Implementation
490 //===----------------------------------------------------------------------===//
491
492 /// EmitValue - Emit label value.
493 ///
494 void DIELabel::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
495   AP->EmitLabelReference(Label, SizeOf(AP, Form),
496                          Form == dwarf::DW_FORM_strp ||
497                              Form == dwarf::DW_FORM_sec_offset ||
498                              Form == dwarf::DW_FORM_ref_addr ||
499                              Form == dwarf::DW_FORM_data4);
500 }
501
502 /// SizeOf - Determine size of label value in bytes.
503 ///
504 unsigned DIELabel::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
505   if (Form == dwarf::DW_FORM_data4) return 4;
506   if (Form == dwarf::DW_FORM_sec_offset) return 4;
507   if (Form == dwarf::DW_FORM_strp) return 4;
508   return AP->getPointerSize();
509 }
510
511 LLVM_DUMP_METHOD
512 void DIELabel::print(raw_ostream &O) const { O << "Lbl: " << Label->getName(); }
513
514 //===----------------------------------------------------------------------===//
515 // DIEDelta Implementation
516 //===----------------------------------------------------------------------===//
517
518 /// EmitValue - Emit delta value.
519 ///
520 void DIEDelta::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
521   AP->EmitLabelDifference(LabelHi, LabelLo, SizeOf(AP, Form));
522 }
523
524 /// SizeOf - Determine size of delta value in bytes.
525 ///
526 unsigned DIEDelta::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->getPointerSize();
531 }
532
533 LLVM_DUMP_METHOD
534 void DIEDelta::print(raw_ostream &O) const {
535   O << "Del: " << LabelHi->getName() << "-" << LabelLo->getName();
536 }
537
538 //===----------------------------------------------------------------------===//
539 // DIEString Implementation
540 //===----------------------------------------------------------------------===//
541
542 /// EmitValue - Emit string value.
543 ///
544 void DIEString::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
545   assert(
546       (Form == dwarf::DW_FORM_strp || Form == dwarf::DW_FORM_GNU_str_index) &&
547       "Expected valid string form");
548
549   // Index of string in symbol table.
550   if (Form == dwarf::DW_FORM_GNU_str_index) {
551     DIEInteger(S.getIndex()).EmitValue(AP, Form);
552     return;
553   }
554
555   // Relocatable symbol.
556   assert(Form == dwarf::DW_FORM_strp);
557   if (AP->MAI->doesDwarfUseRelocationsAcrossSections()) {
558     DIELabel(S.getSymbol()).EmitValue(AP, Form);
559     return;
560   }
561
562   // Offset into symbol table.
563   DIEInteger(S.getOffset()).EmitValue(AP, Form);
564 }
565
566 /// SizeOf - Determine size of delta value in bytes.
567 ///
568 unsigned DIEString::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
569   assert(
570       (Form == dwarf::DW_FORM_strp || Form == dwarf::DW_FORM_GNU_str_index) &&
571       "Expected valid string form");
572
573   // Index of string in symbol table.
574   if (Form == dwarf::DW_FORM_GNU_str_index)
575     return DIEInteger(S.getIndex()).SizeOf(AP, Form);
576
577   // Relocatable symbol.
578   if (AP->MAI->doesDwarfUseRelocationsAcrossSections())
579     return DIELabel(S.getSymbol()).SizeOf(AP, Form);
580
581   // Offset into symbol table.
582   return DIEInteger(S.getOffset()).SizeOf(AP, Form);
583 }
584
585 LLVM_DUMP_METHOD
586 void DIEString::print(raw_ostream &O) const {
587   O << "String: " << S.getString();
588 }
589
590 //===----------------------------------------------------------------------===//
591 // DIEInlineString Implementation
592 //===----------------------------------------------------------------------===//
593 void DIEInlineString::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
594   if (Form == dwarf::DW_FORM_string) {
595     for (char ch : S)
596       AP->EmitInt8(ch);
597     AP->EmitInt8(0);
598     return;
599   }
600   llvm_unreachable("Expected valid string form");
601 }
602
603 unsigned DIEInlineString::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
604   // Emit string bytes + NULL byte.
605   return S.size() + 1;
606 }
607
608 LLVM_DUMP_METHOD
609 void DIEInlineString::print(raw_ostream &O) const {
610   O << "InlineString: " << S;
611 }
612
613 //===----------------------------------------------------------------------===//
614 // DIEEntry Implementation
615 //===----------------------------------------------------------------------===//
616
617 /// EmitValue - Emit debug information entry offset.
618 ///
619 void DIEEntry::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
620
621   switch (Form) {
622   case dwarf::DW_FORM_ref1:
623   case dwarf::DW_FORM_ref2:
624   case dwarf::DW_FORM_ref4:
625   case dwarf::DW_FORM_ref8:
626     AP->OutStreamer->EmitIntValue(Entry->getOffset(), SizeOf(AP, Form));
627     return;
628
629   case dwarf::DW_FORM_ref_udata:
630     AP->EmitULEB128(Entry->getOffset());
631     return;
632
633   case dwarf::DW_FORM_ref_addr: {
634     // Get the absolute offset for this DIE within the debug info/types section.
635     unsigned Addr = Entry->getDebugSectionOffset();
636     if (AP->MAI->doesDwarfUseRelocationsAcrossSections()) {
637       const DwarfDebug *DD = AP->getDwarfDebug();
638       if (DD)
639         assert(!DD->useSplitDwarf() &&
640                "TODO: dwo files can't have relocations.");
641       const DIEUnit *Unit = Entry->getUnit();
642       assert(Unit && "CUDie should belong to a CU.");
643       MCSection *Section = Unit->getSection();
644       if (Section) {
645         const MCSymbol *SectionSym = Section->getBeginSymbol();
646         AP->EmitLabelPlusOffset(SectionSym, Addr, SizeOf(AP, Form), true);
647         return;
648       }
649     }
650     AP->OutStreamer->EmitIntValue(Addr, SizeOf(AP, Form));
651     return;
652   }
653   default:
654     llvm_unreachable("Improper form for DIE reference");
655   }
656 }
657
658 unsigned DIEEntry::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
659   switch (Form) {
660   case dwarf::DW_FORM_ref1:
661     return 1;
662   case dwarf::DW_FORM_ref2:
663     return 2;
664   case dwarf::DW_FORM_ref4:
665     return 4;
666   case dwarf::DW_FORM_ref8:
667     return 8;
668   case dwarf::DW_FORM_ref_udata:
669     return getULEB128Size(Entry->getOffset());
670   case dwarf::DW_FORM_ref_addr:
671     if (AP->getDwarfVersion() == 2)
672       return AP->getPointerSize();
673     switch (AP->OutStreamer->getContext().getDwarfFormat()) {
674     case dwarf::DWARF32:
675       return 4;
676     case dwarf::DWARF64:
677       return 8;
678     }
679     llvm_unreachable("Invalid DWARF format");
680
681   default:
682     llvm_unreachable("Improper form for DIE reference");
683   }
684 }
685
686 LLVM_DUMP_METHOD
687 void DIEEntry::print(raw_ostream &O) const {
688   O << format("Die: 0x%lx", (long)(intptr_t)&Entry);
689 }
690
691 //===----------------------------------------------------------------------===//
692 // DIELoc Implementation
693 //===----------------------------------------------------------------------===//
694
695 /// ComputeSize - calculate the size of the location expression.
696 ///
697 unsigned DIELoc::ComputeSize(const AsmPrinter *AP) const {
698   if (!Size) {
699     for (const auto &V : values())
700       Size += V.SizeOf(AP);
701   }
702
703   return Size;
704 }
705
706 /// EmitValue - Emit location data.
707 ///
708 void DIELoc::EmitValue(const AsmPrinter *Asm, dwarf::Form Form) const {
709   switch (Form) {
710   default: llvm_unreachable("Improper form for block");
711   case dwarf::DW_FORM_block1: Asm->EmitInt8(Size);    break;
712   case dwarf::DW_FORM_block2: Asm->EmitInt16(Size);   break;
713   case dwarf::DW_FORM_block4: Asm->EmitInt32(Size);   break;
714   case dwarf::DW_FORM_block:
715   case dwarf::DW_FORM_exprloc:
716     Asm->EmitULEB128(Size); break;
717   }
718
719   for (const auto &V : values())
720     V.EmitValue(Asm);
721 }
722
723 /// SizeOf - Determine size of location data in bytes.
724 ///
725 unsigned DIELoc::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
726   switch (Form) {
727   case dwarf::DW_FORM_block1: return Size + sizeof(int8_t);
728   case dwarf::DW_FORM_block2: return Size + sizeof(int16_t);
729   case dwarf::DW_FORM_block4: return Size + sizeof(int32_t);
730   case dwarf::DW_FORM_block:
731   case dwarf::DW_FORM_exprloc:
732     return Size + getULEB128Size(Size);
733   default: llvm_unreachable("Improper form for block");
734   }
735 }
736
737 LLVM_DUMP_METHOD
738 void DIELoc::print(raw_ostream &O) const {
739   printValues(O, *this, "ExprLoc", Size, 5);
740 }
741
742 //===----------------------------------------------------------------------===//
743 // DIEBlock Implementation
744 //===----------------------------------------------------------------------===//
745
746 /// ComputeSize - calculate the size of the block.
747 ///
748 unsigned DIEBlock::ComputeSize(const AsmPrinter *AP) const {
749   if (!Size) {
750     for (const auto &V : values())
751       Size += V.SizeOf(AP);
752   }
753
754   return Size;
755 }
756
757 /// EmitValue - Emit block data.
758 ///
759 void DIEBlock::EmitValue(const AsmPrinter *Asm, dwarf::Form Form) const {
760   switch (Form) {
761   default: llvm_unreachable("Improper form for block");
762   case dwarf::DW_FORM_block1: Asm->EmitInt8(Size);    break;
763   case dwarf::DW_FORM_block2: Asm->EmitInt16(Size);   break;
764   case dwarf::DW_FORM_block4: Asm->EmitInt32(Size);   break;
765   case dwarf::DW_FORM_block:  Asm->EmitULEB128(Size); break;
766   }
767
768   for (const auto &V : values())
769     V.EmitValue(Asm);
770 }
771
772 /// SizeOf - Determine size of block data in bytes.
773 ///
774 unsigned DIEBlock::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
775   switch (Form) {
776   case dwarf::DW_FORM_block1: return Size + sizeof(int8_t);
777   case dwarf::DW_FORM_block2: return Size + sizeof(int16_t);
778   case dwarf::DW_FORM_block4: return Size + sizeof(int32_t);
779   case dwarf::DW_FORM_block:  return Size + getULEB128Size(Size);
780   default: llvm_unreachable("Improper form for block");
781   }
782 }
783
784 LLVM_DUMP_METHOD
785 void DIEBlock::print(raw_ostream &O) const {
786   printValues(O, *this, "Blk", Size, 5);
787 }
788
789 //===----------------------------------------------------------------------===//
790 // DIELocList Implementation
791 //===----------------------------------------------------------------------===//
792
793 unsigned DIELocList::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
794   if (Form == dwarf::DW_FORM_data4)
795     return 4;
796   if (Form == dwarf::DW_FORM_sec_offset)
797     return 4;
798   return AP->getPointerSize();
799 }
800
801 /// EmitValue - Emit label value.
802 ///
803 void DIELocList::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
804   DwarfDebug *DD = AP->getDwarfDebug();
805   MCSymbol *Label = DD->getDebugLocs().getList(Index).Label;
806   AP->emitDwarfSymbolReference(Label, /*ForceOffset*/ DD->useSplitDwarf());
807 }
808
809 LLVM_DUMP_METHOD
810 void DIELocList::print(raw_ostream &O) const { O << "LocList: " << Index; }