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 "DwarfUnit.h"
17 #include "llvm/ADT/Twine.h"
18 #include "llvm/CodeGen/AsmPrinter.h"
19 #include "llvm/Config/llvm-config.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 LLVM_DEBUG(dbgs() << "Invalid form " << format("0x%x", AttrData
.getForm())
90 << " for DWARF version " << AP
->getDwarfVersion()
92 llvm_unreachable("Invalid form for specified DWARF version");
95 AP
->emitULEB128(AttrData
.getForm(),
96 dwarf::FormEncodingString(AttrData
.getForm()).data());
98 // Emit value for DW_FORM_implicit_const.
99 if (AttrData
.getForm() == dwarf::DW_FORM_implicit_const
)
100 AP
->emitSLEB128(AttrData
.getValue());
103 // Mark end of abbreviation.
104 AP
->emitULEB128(0, "EOM(1)");
105 AP
->emitULEB128(0, "EOM(2)");
109 void DIEAbbrev::print(raw_ostream
&O
) const {
110 O
<< "Abbreviation @"
111 << format("0x%lx", (long)(intptr_t)this)
113 << dwarf::TagString(Tag
)
115 << dwarf::ChildrenString(Children
)
118 for (unsigned i
= 0, N
= Data
.size(); i
< N
; ++i
) {
120 << dwarf::AttributeString(Data
[i
].getAttribute())
122 << dwarf::FormEncodingString(Data
[i
].getForm());
124 if (Data
[i
].getForm() == dwarf::DW_FORM_implicit_const
)
125 O
<< " " << Data
[i
].getValue();
131 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
132 LLVM_DUMP_METHOD
void DIEAbbrev::dump() const {
137 //===----------------------------------------------------------------------===//
138 // DIEAbbrevSet Implementation
139 //===----------------------------------------------------------------------===//
141 DIEAbbrevSet::~DIEAbbrevSet() {
142 for (DIEAbbrev
*Abbrev
: Abbreviations
)
143 Abbrev
->~DIEAbbrev();
146 DIEAbbrev
&DIEAbbrevSet::uniqueAbbreviation(DIE
&Die
) {
149 DIEAbbrev Abbrev
= Die
.generateAbbrev();
153 if (DIEAbbrev
*Existing
=
154 AbbreviationsSet
.FindNodeOrInsertPos(ID
, InsertPos
)) {
155 Die
.setAbbrevNumber(Existing
->getNumber());
159 // Move the abbreviation to the heap and assign a number.
160 DIEAbbrev
*New
= new (Alloc
) DIEAbbrev(std::move(Abbrev
));
161 Abbreviations
.push_back(New
);
162 New
->setNumber(Abbreviations
.size());
163 Die
.setAbbrevNumber(Abbreviations
.size());
165 // Store it for lookup.
166 AbbreviationsSet
.InsertNode(New
, InsertPos
);
170 void DIEAbbrevSet::Emit(const AsmPrinter
*AP
, MCSection
*Section
) const {
171 if (!Abbreviations
.empty()) {
172 // Start the debug abbrev section.
173 AP
->OutStreamer
->SwitchSection(Section
);
174 AP
->emitDwarfAbbrevs(Abbreviations
);
178 //===----------------------------------------------------------------------===//
179 // DIE Implementation
180 //===----------------------------------------------------------------------===//
182 DIE
*DIE::getParent() const {
183 return Owner
.dyn_cast
<DIE
*>();
186 DIEAbbrev
DIE::generateAbbrev() const {
187 DIEAbbrev
Abbrev(Tag
, hasChildren());
188 for (const DIEValue
&V
: values())
189 if (V
.getForm() == dwarf::DW_FORM_implicit_const
)
190 Abbrev
.AddImplicitConstAttribute(V
.getAttribute(),
191 V
.getDIEInteger().getValue());
193 Abbrev
.AddAttribute(V
.getAttribute(), V
.getForm());
197 uint64_t DIE::getDebugSectionOffset() const {
198 const DIEUnit
*Unit
= getUnit();
199 assert(Unit
&& "DIE must be owned by a DIEUnit to get its absolute offset");
200 return Unit
->getDebugSectionOffset() + getOffset();
203 const DIE
*DIE::getUnitDie() const {
206 if (p
->getTag() == dwarf::DW_TAG_compile_unit
||
207 p
->getTag() == dwarf::DW_TAG_type_unit
)
214 DIEUnit
*DIE::getUnit() const {
215 const DIE
*UnitDie
= getUnitDie();
217 return UnitDie
->Owner
.dyn_cast
<DIEUnit
*>();
221 DIEValue
DIE::findAttribute(dwarf::Attribute Attribute
) const {
222 // Iterate through all the attributes until we find the one we're
223 // looking for, if we can't find it return NULL.
224 for (const auto &V
: values())
225 if (V
.getAttribute() == Attribute
)
231 static void printValues(raw_ostream
&O
, const DIEValueList
&Values
,
232 StringRef Type
, unsigned Size
, unsigned IndentCount
) {
233 O
<< Type
<< ": Size: " << Size
<< "\n";
236 const std::string
Indent(IndentCount
, ' ');
237 for (const auto &V
: Values
.values()) {
239 O
<< "Blk[" << I
++ << "]";
240 O
<< " " << dwarf::FormEncodingString(V
.getForm()) << " ";
247 void DIE::print(raw_ostream
&O
, unsigned IndentCount
) const {
248 const std::string
Indent(IndentCount
, ' ');
249 O
<< Indent
<< "Die: " << format("0x%lx", (long)(intptr_t) this)
250 << ", Offset: " << Offset
<< ", Size: " << Size
<< "\n";
252 O
<< Indent
<< dwarf::TagString(getTag()) << " "
253 << dwarf::ChildrenString(hasChildren()) << "\n";
256 for (const auto &V
: values()) {
258 O
<< dwarf::AttributeString(V
.getAttribute());
259 O
<< " " << dwarf::FormEncodingString(V
.getForm()) << " ";
265 for (const auto &Child
: children())
266 Child
.print(O
, IndentCount
+ 4);
271 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
272 LLVM_DUMP_METHOD
void DIE::dump() const {
277 unsigned DIE::computeOffsetsAndAbbrevs(const dwarf::FormParams
&FormParams
,
278 DIEAbbrevSet
&AbbrevSet
,
280 // Unique the abbreviation and fill in the abbreviation number so this DIE
282 const DIEAbbrev
&Abbrev
= AbbrevSet
.uniqueAbbreviation(*this);
284 // Set compile/type unit relative offset of this DIE.
287 // Add the byte size of the abbreviation code.
288 CUOffset
+= getULEB128Size(getAbbrevNumber());
290 // Add the byte size of all the DIE attribute values.
291 for (const auto &V
: values())
292 CUOffset
+= V
.sizeOf(FormParams
);
294 // Let the children compute their offsets and abbreviation numbers.
297 assert(Abbrev
.hasChildren() && "Children flag not set");
299 for (auto &Child
: children())
301 Child
.computeOffsetsAndAbbrevs(FormParams
, AbbrevSet
, CUOffset
);
303 // Each child chain is terminated with a zero byte, adjust the offset.
304 CUOffset
+= sizeof(int8_t);
307 // Compute the byte size of this DIE and all of its children correctly. This
308 // is needed so that top level DIE can help the compile unit set its length
310 setSize(CUOffset
- getOffset());
314 //===----------------------------------------------------------------------===//
315 // DIEUnit Implementation
316 //===----------------------------------------------------------------------===//
317 DIEUnit::DIEUnit(dwarf::Tag UnitTag
)
318 : Die(UnitTag
), Section(nullptr), Offset(0) {
320 assert((UnitTag
== dwarf::DW_TAG_compile_unit
||
321 UnitTag
== dwarf::DW_TAG_skeleton_unit
||
322 UnitTag
== dwarf::DW_TAG_type_unit
||
323 UnitTag
== dwarf::DW_TAG_partial_unit
) &&
324 "expected a unit TAG");
327 void DIEValue::emitValue(const AsmPrinter
*AP
) const {
330 llvm_unreachable("Expected valid DIEValue");
331 #define HANDLE_DIEVALUE(T) \
333 getDIE##T().emitValue(AP, Form); \
335 #include "llvm/CodeGen/DIEValue.def"
339 unsigned DIEValue::sizeOf(const dwarf::FormParams
&FormParams
) const {
342 llvm_unreachable("Expected valid DIEValue");
343 #define HANDLE_DIEVALUE(T) \
345 return getDIE##T().sizeOf(FormParams, Form);
346 #include "llvm/CodeGen/DIEValue.def"
348 llvm_unreachable("Unknown DIE kind");
352 void DIEValue::print(raw_ostream
&O
) const {
355 llvm_unreachable("Expected valid DIEValue");
356 #define HANDLE_DIEVALUE(T) \
358 getDIE##T().print(O); \
360 #include "llvm/CodeGen/DIEValue.def"
364 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
365 LLVM_DUMP_METHOD
void DIEValue::dump() const {
370 //===----------------------------------------------------------------------===//
371 // DIEInteger Implementation
372 //===----------------------------------------------------------------------===//
374 /// EmitValue - Emit integer of appropriate size.
376 void DIEInteger::emitValue(const AsmPrinter
*Asm
, dwarf::Form Form
) const {
378 case dwarf::DW_FORM_implicit_const
:
379 case dwarf::DW_FORM_flag_present
:
380 // Emit something to keep the lines and comments in sync.
381 // FIXME: Is there a better way to do this?
382 Asm
->OutStreamer
->AddBlankLine();
384 case dwarf::DW_FORM_flag
:
385 case dwarf::DW_FORM_ref1
:
386 case dwarf::DW_FORM_data1
:
387 case dwarf::DW_FORM_strx1
:
388 case dwarf::DW_FORM_addrx1
:
389 case dwarf::DW_FORM_ref2
:
390 case dwarf::DW_FORM_data2
:
391 case dwarf::DW_FORM_strx2
:
392 case dwarf::DW_FORM_addrx2
:
393 case dwarf::DW_FORM_strx3
:
394 case dwarf::DW_FORM_strp
:
395 case dwarf::DW_FORM_ref4
:
396 case dwarf::DW_FORM_data4
:
397 case dwarf::DW_FORM_ref_sup4
:
398 case dwarf::DW_FORM_strx4
:
399 case dwarf::DW_FORM_addrx4
:
400 case dwarf::DW_FORM_ref8
:
401 case dwarf::DW_FORM_ref_sig8
:
402 case dwarf::DW_FORM_data8
:
403 case dwarf::DW_FORM_ref_sup8
:
404 case dwarf::DW_FORM_GNU_ref_alt
:
405 case dwarf::DW_FORM_GNU_strp_alt
:
406 case dwarf::DW_FORM_line_strp
:
407 case dwarf::DW_FORM_sec_offset
:
408 case dwarf::DW_FORM_strp_sup
:
409 case dwarf::DW_FORM_addr
:
410 case dwarf::DW_FORM_ref_addr
:
411 Asm
->OutStreamer
->emitIntValue(Integer
,
412 sizeOf(Asm
->getDwarfFormParams(), Form
));
414 case dwarf::DW_FORM_GNU_str_index
:
415 case dwarf::DW_FORM_GNU_addr_index
:
416 case dwarf::DW_FORM_ref_udata
:
417 case dwarf::DW_FORM_strx
:
418 case dwarf::DW_FORM_addrx
:
419 case dwarf::DW_FORM_rnglistx
:
420 case dwarf::DW_FORM_udata
:
421 Asm
->emitULEB128(Integer
);
423 case dwarf::DW_FORM_sdata
:
424 Asm
->emitSLEB128(Integer
);
426 default: llvm_unreachable("DIE Value form not supported yet");
430 /// sizeOf - Determine size of integer value in bytes.
432 unsigned DIEInteger::sizeOf(const dwarf::FormParams
&FormParams
,
433 dwarf::Form Form
) const {
434 if (Optional
<uint8_t> FixedSize
=
435 dwarf::getFixedFormByteSize(Form
, FormParams
))
439 case dwarf::DW_FORM_GNU_str_index
:
440 case dwarf::DW_FORM_GNU_addr_index
:
441 case dwarf::DW_FORM_ref_udata
:
442 case dwarf::DW_FORM_strx
:
443 case dwarf::DW_FORM_addrx
:
444 case dwarf::DW_FORM_rnglistx
:
445 case dwarf::DW_FORM_udata
:
446 return getULEB128Size(Integer
);
447 case dwarf::DW_FORM_sdata
:
448 return getSLEB128Size(Integer
);
449 default: llvm_unreachable("DIE Value form not supported yet");
454 void DIEInteger::print(raw_ostream
&O
) const {
455 O
<< "Int: " << (int64_t)Integer
<< " 0x";
456 O
.write_hex(Integer
);
459 //===----------------------------------------------------------------------===//
460 // DIEExpr Implementation
461 //===----------------------------------------------------------------------===//
463 /// EmitValue - Emit expression value.
465 void DIEExpr::emitValue(const AsmPrinter
*AP
, dwarf::Form Form
) const {
466 AP
->emitDebugValue(Expr
, sizeOf(AP
->getDwarfFormParams(), Form
));
469 /// SizeOf - Determine size of expression value in bytes.
471 unsigned DIEExpr::sizeOf(const dwarf::FormParams
&FormParams
,
472 dwarf::Form Form
) const {
474 case dwarf::DW_FORM_data4
:
476 case dwarf::DW_FORM_data8
:
478 case dwarf::DW_FORM_sec_offset
:
479 return FormParams
.getDwarfOffsetByteSize();
481 llvm_unreachable("DIE Value form not supported yet");
486 void DIEExpr::print(raw_ostream
&O
) const { O
<< "Expr: " << *Expr
; }
488 //===----------------------------------------------------------------------===//
489 // DIELabel Implementation
490 //===----------------------------------------------------------------------===//
492 /// EmitValue - Emit label value.
494 void DIELabel::emitValue(const AsmPrinter
*AP
, dwarf::Form Form
) const {
495 bool IsSectionRelative
= Form
!= dwarf::DW_FORM_addr
;
496 AP
->emitLabelReference(Label
, sizeOf(AP
->getDwarfFormParams(), Form
),
500 /// sizeOf - Determine size of label value in bytes.
502 unsigned DIELabel::sizeOf(const dwarf::FormParams
&FormParams
,
503 dwarf::Form Form
) const {
505 case dwarf::DW_FORM_data4
:
507 case dwarf::DW_FORM_data8
:
509 case dwarf::DW_FORM_sec_offset
:
510 case dwarf::DW_FORM_strp
:
511 return FormParams
.getDwarfOffsetByteSize();
512 case dwarf::DW_FORM_addr
:
513 return FormParams
.AddrSize
;
515 llvm_unreachable("DIE Value form not supported yet");
520 void DIELabel::print(raw_ostream
&O
) const { O
<< "Lbl: " << Label
->getName(); }
522 //===----------------------------------------------------------------------===//
523 // DIEBaseTypeRef Implementation
524 //===----------------------------------------------------------------------===//
526 void DIEBaseTypeRef::emitValue(const AsmPrinter
*AP
, dwarf::Form Form
) const {
527 uint64_t Offset
= CU
->ExprRefedBaseTypes
[Index
].Die
->getOffset();
528 assert(Offset
< (1ULL << (ULEB128PadSize
* 7)) && "Offset wont fit");
529 AP
->emitULEB128(Offset
, nullptr, ULEB128PadSize
);
532 unsigned DIEBaseTypeRef::sizeOf(const dwarf::FormParams
&, dwarf::Form
) const {
533 return ULEB128PadSize
;
537 void DIEBaseTypeRef::print(raw_ostream
&O
) const { O
<< "BaseTypeRef: " << Index
; }
539 //===----------------------------------------------------------------------===//
540 // DIEDelta Implementation
541 //===----------------------------------------------------------------------===//
543 /// EmitValue - Emit delta value.
545 void DIEDelta::emitValue(const AsmPrinter
*AP
, dwarf::Form Form
) const {
546 AP
->emitLabelDifference(LabelHi
, LabelLo
,
547 sizeOf(AP
->getDwarfFormParams(), Form
));
550 /// SizeOf - Determine size of delta value in bytes.
552 unsigned DIEDelta::sizeOf(const dwarf::FormParams
&FormParams
,
553 dwarf::Form Form
) const {
555 case dwarf::DW_FORM_data4
:
557 case dwarf::DW_FORM_data8
:
559 case dwarf::DW_FORM_sec_offset
:
560 return FormParams
.getDwarfOffsetByteSize();
562 llvm_unreachable("DIE Value form not supported yet");
567 void DIEDelta::print(raw_ostream
&O
) const {
568 O
<< "Del: " << LabelHi
->getName() << "-" << LabelLo
->getName();
571 //===----------------------------------------------------------------------===//
572 // DIEString Implementation
573 //===----------------------------------------------------------------------===//
575 /// EmitValue - Emit string value.
577 void DIEString::emitValue(const AsmPrinter
*AP
, dwarf::Form Form
) const {
578 // Index of string in symbol table.
580 case dwarf::DW_FORM_GNU_str_index
:
581 case dwarf::DW_FORM_strx
:
582 case dwarf::DW_FORM_strx1
:
583 case dwarf::DW_FORM_strx2
:
584 case dwarf::DW_FORM_strx3
:
585 case dwarf::DW_FORM_strx4
:
586 DIEInteger(S
.getIndex()).emitValue(AP
, Form
);
588 case dwarf::DW_FORM_strp
:
589 if (AP
->MAI
->doesDwarfUseRelocationsAcrossSections())
590 DIELabel(S
.getSymbol()).emitValue(AP
, Form
);
592 DIEInteger(S
.getOffset()).emitValue(AP
, Form
);
595 llvm_unreachable("Expected valid string form");
599 /// sizeOf - Determine size of delta value in bytes.
601 unsigned DIEString::sizeOf(const dwarf::FormParams
&FormParams
,
602 dwarf::Form Form
) const {
603 // Index of string in symbol table.
605 case dwarf::DW_FORM_GNU_str_index
:
606 case dwarf::DW_FORM_strx
:
607 case dwarf::DW_FORM_strx1
:
608 case dwarf::DW_FORM_strx2
:
609 case dwarf::DW_FORM_strx3
:
610 case dwarf::DW_FORM_strx4
:
611 return DIEInteger(S
.getIndex()).sizeOf(FormParams
, Form
);
612 case dwarf::DW_FORM_strp
:
613 if (FormParams
.DwarfUsesRelocationsAcrossSections
)
614 return DIELabel(S
.getSymbol()).sizeOf(FormParams
, Form
);
615 return DIEInteger(S
.getOffset()).sizeOf(FormParams
, Form
);
617 llvm_unreachable("Expected valid string form");
622 void DIEString::print(raw_ostream
&O
) const {
623 O
<< "String: " << S
.getString();
626 //===----------------------------------------------------------------------===//
627 // DIEInlineString Implementation
628 //===----------------------------------------------------------------------===//
629 void DIEInlineString::emitValue(const AsmPrinter
*AP
, dwarf::Form Form
) const {
630 if (Form
== dwarf::DW_FORM_string
) {
631 AP
->OutStreamer
->emitBytes(S
);
635 llvm_unreachable("Expected valid string form");
638 unsigned DIEInlineString::sizeOf(const dwarf::FormParams
&, dwarf::Form
) const {
639 // Emit string bytes + NULL byte.
644 void DIEInlineString::print(raw_ostream
&O
) const {
645 O
<< "InlineString: " << S
;
648 //===----------------------------------------------------------------------===//
649 // DIEEntry Implementation
650 //===----------------------------------------------------------------------===//
652 /// EmitValue - Emit debug information entry offset.
654 void DIEEntry::emitValue(const AsmPrinter
*AP
, dwarf::Form Form
) const {
657 case dwarf::DW_FORM_ref1
:
658 case dwarf::DW_FORM_ref2
:
659 case dwarf::DW_FORM_ref4
:
660 case dwarf::DW_FORM_ref8
:
661 AP
->OutStreamer
->emitIntValue(Entry
->getOffset(),
662 sizeOf(AP
->getDwarfFormParams(), Form
));
665 case dwarf::DW_FORM_ref_udata
:
666 AP
->emitULEB128(Entry
->getOffset());
669 case dwarf::DW_FORM_ref_addr
: {
670 // Get the absolute offset for this DIE within the debug info/types section.
671 uint64_t Addr
= Entry
->getDebugSectionOffset();
672 if (const MCSymbol
*SectionSym
=
673 Entry
->getUnit()->getCrossSectionRelativeBaseAddress()) {
674 AP
->emitLabelPlusOffset(SectionSym
, Addr
,
675 sizeOf(AP
->getDwarfFormParams(), Form
), true);
679 AP
->OutStreamer
->emitIntValue(Addr
, sizeOf(AP
->getDwarfFormParams(), Form
));
683 llvm_unreachable("Improper form for DIE reference");
687 unsigned DIEEntry::sizeOf(const dwarf::FormParams
&FormParams
,
688 dwarf::Form Form
) const {
690 case dwarf::DW_FORM_ref1
:
692 case dwarf::DW_FORM_ref2
:
694 case dwarf::DW_FORM_ref4
:
696 case dwarf::DW_FORM_ref8
:
698 case dwarf::DW_FORM_ref_udata
:
699 return getULEB128Size(Entry
->getOffset());
700 case dwarf::DW_FORM_ref_addr
:
701 return FormParams
.getRefAddrByteSize();
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 unsigned DIELoc::computeSize(const dwarf::FormParams
&FormParams
) const {
719 for (const auto &V
: values())
720 Size
+= V
.sizeOf(FormParams
);
726 /// EmitValue - Emit location data.
728 void DIELoc::emitValue(const AsmPrinter
*Asm
, dwarf::Form Form
) const {
730 default: llvm_unreachable("Improper form for block");
731 case dwarf::DW_FORM_block1
: Asm
->emitInt8(Size
); break;
732 case dwarf::DW_FORM_block2
: Asm
->emitInt16(Size
); break;
733 case dwarf::DW_FORM_block4
: Asm
->emitInt32(Size
); break;
734 case dwarf::DW_FORM_block
:
735 case dwarf::DW_FORM_exprloc
:
736 Asm
->emitULEB128(Size
);
740 for (const auto &V
: values())
744 /// sizeOf - Determine size of location data in bytes.
746 unsigned DIELoc::sizeOf(const dwarf::FormParams
&, dwarf::Form Form
) const {
748 case dwarf::DW_FORM_block1
: return Size
+ sizeof(int8_t);
749 case dwarf::DW_FORM_block2
: return Size
+ sizeof(int16_t);
750 case dwarf::DW_FORM_block4
: return Size
+ sizeof(int32_t);
751 case dwarf::DW_FORM_block
:
752 case dwarf::DW_FORM_exprloc
:
753 return Size
+ getULEB128Size(Size
);
754 default: llvm_unreachable("Improper form for block");
759 void DIELoc::print(raw_ostream
&O
) const {
760 printValues(O
, *this, "ExprLoc", Size
, 5);
763 //===----------------------------------------------------------------------===//
764 // DIEBlock Implementation
765 //===----------------------------------------------------------------------===//
767 unsigned DIEBlock::computeSize(const dwarf::FormParams
&FormParams
) const {
769 for (const auto &V
: values())
770 Size
+= V
.sizeOf(FormParams
);
776 /// EmitValue - Emit block data.
778 void DIEBlock::emitValue(const AsmPrinter
*Asm
, dwarf::Form Form
) const {
780 default: llvm_unreachable("Improper form for block");
781 case dwarf::DW_FORM_block1
: Asm
->emitInt8(Size
); break;
782 case dwarf::DW_FORM_block2
: Asm
->emitInt16(Size
); break;
783 case dwarf::DW_FORM_block4
: Asm
->emitInt32(Size
); break;
784 case dwarf::DW_FORM_exprloc
:
785 case dwarf::DW_FORM_block
:
786 Asm
->emitULEB128(Size
);
788 case dwarf::DW_FORM_string
: break;
789 case dwarf::DW_FORM_data16
: break;
792 for (const auto &V
: values())
796 /// sizeOf - Determine size of block data in bytes.
798 unsigned DIEBlock::sizeOf(const dwarf::FormParams
&, dwarf::Form Form
) const {
800 case dwarf::DW_FORM_block1
: return Size
+ sizeof(int8_t);
801 case dwarf::DW_FORM_block2
: return Size
+ sizeof(int16_t);
802 case dwarf::DW_FORM_block4
: return Size
+ sizeof(int32_t);
803 case dwarf::DW_FORM_exprloc
:
804 case dwarf::DW_FORM_block
: return Size
+ getULEB128Size(Size
);
805 case dwarf::DW_FORM_data16
: return 16;
806 default: llvm_unreachable("Improper form for block");
811 void DIEBlock::print(raw_ostream
&O
) const {
812 printValues(O
, *this, "Blk", Size
, 5);
815 //===----------------------------------------------------------------------===//
816 // DIELocList Implementation
817 //===----------------------------------------------------------------------===//
819 unsigned DIELocList::sizeOf(const dwarf::FormParams
&FormParams
,
820 dwarf::Form Form
) const {
822 case dwarf::DW_FORM_loclistx
:
823 return getULEB128Size(Index
);
824 case dwarf::DW_FORM_data4
:
825 assert(FormParams
.Format
!= dwarf::DWARF64
&&
826 "DW_FORM_data4 is not suitable to emit a pointer to a location list "
827 "in the 64-bit DWARF format");
829 case dwarf::DW_FORM_data8
:
830 assert(FormParams
.Format
== dwarf::DWARF64
&&
831 "DW_FORM_data8 is not suitable to emit a pointer to a location list "
832 "in the 32-bit DWARF format");
834 case dwarf::DW_FORM_sec_offset
:
835 return FormParams
.getDwarfOffsetByteSize();
837 llvm_unreachable("DIE Value form not supported yet");
841 /// EmitValue - Emit label value.
843 void DIELocList::emitValue(const AsmPrinter
*AP
, dwarf::Form Form
) const {
844 if (Form
== dwarf::DW_FORM_loclistx
) {
845 AP
->emitULEB128(Index
);
848 DwarfDebug
*DD
= AP
->getDwarfDebug();
849 MCSymbol
*Label
= DD
->getDebugLocs().getList(Index
).Label
;
850 AP
->emitDwarfSymbolReference(Label
, /*ForceOffset*/ DD
->useSplitDwarf());
854 void DIELocList::print(raw_ostream
&O
) const { O
<< "LocList: " << Index
; }
856 //===----------------------------------------------------------------------===//
857 // DIEAddrOffset Implementation
858 //===----------------------------------------------------------------------===//
860 unsigned DIEAddrOffset::sizeOf(const dwarf::FormParams
&FormParams
,
862 return Addr
.sizeOf(FormParams
, dwarf::DW_FORM_addrx
) +
863 Offset
.sizeOf(FormParams
, dwarf::DW_FORM_data4
);
866 /// EmitValue - Emit label value.
868 void DIEAddrOffset::emitValue(const AsmPrinter
*AP
, dwarf::Form Form
) const {
869 Addr
.emitValue(AP
, dwarf::DW_FORM_addrx
);
870 Offset
.emitValue(AP
, dwarf::DW_FORM_data4
);
874 void DIEAddrOffset::print(raw_ostream
&O
) const {