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 //===----------------------------------------------------------------------===//
35 // DIEAbbrevData Implementation
36 //===----------------------------------------------------------------------===//
38 /// Profile - Used to gather unique data for the abbreviation folding set.
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 if (Form == dwarf::DW_FORM_implicit_const)
49 //===----------------------------------------------------------------------===//
50 // DIEAbbrev Implementation
51 //===----------------------------------------------------------------------===//
53 /// Profile - Used to gather unique data for the abbreviation folding set.
55 void DIEAbbrev::Profile(FoldingSetNodeID &ID) const {
56 ID.AddInteger(unsigned(Tag));
57 ID.AddInteger(unsigned(Children));
59 // For each attribute description.
60 for (unsigned i = 0, N = Data.size(); i < N; ++i)
64 /// Emit - Print the abbreviation using the specified asm printer.
66 void DIEAbbrev::Emit(const AsmPrinter *AP) const {
67 // Emit its Dwarf tag type.
68 AP->EmitULEB128(Tag, dwarf::TagString(Tag).data());
70 // Emit whether it has children DIEs.
71 AP->EmitULEB128((unsigned)Children, dwarf::ChildrenString(Children).data());
73 // For each attribute description.
74 for (unsigned i = 0, N = Data.size(); i < N; ++i) {
75 const DIEAbbrevData &AttrData = Data[i];
77 // Emit attribute type.
78 AP->EmitULEB128(AttrData.getAttribute(),
79 dwarf::AttributeString(AttrData.getAttribute()).data());
82 AP->EmitULEB128(AttrData.getForm(),
83 dwarf::FormEncodingString(AttrData.getForm()).data());
85 // Emit value for DW_FORM_implicit_const.
86 if (AttrData.getForm() == dwarf::DW_FORM_implicit_const) {
87 assert(AP->getDwarfVersion() >= 5 &&
88 "DW_FORM_implicit_const is supported starting from DWARFv5");
89 AP->EmitSLEB128(AttrData.getValue());
93 // Mark end of abbreviation.
94 AP->EmitULEB128(0, "EOM(1)");
95 AP->EmitULEB128(0, "EOM(2)");
99 void DIEAbbrev::print(raw_ostream &O) {
100 O << "Abbreviation @"
101 << format("0x%lx", (long)(intptr_t)this)
103 << dwarf::TagString(Tag)
105 << dwarf::ChildrenString(Children)
108 for (unsigned i = 0, N = Data.size(); i < N; ++i) {
110 << dwarf::AttributeString(Data[i].getAttribute())
112 << dwarf::FormEncodingString(Data[i].getForm());
114 if (Data[i].getForm() == dwarf::DW_FORM_implicit_const)
115 O << " " << Data[i].getValue();
121 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
122 LLVM_DUMP_METHOD void DIEAbbrev::dump() {
127 //===----------------------------------------------------------------------===//
128 // DIEAbbrevSet Implementation
129 //===----------------------------------------------------------------------===//
131 DIEAbbrevSet::~DIEAbbrevSet() {
132 for (DIEAbbrev *Abbrev : Abbreviations)
133 Abbrev->~DIEAbbrev();
136 DIEAbbrev &DIEAbbrevSet::uniqueAbbreviation(DIE &Die) {
139 DIEAbbrev Abbrev = Die.generateAbbrev();
143 if (DIEAbbrev *Existing =
144 AbbreviationsSet.FindNodeOrInsertPos(ID, InsertPos)) {
145 Die.setAbbrevNumber(Existing->getNumber());
149 // Move the abbreviation to the heap and assign a number.
150 DIEAbbrev *New = new (Alloc) DIEAbbrev(std::move(Abbrev));
151 Abbreviations.push_back(New);
152 New->setNumber(Abbreviations.size());
153 Die.setAbbrevNumber(Abbreviations.size());
155 // Store it for lookup.
156 AbbreviationsSet.InsertNode(New, InsertPos);
160 void DIEAbbrevSet::Emit(const AsmPrinter *AP, MCSection *Section) const {
161 if (!Abbreviations.empty()) {
162 // Start the debug abbrev section.
163 AP->OutStreamer->SwitchSection(Section);
164 AP->emitDwarfAbbrevs(Abbreviations);
168 //===----------------------------------------------------------------------===//
169 // DIE Implementation
170 //===----------------------------------------------------------------------===//
172 DIE *DIE::getParent() const {
173 return Owner.dyn_cast<DIE*>();
176 DIEAbbrev DIE::generateAbbrev() const {
177 DIEAbbrev Abbrev(Tag, hasChildren());
178 for (const DIEValue &V : values())
179 if (V.getForm() == dwarf::DW_FORM_implicit_const)
180 Abbrev.AddImplicitConstAttribute(V.getAttribute(),
181 V.getDIEInteger().getValue());
183 Abbrev.AddAttribute(V.getAttribute(), V.getForm());
187 unsigned DIE::getDebugSectionOffset() const {
188 const DIEUnit *Unit = getUnit();
189 assert(Unit && "DIE must be owned by a DIEUnit to get its absolute offset");
190 return Unit->getDebugSectionOffset() + getOffset();
193 const DIE *DIE::getUnitDie() const {
196 if (p->getTag() == dwarf::DW_TAG_compile_unit ||
197 p->getTag() == dwarf::DW_TAG_type_unit)
204 const DIEUnit *DIE::getUnit() const {
205 const DIE *UnitDie = getUnitDie();
207 return UnitDie->Owner.dyn_cast<DIEUnit*>();
211 DIEValue DIE::findAttribute(dwarf::Attribute Attribute) const {
212 // Iterate through all the attributes until we find the one we're
213 // looking for, if we can't find it return NULL.
214 for (const auto &V : values())
215 if (V.getAttribute() == Attribute)
221 static void printValues(raw_ostream &O, const DIEValueList &Values,
222 StringRef Type, unsigned Size, unsigned IndentCount) {
223 O << Type << ": Size: " << Size << "\n";
226 const std::string Indent(IndentCount, ' ');
227 for (const auto &V : Values.values()) {
229 O << "Blk[" << I++ << "]";
230 O << " " << dwarf::FormEncodingString(V.getForm()) << " ";
237 void DIE::print(raw_ostream &O, unsigned IndentCount) const {
238 const std::string Indent(IndentCount, ' ');
239 O << Indent << "Die: " << format("0x%lx", (long)(intptr_t) this)
240 << ", Offset: " << Offset << ", Size: " << Size << "\n";
242 O << Indent << dwarf::TagString(getTag()) << " "
243 << dwarf::ChildrenString(hasChildren()) << "\n";
246 for (const auto &V : values()) {
248 O << dwarf::AttributeString(V.getAttribute());
249 O << " " << dwarf::FormEncodingString(V.getForm()) << " ";
255 for (const auto &Child : children())
256 Child.print(O, IndentCount + 4);
261 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
262 LLVM_DUMP_METHOD void DIE::dump() {
267 unsigned DIE::computeOffsetsAndAbbrevs(const AsmPrinter *AP,
268 DIEAbbrevSet &AbbrevSet,
270 // Unique the abbreviation and fill in the abbreviation number so this DIE
272 const DIEAbbrev &Abbrev = AbbrevSet.uniqueAbbreviation(*this);
274 // Set compile/type unit relative offset of this DIE.
277 // Add the byte size of the abbreviation code.
278 CUOffset += getULEB128Size(getAbbrevNumber());
280 // Add the byte size of all the DIE attribute values.
281 for (const auto &V : values())
282 CUOffset += V.SizeOf(AP);
284 // Let the children compute their offsets and abbreviation numbers.
287 assert(Abbrev.hasChildren() && "Children flag not set");
289 for (auto &Child : children())
290 CUOffset = Child.computeOffsetsAndAbbrevs(AP, AbbrevSet, CUOffset);
292 // Each child chain is terminated with a zero byte, adjust the offset.
293 CUOffset += sizeof(int8_t);
296 // Compute the byte size of this DIE and all of its children correctly. This
297 // is needed so that top level DIE can help the compile unit set its length
299 setSize(CUOffset - getOffset());
303 //===----------------------------------------------------------------------===//
304 // DIEUnit Implementation
305 //===----------------------------------------------------------------------===//
306 DIEUnit::DIEUnit(uint16_t V, uint8_t A, dwarf::Tag UnitTag)
307 : Die(UnitTag), Section(nullptr), Offset(0), Length(0), Version(V),
311 assert((UnitTag == dwarf::DW_TAG_compile_unit ||
312 UnitTag == dwarf::DW_TAG_type_unit ||
313 UnitTag == dwarf::DW_TAG_partial_unit) && "expected a unit TAG");
316 void DIEValue::EmitValue(const AsmPrinter *AP) const {
319 llvm_unreachable("Expected valid DIEValue");
320 #define HANDLE_DIEVALUE(T) \
322 getDIE##T().EmitValue(AP, Form); \
324 #include "llvm/CodeGen/DIEValue.def"
328 unsigned DIEValue::SizeOf(const AsmPrinter *AP) const {
331 llvm_unreachable("Expected valid DIEValue");
332 #define HANDLE_DIEVALUE(T) \
334 return getDIE##T().SizeOf(AP, Form);
335 #include "llvm/CodeGen/DIEValue.def"
337 llvm_unreachable("Unknown DIE kind");
341 void DIEValue::print(raw_ostream &O) const {
344 llvm_unreachable("Expected valid DIEValue");
345 #define HANDLE_DIEVALUE(T) \
347 getDIE##T().print(O); \
349 #include "llvm/CodeGen/DIEValue.def"
353 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
354 LLVM_DUMP_METHOD void DIEValue::dump() const {
359 //===----------------------------------------------------------------------===//
360 // DIEInteger Implementation
361 //===----------------------------------------------------------------------===//
363 /// EmitValue - Emit integer of appropriate size.
365 void DIEInteger::EmitValue(const AsmPrinter *Asm, dwarf::Form Form) const {
367 case dwarf::DW_FORM_implicit_const:
368 case dwarf::DW_FORM_flag_present:
369 // Emit something to keep the lines and comments in sync.
370 // FIXME: Is there a better way to do this?
371 Asm->OutStreamer->AddBlankLine();
373 case dwarf::DW_FORM_flag:
374 case dwarf::DW_FORM_ref1:
375 case dwarf::DW_FORM_data1:
376 case dwarf::DW_FORM_strx1:
377 case dwarf::DW_FORM_addrx1:
378 case dwarf::DW_FORM_ref2:
379 case dwarf::DW_FORM_data2:
380 case dwarf::DW_FORM_strx2:
381 case dwarf::DW_FORM_addrx2:
382 case dwarf::DW_FORM_strp:
383 case dwarf::DW_FORM_ref4:
384 case dwarf::DW_FORM_data4:
385 case dwarf::DW_FORM_ref_sup4:
386 case dwarf::DW_FORM_strx4:
387 case dwarf::DW_FORM_addrx4:
388 case dwarf::DW_FORM_ref8:
389 case dwarf::DW_FORM_ref_sig8:
390 case dwarf::DW_FORM_data8:
391 case dwarf::DW_FORM_ref_sup8:
392 case dwarf::DW_FORM_GNU_ref_alt:
393 case dwarf::DW_FORM_GNU_strp_alt:
394 case dwarf::DW_FORM_line_strp:
395 case dwarf::DW_FORM_sec_offset:
396 case dwarf::DW_FORM_strp_sup:
397 case dwarf::DW_FORM_addr:
398 case dwarf::DW_FORM_ref_addr:
399 Asm->OutStreamer->EmitIntValue(Integer, SizeOf(Asm, Form));
401 case dwarf::DW_FORM_GNU_str_index:
402 case dwarf::DW_FORM_GNU_addr_index:
403 case dwarf::DW_FORM_ref_udata:
404 case dwarf::DW_FORM_udata:
405 Asm->EmitULEB128(Integer);
407 case dwarf::DW_FORM_sdata:
408 Asm->EmitSLEB128(Integer);
410 default: llvm_unreachable("DIE Value form not supported yet");
414 /// SizeOf - Determine size of integer value in bytes.
416 unsigned DIEInteger::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
418 case dwarf::DW_FORM_implicit_const:
419 case dwarf::DW_FORM_flag_present:
421 case dwarf::DW_FORM_flag:
422 case dwarf::DW_FORM_ref1:
423 case dwarf::DW_FORM_data1:
424 case dwarf::DW_FORM_strx1:
425 case dwarf::DW_FORM_addrx1:
426 return sizeof(int8_t);
427 case dwarf::DW_FORM_ref2:
428 case dwarf::DW_FORM_data2:
429 case dwarf::DW_FORM_strx2:
430 case dwarf::DW_FORM_addrx2:
431 return sizeof(int16_t);
432 case dwarf::DW_FORM_ref4:
433 case dwarf::DW_FORM_data4:
434 case dwarf::DW_FORM_ref_sup4:
435 case dwarf::DW_FORM_strx4:
436 case dwarf::DW_FORM_addrx4:
437 return sizeof(int32_t);
438 case dwarf::DW_FORM_ref8:
439 case dwarf::DW_FORM_ref_sig8:
440 case dwarf::DW_FORM_data8:
441 case dwarf::DW_FORM_ref_sup8:
442 return sizeof(int64_t);
443 case dwarf::DW_FORM_ref_addr:
444 if (AP->getDwarfVersion() == 2)
445 return AP->getPointerSize();
447 case dwarf::DW_FORM_strp:
448 case dwarf::DW_FORM_GNU_ref_alt:
449 case dwarf::DW_FORM_GNU_strp_alt:
450 case dwarf::DW_FORM_line_strp:
451 case dwarf::DW_FORM_sec_offset:
452 case dwarf::DW_FORM_strp_sup:
453 switch (AP->OutStreamer->getContext().getDwarfFormat()) {
459 llvm_unreachable("Invalid DWARF format");
460 case dwarf::DW_FORM_GNU_str_index:
461 case dwarf::DW_FORM_GNU_addr_index:
462 case dwarf::DW_FORM_ref_udata:
463 case dwarf::DW_FORM_udata:
464 return getULEB128Size(Integer);
465 case dwarf::DW_FORM_sdata:
466 return getSLEB128Size(Integer);
467 case dwarf::DW_FORM_addr:
468 return AP->getPointerSize();
469 default: llvm_unreachable("DIE Value form not supported yet");
474 void DIEInteger::print(raw_ostream &O) const {
475 O << "Int: " << (int64_t)Integer << " 0x";
476 O.write_hex(Integer);
479 //===----------------------------------------------------------------------===//
480 // DIEExpr Implementation
481 //===----------------------------------------------------------------------===//
483 /// EmitValue - Emit expression value.
485 void DIEExpr::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
486 AP->EmitDebugThreadLocal(Expr, SizeOf(AP, Form));
489 /// SizeOf - Determine size of expression value in bytes.
491 unsigned DIEExpr::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
492 if (Form == dwarf::DW_FORM_data4) return 4;
493 if (Form == dwarf::DW_FORM_sec_offset) return 4;
494 if (Form == dwarf::DW_FORM_strp) return 4;
495 return AP->getPointerSize();
499 void DIEExpr::print(raw_ostream &O) const { O << "Expr: " << *Expr; }
501 //===----------------------------------------------------------------------===//
502 // DIELabel Implementation
503 //===----------------------------------------------------------------------===//
505 /// EmitValue - Emit label value.
507 void DIELabel::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
508 AP->EmitLabelReference(Label, SizeOf(AP, Form),
509 Form == dwarf::DW_FORM_strp ||
510 Form == dwarf::DW_FORM_sec_offset ||
511 Form == dwarf::DW_FORM_ref_addr ||
512 Form == dwarf::DW_FORM_data4);
515 /// SizeOf - Determine size of label value in bytes.
517 unsigned DIELabel::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
518 if (Form == dwarf::DW_FORM_data4) return 4;
519 if (Form == dwarf::DW_FORM_sec_offset) return 4;
520 if (Form == dwarf::DW_FORM_strp) return 4;
521 return AP->getPointerSize();
525 void DIELabel::print(raw_ostream &O) const { O << "Lbl: " << Label->getName(); }
527 //===----------------------------------------------------------------------===//
528 // DIEDelta Implementation
529 //===----------------------------------------------------------------------===//
531 /// EmitValue - Emit delta value.
533 void DIEDelta::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
534 AP->EmitLabelDifference(LabelHi, LabelLo, SizeOf(AP, Form));
537 /// SizeOf - Determine size of delta value in bytes.
539 unsigned DIEDelta::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
540 if (Form == dwarf::DW_FORM_data4) return 4;
541 if (Form == dwarf::DW_FORM_sec_offset) return 4;
542 if (Form == dwarf::DW_FORM_strp) return 4;
543 return AP->getPointerSize();
547 void DIEDelta::print(raw_ostream &O) const {
548 O << "Del: " << LabelHi->getName() << "-" << LabelLo->getName();
551 //===----------------------------------------------------------------------===//
552 // DIEString Implementation
553 //===----------------------------------------------------------------------===//
555 /// EmitValue - Emit string value.
557 void DIEString::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
559 (Form == dwarf::DW_FORM_strp || Form == dwarf::DW_FORM_GNU_str_index) &&
560 "Expected valid string form");
562 // Index of string in symbol table.
563 if (Form == dwarf::DW_FORM_GNU_str_index) {
564 DIEInteger(S.getIndex()).EmitValue(AP, Form);
568 // Relocatable symbol.
569 assert(Form == dwarf::DW_FORM_strp);
570 if (AP->MAI->doesDwarfUseRelocationsAcrossSections()) {
571 DIELabel(S.getSymbol()).EmitValue(AP, Form);
575 // Offset into symbol table.
576 DIEInteger(S.getOffset()).EmitValue(AP, Form);
579 /// SizeOf - Determine size of delta value in bytes.
581 unsigned DIEString::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
583 (Form == dwarf::DW_FORM_strp || Form == dwarf::DW_FORM_GNU_str_index) &&
584 "Expected valid string form");
586 // Index of string in symbol table.
587 if (Form == dwarf::DW_FORM_GNU_str_index)
588 return DIEInteger(S.getIndex()).SizeOf(AP, Form);
590 // Relocatable symbol.
591 if (AP->MAI->doesDwarfUseRelocationsAcrossSections())
592 return DIELabel(S.getSymbol()).SizeOf(AP, Form);
594 // Offset into symbol table.
595 return DIEInteger(S.getOffset()).SizeOf(AP, Form);
599 void DIEString::print(raw_ostream &O) const {
600 O << "String: " << S.getString();
603 //===----------------------------------------------------------------------===//
604 // DIEInlineString Implementation
605 //===----------------------------------------------------------------------===//
606 void DIEInlineString::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
607 if (Form == dwarf::DW_FORM_string) {
613 llvm_unreachable("Expected valid string form");
616 unsigned DIEInlineString::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
617 // Emit string bytes + NULL byte.
622 void DIEInlineString::print(raw_ostream &O) const {
623 O << "InlineString: " << S;
626 //===----------------------------------------------------------------------===//
627 // DIEEntry Implementation
628 //===----------------------------------------------------------------------===//
630 /// EmitValue - Emit debug information entry offset.
632 void DIEEntry::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
635 case dwarf::DW_FORM_ref1:
636 case dwarf::DW_FORM_ref2:
637 case dwarf::DW_FORM_ref4:
638 case dwarf::DW_FORM_ref8:
639 AP->OutStreamer->EmitIntValue(Entry->getOffset(), SizeOf(AP, Form));
642 case dwarf::DW_FORM_ref_udata:
643 AP->EmitULEB128(Entry->getOffset());
646 case dwarf::DW_FORM_ref_addr: {
647 // Get the absolute offset for this DIE within the debug info/types section.
648 unsigned Addr = Entry->getDebugSectionOffset();
649 if (AP->MAI->doesDwarfUseRelocationsAcrossSections()) {
650 const DwarfDebug *DD = AP->getDwarfDebug();
652 assert(!DD->useSplitDwarf() &&
653 "TODO: dwo files can't have relocations.");
654 const DIEUnit *Unit = Entry->getUnit();
655 assert(Unit && "CUDie should belong to a CU.");
656 MCSection *Section = Unit->getSection();
658 const MCSymbol *SectionSym = Section->getBeginSymbol();
659 AP->EmitLabelPlusOffset(SectionSym, Addr, SizeOf(AP, Form), true);
663 AP->OutStreamer->EmitIntValue(Addr, SizeOf(AP, Form));
667 llvm_unreachable("Improper form for DIE reference");
671 unsigned DIEEntry::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
673 case dwarf::DW_FORM_ref1:
675 case dwarf::DW_FORM_ref2:
677 case dwarf::DW_FORM_ref4:
679 case dwarf::DW_FORM_ref8:
681 case dwarf::DW_FORM_ref_udata:
682 return getULEB128Size(Entry->getOffset());
683 case dwarf::DW_FORM_ref_addr:
684 if (AP->getDwarfVersion() == 2)
685 return AP->getPointerSize();
686 switch (AP->OutStreamer->getContext().getDwarfFormat()) {
692 llvm_unreachable("Invalid DWARF format");
695 llvm_unreachable("Improper form for DIE reference");
700 void DIEEntry::print(raw_ostream &O) const {
701 O << format("Die: 0x%lx", (long)(intptr_t)&Entry);
704 //===----------------------------------------------------------------------===//
705 // DIELoc Implementation
706 //===----------------------------------------------------------------------===//
708 /// ComputeSize - calculate the size of the location expression.
710 unsigned DIELoc::ComputeSize(const AsmPrinter *AP) const {
712 for (const auto &V : values())
713 Size += V.SizeOf(AP);
719 /// EmitValue - Emit location data.
721 void DIELoc::EmitValue(const AsmPrinter *Asm, dwarf::Form Form) const {
723 default: llvm_unreachable("Improper form for block");
724 case dwarf::DW_FORM_block1: Asm->EmitInt8(Size); break;
725 case dwarf::DW_FORM_block2: Asm->EmitInt16(Size); break;
726 case dwarf::DW_FORM_block4: Asm->EmitInt32(Size); break;
727 case dwarf::DW_FORM_block:
728 case dwarf::DW_FORM_exprloc:
729 Asm->EmitULEB128(Size); break;
732 for (const auto &V : values())
736 /// SizeOf - Determine size of location data in bytes.
738 unsigned DIELoc::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
740 case dwarf::DW_FORM_block1: return Size + sizeof(int8_t);
741 case dwarf::DW_FORM_block2: return Size + sizeof(int16_t);
742 case dwarf::DW_FORM_block4: return Size + sizeof(int32_t);
743 case dwarf::DW_FORM_block:
744 case dwarf::DW_FORM_exprloc:
745 return Size + getULEB128Size(Size);
746 default: llvm_unreachable("Improper form for block");
751 void DIELoc::print(raw_ostream &O) const {
752 printValues(O, *this, "ExprLoc", Size, 5);
755 //===----------------------------------------------------------------------===//
756 // DIEBlock Implementation
757 //===----------------------------------------------------------------------===//
759 /// ComputeSize - calculate the size of the block.
761 unsigned DIEBlock::ComputeSize(const AsmPrinter *AP) const {
763 for (const auto &V : values())
764 Size += V.SizeOf(AP);
770 /// EmitValue - Emit block data.
772 void DIEBlock::EmitValue(const AsmPrinter *Asm, dwarf::Form Form) const {
774 default: llvm_unreachable("Improper form for block");
775 case dwarf::DW_FORM_block1: Asm->EmitInt8(Size); break;
776 case dwarf::DW_FORM_block2: Asm->EmitInt16(Size); break;
777 case dwarf::DW_FORM_block4: Asm->EmitInt32(Size); break;
778 case dwarf::DW_FORM_block: Asm->EmitULEB128(Size); break;
781 for (const auto &V : values())
785 /// SizeOf - Determine size of block data in bytes.
787 unsigned DIEBlock::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
789 case dwarf::DW_FORM_block1: return Size + sizeof(int8_t);
790 case dwarf::DW_FORM_block2: return Size + sizeof(int16_t);
791 case dwarf::DW_FORM_block4: return Size + sizeof(int32_t);
792 case dwarf::DW_FORM_block: return Size + getULEB128Size(Size);
793 default: llvm_unreachable("Improper form for block");
798 void DIEBlock::print(raw_ostream &O) const {
799 printValues(O, *this, "Blk", Size, 5);
802 //===----------------------------------------------------------------------===//
803 // DIELocList Implementation
804 //===----------------------------------------------------------------------===//
806 unsigned DIELocList::SizeOf(const AsmPrinter *AP, dwarf::Form Form) const {
807 if (Form == dwarf::DW_FORM_data4)
809 if (Form == dwarf::DW_FORM_sec_offset)
811 return AP->getPointerSize();
814 /// EmitValue - Emit label value.
816 void DIELocList::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
817 DwarfDebug *DD = AP->getDwarfDebug();
818 MCSymbol *Label = DD->getDebugLocs().getList(Index).Label;
819 AP->emitDwarfSymbolReference(Label, /*ForceOffset*/ DD->useSplitDwarf());
823 void DIELocList::print(raw_ostream &O) const { O << "LocList: " << Index; }