LLVM 17.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
177 return Owner.dyn_cast<DIE*>();
178}
179
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());
186 else
187 Abbrev.AddAttribute(V.getAttribute(), V.getForm());
188 return Abbrev;
189}
190
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();
195}
196
197const DIE *DIE::getUnitDie() const {
198 const DIE *p = this;
199 while (p) {
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)
203 return p;
204 p = p->getParent();
205 }
206 return nullptr;
207}
208
210 const DIE *UnitDie = getUnitDie();
211 if (UnitDie)
212 return UnitDie->Owner.dyn_cast<DIEUnit*>();
213 return nullptr;
214}
215
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)
221 return V;
222 return DIEValue();
223}
224
226static void printValues(raw_ostream &O, const DIEValueList &Values,
227 StringRef Type, unsigned Size, unsigned IndentCount) {
228 O << Type << ": Size: " << Size << "\n";
229
230 unsigned I = 0;
231 const std::string Indent(IndentCount, ' ');
232 for (const auto &V : Values.values()) {
233 O << Indent;
234 O << "Blk[" << I++ << "]";
235 O << " " << dwarf::FormEncodingString(V.getForm()) << " ";
236 V.print(O);
237 O << "\n";
238 }
239}
240
242void 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";
246
247 O << Indent << dwarf::TagString(getTag()) << " "
249
250 IndentCount += 2;
251 for (const auto &V : values()) {
252 O << Indent;
253 O << dwarf::AttributeString(V.getAttribute());
254 O << " " << dwarf::FormEncodingString(V.getForm()) << " ";
255 V.print(O);
256 O << "\n";
257 }
258 IndentCount -= 2;
259
260 for (const auto &Child : children())
261 Child.print(O, IndentCount + 4);
262
263 O << "\n";
264}
265
266#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
268 print(dbgs());
269}
270#endif
271
273 DIEAbbrevSet &AbbrevSet,
274 unsigned CUOffset) {
275 // Unique the abbreviation and fill in the abbreviation number so this DIE
276 // can be emitted.
277 const DIEAbbrev &Abbrev = AbbrevSet.uniqueAbbreviation(*this);
278
279 // Set compile/type unit relative offset of this DIE.
280 setOffset(CUOffset);
281
282 // Add the byte size of the abbreviation code.
283 CUOffset += getULEB128Size(getAbbrevNumber());
284
285 // Add the byte size of all the DIE attribute values.
286 for (const auto &V : values())
287 CUOffset += V.sizeOf(FormParams);
288
289 // Let the children compute their offsets and abbreviation numbers.
290 if (hasChildren()) {
291 (void)Abbrev;
292 assert(Abbrev.hasChildren() && "Children flag not set");
293
294 for (auto &Child : children())
295 CUOffset =
296 Child.computeOffsetsAndAbbrevs(FormParams, AbbrevSet, CUOffset);
297
298 // Each child chain is terminated with a zero byte, adjust the offset.
299 CUOffset += sizeof(int8_t);
300 }
301
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
304 // correctly.
305 setSize(CUOffset - getOffset());
306 return CUOffset;
307}
308
309//===----------------------------------------------------------------------===//
310// DIEUnit Implementation
311//===----------------------------------------------------------------------===//
312DIEUnit::DIEUnit(dwarf::Tag UnitTag) : Die(UnitTag) {
313 Die.Owner = this;
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");
319}
320
321void DIEValue::emitValue(const AsmPrinter *AP) const {
322 switch (Ty) {
323 case isNone:
324 llvm_unreachable("Expected valid DIEValue");
325#define HANDLE_DIEVALUE(T) \
326 case is##T: \
327 getDIE##T().emitValue(AP, Form); \
328 break;
329#include "llvm/CodeGen/DIEValue.def"
330 }
331}
332
334 switch (Ty) {
335 case isNone:
336 llvm_unreachable("Expected valid DIEValue");
337#define HANDLE_DIEVALUE(T) \
338 case is##T: \
339 return getDIE##T().sizeOf(FormParams, Form);
340#include "llvm/CodeGen/DIEValue.def"
341 }
342 llvm_unreachable("Unknown DIE kind");
343}
344
347 switch (Ty) {
348 case isNone:
349 llvm_unreachable("Expected valid DIEValue");
350#define HANDLE_DIEVALUE(T) \
351 case is##T: \
352 getDIE##T().print(O); \
353 break;
354#include "llvm/CodeGen/DIEValue.def"
355 }
356}
357
358#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
360 print(dbgs());
361}
362#endif
363
364//===----------------------------------------------------------------------===//
365// DIEInteger Implementation
366//===----------------------------------------------------------------------===//
367
368/// EmitValue - Emit integer of appropriate size.
369///
371 switch (Form) {
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();
377 return;
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_addrx3:
389 case dwarf::DW_FORM_strp:
390 case dwarf::DW_FORM_ref4:
391 case dwarf::DW_FORM_data4:
392 case dwarf::DW_FORM_ref_sup4:
393 case dwarf::DW_FORM_strx4:
394 case dwarf::DW_FORM_addrx4:
395 case dwarf::DW_FORM_ref8:
396 case dwarf::DW_FORM_ref_sig8:
397 case dwarf::DW_FORM_data8:
398 case dwarf::DW_FORM_ref_sup8:
399 case dwarf::DW_FORM_GNU_ref_alt:
400 case dwarf::DW_FORM_GNU_strp_alt:
401 case dwarf::DW_FORM_line_strp:
402 case dwarf::DW_FORM_sec_offset:
403 case dwarf::DW_FORM_strp_sup:
404 case dwarf::DW_FORM_addr:
405 case dwarf::DW_FORM_ref_addr:
406 Asm->OutStreamer->emitIntValue(Integer,
407 sizeOf(Asm->getDwarfFormParams(), Form));
408 return;
409 case dwarf::DW_FORM_GNU_str_index:
410 case dwarf::DW_FORM_GNU_addr_index:
411 case dwarf::DW_FORM_ref_udata:
412 case dwarf::DW_FORM_strx:
413 case dwarf::DW_FORM_addrx:
414 case dwarf::DW_FORM_rnglistx:
415 case dwarf::DW_FORM_udata:
416 Asm->emitULEB128(Integer);
417 return;
418 case dwarf::DW_FORM_sdata:
419 Asm->emitSLEB128(Integer);
420 return;
421 default: llvm_unreachable("DIE Value form not supported yet");
422 }
423}
424
425/// sizeOf - Determine size of integer value in bytes.
426///
428 dwarf::Form Form) const {
429 if (std::optional<uint8_t> FixedSize =
431 return *FixedSize;
432
433 switch (Form) {
434 case dwarf::DW_FORM_GNU_str_index:
435 case dwarf::DW_FORM_GNU_addr_index:
436 case dwarf::DW_FORM_ref_udata:
437 case dwarf::DW_FORM_strx:
438 case dwarf::DW_FORM_addrx:
439 case dwarf::DW_FORM_rnglistx:
440 case dwarf::DW_FORM_udata:
441 return getULEB128Size(Integer);
442 case dwarf::DW_FORM_sdata:
443 return getSLEB128Size(Integer);
444 default: llvm_unreachable("DIE Value form not supported yet");
445 }
446}
447
450 O << "Int: " << (int64_t)Integer << " 0x";
451 O.write_hex(Integer);
452}
453
454//===----------------------------------------------------------------------===//
455// DIEExpr Implementation
456//===----------------------------------------------------------------------===//
457
458/// EmitValue - Emit expression value.
459///
461 AP->emitDebugValue(Expr, sizeOf(AP->getDwarfFormParams(), Form));
462}
463
464/// SizeOf - Determine size of expression value in bytes.
465///
467 dwarf::Form Form) const {
468 switch (Form) {
469 case dwarf::DW_FORM_data4:
470 return 4;
471 case dwarf::DW_FORM_data8:
472 return 8;
473 case dwarf::DW_FORM_sec_offset:
475 default:
476 llvm_unreachable("DIE Value form not supported yet");
477 }
478}
479
481void DIEExpr::print(raw_ostream &O) const { O << "Expr: " << *Expr; }
482
483//===----------------------------------------------------------------------===//
484// DIELabel Implementation
485//===----------------------------------------------------------------------===//
486
487/// EmitValue - Emit label value.
488///
490 bool IsSectionRelative = Form != dwarf::DW_FORM_addr;
492 IsSectionRelative);
493}
494
495/// sizeOf - Determine size of label value in bytes.
496///
498 dwarf::Form Form) const {
499 switch (Form) {
500 case dwarf::DW_FORM_data4:
501 return 4;
502 case dwarf::DW_FORM_data8:
503 return 8;
504 case dwarf::DW_FORM_sec_offset:
505 case dwarf::DW_FORM_strp:
507 case dwarf::DW_FORM_addr:
508 return FormParams.AddrSize;
509 default:
510 llvm_unreachable("DIE Value form not supported yet");
511 }
512}
513
515void DIELabel::print(raw_ostream &O) const { O << "Lbl: " << Label->getName(); }
516
517//===----------------------------------------------------------------------===//
518// DIEBaseTypeRef Implementation
519//===----------------------------------------------------------------------===//
520
522 uint64_t Offset = CU->ExprRefedBaseTypes[Index].Die->getOffset();
523 assert(Offset < (1ULL << (ULEB128PadSize * 7)) && "Offset wont fit");
524 AP->emitULEB128(Offset, nullptr, ULEB128PadSize);
525}
526
528 return ULEB128PadSize;
529}
530
532void DIEBaseTypeRef::print(raw_ostream &O) const { O << "BaseTypeRef: " << Index; }
533
534//===----------------------------------------------------------------------===//
535// DIEDelta Implementation
536//===----------------------------------------------------------------------===//
537
538/// EmitValue - Emit delta value.
539///
541 AP->emitLabelDifference(LabelHi, LabelLo,
543}
544
545/// SizeOf - Determine size of delta value in bytes.
546///
548 dwarf::Form Form) const {
549 switch (Form) {
550 case dwarf::DW_FORM_data4:
551 return 4;
552 case dwarf::DW_FORM_data8:
553 return 8;
554 case dwarf::DW_FORM_sec_offset:
556 default:
557 llvm_unreachable("DIE Value form not supported yet");
558 }
559}
560
563 O << "Del: " << LabelHi->getName() << "-" << LabelLo->getName();
564}
565
566//===----------------------------------------------------------------------===//
567// DIEString Implementation
568//===----------------------------------------------------------------------===//
569
570/// EmitValue - Emit string value.
571///
573 // Index of string in symbol table.
574 switch (Form) {
575 case dwarf::DW_FORM_GNU_str_index:
576 case dwarf::DW_FORM_strx:
577 case dwarf::DW_FORM_strx1:
578 case dwarf::DW_FORM_strx2:
579 case dwarf::DW_FORM_strx3:
580 case dwarf::DW_FORM_strx4:
582 return;
583 case dwarf::DW_FORM_strp:
586 else
588 return;
589 default:
590 llvm_unreachable("Expected valid string form");
591 }
592}
593
594/// sizeOf - Determine size of delta value in bytes.
595///
597 dwarf::Form Form) const {
598 // Index of string in symbol table.
599 switch (Form) {
600 case dwarf::DW_FORM_GNU_str_index:
601 case dwarf::DW_FORM_strx:
602 case dwarf::DW_FORM_strx1:
603 case dwarf::DW_FORM_strx2:
604 case dwarf::DW_FORM_strx3:
605 case dwarf::DW_FORM_strx4:
607 case dwarf::DW_FORM_strp:
611 default:
612 llvm_unreachable("Expected valid string form");
613 }
614}
615
618 O << "String: " << S.getString();
619}
620
621//===----------------------------------------------------------------------===//
622// DIEInlineString Implementation
623//===----------------------------------------------------------------------===//
625 if (Form == dwarf::DW_FORM_string) {
626 AP->OutStreamer->emitBytes(S);
627 AP->emitInt8(0);
628 return;
629 }
630 llvm_unreachable("Expected valid string form");
631}
632
634 // Emit string bytes + NULL byte.
635 return S.size() + 1;
636}
637
640 O << "InlineString: " << S;
641}
642
643//===----------------------------------------------------------------------===//
644// DIEEntry Implementation
645//===----------------------------------------------------------------------===//
646
647/// EmitValue - Emit debug information entry offset.
648///
650
651 switch (Form) {
652 case dwarf::DW_FORM_ref1:
653 case dwarf::DW_FORM_ref2:
654 case dwarf::DW_FORM_ref4:
655 case dwarf::DW_FORM_ref8:
656 AP->OutStreamer->emitIntValue(Entry->getOffset(),
658 return;
659
660 case dwarf::DW_FORM_ref_udata:
661 AP->emitULEB128(Entry->getOffset());
662 return;
663
664 case dwarf::DW_FORM_ref_addr: {
665 // Get the absolute offset for this DIE within the debug info/types section.
667 if (const MCSymbol *SectionSym =
669 AP->emitLabelPlusOffset(SectionSym, Addr,
670 sizeOf(AP->getDwarfFormParams(), Form), true);
671 return;
672 }
673
674 AP->OutStreamer->emitIntValue(Addr, sizeOf(AP->getDwarfFormParams(), Form));
675 return;
676 }
677 default:
678 llvm_unreachable("Improper form for DIE reference");
679 }
680}
681
683 dwarf::Form Form) const {
684 switch (Form) {
685 case dwarf::DW_FORM_ref1:
686 return 1;
687 case dwarf::DW_FORM_ref2:
688 return 2;
689 case dwarf::DW_FORM_ref4:
690 return 4;
691 case dwarf::DW_FORM_ref8:
692 return 8;
693 case dwarf::DW_FORM_ref_udata:
694 return getULEB128Size(Entry->getOffset());
695 case dwarf::DW_FORM_ref_addr:
697
698 default:
699 llvm_unreachable("Improper form for DIE reference");
700 }
701}
702
705 O << format("Die: 0x%lx", (long)(intptr_t)&Entry);
706}
707
708//===----------------------------------------------------------------------===//
709// DIELoc Implementation
710//===----------------------------------------------------------------------===//
711
713 if (!Size) {
714 for (const auto &V : values())
715 Size += V.sizeOf(FormParams);
716 }
717
718 return Size;
719}
720
721/// EmitValue - Emit location data.
722///
724 switch (Form) {
725 default: llvm_unreachable("Improper form for block");
726 case dwarf::DW_FORM_block1: Asm->emitInt8(Size); break;
727 case dwarf::DW_FORM_block2: Asm->emitInt16(Size); break;
728 case dwarf::DW_FORM_block4: Asm->emitInt32(Size); break;
729 case dwarf::DW_FORM_block:
730 case dwarf::DW_FORM_exprloc:
731 Asm->emitULEB128(Size);
732 break;
733 }
734
735 for (const auto &V : values())
736 V.emitValue(Asm);
737}
738
739/// sizeOf - Determine size of location data in bytes.
740///
742 switch (Form) {
743 case dwarf::DW_FORM_block1: return Size + sizeof(int8_t);
744 case dwarf::DW_FORM_block2: return Size + sizeof(int16_t);
745 case dwarf::DW_FORM_block4: return Size + sizeof(int32_t);
746 case dwarf::DW_FORM_block:
747 case dwarf::DW_FORM_exprloc:
748 return Size + getULEB128Size(Size);
749 default: llvm_unreachable("Improper form for block");
750 }
751}
752
755 printValues(O, *this, "ExprLoc", Size, 5);
756}
757
758//===----------------------------------------------------------------------===//
759// DIEBlock Implementation
760//===----------------------------------------------------------------------===//
761
763 if (!Size) {
764 for (const auto &V : values())
765 Size += V.sizeOf(FormParams);
766 }
767
768 return Size;
769}
770
771/// EmitValue - Emit block data.
772///
774 switch (Form) {
775 default: llvm_unreachable("Improper form for block");
776 case dwarf::DW_FORM_block1: Asm->emitInt8(Size); break;
777 case dwarf::DW_FORM_block2: Asm->emitInt16(Size); break;
778 case dwarf::DW_FORM_block4: Asm->emitInt32(Size); break;
779 case dwarf::DW_FORM_exprloc:
780 case dwarf::DW_FORM_block:
781 Asm->emitULEB128(Size);
782 break;
783 case dwarf::DW_FORM_string: break;
784 case dwarf::DW_FORM_data16: break;
785 }
786
787 for (const auto &V : values())
788 V.emitValue(Asm);
789}
790
791/// sizeOf - Determine size of block data in bytes.
792///
794 switch (Form) {
795 case dwarf::DW_FORM_block1: return Size + sizeof(int8_t);
796 case dwarf::DW_FORM_block2: return Size + sizeof(int16_t);
797 case dwarf::DW_FORM_block4: return Size + sizeof(int32_t);
798 case dwarf::DW_FORM_exprloc:
799 case dwarf::DW_FORM_block: return Size + getULEB128Size(Size);
800 case dwarf::DW_FORM_data16: return 16;
801 default: llvm_unreachable("Improper form for block");
802 }
803}
804
807 printValues(O, *this, "Blk", Size, 5);
808}
809
810//===----------------------------------------------------------------------===//
811// DIELocList Implementation
812//===----------------------------------------------------------------------===//
813
815 dwarf::Form Form) const {
816 switch (Form) {
817 case dwarf::DW_FORM_loclistx:
818 return getULEB128Size(Index);
819 case dwarf::DW_FORM_data4:
821 "DW_FORM_data4 is not suitable to emit a pointer to a location list "
822 "in the 64-bit DWARF format");
823 return 4;
824 case dwarf::DW_FORM_data8:
826 "DW_FORM_data8 is not suitable to emit a pointer to a location list "
827 "in the 32-bit DWARF format");
828 return 8;
829 case dwarf::DW_FORM_sec_offset:
831 default:
832 llvm_unreachable("DIE Value form not supported yet");
833 }
834}
835
836/// EmitValue - Emit label value.
837///
839 if (Form == dwarf::DW_FORM_loclistx) {
840 AP->emitULEB128(Index);
841 return;
842 }
843 DwarfDebug *DD = AP->getDwarfDebug();
844 MCSymbol *Label = DD->getDebugLocs().getList(Index).Label;
845 AP->emitDwarfSymbolReference(Label, /*ForceOffset*/ DD->useSplitDwarf());
846}
847
849void DIELocList::print(raw_ostream &O) const { O << "LocList: " << Index; }
850
851//===----------------------------------------------------------------------===//
852// DIEAddrOffset Implementation
853//===----------------------------------------------------------------------===//
854
856 dwarf::Form) const {
857 return Addr.sizeOf(FormParams, dwarf::DW_FORM_addrx) +
858 Offset.sizeOf(FormParams, dwarf::DW_FORM_data4);
859}
860
861/// EmitValue - Emit label value.
862///
864 Addr.emitValue(AP, dwarf::DW_FORM_addrx);
865 Offset.emitValue(AP, dwarf::DW_FORM_data4);
866}
867
870 O << "AddrOffset: ";
871 Addr.print(O);
872 O << " + ";
873 Offset.print(O);
874}
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition: Compiler.h:492
static LLVM_DUMP_METHOD void printValues(raw_ostream &O, const DIEValueList &Values, StringRef Type, unsigned Size, unsigned IndentCount)
Definition: DIE.cpp:226
#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:886
DwarfDebug * getDwarfDebug()
Definition: AsmPrinter.h:249
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:755
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:675
uint16_t getDwarfVersion() const
dwarf::FormParams getDwarfFormParams() const
Returns information about the byte size of DW_FORM values.
bool doesDwarfUseRelocationsAcrossSections() const
Definition: AsmPrinter.h:334
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:869
unsigned sizeOf(const dwarf::FormParams &FormParams, dwarf::Form Form) const
Definition: DIE.cpp:855
void emitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit label value.
Definition: DIE.cpp:863
void emitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit base type reference.
Definition: DIE.cpp:521
void print(raw_ostream &O) const
Definition: DIE.cpp:532
unsigned sizeOf(const dwarf::FormParams &, dwarf::Form) const
sizeOf - Determine size of the base type reference in bytes.
Definition: DIE.cpp:527
unsigned sizeOf(const dwarf::FormParams &, dwarf::Form Form) const
sizeOf - Determine size of block data in bytes.
Definition: DIE.cpp:793
void print(raw_ostream &O) const
Definition: DIE.cpp:806
void emitValue(const AsmPrinter *Asm, dwarf::Form Form) const
EmitValue - Emit block data.
Definition: DIE.cpp:773
unsigned computeSize(const dwarf::FormParams &FormParams) const
Calculate the size of the location expression.
Definition: DIE.cpp:762
void print(raw_ostream &O) const
Definition: DIE.cpp:562
unsigned sizeOf(const dwarf::FormParams &FormParams, dwarf::Form Form) const
SizeOf - Determine size of delta value in bytes.
Definition: DIE.cpp:547
void emitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit delta value.
Definition: DIE.cpp:540
void emitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit debug information entry offset.
Definition: DIE.cpp:649
void print(raw_ostream &O) const
Definition: DIE.cpp:704
unsigned sizeOf(const dwarf::FormParams &FormParams, dwarf::Form Form) const
Definition: DIE.cpp:682
void print(raw_ostream &O) const
Definition: DIE.cpp:481
void emitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit expression value.
Definition: DIE.cpp:460
unsigned sizeOf(const dwarf::FormParams &FormParams, dwarf::Form Form) const
SizeOf - Determine size of expression value in bytes.
Definition: DIE.cpp:466
void emitValue(const AsmPrinter *AP, dwarf::Form Form) const
Definition: DIE.cpp:624
void print(raw_ostream &O) const
Definition: DIE.cpp:639
unsigned sizeOf(const dwarf::FormParams &, dwarf::Form) const
Definition: DIE.cpp:633
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:427
void print(raw_ostream &O) const
Definition: DIE.cpp:449
void emitValue(const AsmPrinter *Asm, dwarf::Form Form) const
EmitValue - Emit integer of appropriate size.
Definition: DIE.cpp:370
A label DIE.
Definition: DIE.h:223
void emitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit label value.
Definition: DIE.cpp:489
void print(raw_ostream &O) const
Definition: DIE.cpp:515
unsigned sizeOf(const dwarf::FormParams &FormParams, dwarf::Form Form) const
sizeOf - Determine size of label value in bytes.
Definition: DIE.cpp:497
void print(raw_ostream &O) const
Definition: DIE.cpp:849
unsigned sizeOf(const dwarf::FormParams &FormParams, dwarf::Form Form) const
Definition: DIE.cpp:814
void emitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit label value.
Definition: DIE.cpp:838
void print(raw_ostream &O) const
Definition: DIE.cpp:754
unsigned sizeOf(const dwarf::FormParams &, dwarf::Form Form) const
sizeOf - Determine size of location data in bytes.
Definition: DIE.cpp:741
void emitValue(const AsmPrinter *Asm, dwarf::Form Form) const
EmitValue - Emit location data.
Definition: DIE.cpp:723
unsigned computeSize(const dwarf::FormParams &FormParams) const
Calculate the size of the location expression.
Definition: DIE.cpp:712
void emitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit string value.
Definition: DIE.cpp:572
void print(raw_ostream &O) const
Definition: DIE.cpp:617
unsigned sizeOf(const dwarf::FormParams &FormParams, dwarf::Form Form) const
sizeOf - Determine size of delta value in bytes.
Definition: DIE.cpp:596
Represents a compile or type unit.
Definition: DIE.h:885
virtual const MCSymbol * getCrossSectionRelativeBaseAddress() const
Definition: DIE.h:914
DIEUnit(dwarf::Tag UnitTag)
Definition: DIE.cpp:312
A list of DIE values.
Definition: DIE.h:667
value_range values()
Definition: DIE.h:732
void print(raw_ostream &O) const
Definition: DIE.cpp:346
void emitValue(const AsmPrinter *AP) const
Emit value via the Dwarf writer.
Definition: DIE.cpp:321
unsigned sizeOf(const dwarf::FormParams &FormParams) const
Return the size of a value in bytes.
Definition: DIE.cpp:333
void dump() const
Definition: DIE.cpp:359
A structured debug information entry.
Definition: DIE.h:744
DIEValue findAttribute(dwarf::Attribute Attribute) const
Find a value in the DIE with the attribute given.
Definition: DIE.cpp:216
void print(raw_ostream &O, unsigned IndentCount=0) const
Definition: DIE.cpp:242
unsigned getAbbrevNumber() const
Definition: DIE.h:779
DIEAbbrev generateAbbrev() const
Generate the abbreviation for this DIE.
Definition: DIE.cpp:180
unsigned computeOffsetsAndAbbrevs(const dwarf::FormParams &FormParams, DIEAbbrevSet &AbbrevSet, unsigned CUOffset)
Compute the offset of this DIE and all its children.
Definition: DIE.cpp:272
void setSize(unsigned S)
Definition: DIE.h:856
DIEUnit * getUnit() const
Climb up the parent chain to get the compile unit or type unit that this DIE belongs to.
Definition: DIE.cpp:209
child_range children()
Definition: DIE.h:800
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:197
void setAbbrevNumber(unsigned I)
Set the abbreviation number for this DIE.
Definition: DIE.h:816
unsigned getOffset() const
Get the compile/type unit relative offset of this DIE.
Definition: DIE.h:782
void setOffset(unsigned O)
Definition: DIE.h:855
bool hasChildren() const
Definition: DIE.h:792
uint64_t getDebugSectionOffset() const
Get the absolute offset within the .debug_info or .debug_types section for this DIE.
Definition: DIE.cpp:191
dwarf::Tag getTag() const
Definition: DIE.h:780
void dump() const
Definition: DIE.cpp:267
DIE * getParent() const
Definition: DIE.cpp:176
const List & getList(size_t LI) const
Collects and handles dwarf debug information.
Definition: DwarfDebug.h:296
const DebugLocStream & getDebugLocs() const
Returns the entries for the .debug_loc section.
Definition: DwarfDebug.h:776
bool useSplitDwarf() const
Returns whether or not to change the current debug info for the split dwarf proposal support.
Definition: DwarfDebug.h:737
FoldingSetNodeID - This class is used to gather all the unique data bits of a node.
Definition: FoldingSet.h:318
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:41
StringRef getName() const
getName - Get the symbol name.
Definition: MCSymbol.h:203
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
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:783
std::optional< uint8_t > getFixedFormByteSize(dwarf::Form Form, FormParams Params)
Get the fixed byte size for a given form.
Definition: Dwarf.cpp:695
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:406
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:124
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:731
bool DwarfUsesRelocationsAcrossSections
True if DWARF v2 output generally uses relocations for references to other .debug_* sections.
Definition: Dwarf.h:737
DwarfFormat Format
Definition: Dwarf.h:734
uint8_t getDwarfOffsetByteSize() const
The size of a reference is determined by the DWARF 32/64-bit format.
Definition: Dwarf.h:749
uint8_t getRefAddrByteSize() const
The definition of the size of form DW_FORM_ref_addr depends on the version.
Definition: Dwarf.h:742