1 //===--- lib/CodeGen/DIE.cpp - DWARF Info Entries -------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // Data structures for DWARF info entries.
11 //===----------------------------------------------------------------------===//
13 #include "llvm/CodeGen/DIE.h"
14 #include "DwarfCompileUnit.h"
15 #include "DwarfDebug.h"
16 #include "llvm/CodeGen/AsmPrinter.h"
17 #include "llvm/Config/llvm-config.h"
18 #include "llvm/MC/MCAsmInfo.h"
19 #include "llvm/MC/MCStreamer.h"
20 #include "llvm/MC/MCSymbol.h"
21 #include "llvm/Support/Debug.h"
22 #include "llvm/Support/ErrorHandling.h"
23 #include "llvm/Support/Format.h"
24 #include "llvm/Support/LEB128.h"
25 #include "llvm/Support/raw_ostream.h"
28 #define DEBUG_TYPE "dwarfdebug"
30 //===----------------------------------------------------------------------===//
31 // DIEAbbrevData Implementation
32 //===----------------------------------------------------------------------===//
34 /// Profile - Used to gather unique data for the abbreviation folding set.
36 void DIEAbbrevData::Profile(FoldingSetNodeID
&ID
) const {
37 // Explicitly cast to an integer type for which FoldingSetNodeID has
38 // overloads. Otherwise MSVC 2010 thinks this call is ambiguous.
39 ID
.AddInteger(unsigned(Attribute
));
40 ID
.AddInteger(unsigned(Form
));
41 if (Form
== dwarf::DW_FORM_implicit_const
)
45 //===----------------------------------------------------------------------===//
46 // DIEAbbrev Implementation
47 //===----------------------------------------------------------------------===//
49 /// Profile - Used to gather unique data for the abbreviation folding set.
51 void DIEAbbrev::Profile(FoldingSetNodeID
&ID
) const {
52 ID
.AddInteger(unsigned(Tag
));
53 ID
.AddInteger(unsigned(Children
));
55 // For each attribute description.
56 for (unsigned i
= 0, N
= Data
.size(); i
< N
; ++i
)
60 /// Emit - Print the abbreviation using the specified asm printer.
62 void DIEAbbrev::Emit(const AsmPrinter
*AP
) const {
63 // Emit its Dwarf tag type.
64 AP
->emitULEB128(Tag
, dwarf::TagString(Tag
).data());
66 // Emit whether it has children DIEs.
67 AP
->emitULEB128((unsigned)Children
, dwarf::ChildrenString(Children
).data());
69 // For each attribute description.
70 for (unsigned i
= 0, N
= Data
.size(); i
< N
; ++i
) {
71 const DIEAbbrevData
&AttrData
= Data
[i
];
73 // Emit attribute type.
74 AP
->emitULEB128(AttrData
.getAttribute(),
75 dwarf::AttributeString(AttrData
.getAttribute()).data());
79 // Could be an assertion, but this way we can see the failing form code
80 // easily, which helps track down where it came from.
81 if (!dwarf::isValidFormForVersion(AttrData
.getForm(),
82 AP
->getDwarfVersion())) {
83 LLVM_DEBUG(dbgs() << "Invalid form " << format("0x%x", AttrData
.getForm())
84 << " for DWARF version " << AP
->getDwarfVersion()
86 llvm_unreachable("Invalid form for specified DWARF version");
89 AP
->emitULEB128(AttrData
.getForm(),
90 dwarf::FormEncodingString(AttrData
.getForm()).data());
92 // Emit value for DW_FORM_implicit_const.
93 if (AttrData
.getForm() == dwarf::DW_FORM_implicit_const
)
94 AP
->emitSLEB128(AttrData
.getValue());
97 // Mark end of abbreviation.
98 AP
->emitULEB128(0, "EOM(1)");
99 AP
->emitULEB128(0, "EOM(2)");
103 void DIEAbbrev::print(raw_ostream
&O
) const {
104 O
<< "Abbreviation @"
105 << format("0x%lx", (long)(intptr_t)this)
107 << dwarf::TagString(Tag
)
109 << dwarf::ChildrenString(Children
)
112 for (unsigned i
= 0, N
= Data
.size(); i
< N
; ++i
) {
114 << dwarf::AttributeString(Data
[i
].getAttribute())
116 << dwarf::FormEncodingString(Data
[i
].getForm());
118 if (Data
[i
].getForm() == dwarf::DW_FORM_implicit_const
)
119 O
<< " " << Data
[i
].getValue();
125 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
126 LLVM_DUMP_METHOD
void DIEAbbrev::dump() const {
131 //===----------------------------------------------------------------------===//
132 // DIEAbbrevSet Implementation
133 //===----------------------------------------------------------------------===//
135 DIEAbbrevSet::~DIEAbbrevSet() {
136 for (DIEAbbrev
*Abbrev
: Abbreviations
)
137 Abbrev
->~DIEAbbrev();
140 DIEAbbrev
&DIEAbbrevSet::uniqueAbbreviation(DIE
&Die
) {
143 DIEAbbrev Abbrev
= Die
.generateAbbrev();
147 if (DIEAbbrev
*Existing
=
148 AbbreviationsSet
.FindNodeOrInsertPos(ID
, InsertPos
)) {
149 Die
.setAbbrevNumber(Existing
->getNumber());
153 // Move the abbreviation to the heap and assign a number.
154 DIEAbbrev
*New
= new (Alloc
) DIEAbbrev(std::move(Abbrev
));
155 Abbreviations
.push_back(New
);
156 New
->setNumber(Abbreviations
.size());
157 Die
.setAbbrevNumber(Abbreviations
.size());
159 // Store it for lookup.
160 AbbreviationsSet
.InsertNode(New
, InsertPos
);
164 void DIEAbbrevSet::Emit(const AsmPrinter
*AP
, MCSection
*Section
) const {
165 if (!Abbreviations
.empty()) {
166 // Start the debug abbrev section.
167 AP
->OutStreamer
->switchSection(Section
);
168 AP
->emitDwarfAbbrevs(Abbreviations
);
172 //===----------------------------------------------------------------------===//
173 // DIE Implementation
174 //===----------------------------------------------------------------------===//
176 DIE
*DIE::getParent() const { return dyn_cast_if_present
<DIE
*>(Owner
); }
178 DIEAbbrev
DIE::generateAbbrev() const {
179 DIEAbbrev
Abbrev(Tag
, hasChildren());
180 for (const DIEValue
&V
: values())
181 if (V
.getForm() == dwarf::DW_FORM_implicit_const
)
182 Abbrev
.AddImplicitConstAttribute(V
.getAttribute(),
183 V
.getDIEInteger().getValue());
185 Abbrev
.AddAttribute(V
.getAttribute(), V
.getForm());
189 uint64_t DIE::getDebugSectionOffset() const {
190 const DIEUnit
*Unit
= getUnit();
191 assert(Unit
&& "DIE must be owned by a DIEUnit to get its absolute offset");
192 return Unit
->getDebugSectionOffset() + getOffset();
195 const DIE
*DIE::getUnitDie() const {
198 if (p
->getTag() == dwarf::DW_TAG_compile_unit
||
199 p
->getTag() == dwarf::DW_TAG_skeleton_unit
||
200 p
->getTag() == dwarf::DW_TAG_type_unit
)
207 DIEUnit
*DIE::getUnit() const {
208 const DIE
*UnitDie
= getUnitDie();
210 return dyn_cast_if_present
<DIEUnit
*>(UnitDie
->Owner
);
214 DIEValue
DIE::findAttribute(dwarf::Attribute Attribute
) const {
215 // Iterate through all the attributes until we find the one we're
216 // looking for, if we can't find it return NULL.
217 for (const auto &V
: values())
218 if (V
.getAttribute() == Attribute
)
224 static void printValues(raw_ostream
&O
, const DIEValueList
&Values
,
225 StringRef Type
, unsigned Size
, unsigned IndentCount
) {
226 O
<< Type
<< ": Size: " << Size
<< "\n";
229 const std::string
Indent(IndentCount
, ' ');
230 for (const auto &V
: Values
.values()) {
232 O
<< "Blk[" << I
++ << "]";
233 O
<< " " << dwarf::FormEncodingString(V
.getForm()) << " ";
240 void DIE::print(raw_ostream
&O
, unsigned IndentCount
) const {
241 const std::string
Indent(IndentCount
, ' ');
242 O
<< Indent
<< "Die: " << format("0x%lx", (long)(intptr_t) this)
243 << ", Offset: " << Offset
<< ", Size: " << Size
<< "\n";
245 O
<< Indent
<< dwarf::TagString(getTag()) << " "
246 << dwarf::ChildrenString(hasChildren()) << "\n";
249 for (const auto &V
: values()) {
251 O
<< dwarf::AttributeString(V
.getAttribute());
252 O
<< " " << dwarf::FormEncodingString(V
.getForm()) << " ";
258 for (const auto &Child
: children())
259 Child
.print(O
, IndentCount
+ 4);
264 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
265 LLVM_DUMP_METHOD
void DIE::dump() const {
270 unsigned DIE::computeOffsetsAndAbbrevs(const dwarf::FormParams
&FormParams
,
271 DIEAbbrevSet
&AbbrevSet
,
273 // Unique the abbreviation and fill in the abbreviation number so this DIE
275 const DIEAbbrev
&Abbrev
= AbbrevSet
.uniqueAbbreviation(*this);
277 // Set compile/type unit relative offset of this DIE.
280 // Add the byte size of the abbreviation code.
281 CUOffset
+= getULEB128Size(getAbbrevNumber());
283 // Add the byte size of all the DIE attribute values.
284 for (const auto &V
: values())
285 CUOffset
+= V
.sizeOf(FormParams
);
287 // Let the children compute their offsets and abbreviation numbers.
290 assert(Abbrev
.hasChildren() && "Children flag not set");
292 for (auto &Child
: children())
294 Child
.computeOffsetsAndAbbrevs(FormParams
, AbbrevSet
, CUOffset
);
296 // Each child chain is terminated with a zero byte, adjust the offset.
297 CUOffset
+= sizeof(int8_t);
300 // Compute the byte size of this DIE and all of its children correctly. This
301 // is needed so that top level DIE can help the compile unit set its length
303 setSize(CUOffset
- getOffset());
307 //===----------------------------------------------------------------------===//
308 // DIEUnit Implementation
309 //===----------------------------------------------------------------------===//
310 DIEUnit::DIEUnit(dwarf::Tag UnitTag
) : Die(UnitTag
) {
312 assert((UnitTag
== dwarf::DW_TAG_compile_unit
||
313 UnitTag
== dwarf::DW_TAG_skeleton_unit
||
314 UnitTag
== dwarf::DW_TAG_type_unit
||
315 UnitTag
== dwarf::DW_TAG_partial_unit
) &&
316 "expected a unit TAG");
319 void DIEValue::emitValue(const AsmPrinter
*AP
) const {
322 llvm_unreachable("Expected valid DIEValue");
323 #define HANDLE_DIEVALUE(T) \
325 getDIE##T().emitValue(AP, Form); \
327 #include "llvm/CodeGen/DIEValue.def"
331 unsigned DIEValue::sizeOf(const dwarf::FormParams
&FormParams
) const {
334 llvm_unreachable("Expected valid DIEValue");
335 #define HANDLE_DIEVALUE(T) \
337 return getDIE##T().sizeOf(FormParams, Form);
338 #include "llvm/CodeGen/DIEValue.def"
340 llvm_unreachable("Unknown DIE kind");
344 void DIEValue::print(raw_ostream
&O
) const {
347 llvm_unreachable("Expected valid DIEValue");
348 #define HANDLE_DIEVALUE(T) \
350 getDIE##T().print(O); \
352 #include "llvm/CodeGen/DIEValue.def"
356 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
357 LLVM_DUMP_METHOD
void DIEValue::dump() const {
362 //===----------------------------------------------------------------------===//
363 // DIEInteger Implementation
364 //===----------------------------------------------------------------------===//
366 /// EmitValue - Emit integer of appropriate size.
368 void DIEInteger::emitValue(const AsmPrinter
*Asm
, dwarf::Form Form
) const {
370 case dwarf::DW_FORM_implicit_const
:
371 case dwarf::DW_FORM_flag_present
:
372 // Emit something to keep the lines and comments in sync.
373 // FIXME: Is there a better way to do this?
374 Asm
->OutStreamer
->addBlankLine();
376 case dwarf::DW_FORM_flag
:
377 case dwarf::DW_FORM_ref1
:
378 case dwarf::DW_FORM_data1
:
379 case dwarf::DW_FORM_strx1
:
380 case dwarf::DW_FORM_addrx1
:
381 case dwarf::DW_FORM_ref2
:
382 case dwarf::DW_FORM_data2
:
383 case dwarf::DW_FORM_strx2
:
384 case dwarf::DW_FORM_addrx2
:
385 case dwarf::DW_FORM_strx3
:
386 case dwarf::DW_FORM_addrx3
:
387 case dwarf::DW_FORM_strp
:
388 case dwarf::DW_FORM_ref4
:
389 case dwarf::DW_FORM_data4
:
390 case dwarf::DW_FORM_ref_sup4
:
391 case dwarf::DW_FORM_strx4
:
392 case dwarf::DW_FORM_addrx4
:
393 case dwarf::DW_FORM_ref8
:
394 case dwarf::DW_FORM_ref_sig8
:
395 case dwarf::DW_FORM_data8
:
396 case dwarf::DW_FORM_ref_sup8
:
397 case dwarf::DW_FORM_GNU_ref_alt
:
398 case dwarf::DW_FORM_GNU_strp_alt
:
399 case dwarf::DW_FORM_line_strp
:
400 case dwarf::DW_FORM_sec_offset
:
401 case dwarf::DW_FORM_strp_sup
:
402 case dwarf::DW_FORM_addr
:
403 case dwarf::DW_FORM_ref_addr
:
404 Asm
->OutStreamer
->emitIntValue(Integer
,
405 sizeOf(Asm
->getDwarfFormParams(), Form
));
407 case dwarf::DW_FORM_GNU_str_index
:
408 case dwarf::DW_FORM_GNU_addr_index
:
409 case dwarf::DW_FORM_ref_udata
:
410 case dwarf::DW_FORM_strx
:
411 case dwarf::DW_FORM_addrx
:
412 case dwarf::DW_FORM_rnglistx
:
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 dwarf::FormParams
&FormParams
,
426 dwarf::Form Form
) const {
427 if (std::optional
<uint8_t> FixedSize
=
428 dwarf::getFixedFormByteSize(Form
, FormParams
))
432 case dwarf::DW_FORM_GNU_str_index
:
433 case dwarf::DW_FORM_GNU_addr_index
:
434 case dwarf::DW_FORM_ref_udata
:
435 case dwarf::DW_FORM_strx
:
436 case dwarf::DW_FORM_addrx
:
437 case dwarf::DW_FORM_rnglistx
:
438 case dwarf::DW_FORM_udata
:
439 return getULEB128Size(Integer
);
440 case dwarf::DW_FORM_sdata
:
441 return getSLEB128Size(Integer
);
442 default: llvm_unreachable("DIE Value form not supported yet");
447 void DIEInteger::print(raw_ostream
&O
) const {
448 O
<< "Int: " << (int64_t)Integer
<< " 0x";
449 O
.write_hex(Integer
);
452 //===----------------------------------------------------------------------===//
453 // DIEExpr Implementation
454 //===----------------------------------------------------------------------===//
456 /// EmitValue - Emit expression value.
458 void DIEExpr::emitValue(const AsmPrinter
*AP
, dwarf::Form Form
) const {
459 AP
->emitDebugValue(Expr
, sizeOf(AP
->getDwarfFormParams(), Form
));
462 /// SizeOf - Determine size of expression value in bytes.
464 unsigned DIEExpr::sizeOf(const dwarf::FormParams
&FormParams
,
465 dwarf::Form Form
) const {
467 case dwarf::DW_FORM_data4
:
469 case dwarf::DW_FORM_data8
:
471 case dwarf::DW_FORM_sec_offset
:
472 return FormParams
.getDwarfOffsetByteSize();
474 llvm_unreachable("DIE Value form not supported yet");
479 void DIEExpr::print(raw_ostream
&O
) const { O
<< "Expr: " << *Expr
; }
481 //===----------------------------------------------------------------------===//
482 // DIELabel Implementation
483 //===----------------------------------------------------------------------===//
485 /// EmitValue - Emit label value.
487 void DIELabel::emitValue(const AsmPrinter
*AP
, dwarf::Form Form
) const {
488 bool IsSectionRelative
= Form
!= dwarf::DW_FORM_addr
;
489 AP
->emitLabelReference(Label
, sizeOf(AP
->getDwarfFormParams(), Form
),
493 /// sizeOf - Determine size of label value in bytes.
495 unsigned DIELabel::sizeOf(const dwarf::FormParams
&FormParams
,
496 dwarf::Form Form
) const {
498 case dwarf::DW_FORM_data4
:
500 case dwarf::DW_FORM_data8
:
502 case dwarf::DW_FORM_sec_offset
:
503 case dwarf::DW_FORM_strp
:
504 return FormParams
.getDwarfOffsetByteSize();
505 case dwarf::DW_FORM_addr
:
506 return FormParams
.AddrSize
;
508 llvm_unreachable("DIE Value form not supported yet");
513 void DIELabel::print(raw_ostream
&O
) const { O
<< "Lbl: " << Label
->getName(); }
515 //===----------------------------------------------------------------------===//
516 // DIEBaseTypeRef Implementation
517 //===----------------------------------------------------------------------===//
519 void DIEBaseTypeRef::emitValue(const AsmPrinter
*AP
, dwarf::Form Form
) const {
520 uint64_t Offset
= CU
->ExprRefedBaseTypes
[Index
].Die
->getOffset();
521 assert(Offset
< (1ULL << (ULEB128PadSize
* 7)) && "Offset wont fit");
522 AP
->emitULEB128(Offset
, nullptr, ULEB128PadSize
);
525 unsigned DIEBaseTypeRef::sizeOf(const dwarf::FormParams
&, dwarf::Form
) const {
526 return ULEB128PadSize
;
530 void DIEBaseTypeRef::print(raw_ostream
&O
) const { O
<< "BaseTypeRef: " << Index
; }
532 //===----------------------------------------------------------------------===//
533 // DIEDelta Implementation
534 //===----------------------------------------------------------------------===//
536 /// EmitValue - Emit delta value.
538 void DIEDelta::emitValue(const AsmPrinter
*AP
, dwarf::Form Form
) const {
539 AP
->emitLabelDifference(LabelHi
, LabelLo
,
540 sizeOf(AP
->getDwarfFormParams(), Form
));
543 /// SizeOf - Determine size of delta value in bytes.
545 unsigned DIEDelta::sizeOf(const dwarf::FormParams
&FormParams
,
546 dwarf::Form Form
) const {
548 case dwarf::DW_FORM_data4
:
550 case dwarf::DW_FORM_data8
:
552 case dwarf::DW_FORM_sec_offset
:
553 return FormParams
.getDwarfOffsetByteSize();
555 llvm_unreachable("DIE Value form not supported yet");
560 void DIEDelta::print(raw_ostream
&O
) const {
561 O
<< "Del: " << LabelHi
->getName() << "-" << LabelLo
->getName();
564 //===----------------------------------------------------------------------===//
565 // DIEString Implementation
566 //===----------------------------------------------------------------------===//
568 /// EmitValue - Emit string value.
570 void DIEString::emitValue(const AsmPrinter
*AP
, dwarf::Form Form
) const {
571 // Index of string in symbol table.
573 case dwarf::DW_FORM_GNU_str_index
:
574 case dwarf::DW_FORM_strx
:
575 case dwarf::DW_FORM_strx1
:
576 case dwarf::DW_FORM_strx2
:
577 case dwarf::DW_FORM_strx3
:
578 case dwarf::DW_FORM_strx4
:
579 DIEInteger(S
.getIndex()).emitValue(AP
, Form
);
581 case dwarf::DW_FORM_strp
:
582 if (AP
->doesDwarfUseRelocationsAcrossSections())
583 DIELabel(S
.getSymbol()).emitValue(AP
, Form
);
585 DIEInteger(S
.getOffset()).emitValue(AP
, Form
);
588 llvm_unreachable("Expected valid string form");
592 /// sizeOf - Determine size of delta value in bytes.
594 unsigned DIEString::sizeOf(const dwarf::FormParams
&FormParams
,
595 dwarf::Form Form
) const {
596 // Index of string in symbol table.
598 case dwarf::DW_FORM_GNU_str_index
:
599 case dwarf::DW_FORM_strx
:
600 case dwarf::DW_FORM_strx1
:
601 case dwarf::DW_FORM_strx2
:
602 case dwarf::DW_FORM_strx3
:
603 case dwarf::DW_FORM_strx4
:
604 return DIEInteger(S
.getIndex()).sizeOf(FormParams
, Form
);
605 case dwarf::DW_FORM_strp
:
606 if (FormParams
.DwarfUsesRelocationsAcrossSections
)
607 return DIELabel(S
.getSymbol()).sizeOf(FormParams
, Form
);
608 return DIEInteger(S
.getOffset()).sizeOf(FormParams
, Form
);
610 llvm_unreachable("Expected valid string form");
615 void DIEString::print(raw_ostream
&O
) const {
616 O
<< "String: " << S
.getString();
619 //===----------------------------------------------------------------------===//
620 // DIEInlineString Implementation
621 //===----------------------------------------------------------------------===//
622 void DIEInlineString::emitValue(const AsmPrinter
*AP
, dwarf::Form Form
) const {
623 if (Form
== dwarf::DW_FORM_string
) {
624 AP
->OutStreamer
->emitBytes(S
);
628 llvm_unreachable("Expected valid string form");
631 unsigned DIEInlineString::sizeOf(const dwarf::FormParams
&, dwarf::Form
) const {
632 // Emit string bytes + NULL byte.
637 void DIEInlineString::print(raw_ostream
&O
) const {
638 O
<< "InlineString: " << S
;
641 //===----------------------------------------------------------------------===//
642 // DIEEntry Implementation
643 //===----------------------------------------------------------------------===//
645 /// EmitValue - Emit debug information entry offset.
647 void DIEEntry::emitValue(const AsmPrinter
*AP
, dwarf::Form Form
) const {
650 case dwarf::DW_FORM_ref1
:
651 case dwarf::DW_FORM_ref2
:
652 case dwarf::DW_FORM_ref4
:
653 case dwarf::DW_FORM_ref8
:
654 AP
->OutStreamer
->emitIntValue(Entry
->getOffset(),
655 sizeOf(AP
->getDwarfFormParams(), Form
));
658 case dwarf::DW_FORM_ref_udata
:
659 AP
->emitULEB128(Entry
->getOffset());
662 case dwarf::DW_FORM_ref_addr
: {
663 // Get the absolute offset for this DIE within the debug info/types section.
664 uint64_t Addr
= Entry
->getDebugSectionOffset();
665 if (const MCSymbol
*SectionSym
=
666 Entry
->getUnit()->getCrossSectionRelativeBaseAddress()) {
667 AP
->emitLabelPlusOffset(SectionSym
, Addr
,
668 sizeOf(AP
->getDwarfFormParams(), Form
), true);
672 AP
->OutStreamer
->emitIntValue(Addr
, sizeOf(AP
->getDwarfFormParams(), Form
));
676 llvm_unreachable("Improper form for DIE reference");
680 unsigned DIEEntry::sizeOf(const dwarf::FormParams
&FormParams
,
681 dwarf::Form Form
) const {
683 case dwarf::DW_FORM_ref1
:
685 case dwarf::DW_FORM_ref2
:
687 case dwarf::DW_FORM_ref4
:
689 case dwarf::DW_FORM_ref8
:
691 case dwarf::DW_FORM_ref_udata
:
692 return getULEB128Size(Entry
->getOffset());
693 case dwarf::DW_FORM_ref_addr
:
694 return FormParams
.getRefAddrByteSize();
697 llvm_unreachable("Improper form for DIE reference");
702 void DIEEntry::print(raw_ostream
&O
) const {
703 O
<< format("Die: 0x%lx", (long)(intptr_t)&Entry
);
706 //===----------------------------------------------------------------------===//
707 // DIELoc Implementation
708 //===----------------------------------------------------------------------===//
710 unsigned DIELoc::computeSize(const dwarf::FormParams
&FormParams
) const {
712 for (const auto &V
: values())
713 Size
+= V
.sizeOf(FormParams
);
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
);
733 for (const auto &V
: values())
737 /// sizeOf - Determine size of location data in bytes.
739 unsigned DIELoc::sizeOf(const dwarf::FormParams
&, dwarf::Form Form
) const {
741 case dwarf::DW_FORM_block1
: return Size
+ sizeof(int8_t);
742 case dwarf::DW_FORM_block2
: return Size
+ sizeof(int16_t);
743 case dwarf::DW_FORM_block4
: return Size
+ sizeof(int32_t);
744 case dwarf::DW_FORM_block
:
745 case dwarf::DW_FORM_exprloc
:
746 return Size
+ getULEB128Size(Size
);
747 default: llvm_unreachable("Improper form for block");
752 void DIELoc::print(raw_ostream
&O
) const {
753 printValues(O
, *this, "ExprLoc", Size
, 5);
756 //===----------------------------------------------------------------------===//
757 // DIEBlock Implementation
758 //===----------------------------------------------------------------------===//
760 unsigned DIEBlock::computeSize(const dwarf::FormParams
&FormParams
) const {
762 for (const auto &V
: values())
763 Size
+= V
.sizeOf(FormParams
);
769 /// EmitValue - Emit block data.
771 void DIEBlock::emitValue(const AsmPrinter
*Asm
, dwarf::Form Form
) const {
773 default: llvm_unreachable("Improper form for block");
774 case dwarf::DW_FORM_block1
: Asm
->emitInt8(Size
); break;
775 case dwarf::DW_FORM_block2
: Asm
->emitInt16(Size
); break;
776 case dwarf::DW_FORM_block4
: Asm
->emitInt32(Size
); break;
777 case dwarf::DW_FORM_exprloc
:
778 case dwarf::DW_FORM_block
:
779 Asm
->emitULEB128(Size
);
781 case dwarf::DW_FORM_string
: break;
782 case dwarf::DW_FORM_data16
: break;
785 for (const auto &V
: values())
789 /// sizeOf - Determine size of block data in bytes.
791 unsigned DIEBlock::sizeOf(const dwarf::FormParams
&, dwarf::Form Form
) const {
793 case dwarf::DW_FORM_block1
: return Size
+ sizeof(int8_t);
794 case dwarf::DW_FORM_block2
: return Size
+ sizeof(int16_t);
795 case dwarf::DW_FORM_block4
: return Size
+ sizeof(int32_t);
796 case dwarf::DW_FORM_exprloc
:
797 case dwarf::DW_FORM_block
: return Size
+ getULEB128Size(Size
);
798 case dwarf::DW_FORM_data16
: return 16;
799 default: llvm_unreachable("Improper form for block");
804 void DIEBlock::print(raw_ostream
&O
) const {
805 printValues(O
, *this, "Blk", Size
, 5);
808 //===----------------------------------------------------------------------===//
809 // DIELocList Implementation
810 //===----------------------------------------------------------------------===//
812 unsigned DIELocList::sizeOf(const dwarf::FormParams
&FormParams
,
813 dwarf::Form Form
) const {
815 case dwarf::DW_FORM_loclistx
:
816 return getULEB128Size(Index
);
817 case dwarf::DW_FORM_data4
:
818 assert(FormParams
.Format
!= dwarf::DWARF64
&&
819 "DW_FORM_data4 is not suitable to emit a pointer to a location list "
820 "in the 64-bit DWARF format");
822 case dwarf::DW_FORM_data8
:
823 assert(FormParams
.Format
== dwarf::DWARF64
&&
824 "DW_FORM_data8 is not suitable to emit a pointer to a location list "
825 "in the 32-bit DWARF format");
827 case dwarf::DW_FORM_sec_offset
:
828 return FormParams
.getDwarfOffsetByteSize();
830 llvm_unreachable("DIE Value form not supported yet");
834 /// EmitValue - Emit label value.
836 void DIELocList::emitValue(const AsmPrinter
*AP
, dwarf::Form Form
) const {
837 if (Form
== dwarf::DW_FORM_loclistx
) {
838 AP
->emitULEB128(Index
);
841 DwarfDebug
*DD
= AP
->getDwarfDebug();
842 MCSymbol
*Label
= DD
->getDebugLocs().getList(Index
).Label
;
843 AP
->emitDwarfSymbolReference(Label
, /*ForceOffset*/ DD
->useSplitDwarf());
847 void DIELocList::print(raw_ostream
&O
) const { O
<< "LocList: " << Index
; }
849 //===----------------------------------------------------------------------===//
850 // DIEAddrOffset Implementation
851 //===----------------------------------------------------------------------===//
853 unsigned DIEAddrOffset::sizeOf(const dwarf::FormParams
&FormParams
,
855 return Addr
.sizeOf(FormParams
, dwarf::DW_FORM_addrx
) +
856 Offset
.sizeOf(FormParams
, dwarf::DW_FORM_data4
);
859 /// EmitValue - Emit label value.
861 void DIEAddrOffset::emitValue(const AsmPrinter
*AP
, dwarf::Form Form
) const {
862 Addr
.emitValue(AP
, dwarf::DW_FORM_addrx
);
863 Offset
.emitValue(AP
, dwarf::DW_FORM_data4
);
867 void DIEAddrOffset::print(raw_ostream
&O
) const {