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