1 //===--- lib/CodeGen/DIE.cpp - DWARF Info Entries -------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Data structures for DWARF info entries.
12 //===----------------------------------------------------------------------===//
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"
34 #define DEBUG_TYPE "dwarfdebug"
36 //===----------------------------------------------------------------------===//
37 // DIEAbbrevData Implementation
38 //===----------------------------------------------------------------------===//
40 /// Profile - Used to gather unique data for the abbreviation folding set.
42 void DIEAbbrevData::Profile(FoldingSetNodeID &ID) const {
43 // Explicitly cast to an integer type for which FoldingSetNodeID has
44 // overloads. Otherwise MSVC 2010 thinks this call is ambiguous.
45 ID.AddInteger(unsigned(Attribute));
46 ID.AddInteger(unsigned(Form));
47 if (Form == dwarf::DW_FORM_implicit_const)
51 //===----------------------------------------------------------------------===//
52 // DIEAbbrev Implementation
53 //===----------------------------------------------------------------------===//
55 /// Profile - Used to gather unique data for the abbreviation folding set.
57 void DIEAbbrev::Profile(FoldingSetNodeID &ID) const {
58 ID.AddInteger(unsigned(Tag));
59 ID.AddInteger(unsigned(Children));
61 // For each attribute description.
62 for (unsigned i = 0, N = Data.size(); i < N; ++i)
66 /// Emit - Print the abbreviation using the specified asm printer.
68 void DIEAbbrev::Emit(const AsmPrinter *AP) const {
69 // Emit its Dwarf tag type.
70 AP->EmitULEB128(Tag, dwarf::TagString(Tag).data());
72 // Emit whether it has children DIEs.
73 AP->EmitULEB128((unsigned)Children, dwarf::ChildrenString(Children).data());
75 // For each attribute description.
76 for (unsigned i = 0, N = Data.size(); i < N; ++i) {
77 const DIEAbbrevData &AttrData = Data[i];
79 // Emit attribute type.
80 AP->EmitULEB128(AttrData.getAttribute(),
81 dwarf::AttributeString(AttrData.getAttribute()).data());
85 // Could be an assertion, but this way we can see the failing form code
86 // easily, which helps track down where it came from.
87 if (!dwarf::isValidFormForVersion(AttrData.getForm(),
88 AP->getDwarfVersion())) {
89 DEBUG(dbgs() << "Invalid form " << format("0x%x", AttrData.getForm())
90 << " for DWARF version " << AP->getDwarfVersion() << "\n");
91 llvm_unreachable("Invalid form for specified DWARF version");
94 AP->EmitULEB128(AttrData.getForm(),
95 dwarf::FormEncodingString(AttrData.getForm()).data());
97 // Emit value for DW_FORM_implicit_const.
98 if (AttrData.getForm() == dwarf::DW_FORM_implicit_const)
99 AP->EmitSLEB128(AttrData.getValue());
102 // Mark end of abbreviation.
103 AP->EmitULEB128(0, "EOM(1)");
104 AP->EmitULEB128(0, "EOM(2)");
108 void DIEAbbrev::print(raw_ostream &O) {
109 O << "Abbreviation @"
110 << format("0x%lx", (long)(intptr_t)this)
112 << dwarf::TagString(Tag)
114 << dwarf::ChildrenString(Children)
117 for (unsigned i = 0, N = Data.size(); i < N; ++i) {
119 << dwarf::AttributeString(Data[i].getAttribute())
121 << dwarf::FormEncodingString(Data[i].getForm());
123 if (Data[i].getForm() == dwarf::DW_FORM_implicit_const)
124 O << " " << Data[i].getValue();
130 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
131 LLVM_DUMP_METHOD void DIEAbbrev::dump() {
136 //===----------------------------------------------------------------------===//
137 // DIEAbbrevSet Implementation
138 //===----------------------------------------------------------------------===//
140 DIEAbbrevSet::~DIEAbbrevSet() {
141 for (DIEAbbrev *Abbrev : Abbreviations)
142 Abbrev->~DIEAbbrev();
145 DIEAbbrev &DIEAbbrevSet::uniqueAbbreviation(DIE &Die) {
148 DIEAbbrev Abbrev = Die.generateAbbrev();
152 if (DIEAbbrev *Existing =
153 AbbreviationsSet.FindNodeOrInsertPos(ID, InsertPos)) {
154 Die.setAbbrevNumber(Existing->getNumber());
158 // Move the abbreviation to the heap and assign a number.
159 DIEAbbrev *New = new (Alloc) DIEAbbrev(std::move(Abbrev));
160 Abbreviations.push_back(New);
161 New->setNumber(Abbreviations.size());
162 Die.setAbbrevNumber(Abbreviations.size());
164 // Store it for lookup.
165 AbbreviationsSet.InsertNode(New, InsertPos);
169 void DIEAbbrevSet::Emit(const AsmPrinter *AP, MCSection *Section) const {
170 if (!Abbreviations.empty()) {
171 // Start the debug abbrev section.
172 AP->OutStreamer->SwitchSection(Section);
173 AP->emitDwarfAbbrevs(Abbreviations);
177 //===----------------------------------------------------------------------===//
178 // DIE Implementation
179 //===----------------------------------------------------------------------===//
181 DIE *DIE::getParent() const {
182 return Owner.dyn_cast<DIE*>();
185 DIEAbbrev DIE::generateAbbrev() const {
186 DIEAbbrev Abbrev(Tag, hasChildren());
187 for (const DIEValue &V : values())
188 if (V.getForm() == dwarf::DW_FORM_implicit_const)
189 Abbrev.AddImplicitConstAttribute(V.getAttribute(),
190 V.getDIEInteger().getValue());
192 Abbrev.AddAttribute(V.getAttribute(), V.getForm());
196 unsigned DIE::getDebugSectionOffset() const {
197 const DIEUnit *Unit = getUnit();
198 assert(Unit && "DIE must be owned by a DIEUnit to get its absolute offset");
199 return Unit->getDebugSectionOffset() + getOffset();
202 const DIE *DIE::getUnitDie() const {
205 if (p->getTag() == dwarf::DW_TAG_compile_unit ||
206 p->getTag() == dwarf::DW_TAG_type_unit)
213 const DIEUnit *DIE::getUnit() const {
214 const DIE *UnitDie = getUnitDie();
216 return UnitDie->Owner.dyn_cast<DIEUnit*>();
220 DIEValue DIE::findAttribute(dwarf::Attribute Attribute) const {
221 // Iterate through all the attributes until we find the one we're
222 // looking for, if we can't find it return NULL.
223 for (const auto &V : values())
224 if (V.getAttribute() == Attribute)
230 static void printValues(raw_ostream &O, const DIEValueList &Values,
231 StringRef Type, unsigned Size, unsigned IndentCount) {
232 O << Type << ": Size: " << Size << "\n";
235 const std::string Indent(IndentCount, ' ');
236 for (const auto &V : Values.values()) {
238 O << "Blk[" << I++ << "]";
239 O << " " << dwarf::FormEncodingString(V.getForm()) << " ";
246 void DIE::print(raw_ostream &O, unsigned IndentCount) const {
247 const std::string Indent(IndentCount, ' ');
248 O << Indent << "Die: " << format("0x%lx", (long)(intptr_t) this)
249 << ", Offset: " << Offset << ", Size: " << Size << "\n";
251 O << Indent << dwarf::TagString(getTag()) << " "
252 << dwarf::ChildrenString(hasChildren()) << "\n";
255 for (const auto &V : values()) {
257 O << dwarf::AttributeString(V.getAttribute());
258 O << " " << dwarf::FormEncodingString(V.getForm()) << " ";
264 for (const auto &Child : children())
265 Child.print(O, IndentCount + 4);
270 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
271 LLVM_DUMP_METHOD void DIE::dump() {
276 unsigned DIE::computeOffsetsAndAbbrevs(const AsmPrinter *AP,
277 DIEAbbrevSet &AbbrevSet,
279 // Unique the abbreviation and fill in the abbreviation number so this DIE
281 const DIEAbbrev &Abbrev = AbbrevSet.uniqueAbbreviation(*this);
283 // Set compile/type unit relative offset of this DIE.
286 // Add the byte size of the abbreviation code.
287 CUOffset += getULEB128Size(getAbbrevNumber());
289 // Add the byte size of all the DIE attribute values.
290 for (const auto &V : values())
291 CUOffset += V.SizeOf(AP);
293 // Let the children compute their offsets and abbreviation numbers.
296 assert(Abbrev.hasChildren() && "Children flag not set");
298 for (auto &Child : children())
299 CUOffset = Child.computeOffsetsAndAbbrevs(AP, AbbrevSet, CUOffset);
301 // Each child chain is terminated with a zero byte, adjust the offset.
302 CUOffset += sizeof(int8_t);
305 // Compute the byte size of this DIE and all of its children correctly. This
306 // is needed so that top level DIE can help the compile unit set its length
308 setSize(CUOffset - getOffset());
312 //===----------------------------------------------------------------------===//
313 // DIEUnit Implementation
314 //===----------------------------------------------------------------------===//
315 DIEUnit::DIEUnit(uint16_t V, uint8_t A, dwarf::Tag UnitTag)
316 : Die(UnitTag), Section(nullptr), Offset(0), Length(0), Version(V),
320 assert((UnitTag == dwarf::DW_TAG_compile_unit ||
321 UnitTag == dwarf::DW_TAG_type_unit ||
322 UnitTag == dwarf::DW_TAG_partial_unit) && "expected a unit TAG");
325 void DIEValue::EmitValue(const AsmPrinter *AP) const {
328 llvm_unreachable("Expected valid DIEValue");
329 #define HANDLE_DIEVALUE(T) \
331 getDIE##T().EmitValue(AP, Form); \
333 #include "llvm/CodeGen/DIEValue.def"
337 unsigned DIEValue::SizeOf(const AsmPrinter *AP) const {
340 llvm_unreachable("Expected valid DIEValue");
341 #define HANDLE_DIEVALUE(T) \
343 return getDIE##T().SizeOf(AP, Form);
344 #include "llvm/CodeGen/DIEValue.def"
346 llvm_unreachable("Unknown DIE kind");
350 void DIEValue::print(raw_ostream &O) const {
353 llvm_unreachable("Expected valid DIEValue");
354 #define HANDLE_DIEVALUE(T) \
356 getDIE##T().print(O); \
358 #include "llvm/CodeGen/DIEValue.def"
362 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
363 LLVM_DUMP_METHOD void DIEValue::dump() const {
368 //===----------------------------------------------------------------------===//
369 // DIEInteger Implementation
370 //===----------------------------------------------------------------------===//
372 /// EmitValue - Emit integer of appropriate size.
374 void DIEInteger::EmitValue(const AsmPrinter *Asm, dwarf::Form Form) const {
376 case dwarf::DW_FORM_implicit_const:
377 case dwarf::DW_FORM_flag_present:
378 // Emit something to keep the lines and comments in sync.
379 // FIXME: Is there a better way to do this?
380 Asm->OutStreamer->AddBlankLine();
382 case dwarf::DW_FORM_flag:
383 case dwarf::DW_FORM_ref1:
384 case dwarf::DW_FORM_data1:
385 case dwarf::DW_FORM_strx1:
386 case dwarf::DW_FORM_addrx1:
387 case dwarf::DW_FORM_ref2:
388 case dwarf::DW_FORM_data2:
389 case dwarf::DW_FORM_strx2:
390 case dwarf::DW_FORM_addrx2:
391 case dwarf::DW_FORM_strp:
392 case dwarf::DW_FORM_ref4:
393 case dwarf::DW_FORM_data4:
394 case dwarf::DW_FORM_ref_sup4:
395 case dwarf::DW_FORM_strx4:
396 case dwarf::DW_FORM_addrx4:
397 case dwarf::DW_FORM_ref8:
398 case dwarf::DW_FORM_ref_sig8:
399 case dwarf::DW_FORM_data8:
400 case dwarf::DW_FORM_ref_sup8:
401 case dwarf::DW_FORM_GNU_ref_alt:
402 case dwarf::DW_FORM_GNU_strp_alt:
403 case dwarf::DW_FORM_line_strp:
404 case dwarf::DW_FORM_sec_offset:
405 case dwarf::DW_FORM_strp_sup:
406 case dwarf::DW_FORM_addr:
407 case dwarf::DW_FORM_ref_addr:
408 Asm->OutStreamer->EmitIntValue(Integer, SizeOf(Asm, Form));
410 case dwarf::DW_FORM_GNU_str_index:
411 case dwarf::DW_FORM_GNU_addr_index:
412 case dwarf::DW_FORM_ref_udata:
413 case dwarf::DW_FORM_udata:
414 Asm->EmitULEB128(Integer);
416 case dwarf::DW_FORM_sdata:
417 Asm->EmitSLEB128(Integer);
419 default: llvm_unreachable("DIE Value form not supported yet");
423 /// SizeOf - Determine size of integer value in bytes.
425 unsigned DIEInteger::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
427 case dwarf::DW_FORM_implicit_const:
428 case dwarf::DW_FORM_flag_present:
430 case dwarf::DW_FORM_flag:
431 case dwarf::DW_FORM_ref1:
432 case dwarf::DW_FORM_data1:
433 case dwarf::DW_FORM_strx1:
434 case dwarf::DW_FORM_addrx1:
435 return sizeof(int8_t);
436 case dwarf::DW_FORM_ref2:
437 case dwarf::DW_FORM_data2:
438 case dwarf::DW_FORM_strx2:
439 case dwarf::DW_FORM_addrx2:
440 return sizeof(int16_t);
441 case dwarf::DW_FORM_ref4:
442 case dwarf::DW_FORM_data4:
443 case dwarf::DW_FORM_ref_sup4:
444 case dwarf::DW_FORM_strx4:
445 case dwarf::DW_FORM_addrx4:
446 return sizeof(int32_t);
447 case dwarf::DW_FORM_ref8:
448 case dwarf::DW_FORM_ref_sig8:
449 case dwarf::DW_FORM_data8:
450 case dwarf::DW_FORM_ref_sup8:
451 return sizeof(int64_t);
452 case dwarf::DW_FORM_ref_addr:
453 if (AP->getDwarfVersion() == 2)
454 return AP->getPointerSize();
456 case dwarf::DW_FORM_strp:
457 case dwarf::DW_FORM_GNU_ref_alt:
458 case dwarf::DW_FORM_GNU_strp_alt:
459 case dwarf::DW_FORM_line_strp:
460 case dwarf::DW_FORM_sec_offset:
461 case dwarf::DW_FORM_strp_sup:
462 switch (AP->OutStreamer->getContext().getDwarfFormat()) {
468 llvm_unreachable("Invalid DWARF format");
469 case dwarf::DW_FORM_GNU_str_index:
470 case dwarf::DW_FORM_GNU_addr_index:
471 case dwarf::DW_FORM_ref_udata:
472 case dwarf::DW_FORM_udata:
473 return getULEB128Size(Integer);
474 case dwarf::DW_FORM_sdata:
475 return getSLEB128Size(Integer);
476 case dwarf::DW_FORM_addr:
477 return AP->getPointerSize();
478 default: llvm_unreachable("DIE Value form not supported yet");
483 void DIEInteger::print(raw_ostream &O) const {
484 O << "Int: " << (int64_t)Integer << " 0x";
485 O.write_hex(Integer);
488 //===----------------------------------------------------------------------===//
489 // DIEExpr Implementation
490 //===----------------------------------------------------------------------===//
492 /// EmitValue - Emit expression value.
494 void DIEExpr::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
495 AP->EmitDebugThreadLocal(Expr, SizeOf(AP, Form));
498 /// SizeOf - Determine size of expression value in bytes.
500 unsigned DIEExpr::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
501 if (Form == dwarf::DW_FORM_data4) return 4;
502 if (Form == dwarf::DW_FORM_sec_offset) return 4;
503 if (Form == dwarf::DW_FORM_strp) return 4;
504 return AP->getPointerSize();
508 void DIEExpr::print(raw_ostream &O) const { O << "Expr: " << *Expr; }
510 //===----------------------------------------------------------------------===//
511 // DIELabel Implementation
512 //===----------------------------------------------------------------------===//
514 /// EmitValue - Emit label value.
516 void DIELabel::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
517 AP->EmitLabelReference(Label, SizeOf(AP, Form),
518 Form == dwarf::DW_FORM_strp ||
519 Form == dwarf::DW_FORM_sec_offset ||
520 Form == dwarf::DW_FORM_ref_addr ||
521 Form == dwarf::DW_FORM_data4);
524 /// SizeOf - Determine size of label value in bytes.
526 unsigned DIELabel::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
527 if (Form == dwarf::DW_FORM_data4) return 4;
528 if (Form == dwarf::DW_FORM_sec_offset) return 4;
529 if (Form == dwarf::DW_FORM_strp) return 4;
530 return AP->MAI->getCodePointerSize();
534 void DIELabel::print(raw_ostream &O) const { O << "Lbl: " << Label->getName(); }
536 //===----------------------------------------------------------------------===//
537 // DIEDelta Implementation
538 //===----------------------------------------------------------------------===//
540 /// EmitValue - Emit delta value.
542 void DIEDelta::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
543 AP->EmitLabelDifference(LabelHi, LabelLo, SizeOf(AP, Form));
546 /// SizeOf - Determine size of delta value in bytes.
548 unsigned DIEDelta::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
549 if (Form == dwarf::DW_FORM_data4) return 4;
550 if (Form == dwarf::DW_FORM_sec_offset) return 4;
551 if (Form == dwarf::DW_FORM_strp) return 4;
552 return AP->MAI->getCodePointerSize();
556 void DIEDelta::print(raw_ostream &O) const {
557 O << "Del: " << LabelHi->getName() << "-" << LabelLo->getName();
560 //===----------------------------------------------------------------------===//
561 // DIEString Implementation
562 //===----------------------------------------------------------------------===//
564 /// EmitValue - Emit string value.
566 void DIEString::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
568 (Form == dwarf::DW_FORM_strp || Form == dwarf::DW_FORM_GNU_str_index) &&
569 "Expected valid string form");
571 // Index of string in symbol table.
572 if (Form == dwarf::DW_FORM_GNU_str_index) {
573 DIEInteger(S.getIndex()).EmitValue(AP, Form);
577 // Relocatable symbol.
578 assert(Form == dwarf::DW_FORM_strp);
579 if (AP->MAI->doesDwarfUseRelocationsAcrossSections()) {
580 DIELabel(S.getSymbol()).EmitValue(AP, Form);
584 // Offset into symbol table.
585 DIEInteger(S.getOffset()).EmitValue(AP, Form);
588 /// SizeOf - Determine size of delta value in bytes.
590 unsigned DIEString::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
592 (Form == dwarf::DW_FORM_strp || Form == dwarf::DW_FORM_GNU_str_index) &&
593 "Expected valid string form");
595 // Index of string in symbol table.
596 if (Form == dwarf::DW_FORM_GNU_str_index)
597 return DIEInteger(S.getIndex()).SizeOf(AP, Form);
599 // Relocatable symbol.
600 if (AP->MAI->doesDwarfUseRelocationsAcrossSections())
601 return DIELabel(S.getSymbol()).SizeOf(AP, Form);
603 // Offset into symbol table.
604 return DIEInteger(S.getOffset()).SizeOf(AP, Form);
608 void DIEString::print(raw_ostream &O) const {
609 O << "String: " << S.getString();
612 //===----------------------------------------------------------------------===//
613 // DIEInlineString Implementation
614 //===----------------------------------------------------------------------===//
615 void DIEInlineString::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
616 if (Form == dwarf::DW_FORM_string) {
622 llvm_unreachable("Expected valid string form");
625 unsigned DIEInlineString::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
626 // Emit string bytes + NULL byte.
631 void DIEInlineString::print(raw_ostream &O) const {
632 O << "InlineString: " << S;
635 //===----------------------------------------------------------------------===//
636 // DIEEntry Implementation
637 //===----------------------------------------------------------------------===//
639 /// EmitValue - Emit debug information entry offset.
641 void DIEEntry::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
644 case dwarf::DW_FORM_ref1:
645 case dwarf::DW_FORM_ref2:
646 case dwarf::DW_FORM_ref4:
647 case dwarf::DW_FORM_ref8:
648 AP->OutStreamer->EmitIntValue(Entry->getOffset(), SizeOf(AP, Form));
651 case dwarf::DW_FORM_ref_udata:
652 AP->EmitULEB128(Entry->getOffset());
655 case dwarf::DW_FORM_ref_addr: {
656 // Get the absolute offset for this DIE within the debug info/types section.
657 unsigned Addr = Entry->getDebugSectionOffset();
658 if (AP->MAI->doesDwarfUseRelocationsAcrossSections()) {
659 const DwarfDebug *DD = AP->getDwarfDebug();
661 assert(!DD->useSplitDwarf() &&
662 "TODO: dwo files can't have relocations.");
663 const DIEUnit *Unit = Entry->getUnit();
664 assert(Unit && "CUDie should belong to a CU.");
665 MCSection *Section = Unit->getSection();
667 const MCSymbol *SectionSym = Section->getBeginSymbol();
668 AP->EmitLabelPlusOffset(SectionSym, Addr, SizeOf(AP, Form), true);
672 AP->OutStreamer->EmitIntValue(Addr, SizeOf(AP, Form));
676 llvm_unreachable("Improper form for DIE reference");
680 unsigned DIEEntry::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
682 case dwarf::DW_FORM_ref1:
684 case dwarf::DW_FORM_ref2:
686 case dwarf::DW_FORM_ref4:
688 case dwarf::DW_FORM_ref8:
690 case dwarf::DW_FORM_ref_udata:
691 return getULEB128Size(Entry->getOffset());
692 case dwarf::DW_FORM_ref_addr:
693 if (AP->getDwarfVersion() == 2)
694 return AP->MAI->getCodePointerSize();
695 switch (AP->OutStreamer->getContext().getDwarfFormat()) {
701 llvm_unreachable("Invalid DWARF format");
704 llvm_unreachable("Improper form for DIE reference");
709 void DIEEntry::print(raw_ostream &O) const {
710 O << format("Die: 0x%lx", (long)(intptr_t)&Entry);
713 //===----------------------------------------------------------------------===//
714 // DIELoc Implementation
715 //===----------------------------------------------------------------------===//
717 /// ComputeSize - calculate the size of the location expression.
719 unsigned DIELoc::ComputeSize(const AsmPrinter *AP) const {
721 for (const auto &V : values())
722 Size += V.SizeOf(AP);
728 /// EmitValue - Emit location data.
730 void DIELoc::EmitValue(const AsmPrinter *Asm, dwarf::Form Form) const {
732 default: llvm_unreachable("Improper form for block");
733 case dwarf::DW_FORM_block1: Asm->EmitInt8(Size); break;
734 case dwarf::DW_FORM_block2: Asm->EmitInt16(Size); break;
735 case dwarf::DW_FORM_block4: Asm->EmitInt32(Size); break;
736 case dwarf::DW_FORM_block:
737 case dwarf::DW_FORM_exprloc:
738 Asm->EmitULEB128(Size); break;
741 for (const auto &V : values())
745 /// SizeOf - Determine size of location data in bytes.
747 unsigned DIELoc::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
749 case dwarf::DW_FORM_block1: return Size + sizeof(int8_t);
750 case dwarf::DW_FORM_block2: return Size + sizeof(int16_t);
751 case dwarf::DW_FORM_block4: return Size + sizeof(int32_t);
752 case dwarf::DW_FORM_block:
753 case dwarf::DW_FORM_exprloc:
754 return Size + getULEB128Size(Size);
755 default: llvm_unreachable("Improper form for block");
760 void DIELoc::print(raw_ostream &O) const {
761 printValues(O, *this, "ExprLoc", Size, 5);
764 //===----------------------------------------------------------------------===//
765 // DIEBlock Implementation
766 //===----------------------------------------------------------------------===//
768 /// ComputeSize - calculate the size of the block.
770 unsigned DIEBlock::ComputeSize(const AsmPrinter *AP) const {
772 for (const auto &V : values())
773 Size += V.SizeOf(AP);
779 /// EmitValue - Emit block data.
781 void DIEBlock::EmitValue(const AsmPrinter *Asm, dwarf::Form Form) const {
783 default: llvm_unreachable("Improper form for block");
784 case dwarf::DW_FORM_block1: Asm->EmitInt8(Size); break;
785 case dwarf::DW_FORM_block2: Asm->EmitInt16(Size); break;
786 case dwarf::DW_FORM_block4: Asm->EmitInt32(Size); break;
787 case dwarf::DW_FORM_block: Asm->EmitULEB128(Size); break;
790 for (const auto &V : values())
794 /// SizeOf - Determine size of block data in bytes.
796 unsigned DIEBlock::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
798 case dwarf::DW_FORM_block1: return Size + sizeof(int8_t);
799 case dwarf::DW_FORM_block2: return Size + sizeof(int16_t);
800 case dwarf::DW_FORM_block4: return Size + sizeof(int32_t);
801 case dwarf::DW_FORM_block: return Size + getULEB128Size(Size);
802 default: llvm_unreachable("Improper form for block");
807 void DIEBlock::print(raw_ostream &O) const {
808 printValues(O, *this, "Blk", Size, 5);
811 //===----------------------------------------------------------------------===//
812 // DIELocList Implementation
813 //===----------------------------------------------------------------------===//
815 unsigned DIELocList::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
816 if (Form == dwarf::DW_FORM_data4)
818 if (Form == dwarf::DW_FORM_sec_offset)
820 return AP->MAI->getCodePointerSize();
823 /// EmitValue - Emit label value.
825 void DIELocList::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
826 DwarfDebug *DD = AP->getDwarfDebug();
827 MCSymbol *Label = DD->getDebugLocs().getList(Index).Label;
828 AP->emitDwarfSymbolReference(Label, /*ForceOffset*/ DD->useSplitDwarf());
832 void DIELocList::print(raw_ostream &O) const { O << "LocList: " << Index; }