LLVM 24.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 (const DIEAbbrevData &D : Data)
57 D.Profile(ID);
58}
59
60/// Emit - Print the abbreviation using the specified asm printer.
61///
62void DIEAbbrev::Emit(const AsmPrinter *AP) const {
63 assert((Tag != DIE::PlaceholderTag) &&
64 "Abbreviation with placeholder tag should not be emitted");
65
66 // Emit its Dwarf tag type.
67 AP->emitULEB128(Tag, dwarf::TagString(Tag).data());
68
69 // Emit whether it has children DIEs.
70 AP->emitULEB128((unsigned)Children, dwarf::ChildrenString(Children).data());
71
72 // For each attribute description.
73 for (const DIEAbbrevData &AttrData : Data) {
74 // Emit attribute type.
75 AP->emitULEB128(AttrData.getAttribute(),
76 dwarf::AttributeString(AttrData.getAttribute()).data());
77
78 // Emit form type.
79#ifndef NDEBUG
80 // Could be an assertion, but this way we can see the failing form code
81 // easily, which helps track down where it came from.
82 if (!dwarf::isValidFormForVersion(AttrData.getForm(),
83 AP->getDwarfVersion())) {
84 LLVM_DEBUG(dbgs() << "Invalid form " << format("0x%x", AttrData.getForm())
85 << " for DWARF version " << AP->getDwarfVersion()
86 << "\n");
87 llvm_unreachable("Invalid form for specified DWARF version");
88 }
89#endif
90 AP->emitULEB128(AttrData.getForm(),
91 dwarf::FormEncodingString(AttrData.getForm()).data());
92
93 // Emit value for DW_FORM_implicit_const.
94 if (AttrData.getForm() == dwarf::DW_FORM_implicit_const)
95 AP->emitSLEB128(AttrData.getValue());
96 }
97
98 // Mark end of abbreviation.
99 AP->emitULEB128(0, "EOM(1)");
100 AP->emitULEB128(0, "EOM(2)");
101}
102
105 O << "Abbreviation @"
106 << format("0x%lx", (long)(intptr_t)this)
107 << " "
108 << dwarf::TagString(Tag)
109 << " "
110 << dwarf::ChildrenString(Children)
111 << '\n';
112
113 for (const DIEAbbrevData &D : Data) {
114 O << " " << dwarf::AttributeString(D.getAttribute()) << " "
115 << dwarf::FormEncodingString(D.getForm());
116
117 if (D.getForm() == dwarf::DW_FORM_implicit_const)
118 O << " " << D.getValue();
119
120 O << '\n';
121 }
122}
123
124#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
126 print(dbgs());
127}
128#endif
129
130//===----------------------------------------------------------------------===//
131// DIEAbbrevSet Implementation
132//===----------------------------------------------------------------------===//
133
135 for (DIEAbbrev *Abbrev : Abbreviations)
136 Abbrev->~DIEAbbrev();
137}
138
140
142 DIEAbbrev Abbrev = Die.generateAbbrev();
143 Abbrev.Profile(ID);
144
146 if (DIEAbbrev *Existing = AbbreviationsSet.lookup(ID, Token)) {
147 Die.setAbbrevNumber(Existing->getNumber());
148 return *Existing;
149 }
150
151 // Move the abbreviation to the heap and assign a number.
152 DIEAbbrev *New = new (Alloc) DIEAbbrev(std::move(Abbrev));
153 Abbreviations.push_back(New);
154 New->setNumber(Abbreviations.size());
155 Die.setAbbrevNumber(Abbreviations.size());
156
157 // Store it for lookup.
158 AbbreviationsSet.insert(New, Token);
159 return *New;
160}
161
162void DIEAbbrevSet::Emit(const AsmPrinter *AP, MCSection *Section) const {
163 if (!Abbreviations.empty()) {
164 // Start the debug abbrev section.
165 AP->OutStreamer->switchSection(Section);
166 AP->emitDwarfAbbrevs(Abbreviations);
167 }
168}
169
170//===----------------------------------------------------------------------===//
171// DIE Implementation
172//===----------------------------------------------------------------------===//
173
174DIE *DIE::getRawParent() const { return dyn_cast_if_present<DIE *>(Owner); }
175
176DIE *DIE::getParent() const {
177 DIE *Parent = getRawParent();
178 assert((!Parent || !Parent->isPlaceholder()) &&
179 "Parent must not be requested when DIE is in a temporary placeholder");
180 return Parent;
181}
182
183void DIE::removeChild(DIE &Child) {
184 assert(Child.getRawParent() == this && "Not a child of this DIE");
185 [[maybe_unused]] bool Removed = Children.deleteNode(Child);
186 assert(Removed && "Child is missing from the list of children");
187 Child.Owner = nullptr;
188}
189
190void DIE::takeChildren(DIE &Other, bool AtFront) {
191 for (DIE &Child : Other.children())
192 Child.Owner = this;
193 if (!AtFront) {
194 Children.takeNodes(Other.Children);
195 return;
196 }
198 Moved.takeNodes(Other.Children);
199 Moved.takeNodes(Children);
200 Children.takeNodes(Moved);
201}
202
205 "Abbrevs should not be generated for placeholder tags");
206
207 DIEAbbrev Abbrev(Tag, hasChildren());
208 for (const DIEValue &V : values())
209 if (V.getForm() == dwarf::DW_FORM_implicit_const)
210 Abbrev.AddImplicitConstAttribute(V.getAttribute(),
211 V.getDIEInteger().getValue());
212 else
213 Abbrev.AddAttribute(V.getAttribute(), V.getForm());
214 return Abbrev;
215}
216
218 const DIEUnit *Unit = getUnit();
219 assert(Unit && "DIE must be owned by a DIEUnit to get its absolute offset");
220 return Unit->getDebugSectionOffset() + getOffset();
221}
222
224 for (const DIE *P = this; P; P = P->getRawParent())
225 if (auto *Unit = dyn_cast_if_present<DIEUnit *>(P->Owner))
226 return Unit;
227 return nullptr;
228}
229
230const DIE *DIE::getUnitDie() const {
231 const DIEUnit *Unit = getUnit();
232 return Unit ? &Unit->getUnitDie() : nullptr;
233}
234
236 // Iterate through all the attributes until we find the one we're
237 // looking for, if we can't find it return NULL.
238 for (const auto &V : values())
239 if (V.getAttribute() == Attribute)
240 return V;
241 return DIEValue();
242}
243
246 StringRef Type, unsigned Size, unsigned IndentCount) {
247 O << Type << ": Size: " << Size << "\n";
248
249 unsigned I = 0;
250 const std::string Indent(IndentCount, ' ');
251 for (const auto &V : Values.values()) {
252 O << Indent;
253 O << "Blk[" << I++ << "]";
254 O << " " << dwarf::FormEncodingString(V.getForm()) << " ";
255 V.print(O);
256 O << "\n";
257 }
258}
259
261void DIE::print(raw_ostream &O, unsigned IndentCount) const {
262 const std::string Indent(IndentCount, ' ');
263 O << Indent << "Die: " << format("0x%lx", (long)(intptr_t) this)
264 << ", Offset: " << Offset << ", Size: " << Size << "\n";
265
266 O << Indent << dwarf::TagString(getTag()) << " "
268
269 IndentCount += 2;
270 for (const auto &V : values()) {
271 O << Indent;
272 O << dwarf::AttributeString(V.getAttribute());
273 O << " " << dwarf::FormEncodingString(V.getForm()) << " ";
274 V.print(O);
275 O << "\n";
276 }
277 IndentCount -= 2;
278
279 for (const auto &Child : children())
280 Child.print(O, IndentCount + 4);
281
282 O << "\n";
283}
284
285#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
287 print(dbgs());
288}
289#endif
290
292 DIEAbbrevSet &AbbrevSet,
293 unsigned CUOffset) {
294 assert(!isPlaceholder() && "Cannot compute offsets for a placeholder DIE");
295
296 // Unique the abbreviation and fill in the abbreviation number so this DIE
297 // can be emitted.
298 const DIEAbbrev &Abbrev = AbbrevSet.uniqueAbbreviation(*this);
299
300 // Set compile/type unit relative offset of this DIE.
301 setOffset(CUOffset);
302
303 // Add the byte size of the abbreviation code.
304 CUOffset += getULEB128Size(getAbbrevNumber());
305
306 // Add the byte size of all the DIE attribute values.
307 for (const auto &V : values())
308 CUOffset += V.sizeOf(FormParams);
309
310 // Let the children compute their offsets and abbreviation numbers.
311 if (hasChildren()) {
312 (void)Abbrev;
313 assert(Abbrev.hasChildren() && "Children flag not set");
314
315 for (auto &Child : children())
316 CUOffset =
317 Child.computeOffsetsAndAbbrevs(FormParams, AbbrevSet, CUOffset);
318
319 // Each child chain is terminated with a zero byte, adjust the offset.
320 CUOffset += sizeof(int8_t);
321 }
322
323 // Compute the byte size of this DIE and all of its children correctly. This
324 // is needed so that top level DIE can help the compile unit set its length
325 // correctly.
326 setSize(CUOffset - getOffset());
327 return CUOffset;
328}
329
330//===----------------------------------------------------------------------===//
331// DIEUnit Implementation
332//===----------------------------------------------------------------------===//
333DIEUnit::DIEUnit(dwarf::Tag UnitTag) : Die(UnitTag) {
334 Die.Owner = this;
335 assert(dwarf::isUnitType(UnitTag) && "expected a unit TAG");
336}
337
338void DIEValue::emitValue(const AsmPrinter *AP) const {
339 switch (Ty) {
340 case isNone:
341 llvm_unreachable("Expected valid DIEValue");
342#define HANDLE_DIEVALUE(T) \
343 case is##T: \
344 getDIE##T().emitValue(AP, Form); \
345 break;
346#include "llvm/CodeGen/DIEValue.def"
347 }
348}
349
350unsigned DIEValue::sizeOf(const dwarf::FormParams &FormParams) const {
351 switch (Ty) {
352 case isNone:
353 llvm_unreachable("Expected valid DIEValue");
354#define HANDLE_DIEVALUE(T) \
355 case is##T: \
356 return getDIE##T().sizeOf(FormParams, Form);
357#include "llvm/CodeGen/DIEValue.def"
358 }
359 llvm_unreachable("Unknown DIE kind");
360}
361
364 switch (Ty) {
365 case isNone:
366 llvm_unreachable("Expected valid DIEValue");
367#define HANDLE_DIEVALUE(T) \
368 case is##T: \
369 getDIE##T().print(O); \
370 break;
371#include "llvm/CodeGen/DIEValue.def"
372 }
373}
374
375#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
377 print(dbgs());
378}
379#endif
380
381//===----------------------------------------------------------------------===//
382// DIEInteger Implementation
383//===----------------------------------------------------------------------===//
384
385/// EmitValue - Emit integer of appropriate size.
386///
387void DIEInteger::emitValue(const AsmPrinter *Asm, dwarf::Form Form) const {
388 switch (Form) {
389 case dwarf::DW_FORM_implicit_const:
390 case dwarf::DW_FORM_flag_present:
391 // Emit something to keep the lines and comments in sync.
392 // FIXME: Is there a better way to do this?
393 Asm->OutStreamer->addBlankLine();
394 return;
395 case dwarf::DW_FORM_flag:
396 case dwarf::DW_FORM_ref1:
397 case dwarf::DW_FORM_data1:
398 case dwarf::DW_FORM_strx1:
399 case dwarf::DW_FORM_addrx1:
400 case dwarf::DW_FORM_ref2:
401 case dwarf::DW_FORM_data2:
402 case dwarf::DW_FORM_strx2:
403 case dwarf::DW_FORM_addrx2:
404 case dwarf::DW_FORM_strx3:
405 case dwarf::DW_FORM_addrx3:
406 case dwarf::DW_FORM_strp:
407 case dwarf::DW_FORM_ref4:
408 case dwarf::DW_FORM_data4:
409 case dwarf::DW_FORM_ref_sup4:
410 case dwarf::DW_FORM_strx4:
411 case dwarf::DW_FORM_addrx4:
412 case dwarf::DW_FORM_ref8:
413 case dwarf::DW_FORM_ref_sig8:
414 case dwarf::DW_FORM_data8:
415 case dwarf::DW_FORM_ref_sup8:
416 case dwarf::DW_FORM_GNU_ref_alt:
417 case dwarf::DW_FORM_GNU_strp_alt:
418 case dwarf::DW_FORM_line_strp:
419 case dwarf::DW_FORM_sec_offset:
420 case dwarf::DW_FORM_strp_sup:
421 case dwarf::DW_FORM_addr:
422 case dwarf::DW_FORM_ref_addr:
423 Asm->OutStreamer->emitIntValue(Integer,
424 sizeOf(Asm->getDwarfFormParams(), Form));
425 return;
426 case dwarf::DW_FORM_GNU_str_index:
427 case dwarf::DW_FORM_GNU_addr_index:
428 case dwarf::DW_FORM_ref_udata:
429 case dwarf::DW_FORM_strx:
430 case dwarf::DW_FORM_addrx:
431 case dwarf::DW_FORM_rnglistx:
432 case dwarf::DW_FORM_udata:
433 Asm->emitULEB128(Integer);
434 return;
435 case dwarf::DW_FORM_sdata:
436 Asm->emitSLEB128(Integer);
437 return;
438 default: llvm_unreachable("DIE Value form not supported yet");
439 }
440}
441
442/// sizeOf - Determine size of integer value in bytes.
443///
444unsigned DIEInteger::sizeOf(const dwarf::FormParams &FormParams,
445 dwarf::Form Form) const {
446 if (std::optional<uint8_t> FixedSize =
447 dwarf::getFixedFormByteSize(Form, FormParams))
448 return *FixedSize;
449
450 switch (Form) {
451 case dwarf::DW_FORM_GNU_str_index:
452 case dwarf::DW_FORM_GNU_addr_index:
453 case dwarf::DW_FORM_ref_udata:
454 case dwarf::DW_FORM_strx:
455 case dwarf::DW_FORM_addrx:
456 case dwarf::DW_FORM_rnglistx:
457 case dwarf::DW_FORM_udata:
458 return getULEB128Size(Integer);
459 case dwarf::DW_FORM_sdata:
460 return getSLEB128Size(Integer);
461 default: llvm_unreachable("DIE Value form not supported yet");
462 }
463}
464
467 O << "Int: " << (int64_t)Integer << " 0x";
468 O.write_hex(Integer);
469}
470
471//===----------------------------------------------------------------------===//
472// DIEExpr Implementation
473//===----------------------------------------------------------------------===//
474
475/// EmitValue - Emit expression value.
476///
477void DIEExpr::emitValue(const AsmPrinter *AP, dwarf::Form Form) const {
478 AP->emitDebugValue(Expr, sizeOf(AP->getDwarfFormParams(), Form));
479}
480
481/// SizeOf - Determine size of expression value in bytes.
482///
483unsigned DIEExpr::sizeOf(const dwarf::FormParams &FormParams,
484 dwarf::Form Form) const {
485 switch (Form) {
486 case dwarf::DW_FORM_data4:
487 return 4;
488 case dwarf::DW_FORM_data8:
489 return 8;
490 case dwarf::DW_FORM_sec_offset:
491 return FormParams.getDwarfOffsetByteSize();
492 default:
493 llvm_unreachable("DIE Value form not supported yet");
494 }
495}
496
499 MCTargetOptions Opts;
500 O << "Expr: ";
501 MCAsmInfo(Opts).printExpr(O, *Expr);
502}
503
504//===----------------------------------------------------------------------===//
505// DIELabel Implementation
506//===----------------------------------------------------------------------===//
507
508/// EmitValue - Emit label value.
509///
510void DIELabel::emitValue(const AsmPrinter *AP, dwarf::Form Form) const {
511 bool IsSectionRelative = Form != dwarf::DW_FORM_addr;
512 AP->emitLabelReference(Label, sizeOf(AP->getDwarfFormParams(), Form),
513 IsSectionRelative);
514}
515
516/// sizeOf - Determine size of label value in bytes.
517///
518unsigned DIELabel::sizeOf(const dwarf::FormParams &FormParams,
519 dwarf::Form Form) const {
520 switch (Form) {
521 case dwarf::DW_FORM_data4:
522 return 4;
523 case dwarf::DW_FORM_data8:
524 return 8;
525 case dwarf::DW_FORM_sec_offset:
526 case dwarf::DW_FORM_strp:
527 return FormParams.getDwarfOffsetByteSize();
528 case dwarf::DW_FORM_addr:
529 return FormParams.AddrSize;
530 default:
531 llvm_unreachable("DIE Value form not supported yet");
532 }
533}
534
536void DIELabel::print(raw_ostream &O) const { O << "Lbl: " << Label->getName(); }
537
538//===----------------------------------------------------------------------===//
539// DIEBaseTypeRef Implementation
540//===----------------------------------------------------------------------===//
541
543 uint64_t Offset = CU->ExprRefedBaseTypes[Index].Die->getOffset();
544 assert(Offset < (1ULL << (ULEB128PadSize * 7)) && "Offset wont fit");
545 AP->emitULEB128(Offset, nullptr, ULEB128PadSize);
546}
547
549 return ULEB128PadSize;
550}
551
553void DIEBaseTypeRef::print(raw_ostream &O) const { O << "BaseTypeRef: " << Index; }
554
555//===----------------------------------------------------------------------===//
556// DIEDelta Implementation
557//===----------------------------------------------------------------------===//
558
559/// EmitValue - Emit delta value.
560///
561void DIEDelta::emitValue(const AsmPrinter *AP, dwarf::Form Form) const {
562 AP->emitLabelDifference(LabelHi, LabelLo,
563 sizeOf(AP->getDwarfFormParams(), Form));
564}
565
566/// SizeOf - Determine size of delta value in bytes.
567///
568unsigned DIEDelta::sizeOf(const dwarf::FormParams &FormParams,
569 dwarf::Form Form) const {
570 switch (Form) {
571 case dwarf::DW_FORM_data4:
572 return 4;
573 case dwarf::DW_FORM_data8:
574 return 8;
575 case dwarf::DW_FORM_sec_offset:
576 return FormParams.getDwarfOffsetByteSize();
577 default:
578 llvm_unreachable("DIE Value form not supported yet");
579 }
580}
581
584 O << "Del: " << LabelHi->getName() << "-" << LabelLo->getName();
585}
586
587//===----------------------------------------------------------------------===//
588// DIEString Implementation
589//===----------------------------------------------------------------------===//
590
591/// EmitValue - Emit string value.
592///
593void DIEString::emitValue(const AsmPrinter *AP, dwarf::Form Form) const {
594 // Index of string in symbol table.
595 switch (Form) {
596 case dwarf::DW_FORM_GNU_str_index:
597 case dwarf::DW_FORM_strx:
598 case dwarf::DW_FORM_strx1:
599 case dwarf::DW_FORM_strx2:
600 case dwarf::DW_FORM_strx3:
601 case dwarf::DW_FORM_strx4:
602 DIEInteger(S.getIndex()).emitValue(AP, Form);
603 return;
604 case dwarf::DW_FORM_strp:
606 DIELabel(S.getSymbol()).emitValue(AP, Form);
607 else
608 DIEInteger(S.getOffset()).emitValue(AP, Form);
609 return;
610 default:
611 llvm_unreachable("Expected valid string form");
612 }
613}
614
615/// sizeOf - Determine size of delta value in bytes.
616///
617unsigned DIEString::sizeOf(const dwarf::FormParams &FormParams,
618 dwarf::Form Form) const {
619 // Index of string in symbol table.
620 switch (Form) {
621 case dwarf::DW_FORM_GNU_str_index:
622 case dwarf::DW_FORM_strx:
623 case dwarf::DW_FORM_strx1:
624 case dwarf::DW_FORM_strx2:
625 case dwarf::DW_FORM_strx3:
626 case dwarf::DW_FORM_strx4:
627 return DIEInteger(S.getIndex()).sizeOf(FormParams, Form);
628 case dwarf::DW_FORM_strp:
630 return DIELabel(S.getSymbol()).sizeOf(FormParams, Form);
631 return DIEInteger(S.getOffset()).sizeOf(FormParams, Form);
632 default:
633 llvm_unreachable("Expected valid string form");
634 }
635}
636
639 O << "String: " << S.getString();
640}
641
642//===----------------------------------------------------------------------===//
643// DIEInlineString Implementation
644//===----------------------------------------------------------------------===//
646 if (Form == dwarf::DW_FORM_string) {
647 AP->OutStreamer->emitBytes(S);
648 AP->emitInt8(0);
649 return;
650 }
651 llvm_unreachable("Expected valid string form");
652}
653
655 // Emit string bytes + NULL byte.
656 return S.size() + 1;
657}
658
661 O << "InlineString: " << S;
662}
663
664//===----------------------------------------------------------------------===//
665// DIEEntry Implementation
666//===----------------------------------------------------------------------===//
667
668/// EmitValue - Emit debug information entry offset.
669///
670void DIEEntry::emitValue(const AsmPrinter *AP, dwarf::Form Form) const {
671
672 switch (Form) {
673 case dwarf::DW_FORM_ref1:
674 case dwarf::DW_FORM_ref2:
675 case dwarf::DW_FORM_ref4:
676 case dwarf::DW_FORM_ref8:
677 AP->OutStreamer->emitIntValue(Entry->getOffset(),
678 sizeOf(AP->getDwarfFormParams(), Form));
679 return;
680
681 case dwarf::DW_FORM_ref_udata:
682 AP->emitULEB128(Entry->getOffset());
683 return;
684
685 case dwarf::DW_FORM_ref_addr: {
686 // Get the absolute offset for this DIE within the debug info/types section.
687 uint64_t Addr = Entry->getDebugSectionOffset();
688 if (const MCSymbol *SectionSym =
689 Entry->getUnit()->getCrossSectionRelativeBaseAddress()) {
690 AP->emitLabelPlusOffset(SectionSym, Addr,
691 sizeOf(AP->getDwarfFormParams(), Form), true);
692 return;
693 }
694
695 AP->OutStreamer->emitIntValue(Addr, sizeOf(AP->getDwarfFormParams(), Form));
696 return;
697 }
698 default:
699 llvm_unreachable("Improper form for DIE reference");
700 }
701}
702
703unsigned DIEEntry::sizeOf(const dwarf::FormParams &FormParams,
704 dwarf::Form Form) const {
705 switch (Form) {
706 case dwarf::DW_FORM_ref1:
707 return 1;
708 case dwarf::DW_FORM_ref2:
709 return 2;
710 case dwarf::DW_FORM_ref4:
711 return 4;
712 case dwarf::DW_FORM_ref8:
713 return 8;
714 case dwarf::DW_FORM_ref_udata:
715 return getULEB128Size(Entry->getOffset());
716 case dwarf::DW_FORM_ref_addr:
717 return FormParams.getRefAddrByteSize();
718
719 default:
720 llvm_unreachable("Improper form for DIE reference");
721 }
722}
723
726 O << format("Die: 0x%lx", (long)(intptr_t)&Entry);
727}
728
729//===----------------------------------------------------------------------===//
730// DIELoc Implementation
731//===----------------------------------------------------------------------===//
732
733unsigned DIELoc::computeSize(const dwarf::FormParams &FormParams) const {
734 if (!Size) {
735 for (const auto &V : values())
736 Size += V.sizeOf(FormParams);
737 }
738
739 return Size;
740}
741
742/// EmitValue - Emit location data.
743///
744void DIELoc::emitValue(const AsmPrinter *Asm, dwarf::Form Form) const {
745 switch (Form) {
746 default: llvm_unreachable("Improper form for block");
747 case dwarf::DW_FORM_block1: Asm->emitInt8(Size); break;
748 case dwarf::DW_FORM_block2: Asm->emitInt16(Size); break;
749 case dwarf::DW_FORM_block4: Asm->emitInt32(Size); break;
750 case dwarf::DW_FORM_block:
751 case dwarf::DW_FORM_exprloc:
752 Asm->emitULEB128(Size);
753 break;
754 }
755
756 for (const auto &V : values())
757 V.emitValue(Asm);
758}
759
760/// sizeOf - Determine size of location data in bytes.
761///
762unsigned DIELoc::sizeOf(const dwarf::FormParams &, dwarf::Form Form) const {
763 switch (Form) {
764 case dwarf::DW_FORM_block1: return Size + sizeof(int8_t);
765 case dwarf::DW_FORM_block2: return Size + sizeof(int16_t);
766 case dwarf::DW_FORM_block4: return Size + sizeof(int32_t);
767 case dwarf::DW_FORM_block:
768 case dwarf::DW_FORM_exprloc:
769 return Size + getULEB128Size(Size);
770 default: llvm_unreachable("Improper form for block");
771 }
772}
773
776 printValues(O, *this, "ExprLoc", Size, 5);
777}
778
779//===----------------------------------------------------------------------===//
780// DIEBlock Implementation
781//===----------------------------------------------------------------------===//
782
783unsigned DIEBlock::computeSize(const dwarf::FormParams &FormParams) const {
784 if (!Size) {
785 for (const auto &V : values())
786 Size += V.sizeOf(FormParams);
787 }
788
789 return Size;
790}
791
792/// EmitValue - Emit block data.
793///
794void DIEBlock::emitValue(const AsmPrinter *Asm, dwarf::Form Form) const {
795 switch (Form) {
796 default: llvm_unreachable("Improper form for block");
797 case dwarf::DW_FORM_block1: Asm->emitInt8(Size); break;
798 case dwarf::DW_FORM_block2: Asm->emitInt16(Size); break;
799 case dwarf::DW_FORM_block4: Asm->emitInt32(Size); break;
800 case dwarf::DW_FORM_exprloc:
801 case dwarf::DW_FORM_block:
802 Asm->emitULEB128(Size);
803 break;
804 case dwarf::DW_FORM_string: break;
805 case dwarf::DW_FORM_data16: break;
806 }
807
808 for (const auto &V : values())
809 V.emitValue(Asm);
810}
811
812/// sizeOf - Determine size of block data in bytes.
813///
814unsigned DIEBlock::sizeOf(const dwarf::FormParams &, dwarf::Form Form) const {
815 switch (Form) {
816 case dwarf::DW_FORM_block1: return Size + sizeof(int8_t);
817 case dwarf::DW_FORM_block2: return Size + sizeof(int16_t);
818 case dwarf::DW_FORM_block4: return Size + sizeof(int32_t);
819 case dwarf::DW_FORM_exprloc:
820 case dwarf::DW_FORM_block: return Size + getULEB128Size(Size);
821 case dwarf::DW_FORM_data16: return 16;
822 default: llvm_unreachable("Improper form for block");
823 }
824}
825
828 printValues(O, *this, "Blk", Size, 5);
829}
830
831//===----------------------------------------------------------------------===//
832// DIELocList Implementation
833//===----------------------------------------------------------------------===//
834
835unsigned DIELocList::sizeOf(const dwarf::FormParams &FormParams,
836 dwarf::Form Form) const {
837 switch (Form) {
838 case dwarf::DW_FORM_loclistx:
839 return getULEB128Size(Index);
840 case dwarf::DW_FORM_data4:
841 assert(FormParams.Format != dwarf::DWARF64 &&
842 "DW_FORM_data4 is not suitable to emit a pointer to a location list "
843 "in the 64-bit DWARF format");
844 return 4;
845 case dwarf::DW_FORM_data8:
846 assert(FormParams.Format == dwarf::DWARF64 &&
847 "DW_FORM_data8 is not suitable to emit a pointer to a location list "
848 "in the 32-bit DWARF format");
849 return 8;
850 case dwarf::DW_FORM_sec_offset:
851 return FormParams.getDwarfOffsetByteSize();
852 default:
853 llvm_unreachable("DIE Value form not supported yet");
854 }
855}
856
857/// EmitValue - Emit label value.
858///
859void DIELocList::emitValue(const AsmPrinter *AP, dwarf::Form Form) const {
860 if (Form == dwarf::DW_FORM_loclistx) {
861 AP->emitULEB128(Index);
862 return;
863 }
864 DwarfDebug *DD = AP->getDwarfDebug();
865 MCSymbol *Label = DD->getDebugLocs().getList(Index).Label;
866 AP->emitDwarfSymbolReference(Label, /*ForceOffset*/ DD->useSplitDwarf());
867}
868
870void DIELocList::print(raw_ostream &O) const { O << "LocList: " << Index; }
871
872//===----------------------------------------------------------------------===//
873// DIEAddrOffset Implementation
874//===----------------------------------------------------------------------===//
875
876unsigned DIEAddrOffset::sizeOf(const dwarf::FormParams &FormParams,
877 dwarf::Form) const {
878 return Addr.sizeOf(FormParams, dwarf::DW_FORM_addrx) +
879 Offset.sizeOf(FormParams, dwarf::DW_FORM_data4);
880}
881
882/// EmitValue - Emit label value.
883///
885 Addr.emitValue(AP, dwarf::DW_FORM_addrx);
886 Offset.emitValue(AP, dwarf::DW_FORM_data4);
887}
888
891 O << "AddrOffset: ";
892 Addr.print(O);
893 O << " + ";
894 Offset.print(O);
895}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition Compiler.h:690
static LLVM_DUMP_METHOD void printValues(raw_ostream &O, const DIEValueList &Values, StringRef Type, unsigned Size, unsigned IndentCount)
Definition DIE.cpp:245
static ManagedStatic< DebugCounterOwner > Owner
#define I(x, y, z)
Definition MD5.cpp:57
#define P(N)
static Split data
#define LLVM_DEBUG(...)
Definition Debug.h:119
This class is intended to be used as a driving class for all asm writers.
Definition AsmPrinter.h:95
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.
DwarfDebug * getDwarfDebug()
Definition AsmPrinter.h:315
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:882
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:110
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:802
uint16_t getDwarfVersion() const
dwarf::FormParams getDwarfFormParams() const
Returns information about the byte size of DW_FORM values.
bool doesDwarfUseRelocationsAcrossSections() const
Definition AsmPrinter.h:401
Functions, function parameters, and return types can have attributes to indicate how they should be t...
Definition Attributes.h:106
Dwarf abbreviation data, describes one attribute of a Dwarf abbreviation.
Definition DIE.h:50
LLVM_ABI void Profile(FoldingSetNodeID &ID) const
Used to gather unique data for the abbreviation folding set.
Definition DIE.cpp:36
Helps unique DIEAbbrev objects and assigns abbreviation numbers.
Definition DIE.h:141
LLVM_ABI ~DIEAbbrevSet()
Definition DIE.cpp:134
LLVM_ABI void Emit(const AsmPrinter *AP, MCSection *Section) const
Print all abbreviations using the specified asm printer.
Definition DIE.cpp:162
LLVM_ABI DIEAbbrev & uniqueAbbreviation(DIE &Die)
Generate the abbreviation declaration for a DIE and return a pointer to the generated abbreviation.
Definition DIE.cpp:139
Dwarf abbreviation, describes the organization of a debug information object.
Definition DIE.h:80
LLVM_ABI void print(raw_ostream &O) const
Definition DIE.cpp:104
void AddImplicitConstAttribute(dwarf::Attribute Attribute, int64_t Value)
Adds attribute with DW_FORM_implicit_const value.
Definition DIE.h:115
LLVM_ABI 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:110
LLVM_ABI void dump() const
Definition DIE.cpp:125
LLVM_ABI 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:103
LLVM_ABI void print(raw_ostream &O) const
Definition DIE.cpp:890
LLVM_ABI unsigned sizeOf(const dwarf::FormParams &FormParams, dwarf::Form Form) const
Definition DIE.cpp:876
LLVM_ABI void emitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit label value.
Definition DIE.cpp:884
LLVM_ABI void emitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit base type reference.
Definition DIE.cpp:542
LLVM_ABI void print(raw_ostream &O) const
Definition DIE.cpp:553
LLVM_ABI unsigned sizeOf(const dwarf::FormParams &, dwarf::Form) const
sizeOf - Determine size of the base type reference in bytes.
Definition DIE.cpp:548
LLVM_ABI unsigned sizeOf(const dwarf::FormParams &, dwarf::Form Form) const
sizeOf - Determine size of block data in bytes.
Definition DIE.cpp:814
LLVM_ABI void print(raw_ostream &O) const
Definition DIE.cpp:827
LLVM_ABI void emitValue(const AsmPrinter *Asm, dwarf::Form Form) const
EmitValue - Emit block data.
Definition DIE.cpp:794
LLVM_ABI unsigned computeSize(const dwarf::FormParams &FormParams) const
Calculate the size of the location expression.
Definition DIE.cpp:783
LLVM_ABI void print(raw_ostream &O) const
Definition DIE.cpp:583
LLVM_ABI unsigned sizeOf(const dwarf::FormParams &FormParams, dwarf::Form Form) const
SizeOf - Determine size of delta value in bytes.
Definition DIE.cpp:568
LLVM_ABI void emitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit delta value.
Definition DIE.cpp:561
LLVM_ABI void emitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit debug information entry offset.
Definition DIE.cpp:670
LLVM_ABI void print(raw_ostream &O) const
Definition DIE.cpp:725
LLVM_ABI unsigned sizeOf(const dwarf::FormParams &FormParams, dwarf::Form Form) const
Definition DIE.cpp:703
LLVM_ABI void print(raw_ostream &O) const
Definition DIE.cpp:498
LLVM_ABI void emitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit expression value.
Definition DIE.cpp:477
LLVM_ABI unsigned sizeOf(const dwarf::FormParams &FormParams, dwarf::Form Form) const
SizeOf - Determine size of expression value in bytes.
Definition DIE.cpp:483
LLVM_ABI void emitValue(const AsmPrinter *AP, dwarf::Form Form) const
Definition DIE.cpp:645
LLVM_ABI void print(raw_ostream &O) const
Definition DIE.cpp:660
LLVM_ABI unsigned sizeOf(const dwarf::FormParams &, dwarf::Form) const
Definition DIE.cpp:654
An integer value DIE.
Definition DIE.h:169
LLVM_ABI unsigned sizeOf(const dwarf::FormParams &FormParams, dwarf::Form Form) const
sizeOf - Determine size of integer value in bytes.
Definition DIE.cpp:444
LLVM_ABI void print(raw_ostream &O) const
Definition DIE.cpp:466
LLVM_ABI void emitValue(const AsmPrinter *Asm, dwarf::Form Form) const
EmitValue - Emit integer of appropriate size.
Definition DIE.cpp:387
A label DIE.
Definition DIE.h:222
LLVM_ABI void emitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit label value.
Definition DIE.cpp:510
LLVM_ABI void print(raw_ostream &O) const
Definition DIE.cpp:536
LLVM_ABI unsigned sizeOf(const dwarf::FormParams &FormParams, dwarf::Form Form) const
sizeOf - Determine size of label value in bytes.
Definition DIE.cpp:518
LLVM_ABI void print(raw_ostream &O) const
Definition DIE.cpp:870
LLVM_ABI unsigned sizeOf(const dwarf::FormParams &FormParams, dwarf::Form Form) const
Definition DIE.cpp:835
LLVM_ABI void emitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit label value.
Definition DIE.cpp:859
LLVM_ABI void print(raw_ostream &O) const
Definition DIE.cpp:775
LLVM_ABI unsigned sizeOf(const dwarf::FormParams &, dwarf::Form Form) const
sizeOf - Determine size of location data in bytes.
Definition DIE.cpp:762
LLVM_ABI void emitValue(const AsmPrinter *Asm, dwarf::Form Form) const
EmitValue - Emit location data.
Definition DIE.cpp:744
LLVM_ABI unsigned computeSize(const dwarf::FormParams &FormParams) const
Calculate the size of the location expression.
Definition DIE.cpp:733
LLVM_ABI void emitValue(const AsmPrinter *AP, dwarf::Form Form) const
EmitValue - Emit string value.
Definition DIE.cpp:593
LLVM_ABI void print(raw_ostream &O) const
Definition DIE.cpp:638
LLVM_ABI unsigned sizeOf(const dwarf::FormParams &FormParams, dwarf::Form Form) const
sizeOf - Determine size of delta value in bytes.
Definition DIE.cpp:617
LLVM_ABI DIEUnit(dwarf::Tag UnitTag)
Definition DIE.cpp:333
A list of DIE values.
Definition DIE.h:705
value_range values()
Definition DIE.h:823
LLVM_ABI void print(raw_ostream &O) const
Definition DIE.cpp:363
LLVM_ABI void emitValue(const AsmPrinter *AP) const
Emit value via the Dwarf writer.
Definition DIE.cpp:338
LLVM_ABI unsigned sizeOf(const dwarf::FormParams &FormParams) const
Return the size of a value in bytes.
Definition DIE.cpp:350
LLVM_ABI void dump() const
Definition DIE.cpp:376
A structured debug information entry.
Definition DIE.h:835
LLVM_ABI DIEValue findAttribute(dwarf::Attribute Attribute) const
Find a value in the DIE with the attribute given.
Definition DIE.cpp:235
LLVM_ABI void print(raw_ostream &O, unsigned IndentCount=0) const
Definition DIE.cpp:261
unsigned getAbbrevNumber() const
Definition DIE.h:879
LLVM_ABI void takeChildren(DIE &Other, bool AtFront=false)
Move all children of Other to this DIE, preserving their order.
Definition DIE.cpp:190
friend class DIEUnit
Definition DIE.h:837
LLVM_ABI DIEAbbrev generateAbbrev() const
Generate the abbreviation for this DIE.
Definition DIE.cpp:203
LLVM_ABI unsigned computeOffsetsAndAbbrevs(const dwarf::FormParams &FormParams, DIEAbbrevSet &AbbrevSet, unsigned CUOffset)
Compute the offset of this DIE and all its children.
Definition DIE.cpp:291
bool isPlaceholder() const
Returns true if DIE is a temporary placeholder.
Definition DIE.h:895
void setSize(unsigned S)
Definition DIE.h:957
LLVM_ABI DIEUnit * getUnit() const
Climb up the parent chain to get the unit that this DIE belongs to.
Definition DIE.cpp:223
child_range children()
Definition DIE.h:902
LLVM_ABI void removeChild(DIE &Child)
Remove Child from the children of this DIE.
Definition DIE.cpp:183
LLVM_ABI const DIE * getUnitDie() const
Climb up the parent chain to get the unit DIE that this DIE belongs to.
Definition DIE.cpp:230
void setAbbrevNumber(unsigned I)
Set the abbreviation number for this DIE.
Definition DIE.h:918
unsigned getOffset() const
Get the compile/type unit relative offset of this DIE.
Definition DIE.h:882
void setOffset(unsigned O)
Definition DIE.h:956
bool hasChildren() const
Definition DIE.h:892
static constexpr dwarf::Tag PlaceholderTag
Internal tag for temporary containers.
Definition DIE.h:861
LLVM_ABI uint64_t getDebugSectionOffset() const
Get the absolute offset within the .debug_info or .debug_types section for this DIE.
Definition DIE.cpp:217
dwarf::Tag getTag() const
Definition DIE.h:880
LLVM_ABI void dump() const
Definition DIE.cpp:286
LLVM_ABI DIE * getParent() const
Definition DIE.cpp:176
const List & getList(size_t LI) const
Collects and handles dwarf debug information.
Definition DwarfDebug.h:352
const DebugLocStream & getDebugLocs() const
Returns the entries for the .debug_loc section.
Definition DwarfDebug.h:915
bool useSplitDwarf() const
Returns whether or not to change the current debug info for split DWARF.
Definition DwarfDebug.h:876
Insertion token: a failed lookup fills it in, the matching insert consumes it.
Definition FoldingSet.h:284
This class is used to gather all the unique data bits of a node.
Definition FoldingSet.h:162
void takeNodes(IntrusiveBackList< T > &Other)
Definition DIE.h:611
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition MCAsmInfo.h:67
void printExpr(raw_ostream &, const MCExpr &) const
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition MCSection.h:580
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition MCSymbol.h:42
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
LLVM_ABI StringRef AttributeString(unsigned Attribute)
Definition Dwarf.cpp:72
LLVM_ABI StringRef FormEncodingString(unsigned Encoding)
Definition Dwarf.cpp:105
LLVM_ABI StringRef ChildrenString(unsigned Children)
Definition Dwarf.cpp:62
LLVM_ABI StringRef TagString(unsigned Tag)
Definition Dwarf.cpp:21
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Attribute
Attributes.
Definition Dwarf.h:125
bool isUnitType(uint8_t UnitType)
Definition Dwarf.h:1013
@ DWARF64
Definition Dwarf.h:93
LLVM_ABI 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:1056
LLVM_ABI std::optional< uint8_t > getFixedFormByteSize(dwarf::Form Form, FormParams Params)
Get the fixed byte size for a given form.
Definition Dwarf.cpp:968
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:577
RelativeUniformCounterPtr Values
Definition InstrProf.h:91
auto dyn_cast_if_present(const Y &Val)
dyn_cast_if_present<X> - Functionally identical to dyn_cast, except that a null (or none in the case ...
Definition Casting.h:732
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:209
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
Definition Format.h:102
@ Other
Any other memory.
Definition ModRef.h:68
LLVM_ABI unsigned getULEB128Size(uint64_t Value)
Utility function to get the size of the ULEB128-encoded value.
Definition LEB128.cpp:19
LLVM_ABI unsigned getSLEB128Size(int64_t Value)
Utility function to get the size of the SLEB128-encoded value.
Definition LEB128.cpp:29
A helper struct providing information about the byte size of DW_FORM values that vary in size dependi...
Definition Dwarf.h:1221
bool DwarfUsesRelocationsAcrossSections
True if DWARF v2 output generally uses relocations for references to other .debug_* sections.
Definition Dwarf.h:1227
DwarfFormat Format
Definition Dwarf.h:1224
uint8_t getDwarfOffsetByteSize() const
The size of a reference is determined by the DWARF 32/64-bit format.
Definition Dwarf.h:1239
uint8_t getRefAddrByteSize() const
The definition of the size of form DW_FORM_ref_addr depends on the version.
Definition Dwarf.h:1232