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 {
177 return Owner
.dyn_cast
<DIE
*>();
180 DIEAbbrev
DIE::generateAbbrev() const {
181 DIEAbbrev
Abbrev(Tag
, hasChildren());
182 for (const DIEValue
&V
: values())
183 if (V
.getForm() == dwarf::DW_FORM_implicit_const
)
184 Abbrev
.AddImplicitConstAttribute(V
.getAttribute(),
185 V
.getDIEInteger().getValue());
187 Abbrev
.AddAttribute(V
.getAttribute(), V
.getForm());
191 uint64_t DIE::getDebugSectionOffset() const {
192 const DIEUnit
*Unit
= getUnit();
193 assert(Unit
&& "DIE must be owned by a DIEUnit to get its absolute offset");
194 return Unit
->getDebugSectionOffset() + getOffset();
197 const DIE
*DIE::getUnitDie() const {
200 if (p
->getTag() == dwarf::DW_TAG_compile_unit
||
201 p
->getTag() == dwarf::DW_TAG_skeleton_unit
||
202 p
->getTag() == dwarf::DW_TAG_type_unit
)
209 DIEUnit
*DIE::getUnit() const {
210 const DIE
*UnitDie
= getUnitDie();
212 return UnitDie
->Owner
.dyn_cast
<DIEUnit
*>();
216 DIEValue
DIE::findAttribute(dwarf::Attribute Attribute
) const {
217 // Iterate through all the attributes until we find the one we're
218 // looking for, if we can't find it return NULL.
219 for (const auto &V
: values())
220 if (V
.getAttribute() == Attribute
)
226 static void printValues(raw_ostream
&O
, const DIEValueList
&Values
,
227 StringRef Type
, unsigned Size
, unsigned IndentCount
) {
228 O
<< Type
<< ": Size: " << Size
<< "\n";
231 const std::string
Indent(IndentCount
, ' ');
232 for (const auto &V
: Values
.values()) {
234 O
<< "Blk[" << I
++ << "]";
235 O
<< " " << dwarf::FormEncodingString(V
.getForm()) << " ";
242 void DIE::print(raw_ostream
&O
, unsigned IndentCount
) const {
243 const std::string
Indent(IndentCount
, ' ');
244 O
<< Indent
<< "Die: " << format("0x%lx", (long)(intptr_t) this)
245 << ", Offset: " << Offset
<< ", Size: " << Size
<< "\n";
247 O
<< Indent
<< dwarf::TagString(getTag()) << " "
248 << dwarf::ChildrenString(hasChildren()) << "\n";
251 for (const auto &V
: values()) {
253 O
<< dwarf::AttributeString(V
.getAttribute());
254 O
<< " " << dwarf::FormEncodingString(V
.getForm()) << " ";
260 for (const auto &Child
: children())
261 Child
.print(O
, IndentCount
+ 4);
266 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
267 LLVM_DUMP_METHOD
void DIE::dump() const {
272 unsigned DIE::computeOffsetsAndAbbrevs(const dwarf::FormParams
&FormParams
,
273 DIEAbbrevSet
&AbbrevSet
,
275 // Unique the abbreviation and fill in the abbreviation number so this DIE
277 const DIEAbbrev
&Abbrev
= AbbrevSet
.uniqueAbbreviation(*this);
279 // Set compile/type unit relative offset of this DIE.
282 // Add the byte size of the abbreviation code.
283 CUOffset
+= getULEB128Size(getAbbrevNumber());
285 // Add the byte size of all the DIE attribute values.
286 for (const auto &V
: values())
287 CUOffset
+= V
.sizeOf(FormParams
);
289 // Let the children compute their offsets and abbreviation numbers.
292 assert(Abbrev
.hasChildren() && "Children flag not set");
294 for (auto &Child
: children())
296 Child
.computeOffsetsAndAbbrevs(FormParams
, AbbrevSet
, CUOffset
);
298 // Each child chain is terminated with a zero byte, adjust the offset.
299 CUOffset
+= sizeof(int8_t);
302 // Compute the byte size of this DIE and all of its children correctly. This
303 // is needed so that top level DIE can help the compile unit set its length
305 setSize(CUOffset
- getOffset());
309 //===----------------------------------------------------------------------===//
310 // DIEUnit Implementation
311 //===----------------------------------------------------------------------===//
312 DIEUnit::DIEUnit(dwarf::Tag UnitTag
) : Die(UnitTag
) {
314 assert((UnitTag
== dwarf::DW_TAG_compile_unit
||
315 UnitTag
== dwarf::DW_TAG_skeleton_unit
||
316 UnitTag
== dwarf::DW_TAG_type_unit
||
317 UnitTag
== dwarf::DW_TAG_partial_unit
) &&
318 "expected a unit TAG");
321 void DIEValue::emitValue(const AsmPrinter
*AP
) const {
324 llvm_unreachable("Expected valid DIEValue");
325 #define HANDLE_DIEVALUE(T) \
327 getDIE##T().emitValue(AP, Form); \
329 #include "llvm/CodeGen/DIEValue.def"
333 unsigned DIEValue::sizeOf(const dwarf::FormParams
&FormParams
) const {
336 llvm_unreachable("Expected valid DIEValue");
337 #define HANDLE_DIEVALUE(T) \
339 return getDIE##T().sizeOf(FormParams, Form);
340 #include "llvm/CodeGen/DIEValue.def"
342 llvm_unreachable("Unknown DIE kind");
346 void DIEValue::print(raw_ostream
&O
) const {
349 llvm_unreachable("Expected valid DIEValue");
350 #define HANDLE_DIEVALUE(T) \
352 getDIE##T().print(O); \
354 #include "llvm/CodeGen/DIEValue.def"
358 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
359 LLVM_DUMP_METHOD
void DIEValue::dump() const {
364 //===----------------------------------------------------------------------===//
365 // DIEInteger Implementation
366 //===----------------------------------------------------------------------===//
368 /// EmitValue - Emit integer of appropriate size.
370 void DIEInteger::emitValue(const AsmPrinter
*Asm
, dwarf::Form Form
) const {
372 case dwarf::DW_FORM_implicit_const
:
373 case dwarf::DW_FORM_flag_present
:
374 // Emit something to keep the lines and comments in sync.
375 // FIXME: Is there a better way to do this?
376 Asm
->OutStreamer
->addBlankLine();
378 case dwarf::DW_FORM_flag
:
379 case dwarf::DW_FORM_ref1
:
380 case dwarf::DW_FORM_data1
:
381 case dwarf::DW_FORM_strx1
:
382 case dwarf::DW_FORM_addrx1
:
383 case dwarf::DW_FORM_ref2
:
384 case dwarf::DW_FORM_data2
:
385 case dwarf::DW_FORM_strx2
:
386 case dwarf::DW_FORM_addrx2
:
387 case dwarf::DW_FORM_strx3
:
388 case dwarf::DW_FORM_strp
:
389 case dwarf::DW_FORM_ref4
:
390 case dwarf::DW_FORM_data4
:
391 case dwarf::DW_FORM_ref_sup4
:
392 case dwarf::DW_FORM_strx4
:
393 case dwarf::DW_FORM_addrx4
:
394 case dwarf::DW_FORM_ref8
:
395 case dwarf::DW_FORM_ref_sig8
:
396 case dwarf::DW_FORM_data8
:
397 case dwarf::DW_FORM_ref_sup8
:
398 case dwarf::DW_FORM_GNU_ref_alt
:
399 case dwarf::DW_FORM_GNU_strp_alt
:
400 case dwarf::DW_FORM_line_strp
:
401 case dwarf::DW_FORM_sec_offset
:
402 case dwarf::DW_FORM_strp_sup
:
403 case dwarf::DW_FORM_addr
:
404 case dwarf::DW_FORM_ref_addr
:
405 Asm
->OutStreamer
->emitIntValue(Integer
,
406 sizeOf(Asm
->getDwarfFormParams(), Form
));
408 case dwarf::DW_FORM_GNU_str_index
:
409 case dwarf::DW_FORM_GNU_addr_index
:
410 case dwarf::DW_FORM_ref_udata
:
411 case dwarf::DW_FORM_strx
:
412 case dwarf::DW_FORM_addrx
:
413 case dwarf::DW_FORM_rnglistx
:
414 case dwarf::DW_FORM_udata
:
415 Asm
->emitULEB128(Integer
);
417 case dwarf::DW_FORM_sdata
:
418 Asm
->emitSLEB128(Integer
);
420 default: llvm_unreachable("DIE Value form not supported yet");
424 /// sizeOf - Determine size of integer value in bytes.
426 unsigned DIEInteger::sizeOf(const dwarf::FormParams
&FormParams
,
427 dwarf::Form Form
) const {
428 if (Optional
<uint8_t> FixedSize
=
429 dwarf::getFixedFormByteSize(Form
, FormParams
))
433 case dwarf::DW_FORM_GNU_str_index
:
434 case dwarf::DW_FORM_GNU_addr_index
:
435 case dwarf::DW_FORM_ref_udata
:
436 case dwarf::DW_FORM_strx
:
437 case dwarf::DW_FORM_addrx
:
438 case dwarf::DW_FORM_rnglistx
:
439 case dwarf::DW_FORM_udata
:
440 return getULEB128Size(Integer
);
441 case dwarf::DW_FORM_sdata
:
442 return getSLEB128Size(Integer
);
443 default: llvm_unreachable("DIE Value form not supported yet");
448 void DIEInteger::print(raw_ostream
&O
) const {
449 O
<< "Int: " << (int64_t)Integer
<< " 0x";
450 O
.write_hex(Integer
);
453 //===----------------------------------------------------------------------===//
454 // DIEExpr Implementation
455 //===----------------------------------------------------------------------===//
457 /// EmitValue - Emit expression value.
459 void DIEExpr::emitValue(const AsmPrinter
*AP
, dwarf::Form Form
) const {
460 AP
->emitDebugValue(Expr
, sizeOf(AP
->getDwarfFormParams(), Form
));
463 /// SizeOf - Determine size of expression value in bytes.
465 unsigned DIEExpr::sizeOf(const dwarf::FormParams
&FormParams
,
466 dwarf::Form Form
) const {
468 case dwarf::DW_FORM_data4
:
470 case dwarf::DW_FORM_data8
:
472 case dwarf::DW_FORM_sec_offset
:
473 return FormParams
.getDwarfOffsetByteSize();
475 llvm_unreachable("DIE Value form not supported yet");
480 void DIEExpr::print(raw_ostream
&O
) const { O
<< "Expr: " << *Expr
; }
482 //===----------------------------------------------------------------------===//
483 // DIELabel Implementation
484 //===----------------------------------------------------------------------===//
486 /// EmitValue - Emit label value.
488 void DIELabel::emitValue(const AsmPrinter
*AP
, dwarf::Form Form
) const {
489 bool IsSectionRelative
= Form
!= dwarf::DW_FORM_addr
;
490 AP
->emitLabelReference(Label
, sizeOf(AP
->getDwarfFormParams(), Form
),
494 /// sizeOf - Determine size of label value in bytes.
496 unsigned DIELabel::sizeOf(const dwarf::FormParams
&FormParams
,
497 dwarf::Form Form
) const {
499 case dwarf::DW_FORM_data4
:
501 case dwarf::DW_FORM_data8
:
503 case dwarf::DW_FORM_sec_offset
:
504 case dwarf::DW_FORM_strp
:
505 return FormParams
.getDwarfOffsetByteSize();
506 case dwarf::DW_FORM_addr
:
507 return FormParams
.AddrSize
;
509 llvm_unreachable("DIE Value form not supported yet");
514 void DIELabel::print(raw_ostream
&O
) const { O
<< "Lbl: " << Label
->getName(); }
516 //===----------------------------------------------------------------------===//
517 // DIEBaseTypeRef Implementation
518 //===----------------------------------------------------------------------===//
520 void DIEBaseTypeRef::emitValue(const AsmPrinter
*AP
, dwarf::Form Form
) const {
521 uint64_t Offset
= CU
->ExprRefedBaseTypes
[Index
].Die
->getOffset();
522 assert(Offset
< (1ULL << (ULEB128PadSize
* 7)) && "Offset wont fit");
523 AP
->emitULEB128(Offset
, nullptr, ULEB128PadSize
);
526 unsigned DIEBaseTypeRef::sizeOf(const dwarf::FormParams
&, dwarf::Form
) const {
527 return ULEB128PadSize
;
531 void DIEBaseTypeRef::print(raw_ostream
&O
) const { O
<< "BaseTypeRef: " << Index
; }
533 //===----------------------------------------------------------------------===//
534 // DIEDelta Implementation
535 //===----------------------------------------------------------------------===//
537 /// EmitValue - Emit delta value.
539 void DIEDelta::emitValue(const AsmPrinter
*AP
, dwarf::Form Form
) const {
540 AP
->emitLabelDifference(LabelHi
, LabelLo
,
541 sizeOf(AP
->getDwarfFormParams(), Form
));
544 /// SizeOf - Determine size of delta value in bytes.
546 unsigned DIEDelta::sizeOf(const dwarf::FormParams
&FormParams
,
547 dwarf::Form Form
) const {
549 case dwarf::DW_FORM_data4
:
551 case dwarf::DW_FORM_data8
:
553 case dwarf::DW_FORM_sec_offset
:
554 return FormParams
.getDwarfOffsetByteSize();
556 llvm_unreachable("DIE Value form not supported yet");
561 void DIEDelta::print(raw_ostream
&O
) const {
562 O
<< "Del: " << LabelHi
->getName() << "-" << LabelLo
->getName();
565 //===----------------------------------------------------------------------===//
566 // DIEString Implementation
567 //===----------------------------------------------------------------------===//
569 /// EmitValue - Emit string value.
571 void DIEString::emitValue(const AsmPrinter
*AP
, dwarf::Form Form
) const {
572 // Index of string in symbol table.
574 case dwarf::DW_FORM_GNU_str_index
:
575 case dwarf::DW_FORM_strx
:
576 case dwarf::DW_FORM_strx1
:
577 case dwarf::DW_FORM_strx2
:
578 case dwarf::DW_FORM_strx3
:
579 case dwarf::DW_FORM_strx4
:
580 DIEInteger(S
.getIndex()).emitValue(AP
, Form
);
582 case dwarf::DW_FORM_strp
:
583 if (AP
->MAI
->doesDwarfUseRelocationsAcrossSections())
584 DIELabel(S
.getSymbol()).emitValue(AP
, Form
);
586 DIEInteger(S
.getOffset()).emitValue(AP
, Form
);
589 llvm_unreachable("Expected valid string form");
593 /// sizeOf - Determine size of delta value in bytes.
595 unsigned DIEString::sizeOf(const dwarf::FormParams
&FormParams
,
596 dwarf::Form Form
) const {
597 // Index of string in symbol table.
599 case dwarf::DW_FORM_GNU_str_index
:
600 case dwarf::DW_FORM_strx
:
601 case dwarf::DW_FORM_strx1
:
602 case dwarf::DW_FORM_strx2
:
603 case dwarf::DW_FORM_strx3
:
604 case dwarf::DW_FORM_strx4
:
605 return DIEInteger(S
.getIndex()).sizeOf(FormParams
, Form
);
606 case dwarf::DW_FORM_strp
:
607 if (FormParams
.DwarfUsesRelocationsAcrossSections
)
608 return DIELabel(S
.getSymbol()).sizeOf(FormParams
, Form
);
609 return DIEInteger(S
.getOffset()).sizeOf(FormParams
, Form
);
611 llvm_unreachable("Expected valid string form");
616 void DIEString::print(raw_ostream
&O
) const {
617 O
<< "String: " << S
.getString();
620 //===----------------------------------------------------------------------===//
621 // DIEInlineString Implementation
622 //===----------------------------------------------------------------------===//
623 void DIEInlineString::emitValue(const AsmPrinter
*AP
, dwarf::Form Form
) const {
624 if (Form
== dwarf::DW_FORM_string
) {
625 AP
->OutStreamer
->emitBytes(S
);
629 llvm_unreachable("Expected valid string form");
632 unsigned DIEInlineString::sizeOf(const dwarf::FormParams
&, dwarf::Form
) const {
633 // Emit string bytes + NULL byte.
638 void DIEInlineString::print(raw_ostream
&O
) const {
639 O
<< "InlineString: " << S
;
642 //===----------------------------------------------------------------------===//
643 // DIEEntry Implementation
644 //===----------------------------------------------------------------------===//
646 /// EmitValue - Emit debug information entry offset.
648 void DIEEntry::emitValue(const AsmPrinter
*AP
, dwarf::Form Form
) const {
651 case dwarf::DW_FORM_ref1
:
652 case dwarf::DW_FORM_ref2
:
653 case dwarf::DW_FORM_ref4
:
654 case dwarf::DW_FORM_ref8
:
655 AP
->OutStreamer
->emitIntValue(Entry
->getOffset(),
656 sizeOf(AP
->getDwarfFormParams(), Form
));
659 case dwarf::DW_FORM_ref_udata
:
660 AP
->emitULEB128(Entry
->getOffset());
663 case dwarf::DW_FORM_ref_addr
: {
664 // Get the absolute offset for this DIE within the debug info/types section.
665 uint64_t Addr
= Entry
->getDebugSectionOffset();
666 if (const MCSymbol
*SectionSym
=
667 Entry
->getUnit()->getCrossSectionRelativeBaseAddress()) {
668 AP
->emitLabelPlusOffset(SectionSym
, Addr
,
669 sizeOf(AP
->getDwarfFormParams(), Form
), true);
673 AP
->OutStreamer
->emitIntValue(Addr
, sizeOf(AP
->getDwarfFormParams(), Form
));
677 llvm_unreachable("Improper form for DIE reference");
681 unsigned DIEEntry::sizeOf(const dwarf::FormParams
&FormParams
,
682 dwarf::Form Form
) const {
684 case dwarf::DW_FORM_ref1
:
686 case dwarf::DW_FORM_ref2
:
688 case dwarf::DW_FORM_ref4
:
690 case dwarf::DW_FORM_ref8
:
692 case dwarf::DW_FORM_ref_udata
:
693 return getULEB128Size(Entry
->getOffset());
694 case dwarf::DW_FORM_ref_addr
:
695 return FormParams
.getRefAddrByteSize();
698 llvm_unreachable("Improper form for DIE reference");
703 void DIEEntry::print(raw_ostream
&O
) const {
704 O
<< format("Die: 0x%lx", (long)(intptr_t)&Entry
);
707 //===----------------------------------------------------------------------===//
708 // DIELoc Implementation
709 //===----------------------------------------------------------------------===//
711 unsigned DIELoc::computeSize(const dwarf::FormParams
&FormParams
) const {
713 for (const auto &V
: values())
714 Size
+= V
.sizeOf(FormParams
);
720 /// EmitValue - Emit location data.
722 void DIELoc::emitValue(const AsmPrinter
*Asm
, dwarf::Form Form
) const {
724 default: llvm_unreachable("Improper form for block");
725 case dwarf::DW_FORM_block1
: Asm
->emitInt8(Size
); break;
726 case dwarf::DW_FORM_block2
: Asm
->emitInt16(Size
); break;
727 case dwarf::DW_FORM_block4
: Asm
->emitInt32(Size
); break;
728 case dwarf::DW_FORM_block
:
729 case dwarf::DW_FORM_exprloc
:
730 Asm
->emitULEB128(Size
);
734 for (const auto &V
: values())
738 /// sizeOf - Determine size of location data in bytes.
740 unsigned DIELoc::sizeOf(const dwarf::FormParams
&, dwarf::Form Form
) const {
742 case dwarf::DW_FORM_block1
: return Size
+ sizeof(int8_t);
743 case dwarf::DW_FORM_block2
: return Size
+ sizeof(int16_t);
744 case dwarf::DW_FORM_block4
: return Size
+ sizeof(int32_t);
745 case dwarf::DW_FORM_block
:
746 case dwarf::DW_FORM_exprloc
:
747 return Size
+ getULEB128Size(Size
);
748 default: llvm_unreachable("Improper form for block");
753 void DIELoc::print(raw_ostream
&O
) const {
754 printValues(O
, *this, "ExprLoc", Size
, 5);
757 //===----------------------------------------------------------------------===//
758 // DIEBlock Implementation
759 //===----------------------------------------------------------------------===//
761 unsigned DIEBlock::computeSize(const dwarf::FormParams
&FormParams
) const {
763 for (const auto &V
: values())
764 Size
+= V
.sizeOf(FormParams
);
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_exprloc
:
779 case dwarf::DW_FORM_block
:
780 Asm
->emitULEB128(Size
);
782 case dwarf::DW_FORM_string
: break;
783 case dwarf::DW_FORM_data16
: break;
786 for (const auto &V
: values())
790 /// sizeOf - Determine size of block data in bytes.
792 unsigned DIEBlock::sizeOf(const dwarf::FormParams
&, dwarf::Form Form
) const {
794 case dwarf::DW_FORM_block1
: return Size
+ sizeof(int8_t);
795 case dwarf::DW_FORM_block2
: return Size
+ sizeof(int16_t);
796 case dwarf::DW_FORM_block4
: return Size
+ sizeof(int32_t);
797 case dwarf::DW_FORM_exprloc
:
798 case dwarf::DW_FORM_block
: return Size
+ getULEB128Size(Size
);
799 case dwarf::DW_FORM_data16
: return 16;
800 default: llvm_unreachable("Improper form for block");
805 void DIEBlock::print(raw_ostream
&O
) const {
806 printValues(O
, *this, "Blk", Size
, 5);
809 //===----------------------------------------------------------------------===//
810 // DIELocList Implementation
811 //===----------------------------------------------------------------------===//
813 unsigned DIELocList::sizeOf(const dwarf::FormParams
&FormParams
,
814 dwarf::Form Form
) const {
816 case dwarf::DW_FORM_loclistx
:
817 return getULEB128Size(Index
);
818 case dwarf::DW_FORM_data4
:
819 assert(FormParams
.Format
!= dwarf::DWARF64
&&
820 "DW_FORM_data4 is not suitable to emit a pointer to a location list "
821 "in the 64-bit DWARF format");
823 case dwarf::DW_FORM_data8
:
824 assert(FormParams
.Format
== dwarf::DWARF64
&&
825 "DW_FORM_data8 is not suitable to emit a pointer to a location list "
826 "in the 32-bit DWARF format");
828 case dwarf::DW_FORM_sec_offset
:
829 return FormParams
.getDwarfOffsetByteSize();
831 llvm_unreachable("DIE Value form not supported yet");
835 /// EmitValue - Emit label value.
837 void DIELocList::emitValue(const AsmPrinter
*AP
, dwarf::Form Form
) const {
838 if (Form
== dwarf::DW_FORM_loclistx
) {
839 AP
->emitULEB128(Index
);
842 DwarfDebug
*DD
= AP
->getDwarfDebug();
843 MCSymbol
*Label
= DD
->getDebugLocs().getList(Index
).Label
;
844 AP
->emitDwarfSymbolReference(Label
, /*ForceOffset*/ DD
->useSplitDwarf());
848 void DIELocList::print(raw_ostream
&O
) const { O
<< "LocList: " << Index
; }
850 //===----------------------------------------------------------------------===//
851 // DIEAddrOffset Implementation
852 //===----------------------------------------------------------------------===//
854 unsigned DIEAddrOffset::sizeOf(const dwarf::FormParams
&FormParams
,
856 return Addr
.sizeOf(FormParams
, dwarf::DW_FORM_addrx
) +
857 Offset
.sizeOf(FormParams
, dwarf::DW_FORM_data4
);
860 /// EmitValue - Emit label value.
862 void DIEAddrOffset::emitValue(const AsmPrinter
*AP
, dwarf::Form Form
) const {
863 Addr
.emitValue(AP
, dwarf::DW_FORM_addrx
);
864 Offset
.emitValue(AP
, dwarf::DW_FORM_data4
);
868 void DIEAddrOffset::print(raw_ostream
&O
) const {