LLVM 19.0.0git
DIE.cpp
Go to the documentation of this file.
1//===--- lib/CodeGen/DIE.cpp - DWARF Info Entries -------------------------===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8//
9// Data structures for DWARF info entries.
10//
11//===----------------------------------------------------------------------===//
12
13#include "llvm/CodeGen/DIE.h"
14#include "DwarfCompileUnit.h"
15#include "DwarfDebug.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"
23#include "llvm/Support/Format.h"
24#include "llvm/Support/LEB128.h"
26using namespace llvm;
27
28#define DEBUG_TYPE "dwarfdebug"
29
30//===----------------------------------------------------------------------===//
31// DIEAbbrevData Implementation
32//===----------------------------------------------------------------------===//
33
34/// Profile - Used to gather unique data for the abbreviation folding set.
35///
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)
42 ID.AddInteger(Value);
43}
44
45//===----------------------------------------------------------------------===//
46// DIEAbbrev Implementation
47//===----------------------------------------------------------------------===//
48
49/// Profile - Used to gather unique data for the abbreviation folding set.
50///
52 ID.AddInteger(unsigned(Tag));
53 ID.AddInteger(unsigned(Children));
54
55 // For each attribute description.
56 for (unsigned i = 0, N = Data.size(); i < N; ++i)
57 Data[i].Profile(ID);
58}
59
60/// Emit - Print the abbreviation using the specified asm printer.
61///
62void DIEAbbrev::Emit(const AsmPrinter *AP) const {
63 // Emit its Dwarf tag type.
64 AP->emitULEB128(Tag, dwarf::TagString(Tag).data());
65
66 // Emit whether it has children DIEs.
67 AP->emitULEB128((unsigned)Children, dwarf::ChildrenString(Children).data());
68
69 // For each attribute description.
70 for (unsigned i = 0, N = Data.size(); i < N; ++i) {
71 const DIEAbbrevData &AttrData = Data[i];
72
73 // Emit attribute type.
74 AP->emitULEB128(AttrData.getAttribute(),
76
77 // Emit form type.
78#ifndef NDEBUG
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.
82 AP->getDwarfVersion())) {
83 LLVM_DEBUG(dbgs() << "Invalid form " << format("0x%x", AttrData.getForm())
84 << " for DWARF version " << AP->getDwarfVersion()
85 << "\n");
86 llvm_unreachable("Invalid form for specified DWARF version");
87 }
88#endif
89 AP->emitULEB128(AttrData.getForm(),
91
92 // Emit value for DW_FORM_implicit_const.
93 if (AttrData.getForm() == dwarf::DW_FORM_implicit_const)
94 AP->emitSLEB128(AttrData.getValue());
95 }
96
97 // Mark end of abbreviation.
98 AP->emitULEB128(0, "EOM(1)");
99 AP->emitULEB128(0, "EOM(2)");
100}
101
104 O << "Abbreviation @"
105 << format("0x%lx", (long)(intptr_t)this)
106 << " "
108 << " "
109 << dwarf::ChildrenString(Children)
110 << '\n';
111
112 for (unsigned i = 0, N = Data.size(); i < N; ++i) {
113 O << " "
114 << dwarf::AttributeString(Data[i].getAttribute())
115 << " "
116 << dwarf::FormEncodingString(Data[i].getForm());
117
118 if (Data[i].getForm() == dwarf::DW_FORM_implicit_const)
119 O << " " << Data[i].getValue();
120
121 O << '\n';
122 }
123}
124
125#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
127 print(dbgs());
128}
129#endif
130
131//===----------------------------------------------------------------------===//
132// DIEAbbrevSet Implementation
133//===----------------------------------------------------------------------===//
134
136 for (DIEAbbrev *Abbrev : Abbreviations)
137 Abbrev->~DIEAbbrev();
138}
139
141
143 DIEAbbrev Abbrev = Die.generateAbbrev();
144 Abbrev.Profile(ID);
145
146 void *InsertPos;
147 if (DIEAbbrev *Existing =
148 AbbreviationsSet.FindNodeOrInsertPos(ID, InsertPos)) {
149 Die.setAbbrevNumber(Existing->getNumber());
150 return *Existing;
151 }
152
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());
158
159 // Store it for lookup.
160 AbbreviationsSet.InsertNode(New, InsertPos);
161 return *New;
162}
163
164void 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);
169 }
170}
171
172//===----------------------------------------------------------------------===//
173// DIE Implementation
174//===----------------------------------------------------------------------===//
175
176DIE *DIE::getParent() const { return dyn_cast_if_present<DIE *>(Owner); }
177
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());
184 else
185 Abbrev.AddAttribute(V.getAttribute(), V.getForm());
186 return Abbrev;
187}
188
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();
193}
194
195const DIE *DIE::getUnitDie() const {
196 const DIE *p = this;
197 while (p) {
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)
201 return p;
202 p = p->getParent();
203 }
204 return nullptr;
205}
206
208 const DIE *UnitDie = getUnitDie();
209 if (UnitDie)
210 return dyn_cast_if_present<DIEUnit *>(UnitDie->Owner);
211 return nullptr;
212}
213
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)
219 return V;
220 return DIEValue();
221}
222
224static void printValues(raw_ostream &O, const DIEValueList &Values,
225 StringRef Type, unsigned Size, unsigned IndentCount) {
226 O << Type << ": Size: " << Size << "\n";
227
228 unsigned I = 0;
229 const std::string Indent(IndentCount, ' ');
230 for (const auto &V : Values.values()) {
231 O << Indent;
232 O << "Blk[" << I++ << "]";
233 O << " " << dwarf::FormEncodingString(V.getForm()) << " ";
234 V.print(O);
235 O << "\n";
236 }
237}
238
240void 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";
244
245 O << Indent << dwarf::TagString(getTag()) << " "
247
248 IndentCount += 2;
249 for (const auto &V : values()) {
250 O << Indent;
251 O << dwarf::AttributeString(V.getAttribute());
252 O << " " << dwarf::FormEncodingString(V.getForm()) << " ";
253 V.print(O);
254 O << "\n";
255 }
256 IndentCount -= 2;
257
258 for (const auto &Child : children())
259 Child.print(O, IndentCount + 4);
260
261 O << "\n";
262}
263
264#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
266 print(dbgs());
267}
268#endif
269
271 DIEAbbrevSet &AbbrevSet,
272 unsigned CUOffset) {
273 // Unique the abbreviation and fill in the abbreviation number so this DIE
274 // can be emitted.
275 const DIEAbbrev &Abbrev = AbbrevSet.uniqueAbbreviation(*this);
276
277 // Set compile/type unit relative offset of this DIE.
278 setOffset(CUOffset);
279
280 // Add the byte size of the abbreviation code.
281 CUOffset += getULEB128Size(getAbbrevNumber());
282
283 // Add the byte size of all the DIE attribute values.
284 for (const auto &V : values())
285 CUOffset += V.sizeOf(FormParams);
286
287 // Let the children compute their offsets and abbreviation numbers.
288 if (hasChildren()) {
289 (void)Abbrev;
290 assert(Abbrev.hasChildren() && "Children flag not set");
291
292 for (auto &Child : children())
293 CUOffset =
294 Child.computeOffsetsAndAbbrevs(FormParams, AbbrevSet, CUOffset);
295
296 // Each child chain is terminated with a zero byte, adjust the offset.
297 CUOffset += sizeof(int8_t);
298 }
299
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
302 // correctly.
303 setSize(CUOffset - getOffset());
304 return CUOffset;
305}
306
307//===----------------------------------------------------------------------===//
308// DIEUnit Implementation
309//===----------------------------------------------------------------------===//
310DIEUnit::DIEUnit(dwarf::Tag UnitTag) : Die(UnitTag) {
311 Die.Owner = this;
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");
317}
318
319void DIEValue::emitValue(const AsmPrinter *AP) const {
320 switch (Ty) {
321 case isNone:
322 llvm_unreachable("Expected valid DIEValue");
323#define HANDLE_DIEVALUE(T) \
324 case is##T: \
325 getDIE##T().emitValue(AP, Form); \
326 break;
327#include "llvm/CodeGen/DIEValue.def"
328 }
329}
330
332 switch (Ty) {
333 case isNone:
334 llvm_unreachable("Expected valid DIEValue");
335#define HANDLE_DIEVALUE(T) \
336 case is##T: \
337 return getDIE##T().sizeOf(FormParams, Form);
338#include "llvm/CodeGen/DIEValue.def"
339 }
340 llvm_unreachable("Unknown DIE kind");
341}
342
345 switch (Ty) {
346 case isNone:
347 llvm_unreachable("Expected valid DIEValue");
348#define HANDLE_DIEVALUE(T) \
349 case is##T: \
350 getDIE##T().print(O); \
351 break;
352#include "llvm/CodeGen/DIEValue.def"
353 }
354}
355
356#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
358 print(dbgs());
359}
360#endif
361
362//===----------------------------------------------------------------------===//
363// DIEInteger Implementation
364//===----------------------------------------------------------------------===//
365
366/// EmitValue - Emit integer of appropriate size.
367///
369 switch (Form) {
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();
375 return;
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));
406 return;
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);
415 return;
416 case dwarf::DW_FORM_sdata:
417 Asm->emitSLEB128(Integer);
418 return;
419 default: llvm_unreachable("DIE Value form not supported yet");
420 }
421}
422
423/// sizeOf - Determine size of integer value in bytes.
424///
426 dwarf::Form Form) const {
427 if (std::optional<uint8_t> FixedSize =
429 return *FixedSize;
430
431 switch (Form) {
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");
443 }
444}
445
448 O << "Int: " << (int64_t)Integer << " 0x";
449 O.write_hex(Integer);
450}
451
452//===----------------------------------------------------------------------===//
453// DIEExpr Implementation
454//===----------------------------------------------------------------------===//
455
456/// EmitValue - Emit expression value.
457///
459 AP->emitDebugValue(Expr, sizeOf(AP->getDwarfFormParams(), Form));
460}
461
462/// SizeOf - Determine size of expression value in bytes.
463///
465 dwarf::Form Form) const {
466 switch (Form) {
467 case dwarf::DW_FORM_data4:
468 return 4;
469 case dwarf::DW_FORM_data8:
470 return 8;
471 case dwarf::DW_FORM_sec_offset:
473 default:
474 llvm_unreachable("DIE Value form not supported yet");
475 }
476}
477
479void DIEExpr::print(raw_ostream &O) const { O << "Expr: " << *Expr; }
480
481//===----------------------------------------------------------------------===//
482// DIELabel Implementation
483//===----------------------------------------------------------------------===//
484
485/// EmitValue - Emit label value.
486///
488 bool IsSectionRelative = Form != dwarf::DW_FORM_addr;
490 IsSectionRelative);
491}
492
493/// sizeOf - Determine size of label value in bytes.
494///
496 dwarf::Form Form) const {
497 switch (Form) {
498 case dwarf::DW_FORM_data4:
499 return 4;
500 case dwarf::DW_FORM_data8:
501 return 8;
502 case dwarf::DW_FORM_sec_offset:
503 case dwarf::DW_FORM_strp:
505 case dwarf::DW_FORM_addr:
506 return FormParams.AddrSize;
507 default:
508 llvm_unreachable("DIE Value form not supported yet");
509 }
510}
511
513void DIELabel::print(raw_ostream &O) const { O << "Lbl: " << Label->getName(); }
514
515//===----------------------------------------------------------------------===//
516// DIEBaseTypeRef Implementation
517//===----------------------------------------------------------------------===//
518
520 uint64_t Offset = CU->ExprRefedBaseTypes[Index].Die->getOffset();
521 assert(Offset < (1ULL << (ULEB128PadSize * 7)) && "Offset wont fit");
522 AP->emitULEB128(Offset, nullptr, ULEB128PadSize);
523}
524
526 return ULEB128PadSize;
527}
528
530void DIEBaseTypeRef::print(raw_ostream &O) const { O << "BaseTypeRef: " << Index; }
531
532//===----------------------------------------------------------------------===//
533// DIEDelta Implementation
534//===----------------------------------------------------------------------===//
535
536/// EmitValue - Emit delta value.
537///
539 AP->emitLabelDifference(LabelHi, LabelLo,
541}
542
543/// SizeOf - Determine size of delta value in bytes.
544///
546 dwarf::Form Form) const {
547 switch (Form) {
548 case dwarf::DW_FORM_data4:
549 return 4;
550 case dwarf::DW_FORM_data8:
551 return 8;
552 case dwarf::DW_FORM_sec_offset:
554 default:
555 llvm_unreachable("DIE Value form not supported yet");
556 }
557}
558
561 O << "Del: " << LabelHi->getName() << "-" << LabelLo->getName();
562}
563
564//===----------------------------------------------------------------------===//
565// DIEString Implementation
566//===----------------------------------------------------------------------===//
567
568/// EmitValue - Emit string value.
569///
571 // Index of string in symbol table.
572 switch (Form) {
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:
580 return;
581 case dwarf::DW_FORM_strp:
584 else
586 return;
587 default:
588 llvm_unreachable("Expected valid string form");
589 }
590}
591
592/// sizeOf - Determine size of delta value in bytes.
593///
595 dwarf::Form Form) const {
596 // Index of string in symbol table.
597 switch (Form) {
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:
605 case dwarf::DW_FORM_strp:
609 default:
610 llvm_unreachable("Expected valid string form");
611 }
612}
613
616 O << "String: " << S.getString();
617}
618
619//===----------------------------------------------------------------------===//
620// DIEInlineString Implementation
621//===----------------------------------------------------------------------===//
623 if (Form == dwarf::DW_FORM_string) {
624 AP->OutStreamer->emitBytes(S);
625 AP->emitInt8(0);
626 return;
627 }
628 llvm_unreachable("Expected valid string form");
629}
630
632 // Emit string bytes + NULL byte.
633 return S.size() + 1;
634}
635
638 O << "InlineString: " << S;
639}
640
641//===----------------------------------------------------------------------===//
642// DIEEntry Implementation
643//===----------------------------------------------------------------------===//
644
645/// EmitValue - Emit debug information entry offset.
646///
648
649 switch (Form) {
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(),
656 return;
657
658 case dwarf::DW_FORM_ref_udata:
659 AP->emitULEB128(Entry->getOffset());
660 return;
661
662 case dwarf::DW_FORM_ref_addr: {
663 // Get the absolute offset for this DIE within the debug info/types section.
665 if (const MCSymbol *SectionSym =
667 AP->emitLabelPlusOffset(SectionSym, Addr,
668 sizeOf(AP->getDwarfFormParams(), Form), true);
669 return;
670 }
671
672 AP->OutStreamer->emitIntValue(Addr, sizeOf(AP->getDwarfFormParams(), Form));
673 return;
674 }
675 default:
676 llvm_unreachable("Improper form for DIE reference");
677 }
678}
679
681 dwarf::Form Form) const {
682 switch (Form) {
683 case dwarf::DW_FORM_ref1:
684 return 1;
685 case dwarf::DW_FORM_ref2:
686 return 2;
687 case dwarf::DW_FORM_ref4:
688 return 4;
689 case dwarf::DW_FORM_ref8:
690 return 8;
691 case dwarf::DW_FORM_ref_udata:
692 return getULEB128Size(Entry->getOffset());
693 case dwarf::DW_FORM_ref_addr:
695
696 default:
697 llvm_unreachable("Improper form for DIE reference");
698 }
699}
700
703 O << format("Die: 0x%lx", (long)(intptr_t)&Entry);
704}
705
706//===----------------------------------------------------------------------===//
707// DIELoc Implementation
708//===----------------------------------------------------------------------===//
709
711 if (!Size) {
712 for (const auto &V : values())
713 Size += V.sizeOf(FormParams);
714 }
715
716 return Size;
717}
718
719/// EmitValue - Emit location data.
720///
722 switch (Form) {
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);
730 break;
731 }
732
733 for (const auto &V : values())
734 V.emitValue(Asm);
735}
736
737/// sizeOf - Determine size of location data in bytes.
738///
740 switch (Form) {
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");
748 }
749}
750
753 printValues(O, *this, "ExprLoc", Size, 5);
754}
755
756//===----------------------------------------------------------------------===//
757// DIEBlock Implementation
758//===----------------------------------------------------------------------===//
759
761 if (!Size) {
762 for (const auto &V : values())
763 Size += V.sizeOf(FormParams);
764 }
765
766 return Size;
767}
768
769/// EmitValue - Emit block data.
770///
772 switch (Form) {
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);
780 break;
781 case dwarf::DW_FORM_string: break;
782 case dwarf::DW_FORM_data16: break;
783 }
784
785 for (const auto &V : values())
786 V.emitValue(Asm);
787}
788
789/// sizeOf - Determine size of block data in bytes.
790///
792 switch (Form) {
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");
800 }
801}
802
805 printValues(O, *this, "Blk", Size, 5);
806}
807
808//===----------------------------------------------------------------------===//
809// DIELocList Implementation
810//===----------------------------------------------------------------------===//
811
813 dwarf::Form Form) const {
814 switch (Form) {
815 case dwarf::DW_FORM_loclistx:
816 return getULEB128Size(Index);
817 case dwarf::DW_FORM_data4:
819 "DW_FORM_data4 is not suitable to emit a pointer to a location list "
820 "in the 64-bit DWARF format");
821 return 4;
822 case dwarf::DW_FORM_data8:
824 "DW_FORM_data8 is not suitable to emit a pointer to a location list "
825 "in the 32-bit DWARF format");
826 return 8;
827 case dwarf::DW_FORM_sec_offset:
829 default:
830 llvm_unreachable("DIE Value form not supported yet");
831 }
832}
833
834/// EmitValue - Emit label value.
835///
837 if (Form == dwarf::DW_FORM_loclistx) {
838 AP->emitULEB128(Index);
839 return;
840 }
841 DwarfDebug *DD = AP->getDwarfDebug();
842 MCSymbol *Label = DD->getDebugLocs().getList(Index).Label;
843 AP->emitDwarfSymbolReference(Label, /*ForceOffset*/ DD->useSplitDwarf());
844}
845
847void DIELocList::print(raw_ostream &O) const { O << "LocList: " << Index; }
848
849//===----------------------------------------------------------------------===//
850// DIEAddrOffset Implementation
851//===----------------------------------------------------------------------===//
852
854 dwarf::Form) const {
855 return Addr.sizeOf(FormParams, dwarf::DW_FORM_addrx) +
856 Offset.sizeOf(FormParams, dwarf::DW_FORM_data4);
857}
858
859/// EmitValue - Emit label value.
860///
862 Addr.emitValue(AP, dwarf::DW_FORM_addrx);
863 Offset.emitValue(AP, dwarf::DW_FORM_data4);
864}
865
868 O << "AddrOffset: ";
869 Addr.print(O);
870 O << " + ";
871 Offset.print(O);
872}
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition: Compiler.h:529
static LLVM_DUMP_METHOD void printValues(raw_ostream &O, const DIEValueList &Values, StringRef Type, unsigned Size, unsigned IndentCount)
Definition: DIE.cpp:224
#define LLVM_DEBUG(X)
Definition: Debug.h:101
uint64_t Addr
uint64_t Size
#define I(x, y, z)
Definition: MD5.cpp:58
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:84
void emitULEB128(uint64_t Value, const char *Desc=nullptr, unsigned PadTo=0) const
Emit the specified unsigned leb128 value.
void emitDwarfSymbolReference(const MCSymbol *Label, bool ForceOffset=false) const
Emit a reference to a symbol for use in dwarf.
virtual void emitDebugValue(const MCExpr *Value, unsigned Size) const
Emit the directive and value for debug thread local expression.
Definition: AsmPrinter.cpp:922
DwarfDebug * getDwarfDebug()
Definition: AsmPrinter.h:245
void emitLabelPlusOffset(const MCSymbol *Label, uint64_t Offset, unsigned Size, bool IsSectionRelative=false) const
Emit something like ".long Label+Offset" where the size in bytes of the directive is specified by Siz...
void emitLabelDifference(const MCSymbol *Hi, const MCSymbol *Lo, unsigned Size) const
Emit something like ".long Hi-Lo" where the size in bytes of the directive is specified by Size and H...
void emitInt8(int Value) const
Emit a byte directive and value.
void emitDwarfAbbrevs(const T &Abbrevs) const
Emit Dwarf abbreviation table.
Definition: AsmPrinter.h:771
void emitSLEB128(int64_t Value, const char *Desc=nullptr) const
Emit the specified signed leb128 value.
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
Definition: AsmPrinter.h:99
void emitLabelReference(const MCSymbol *Label, unsigned Size, bool IsSectionRelative=false) const
Emit something like ".long Label" where the size in bytes of the directive is specified by Size and L...
Definition: AsmPrinter.h:691
uint16_t getDwarfVersion() const
dwarf::FormParams getDwarfFormParams() const
Returns information about the byte size of DW_FORM values.
bool doesDwarfUseRelocationsAcrossSections() const
Definition: AsmPrinter.h:330
Dwarf abbreviation data, describes one attribute of a Dwarf abbreviation.
Definition: DIE.h:49
dwarf::Form getForm() const
Definition: DIE.h:68
dwarf::Attribute getAttribute() const
Accessors.
Definition: DIE.h:67
void Profile(FoldingSetNodeID &ID) const
Used to gather unique data for the abbreviation folding set.
Definition: DIE.cpp:36
int64_t getValue() const
Definition: DIE.h:69
Helps unique DIEAbbrev objects and assigns abbreviation numbers.
Definition: DIE.h:140
void Emit(const AsmPrinter *AP, MCSection *Section) const
Print all abbreviations using the specified asm printer.
Definition: DIE.cpp:164
DIEAbbrev & uniqueAbbreviation(DIE &Die)
Generate the abbreviation declaration for a DIE and return a pointer to the generated abbreviation.
Definition: DIE.cpp:140
Dwarf abbreviation, describes the organization of a debug information object.
Definition: DIE.h:79
void print(raw_ostream &O) const
Definition: DIE.cpp:103
void AddImplicitConstAttribute(dwarf::Attribute Attribute, int64_t Value)
Adds attribute with DW_FORM_implicit_const value.
Definition: DIE.h:114
void Emit(const AsmPrinter *AP) const
Print the abbreviation using the specified asm printer.
Definition: DIE.cpp:62
void AddAttribute(dwarf::Attribute Attribute, dwarf::Form Form)
Adds another set of attribute information to the abbreviation.
Definition: DIE.h:109
void dump() const
Definition: DIE.cpp:126
void Profile(FoldingSetNodeID &ID) const
Used to gather unique data for the abbreviation folding set.
Definition: DIE.cpp:51
bool hasChildren() const
Definition: DIE.h:102
void print(raw_ostream &O) const
Definition: DIE.cpp:867
unsigned sizeOf(const dwarf::FormParams &FormParams, dwarf::Form Form) const
Definition: DIE.cpp:853
void emitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit label value.
Definition: DIE.cpp:861
void emitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit base type reference.
Definition: DIE.cpp:519
void print(raw_ostream &O) const
Definition: DIE.cpp:530
unsigned sizeOf(const dwarf::FormParams &, dwarf::Form) const
sizeOf - Determine size of the base type reference in bytes.
Definition: DIE.cpp:525
unsigned sizeOf(const dwarf::FormParams &, dwarf::Form Form) const
sizeOf - Determine size of block data in bytes.
Definition: DIE.cpp:791
void print(raw_ostream &O) const
Definition: DIE.cpp:804
void emitValue(const AsmPrinter *Asm, dwarf::Form Form) const
EmitValue - Emit block data.
Definition: DIE.cpp:771
unsigned computeSize(const dwarf::FormParams &FormParams) const
Calculate the size of the location expression.
Definition: DIE.cpp:760
void print(raw_ostream &O) const
Definition: DIE.cpp:560
unsigned sizeOf(const dwarf::FormParams &FormParams, dwarf::Form Form) const
SizeOf - Determine size of delta value in bytes.
Definition: DIE.cpp:545
void emitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit delta value.
Definition: DIE.cpp:538
void emitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit debug information entry offset.
Definition: DIE.cpp:647
void print(raw_ostream &O) const
Definition: DIE.cpp:702
unsigned sizeOf(const dwarf::FormParams &FormParams, dwarf::Form Form) const
Definition: DIE.cpp:680
void print(raw_ostream &O) const
Definition: DIE.cpp:479
void emitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit expression value.
Definition: DIE.cpp:458
unsigned sizeOf(const dwarf::FormParams &FormParams, dwarf::Form Form) const
SizeOf - Determine size of expression value in bytes.
Definition: DIE.cpp:464
void emitValue(const AsmPrinter *AP, dwarf::Form Form) const
Definition: DIE.cpp:622
void print(raw_ostream &O) const
Definition: DIE.cpp:637
unsigned sizeOf(const dwarf::FormParams &, dwarf::Form) const
Definition: DIE.cpp:631
An integer value DIE.
Definition: DIE.h:168
unsigned sizeOf(const dwarf::FormParams &FormParams, dwarf::Form Form) const
sizeOf - Determine size of integer value in bytes.
Definition: DIE.cpp:425
void print(raw_ostream &O) const
Definition: DIE.cpp:447
void emitValue(const AsmPrinter *Asm, dwarf::Form Form) const
EmitValue - Emit integer of appropriate size.
Definition: DIE.cpp:368
A label DIE.
Definition: DIE.h:223
void emitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit label value.
Definition: DIE.cpp:487
void print(raw_ostream &O) const
Definition: DIE.cpp:513
unsigned sizeOf(const dwarf::FormParams &FormParams, dwarf::Form Form) const
sizeOf - Determine size of label value in bytes.
Definition: DIE.cpp:495
void print(raw_ostream &O) const
Definition: DIE.cpp:847
unsigned sizeOf(const dwarf::FormParams &FormParams, dwarf::Form Form) const
Definition: DIE.cpp:812
void emitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit label value.
Definition: DIE.cpp:836
void print(raw_ostream &O) const
Definition: DIE.cpp:752
unsigned sizeOf(const dwarf::FormParams &, dwarf::Form Form) const
sizeOf - Determine size of location data in bytes.
Definition: DIE.cpp:739
void emitValue(const AsmPrinter *Asm, dwarf::Form Form) const
EmitValue - Emit location data.
Definition: DIE.cpp:721
unsigned computeSize(const dwarf::FormParams &FormParams) const
Calculate the size of the location expression.
Definition: DIE.cpp:710
void emitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit string value.
Definition: DIE.cpp:570
void print(raw_ostream &O) const
Definition: DIE.cpp:615
unsigned sizeOf(const dwarf::FormParams &FormParams, dwarf::Form Form) const
sizeOf - Determine size of delta value in bytes.
Definition: DIE.cpp:594
Represents a compile or type unit.
Definition: DIE.h:960
virtual const MCSymbol * getCrossSectionRelativeBaseAddress() const
Definition: DIE.h:989
DIEUnit(dwarf::Tag UnitTag)
Definition: DIE.cpp:310
A list of DIE values.
Definition: DIE.h:689
value_range values()
Definition: DIE.h:807
void print(raw_ostream &O) const
Definition: DIE.cpp:344
void emitValue(const AsmPrinter *AP) const
Emit value via the Dwarf writer.
Definition: DIE.cpp:319
unsigned sizeOf(const dwarf::FormParams &FormParams) const
Return the size of a value in bytes.
Definition: DIE.cpp:331
void dump() const
Definition: DIE.cpp:357
A structured debug information entry.
Definition: DIE.h:819
DIEValue findAttribute(dwarf::Attribute Attribute) const
Find a value in the DIE with the attribute given.
Definition: DIE.cpp:214
void print(raw_ostream &O, unsigned IndentCount=0) const
Definition: DIE.cpp:240
unsigned getAbbrevNumber() const
Definition: DIE.h:854
DIEAbbrev generateAbbrev() const
Generate the abbreviation for this DIE.
Definition: DIE.cpp:178
unsigned computeOffsetsAndAbbrevs(const dwarf::FormParams &FormParams, DIEAbbrevSet &AbbrevSet, unsigned CUOffset)
Compute the offset of this DIE and all its children.
Definition: DIE.cpp:270
void setSize(unsigned S)
Definition: DIE.h:931
DIEUnit * getUnit() const
Climb up the parent chain to get the compile unit or type unit that this DIE belongs to.
Definition: DIE.cpp:207
child_range children()
Definition: DIE.h:875
const DIE * getUnitDie() const
Climb up the parent chain to get the compile unit or type unit DIE that this DIE belongs to.
Definition: DIE.cpp:195
void setAbbrevNumber(unsigned I)
Set the abbreviation number for this DIE.
Definition: DIE.h:891
unsigned getOffset() const
Get the compile/type unit relative offset of this DIE.
Definition: DIE.h:857
void setOffset(unsigned O)
Definition: DIE.h:930
bool hasChildren() const
Definition: DIE.h:867
uint64_t getDebugSectionOffset() const
Get the absolute offset within the .debug_info or .debug_types section for this DIE.
Definition: DIE.cpp:189
dwarf::Tag getTag() const
Definition: DIE.h:855
void dump() const
Definition: DIE.cpp:265
DIE * getParent() const
Definition: DIE.cpp:176
const List & getList(size_t LI) const
Collects and handles dwarf debug information.
Definition: DwarfDebug.h:351
const DebugLocStream & getDebugLocs() const
Returns the entries for the .debug_loc section.
Definition: DwarfDebug.h:845
bool useSplitDwarf() const
Returns whether or not to change the current debug info for the split dwarf proposal support.
Definition: DwarfDebug.h:806
FoldingSetNodeID - This class is used to gather all the unique data bits of a node.
Definition: FoldingSet.h:319
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:39
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:40
StringRef getName() const
getName - Get the symbol name.
Definition: MCSymbol.h:205
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
constexpr size_t size() const
size - Get the string size.
Definition: StringRef.h:137
constexpr const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Definition: StringRef.h:131
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
LLVM Value Representation.
Definition: Value.h:74
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
StringRef AttributeString(unsigned Attribute)
Definition: Dwarf.cpp:72
StringRef FormEncodingString(unsigned Encoding)
Definition: Dwarf.cpp:105
StringRef ChildrenString(unsigned Children)
Definition: Dwarf.cpp:62
StringRef TagString(unsigned Tag)
Definition: Dwarf.cpp:21
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
Attribute
Attributes.
Definition: Dwarf.h:123
@ DWARF64
Definition: Dwarf.h:91
bool isValidFormForVersion(Form F, unsigned Version, bool ExtensionsOk=true)
Tells whether the specified form is defined in the specified version, or is an extension if extension...
Definition: Dwarf.cpp:817
std::optional< uint8_t > getFixedFormByteSize(dwarf::Form Form, FormParams Params)
Get the fixed byte size for a given form.
Definition: Dwarf.cpp:729
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:456
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
Definition: Format.h:125
unsigned getULEB128Size(uint64_t Value)
Utility function to get the size of the ULEB128-encoded value.
Definition: LEB128.cpp:19
unsigned getSLEB128Size(int64_t Value)
Utility function to get the size of the SLEB128-encoded value.
Definition: LEB128.cpp:29
#define N
A helper struct providing information about the byte size of DW_FORM values that vary in size dependi...
Definition: Dwarf.h:762
bool DwarfUsesRelocationsAcrossSections
True if DWARF v2 output generally uses relocations for references to other .debug_* sections.
Definition: Dwarf.h:768
DwarfFormat Format
Definition: Dwarf.h:765
uint8_t getDwarfOffsetByteSize() const
The size of a reference is determined by the DWARF 32/64-bit format.
Definition: Dwarf.h:780
uint8_t getRefAddrByteSize() const
The definition of the size of form DW_FORM_ref_addr depends on the version.
Definition: Dwarf.h:773