LLVM 19.0.0git
DwarfUnit.cpp
Go to the documentation of this file.
1//===-- llvm/CodeGen/DwarfUnit.cpp - Dwarf Type and Compile Units ---------===//
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// This file contains support for constructing a dwarf compile unit.
10//
11//===----------------------------------------------------------------------===//
12
13#include "DwarfUnit.h"
14#include "AddressPool.h"
15#include "DwarfCompileUnit.h"
16#include "DwarfExpression.h"
17#include "llvm/ADT/APFloat.h"
18#include "llvm/ADT/APInt.h"
20#include "llvm/IR/Constants.h"
21#include "llvm/IR/DataLayout.h"
22#include "llvm/IR/GlobalValue.h"
23#include "llvm/IR/Metadata.h"
24#include "llvm/MC/MCAsmInfo.h"
25#include "llvm/MC/MCContext.h"
26#include "llvm/MC/MCDwarf.h"
27#include "llvm/MC/MCSection.h"
28#include "llvm/MC/MCStreamer.h"
31#include <cassert>
32#include <cstdint>
33#include <string>
34#include <utility>
35
36using namespace llvm;
37
38#define DEBUG_TYPE "dwarfdebug"
39
42 : DwarfExpression(AP.getDwarfVersion(), CU), AP(AP), OutDIE(DIE) {}
43
44void DIEDwarfExpression::emitOp(uint8_t Op, const char* Comment) {
45 CU.addUInt(getActiveDIE(), dwarf::DW_FORM_data1, Op);
46}
47
48void DIEDwarfExpression::emitSigned(int64_t Value) {
49 CU.addSInt(getActiveDIE(), dwarf::DW_FORM_sdata, Value);
50}
51
52void DIEDwarfExpression::emitUnsigned(uint64_t Value) {
53 CU.addUInt(getActiveDIE(), dwarf::DW_FORM_udata, Value);
54}
55
56void DIEDwarfExpression::emitData1(uint8_t Value) {
57 CU.addUInt(getActiveDIE(), dwarf::DW_FORM_data1, Value);
58}
59
60void DIEDwarfExpression::emitBaseTypeRef(uint64_t Idx) {
61 CU.addBaseTypeRef(getActiveDIE(), Idx);
62}
63
64void DIEDwarfExpression::enableTemporaryBuffer() {
65 assert(!IsBuffering && "Already buffering?");
66 IsBuffering = true;
67}
68
69void DIEDwarfExpression::disableTemporaryBuffer() { IsBuffering = false; }
70
71unsigned DIEDwarfExpression::getTemporaryBufferSize() {
72 return TmpDIE.computeSize(AP.getDwarfFormParams());
73}
74
75void DIEDwarfExpression::commitTemporaryBuffer() { OutDIE.takeValues(TmpDIE); }
76
77bool DIEDwarfExpression::isFrameRegister(const TargetRegisterInfo &TRI,
78 llvm::Register MachineReg) {
79 return MachineReg == TRI.getFrameRegister(*AP.MF);
80}
81
83 AsmPrinter *A, DwarfDebug *DW, DwarfFile *DWU,
84 unsigned UniqueID)
85 : DIEUnit(UnitTag), UniqueID(UniqueID), CUNode(Node), Asm(A), DD(DW),
86 DU(DWU) {}
87
89 DwarfDebug *DW, DwarfFile *DWU, unsigned UniqueID,
90 MCDwarfDwoLineTable *SplitLineTable)
91 : DwarfUnit(dwarf::DW_TAG_type_unit, CU.getCUNode(), A, DW, DWU, UniqueID),
92 CU(CU), SplitLineTable(SplitLineTable) {}
93
95 for (DIEBlock *B : DIEBlocks)
96 B->~DIEBlock();
97 for (DIELoc *L : DIELocs)
98 L->~DIELoc();
99}
100
101int64_t DwarfUnit::getDefaultLowerBound() const {
102 switch (getLanguage()) {
103 default:
104 break;
105
106 // The languages below have valid values in all DWARF versions.
107 case dwarf::DW_LANG_C:
108 case dwarf::DW_LANG_C89:
109 case dwarf::DW_LANG_C_plus_plus:
110 return 0;
111
112 case dwarf::DW_LANG_Fortran77:
113 case dwarf::DW_LANG_Fortran90:
114 return 1;
115
116 // The languages below have valid values only if the DWARF version >= 3.
117 case dwarf::DW_LANG_C99:
118 case dwarf::DW_LANG_ObjC:
119 case dwarf::DW_LANG_ObjC_plus_plus:
120 if (DD->getDwarfVersion() >= 3)
121 return 0;
122 break;
123
124 case dwarf::DW_LANG_Fortran95:
125 if (DD->getDwarfVersion() >= 3)
126 return 1;
127 break;
128
129 // Starting with DWARF v4, all defined languages have valid values.
130 case dwarf::DW_LANG_D:
131 case dwarf::DW_LANG_Java:
132 case dwarf::DW_LANG_Python:
133 case dwarf::DW_LANG_UPC:
134 if (DD->getDwarfVersion() >= 4)
135 return 0;
136 break;
137
138 case dwarf::DW_LANG_Ada83:
139 case dwarf::DW_LANG_Ada95:
140 case dwarf::DW_LANG_Cobol74:
141 case dwarf::DW_LANG_Cobol85:
142 case dwarf::DW_LANG_Modula2:
143 case dwarf::DW_LANG_Pascal83:
144 case dwarf::DW_LANG_PLI:
145 if (DD->getDwarfVersion() >= 4)
146 return 1;
147 break;
148
149 // The languages below are new in DWARF v5.
150 case dwarf::DW_LANG_BLISS:
151 case dwarf::DW_LANG_C11:
152 case dwarf::DW_LANG_C_plus_plus_03:
153 case dwarf::DW_LANG_C_plus_plus_11:
154 case dwarf::DW_LANG_C_plus_plus_14:
155 case dwarf::DW_LANG_Dylan:
156 case dwarf::DW_LANG_Go:
157 case dwarf::DW_LANG_Haskell:
158 case dwarf::DW_LANG_OCaml:
159 case dwarf::DW_LANG_OpenCL:
160 case dwarf::DW_LANG_RenderScript:
161 case dwarf::DW_LANG_Rust:
162 case dwarf::DW_LANG_Swift:
163 if (DD->getDwarfVersion() >= 5)
164 return 0;
165 break;
166
167 case dwarf::DW_LANG_Fortran03:
168 case dwarf::DW_LANG_Fortran08:
169 case dwarf::DW_LANG_Julia:
170 case dwarf::DW_LANG_Modula3:
171 if (DD->getDwarfVersion() >= 5)
172 return 1;
173 break;
174 }
175
176 return -1;
177}
178
179/// Check whether the DIE for this MDNode can be shared across CUs.
181 // When the MDNode can be part of the type system, the DIE can be shared
182 // across CUs.
183 // Combining type units and cross-CU DIE sharing is lower value (since
184 // cross-CU DIE sharing is used in LTO and removes type redundancy at that
185 // level already) but may be implementable for some value in projects
186 // building multiple independent libraries with LTO and then linking those
187 // together.
188 if (isDwoUnit() && !DD->shareAcrossDWOCUs())
189 return false;
190 return (isa<DIType>(D) ||
191 (isa<DISubprogram>(D) && !cast<DISubprogram>(D)->isDefinition())) &&
193}
194
197 return DU->getDIE(D);
198 return MDNodeToDieMap.lookup(D);
199}
200
203 DU->insertDIE(Desc, D);
204 return;
205 }
206 MDNodeToDieMap.insert(std::make_pair(Desc, D));
207}
208
210 MDNodeToDieMap.insert(std::make_pair(nullptr, D));
211}
212
214 if (DD->getDwarfVersion() >= 4)
215 addAttribute(Die, Attribute, dwarf::DW_FORM_flag_present, DIEInteger(1));
216 else
217 addAttribute(Die, Attribute, dwarf::DW_FORM_flag, DIEInteger(1));
218}
219
221 std::optional<dwarf::Form> Form, uint64_t Integer) {
222 if (!Form)
224 assert(Form != dwarf::DW_FORM_implicit_const &&
225 "DW_FORM_implicit_const is used only for signed integers");
227}
228
232}
233
235 std::optional<dwarf::Form> Form, int64_t Integer) {
236 if (!Form)
239}
240
241void DwarfUnit::addSInt(DIELoc &Die, std::optional<dwarf::Form> Form,
242 int64_t Integer) {
244}
245
249 return;
250
251 if (DD->useInlineStrings()) {
252 addAttribute(Die, Attribute, dwarf::DW_FORM_string,
255 return;
256 }
257 dwarf::Form IxForm =
258 isDwoUnit() ? dwarf::DW_FORM_GNU_str_index : dwarf::DW_FORM_strp;
259
260 auto StringPoolEntry =
261 useSegmentedStringOffsetsTable() || IxForm == dwarf::DW_FORM_GNU_str_index
264
265 // For DWARF v5 and beyond, use the smallest strx? form possible.
267 IxForm = dwarf::DW_FORM_strx1;
268 unsigned Index = StringPoolEntry.getIndex();
269 if (Index > 0xffffff)
270 IxForm = dwarf::DW_FORM_strx4;
271 else if (Index > 0xffff)
272 IxForm = dwarf::DW_FORM_strx3;
273 else if (Index > 0xff)
274 IxForm = dwarf::DW_FORM_strx2;
275 }
276 addAttribute(Die, Attribute, IxForm, DIEString(StringPoolEntry));
277}
278
280 dwarf::Form Form, const MCSymbol *Label) {
281 addAttribute(Die, Attribute, Form, DIELabel(Label));
282}
283
285 addLabel(Die, (dwarf::Attribute)0, Form, Label);
286}
287
291}
292
293unsigned DwarfTypeUnit::getOrCreateSourceID(const DIFile *File) {
294 if (!SplitLineTable)
295 return getCU().getOrCreateSourceID(File);
296 if (!UsedLineTable) {
297 UsedLineTable = true;
298 // This is a split type unit that needs a line table.
299 addSectionOffset(getUnitDie(), dwarf::DW_AT_stmt_list, 0);
300 }
301 return SplitLineTable->getFile(
302 File->getDirectory(), File->getFilename(), DD->getMD5AsBytes(File),
303 Asm->OutContext.getDwarfVersion(), File->getSource());
304}
305
307 bool UseAddrOffsetFormOrExpressions =
309
310 const MCSymbol *Base = nullptr;
311 if (Label->isInSection() && UseAddrOffsetFormOrExpressions)
312 Base = DD->getSectionLabel(&Label->getSection());
313
315
316 if (DD->getDwarfVersion() >= 5) {
317 addUInt(Die, dwarf::DW_FORM_data1, dwarf::DW_OP_addrx);
318 addUInt(Die, dwarf::DW_FORM_addrx, Index);
319 } else {
320 addUInt(Die, dwarf::DW_FORM_data1, dwarf::DW_OP_GNU_addr_index);
321 addUInt(Die, dwarf::DW_FORM_GNU_addr_index, Index);
322 }
323
324 if (Base && Base != Label) {
325 addUInt(Die, dwarf::DW_FORM_data1, dwarf::DW_OP_const4u);
326 addLabelDelta(Die, (dwarf::Attribute)0, Label, Base);
327 addUInt(Die, dwarf::DW_FORM_data1, dwarf::DW_OP_plus);
328 }
329}
330
332 if (DD->getDwarfVersion() >= 5) {
333 addPoolOpAddress(Die, Sym);
334 return;
335 }
336
337 if (DD->useSplitDwarf()) {
338 addPoolOpAddress(Die, Sym);
339 return;
340 }
341
342 addUInt(Die, dwarf::DW_FORM_data1, dwarf::DW_OP_addr);
343 addLabel(Die, dwarf::DW_FORM_addr, Sym);
344}
345
347 const MCSymbol *Hi, const MCSymbol *Lo) {
348 addAttribute(Die, Attribute, dwarf::DW_FORM_data4,
350}
351
353 addDIEEntry(Die, Attribute, DIEEntry(Entry));
354}
355
357 // Flag the type unit reference as a declaration so that if it contains
358 // members (implicit special members, static data member definitions, member
359 // declarations for definitions in this CU, etc) consumers don't get confused
360 // and think this is a full definition.
361 addFlag(Die, dwarf::DW_AT_declaration);
362
363 addAttribute(Die, dwarf::DW_AT_signature, dwarf::DW_FORM_ref_sig8,
364 DIEInteger(Signature));
365}
366
368 DIEEntry Entry) {
369 const DIEUnit *CU = Die.getUnit();
370 const DIEUnit *EntryCU = Entry.getEntry().getUnit();
371 if (!CU)
372 // We assume that Die belongs to this CU, if it is not linked to any CU yet.
373 CU = getUnitDie().getUnit();
374 if (!EntryCU)
375 EntryCU = getUnitDie().getUnit();
376 assert(EntryCU == CU || !DD->useSplitDwarf() || DD->shareAcrossDWOCUs() ||
377 !static_cast<const DwarfUnit*>(CU)->isDwoUnit());
379 EntryCU == CU ? dwarf::DW_FORM_ref4 : dwarf::DW_FORM_ref_addr,
380 Entry);
381}
382
384 DIE &Die = Parent.addChild(DIE::get(DIEValueAllocator, Tag));
385 if (N)
386 insertDIE(N, &Die);
387 return Die;
388}
389
392 DIELocs.push_back(Loc); // Memoize so we can call the destructor later on.
393 addAttribute(Die, Attribute, Loc->BestForm(DD->getDwarfVersion()), Loc);
394}
395
397 DIEBlock *Block) {
398 Block->computeSize(Asm->getDwarfFormParams());
399 DIEBlocks.push_back(Block); // Memoize so we can call the destructor later on.
401}
402
404 DIEBlock *Block) {
405 addBlock(Die, Attribute, Block->BestForm(), Block);
406}
407
408void DwarfUnit::addSourceLine(DIE &Die, unsigned Line, const DIFile *File) {
409 if (Line == 0)
410 return;
411
412 unsigned FileID = getOrCreateSourceID(File);
413 addUInt(Die, dwarf::DW_AT_decl_file, std::nullopt, FileID);
414 addUInt(Die, dwarf::DW_AT_decl_line, std::nullopt, Line);
415}
416
418 assert(V);
419
420 addSourceLine(Die, V->getLine(), V->getFile());
421}
422
424 assert(G);
425
426 addSourceLine(Die, G->getLine(), G->getFile());
427}
428
430 assert(SP);
431
432 addSourceLine(Die, SP->getLine(), SP->getFile());
433}
434
436 assert(L);
437
438 addSourceLine(Die, L->getLine(), L->getFile());
439}
440
441void DwarfUnit::addSourceLine(DIE &Die, const DIType *Ty) {
442 assert(Ty);
443
444 addSourceLine(Die, Ty->getLine(), Ty->getFile());
445}
446
448 assert(Ty);
449
450 addSourceLine(Die, Ty->getLine(), Ty->getFile());
451}
452
454 // Pass this down to addConstantValue as an unsigned bag of bits.
455 addConstantValue(Die, CFP->getValueAPF().bitcastToAPInt(), true);
456}
457
459 const DIType *Ty) {
460 addConstantValue(Die, CI->getValue(), Ty);
461}
462
463void DwarfUnit::addConstantValue(DIE &Die, uint64_t Val, const DIType *Ty) {
464 addConstantValue(Die, DD->isUnsignedDIType(Ty), Val);
465}
466
468 // FIXME: This is a bit conservative/simple - it emits negative values always
469 // sign extended to 64 bits rather than minimizing the number of bytes.
470 addUInt(Die, dwarf::DW_AT_const_value,
471 Unsigned ? dwarf::DW_FORM_udata : dwarf::DW_FORM_sdata, Val);
472}
473
474void DwarfUnit::addConstantValue(DIE &Die, const APInt &Val, const DIType *Ty) {
475 addConstantValue(Die, Val, DD->isUnsignedDIType(Ty));
476}
477
478void DwarfUnit::addConstantValue(DIE &Die, const APInt &Val, bool Unsigned) {
479 unsigned CIBitWidth = Val.getBitWidth();
480 if (CIBitWidth <= 64) {
482 Unsigned ? Val.getZExtValue() : Val.getSExtValue());
483 return;
484 }
485
487
488 // Get the raw data form of the large APInt.
489 const uint64_t *Ptr64 = Val.getRawData();
490
491 int NumBytes = Val.getBitWidth() / 8; // 8 bits per byte.
492 bool LittleEndian = Asm->getDataLayout().isLittleEndian();
493
494 // Output the constant to DWARF one byte at a time.
495 for (int i = 0; i < NumBytes; i++) {
496 uint8_t c;
497 if (LittleEndian)
498 c = Ptr64[i / 8] >> (8 * (i & 7));
499 else
500 c = Ptr64[(NumBytes - 1 - i) / 8] >> (8 * ((NumBytes - 1 - i) & 7));
501 addUInt(*Block, dwarf::DW_FORM_data1, c);
502 }
503
504 addBlock(Die, dwarf::DW_AT_const_value, Block);
505}
506
508 if (!LinkageName.empty())
509 addString(Die,
510 DD->getDwarfVersion() >= 4 ? dwarf::DW_AT_linkage_name
511 : dwarf::DW_AT_MIPS_linkage_name,
513}
514
515void DwarfUnit::addTemplateParams(DIE &Buffer, DINodeArray TParams) {
516 // Add template parameters.
517 for (const auto *Element : TParams) {
518 if (auto *TTP = dyn_cast<DITemplateTypeParameter>(Element))
519 constructTemplateTypeParameterDIE(Buffer, TTP);
520 else if (auto *TVP = dyn_cast<DITemplateValueParameter>(Element))
521 constructTemplateValueParameterDIE(Buffer, TVP);
522 }
523}
524
525/// Add thrown types.
526void DwarfUnit::addThrownTypes(DIE &Die, DINodeArray ThrownTypes) {
527 for (const auto *Ty : ThrownTypes) {
528 DIE &TT = createAndAddDIE(dwarf::DW_TAG_thrown_type, Die);
529 addType(TT, cast<DIType>(Ty));
530 }
531}
532
534 if ((Flags & DINode::FlagAccessibility) == DINode::FlagProtected)
535 addUInt(Die, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,
537 else if ((Flags & DINode::FlagAccessibility) == DINode::FlagPrivate)
538 addUInt(Die, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,
540 else if ((Flags & DINode::FlagAccessibility) == DINode::FlagPublic)
541 addUInt(Die, dwarf::DW_AT_accessibility, dwarf::DW_FORM_data1,
543}
544
546 if (!Context || isa<DIFile>(Context) || isa<DICompileUnit>(Context))
547 return &getUnitDie();
548 if (auto *T = dyn_cast<DIType>(Context))
549 return getOrCreateTypeDIE(T);
550 if (auto *NS = dyn_cast<DINamespace>(Context))
551 return getOrCreateNameSpace(NS);
552 if (auto *SP = dyn_cast<DISubprogram>(Context))
553 return getOrCreateSubprogramDIE(SP);
554 if (auto *M = dyn_cast<DIModule>(Context))
555 return getOrCreateModule(M);
556 return getDIE(Context);
557}
558
560 auto *Context = Ty->getScope();
561 DIE *ContextDIE = getOrCreateContextDIE(Context);
562
563 if (DIE *TyDIE = getDIE(Ty))
564 return TyDIE;
565
566 // Create new type.
567 DIE &TyDIE = createAndAddDIE(Ty->getTag(), *ContextDIE, Ty);
568
569 constructTypeDIE(TyDIE, cast<DICompositeType>(Ty));
570
571 updateAcceleratorTables(Context, Ty, TyDIE);
572 return &TyDIE;
573}
574
575DIE *DwarfUnit::createTypeDIE(const DIScope *Context, DIE &ContextDIE,
576 const DIType *Ty) {
577 // Create new type.
578 DIE &TyDIE = createAndAddDIE(Ty->getTag(), ContextDIE, Ty);
579
580 updateAcceleratorTables(Context, Ty, TyDIE);
581
582 if (auto *BT = dyn_cast<DIBasicType>(Ty))
583 constructTypeDIE(TyDIE, BT);
584 else if (auto *ST = dyn_cast<DIStringType>(Ty))
585 constructTypeDIE(TyDIE, ST);
586 else if (auto *STy = dyn_cast<DISubroutineType>(Ty))
587 constructTypeDIE(TyDIE, STy);
588 else if (auto *CTy = dyn_cast<DICompositeType>(Ty)) {
589 if (DD->generateTypeUnits() && !Ty->isForwardDecl() &&
590 (Ty->getRawName() || CTy->getRawIdentifier())) {
591 // Skip updating the accelerator tables since this is not the full type.
592 if (MDString *TypeId = CTy->getRawIdentifier())
593 DD->addDwarfTypeUnitType(getCU(), TypeId->getString(), TyDIE, CTy);
594 else
595 finishNonUnitTypeDIE(TyDIE, CTy);
596 return &TyDIE;
597 }
598 constructTypeDIE(TyDIE, CTy);
599 } else {
600 constructTypeDIE(TyDIE, cast<DIDerivedType>(Ty));
601 }
602
603 return &TyDIE;
604}
605
607 if (!TyNode)
608 return nullptr;
609
610 auto *Ty = cast<DIType>(TyNode);
611
612 // DW_TAG_restrict_type is not supported in DWARF2
613 if (Ty->getTag() == dwarf::DW_TAG_restrict_type && DD->getDwarfVersion() <= 2)
614 return getOrCreateTypeDIE(cast<DIDerivedType>(Ty)->getBaseType());
615
616 // DW_TAG_atomic_type is not supported in DWARF < 5
617 if (Ty->getTag() == dwarf::DW_TAG_atomic_type && DD->getDwarfVersion() < 5)
618 return getOrCreateTypeDIE(cast<DIDerivedType>(Ty)->getBaseType());
619
620 // Construct the context before querying for the existence of the DIE in case
621 // such construction creates the DIE.
622 auto *Context = Ty->getScope();
623 DIE *ContextDIE = getOrCreateContextDIE(Context);
624 assert(ContextDIE);
625
626 if (DIE *TyDIE = getDIE(Ty))
627 return TyDIE;
628
629 return static_cast<DwarfUnit *>(ContextDIE->getUnit())
630 ->createTypeDIE(Context, *ContextDIE, Ty);
631}
632
633void DwarfUnit::updateAcceleratorTables(const DIScope *Context,
634 const DIType *Ty, const DIE &TyDIE) {
635 if (!Ty->getName().empty() && !Ty->isForwardDecl()) {
636 bool IsImplementation = false;
637 if (auto *CT = dyn_cast<DICompositeType>(Ty)) {
638 // A runtime language of 0 actually means C/C++ and that any
639 // non-negative value is some version of Objective-C/C++.
640 IsImplementation = CT->getRuntimeLang() == 0 || CT->isObjcClassComplete();
641 }
642 unsigned Flags = IsImplementation ? dwarf::DW_FLAG_type_implementation : 0;
643 DD->addAccelType(*this, CUNode->getNameTableKind(), Ty->getName(), TyDIE,
644 Flags);
645
646 if (!Context || isa<DICompileUnit>(Context) || isa<DIFile>(Context) ||
647 isa<DINamespace>(Context) || isa<DICommonBlock>(Context))
648 addGlobalType(Ty, TyDIE, Context);
649 }
650}
651
652void DwarfUnit::addType(DIE &Entity, const DIType *Ty,
654 assert(Ty && "Trying to add a type that doesn't exist?");
656}
657
658std::string DwarfUnit::getParentContextString(const DIScope *Context) const {
659 if (!Context)
660 return "";
661
662 // FIXME: Decide whether to implement this for non-C++ languages.
664 return "";
665
666 std::string CS;
668 while (!isa<DICompileUnit>(Context)) {
669 Parents.push_back(Context);
670 if (const DIScope *S = Context->getScope())
671 Context = S;
672 else
673 // Structure, etc types will have a NULL context if they're at the top
674 // level.
675 break;
676 }
677
678 // Reverse iterate over our list to go from the outermost construct to the
679 // innermost.
680 for (const DIScope *Ctx : llvm::reverse(Parents)) {
681 StringRef Name = Ctx->getName();
682 if (Name.empty() && isa<DINamespace>(Ctx))
683 Name = "(anonymous namespace)";
684 if (!Name.empty()) {
685 CS += Name;
686 CS += "::";
687 }
688 }
689 return CS;
690}
691
692void DwarfUnit::constructTypeDIE(DIE &Buffer, const DIBasicType *BTy) {
693 // Get core information.
694 StringRef Name = BTy->getName();
695 // Add name if not anonymous or intermediate type.
696 if (!Name.empty())
697 addString(Buffer, dwarf::DW_AT_name, Name);
698
699 // An unspecified type only has a name attribute.
700 if (BTy->getTag() == dwarf::DW_TAG_unspecified_type)
701 return;
702
703 if (BTy->getTag() != dwarf::DW_TAG_string_type)
704 addUInt(Buffer, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1,
705 BTy->getEncoding());
706
707 uint64_t Size = BTy->getSizeInBits() >> 3;
708 addUInt(Buffer, dwarf::DW_AT_byte_size, std::nullopt, Size);
709
710 if (BTy->isBigEndian())
711 addUInt(Buffer, dwarf::DW_AT_endianity, std::nullopt, dwarf::DW_END_big);
712 else if (BTy->isLittleEndian())
713 addUInt(Buffer, dwarf::DW_AT_endianity, std::nullopt, dwarf::DW_END_little);
714}
715
716void DwarfUnit::constructTypeDIE(DIE &Buffer, const DIStringType *STy) {
717 // Get core information.
718 StringRef Name = STy->getName();
719 // Add name if not anonymous or intermediate type.
720 if (!Name.empty())
721 addString(Buffer, dwarf::DW_AT_name, Name);
722
723 if (DIVariable *Var = STy->getStringLength()) {
724 if (auto *VarDIE = getDIE(Var))
725 addDIEEntry(Buffer, dwarf::DW_AT_string_length, *VarDIE);
726 } else if (DIExpression *Expr = STy->getStringLengthExp()) {
727 DIELoc *Loc = new (DIEValueAllocator) DIELoc;
728 DIEDwarfExpression DwarfExpr(*Asm, getCU(), *Loc);
729 // This is to describe the memory location of the
730 // length of a Fortran deferred length string, so
731 // lock it down as such.
732 DwarfExpr.setMemoryLocationKind();
733 DwarfExpr.addExpression(Expr);
734 addBlock(Buffer, dwarf::DW_AT_string_length, DwarfExpr.finalize());
735 } else {
736 uint64_t Size = STy->getSizeInBits() >> 3;
737 addUInt(Buffer, dwarf::DW_AT_byte_size, std::nullopt, Size);
738 }
739
740 if (DIExpression *Expr = STy->getStringLocationExp()) {
741 DIELoc *Loc = new (DIEValueAllocator) DIELoc;
742 DIEDwarfExpression DwarfExpr(*Asm, getCU(), *Loc);
743 // This is to describe the memory location of the
744 // string, so lock it down as such.
745 DwarfExpr.setMemoryLocationKind();
746 DwarfExpr.addExpression(Expr);
747 addBlock(Buffer, dwarf::DW_AT_data_location, DwarfExpr.finalize());
748 }
749
750 if (STy->getEncoding()) {
751 // For eventual Unicode support.
752 addUInt(Buffer, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1,
753 STy->getEncoding());
754 }
755}
756
757void DwarfUnit::constructTypeDIE(DIE &Buffer, const DIDerivedType *DTy) {
758 // Get core information.
759 StringRef Name = DTy->getName();
760 uint64_t Size = DTy->getSizeInBits() >> 3;
761 uint16_t Tag = Buffer.getTag();
762
763 // Map to main type, void will not have a type.
764 const DIType *FromTy = DTy->getBaseType();
765 if (FromTy)
766 addType(Buffer, FromTy);
767
768 // Add name if not anonymous or intermediate type.
769 if (!Name.empty())
770 addString(Buffer, dwarf::DW_AT_name, Name);
771
772 addAnnotation(Buffer, DTy->getAnnotations());
773
774 // If alignment is specified for a typedef , create and insert DW_AT_alignment
775 // attribute in DW_TAG_typedef DIE.
776 if (Tag == dwarf::DW_TAG_typedef && DD->getDwarfVersion() >= 5) {
777 uint32_t AlignInBytes = DTy->getAlignInBytes();
778 if (AlignInBytes > 0)
779 addUInt(Buffer, dwarf::DW_AT_alignment, dwarf::DW_FORM_udata,
780 AlignInBytes);
781 }
782
783 // Add size if non-zero (derived types might be zero-sized.)
784 if (Size && Tag != dwarf::DW_TAG_pointer_type
785 && Tag != dwarf::DW_TAG_ptr_to_member_type
786 && Tag != dwarf::DW_TAG_reference_type
787 && Tag != dwarf::DW_TAG_rvalue_reference_type)
788 addUInt(Buffer, dwarf::DW_AT_byte_size, std::nullopt, Size);
789
790 if (Tag == dwarf::DW_TAG_ptr_to_member_type)
791 addDIEEntry(Buffer, dwarf::DW_AT_containing_type,
792 *getOrCreateTypeDIE(cast<DIDerivedType>(DTy)->getClassType()));
793
794 addAccess(Buffer, DTy->getFlags());
795
796 // Add source line info if available and TyDesc is not a forward declaration.
797 if (!DTy->isForwardDecl())
798 addSourceLine(Buffer, DTy);
799
800 // If DWARF address space value is other than None, add it. The IR
801 // verifier checks that DWARF address space only exists for pointer
802 // or reference types.
803 if (DTy->getDWARFAddressSpace())
804 addUInt(Buffer, dwarf::DW_AT_address_class, dwarf::DW_FORM_data4,
805 *DTy->getDWARFAddressSpace());
806 if (auto PtrAuthData = DTy->getPtrAuthData()) {
807 addUInt(Buffer, dwarf::DW_AT_LLVM_ptrauth_key, dwarf::DW_FORM_data1,
808 PtrAuthData->key());
809 if (PtrAuthData->isAddressDiscriminated())
810 addFlag(Buffer, dwarf::DW_AT_LLVM_ptrauth_address_discriminated);
811 addUInt(Buffer, dwarf::DW_AT_LLVM_ptrauth_extra_discriminator,
812 dwarf::DW_FORM_data2, PtrAuthData->extraDiscriminator());
813 if (PtrAuthData->isaPointer())
814 addFlag(Buffer, dwarf::DW_AT_LLVM_ptrauth_isa_pointer);
815 if (PtrAuthData->authenticatesNullValues())
816 addFlag(Buffer, dwarf::DW_AT_LLVM_ptrauth_authenticates_null_values);
817 }
818}
819
821 for (unsigned i = 1, N = Args.size(); i < N; ++i) {
822 const DIType *Ty = Args[i];
823 if (!Ty) {
824 assert(i == N-1 && "Unspecified parameter must be the last argument");
825 createAndAddDIE(dwarf::DW_TAG_unspecified_parameters, Buffer);
826 } else {
827 DIE &Arg = createAndAddDIE(dwarf::DW_TAG_formal_parameter, Buffer);
828 addType(Arg, Ty);
829 if (Ty->isArtificial())
830 addFlag(Arg, dwarf::DW_AT_artificial);
831 }
832 }
833}
834
835void DwarfUnit::constructTypeDIE(DIE &Buffer, const DISubroutineType *CTy) {
836 // Add return type. A void return won't have a type.
837 auto Elements = cast<DISubroutineType>(CTy)->getTypeArray();
838 if (Elements.size())
839 if (auto RTy = Elements[0])
840 addType(Buffer, RTy);
841
842 bool isPrototyped = true;
843 if (Elements.size() == 2 && !Elements[1])
844 isPrototyped = false;
845
846 constructSubprogramArguments(Buffer, Elements);
847
848 // Add prototype flag if we're dealing with a C language and the function has
849 // been prototyped.
850 if (isPrototyped && dwarf::isC((dwarf::SourceLanguage)getLanguage()))
851 addFlag(Buffer, dwarf::DW_AT_prototyped);
852
853 // Add a DW_AT_calling_convention if this has an explicit convention.
854 if (CTy->getCC() && CTy->getCC() != dwarf::DW_CC_normal)
855 addUInt(Buffer, dwarf::DW_AT_calling_convention, dwarf::DW_FORM_data1,
856 CTy->getCC());
857
858 if (CTy->isLValueReference())
859 addFlag(Buffer, dwarf::DW_AT_reference);
860
861 if (CTy->isRValueReference())
862 addFlag(Buffer, dwarf::DW_AT_rvalue_reference);
863}
864
865void DwarfUnit::addAnnotation(DIE &Buffer, DINodeArray Annotations) {
866 if (!Annotations)
867 return;
868
869 for (const Metadata *Annotation : Annotations->operands()) {
870 const MDNode *MD = cast<MDNode>(Annotation);
871 const MDString *Name = cast<MDString>(MD->getOperand(0));
872 const auto &Value = MD->getOperand(1);
873
874 DIE &AnnotationDie = createAndAddDIE(dwarf::DW_TAG_LLVM_annotation, Buffer);
875 addString(AnnotationDie, dwarf::DW_AT_name, Name->getString());
876 if (const auto *Data = dyn_cast<MDString>(Value))
877 addString(AnnotationDie, dwarf::DW_AT_const_value, Data->getString());
878 else if (const auto *Data = dyn_cast<ConstantAsMetadata>(Value))
879 addConstantValue(AnnotationDie, Data->getValue()->getUniqueInteger(),
880 /*Unsigned=*/true);
881 else
882 assert(false && "Unsupported annotation value type");
883 }
884}
885
887 // Add name if not anonymous or intermediate type.
888 StringRef Name = CTy->getName();
889
890 uint64_t Size = CTy->getSizeInBits() >> 3;
891 uint16_t Tag = Buffer.getTag();
892
893 switch (Tag) {
894 case dwarf::DW_TAG_array_type:
895 constructArrayTypeDIE(Buffer, CTy);
896 break;
897 case dwarf::DW_TAG_enumeration_type:
898 constructEnumTypeDIE(Buffer, CTy);
899 break;
900 case dwarf::DW_TAG_variant_part:
901 case dwarf::DW_TAG_structure_type:
902 case dwarf::DW_TAG_union_type:
903 case dwarf::DW_TAG_class_type:
904 case dwarf::DW_TAG_namelist: {
905 // Emit the discriminator for a variant part.
906 DIDerivedType *Discriminator = nullptr;
907 if (Tag == dwarf::DW_TAG_variant_part) {
908 Discriminator = CTy->getDiscriminator();
909 if (Discriminator) {
910 // DWARF says:
911 // If the variant part has a discriminant, the discriminant is
912 // represented by a separate debugging information entry which is
913 // a child of the variant part entry.
914 DIE &DiscMember = constructMemberDIE(Buffer, Discriminator);
915 addDIEEntry(Buffer, dwarf::DW_AT_discr, DiscMember);
916 }
917 }
918
919 // Add template parameters to a class, structure or union types.
920 if (Tag == dwarf::DW_TAG_class_type ||
921 Tag == dwarf::DW_TAG_structure_type || Tag == dwarf::DW_TAG_union_type)
922 addTemplateParams(Buffer, CTy->getTemplateParams());
923
924 // Add elements to structure type.
925 DINodeArray Elements = CTy->getElements();
926 for (const auto *Element : Elements) {
927 if (!Element)
928 continue;
929 if (auto *SP = dyn_cast<DISubprogram>(Element))
931 else if (auto *DDTy = dyn_cast<DIDerivedType>(Element)) {
932 if (DDTy->getTag() == dwarf::DW_TAG_friend) {
933 DIE &ElemDie = createAndAddDIE(dwarf::DW_TAG_friend, Buffer);
934 addType(ElemDie, DDTy->getBaseType(), dwarf::DW_AT_friend);
935 } else if (DDTy->isStaticMember()) {
937 } else if (Tag == dwarf::DW_TAG_variant_part) {
938 // When emitting a variant part, wrap each member in
939 // DW_TAG_variant.
940 DIE &Variant = createAndAddDIE(dwarf::DW_TAG_variant, Buffer);
941 if (const ConstantInt *CI =
942 dyn_cast_or_null<ConstantInt>(DDTy->getDiscriminantValue())) {
943 if (DD->isUnsignedDIType(Discriminator->getBaseType()))
944 addUInt(Variant, dwarf::DW_AT_discr_value, std::nullopt,
945 CI->getZExtValue());
946 else
947 addSInt(Variant, dwarf::DW_AT_discr_value, std::nullopt,
948 CI->getSExtValue());
949 }
950 constructMemberDIE(Variant, DDTy);
951 } else {
952 constructMemberDIE(Buffer, DDTy);
953 }
954 } else if (auto *Property = dyn_cast<DIObjCProperty>(Element)) {
955 DIE &ElemDie = createAndAddDIE(Property->getTag(), Buffer);
956 StringRef PropertyName = Property->getName();
957 addString(ElemDie, dwarf::DW_AT_APPLE_property_name, PropertyName);
958 if (Property->getType())
959 addType(ElemDie, Property->getType());
960 addSourceLine(ElemDie, Property);
961 StringRef GetterName = Property->getGetterName();
962 if (!GetterName.empty())
963 addString(ElemDie, dwarf::DW_AT_APPLE_property_getter, GetterName);
964 StringRef SetterName = Property->getSetterName();
965 if (!SetterName.empty())
966 addString(ElemDie, dwarf::DW_AT_APPLE_property_setter, SetterName);
967 if (unsigned PropertyAttributes = Property->getAttributes())
968 addUInt(ElemDie, dwarf::DW_AT_APPLE_property_attribute, std::nullopt,
969 PropertyAttributes);
970 } else if (auto *Composite = dyn_cast<DICompositeType>(Element)) {
971 if (Composite->getTag() == dwarf::DW_TAG_variant_part) {
972 DIE &VariantPart = createAndAddDIE(Composite->getTag(), Buffer);
973 constructTypeDIE(VariantPart, Composite);
974 }
975 } else if (Tag == dwarf::DW_TAG_namelist) {
976 auto *Var = dyn_cast<DINode>(Element);
977 auto *VarDIE = getDIE(Var);
978 if (VarDIE) {
979 DIE &ItemDie = createAndAddDIE(dwarf::DW_TAG_namelist_item, Buffer);
980 addDIEEntry(ItemDie, dwarf::DW_AT_namelist_item, *VarDIE);
981 }
982 }
983 }
984
985 if (CTy->isAppleBlockExtension())
986 addFlag(Buffer, dwarf::DW_AT_APPLE_block);
987
988 if (CTy->getExportSymbols())
989 addFlag(Buffer, dwarf::DW_AT_export_symbols);
990
991 // This is outside the DWARF spec, but GDB expects a DW_AT_containing_type
992 // inside C++ composite types to point to the base class with the vtable.
993 // Rust uses DW_AT_containing_type to link a vtable to the type
994 // for which it was created.
995 if (auto *ContainingType = CTy->getVTableHolder())
996 addDIEEntry(Buffer, dwarf::DW_AT_containing_type,
997 *getOrCreateTypeDIE(ContainingType));
998
999 if (CTy->isObjcClassComplete())
1000 addFlag(Buffer, dwarf::DW_AT_APPLE_objc_complete_type);
1001
1002 // Add the type's non-standard calling convention.
1003 // DW_CC_pass_by_value/DW_CC_pass_by_reference are introduced in DWARF 5.
1004 if (!Asm->TM.Options.DebugStrictDwarf || DD->getDwarfVersion() >= 5) {
1005 uint8_t CC = 0;
1006 if (CTy->isTypePassByValue())
1007 CC = dwarf::DW_CC_pass_by_value;
1008 else if (CTy->isTypePassByReference())
1009 CC = dwarf::DW_CC_pass_by_reference;
1010 if (CC)
1011 addUInt(Buffer, dwarf::DW_AT_calling_convention, dwarf::DW_FORM_data1,
1012 CC);
1013 }
1014 break;
1015 }
1016 default:
1017 break;
1018 }
1019
1020 // Add name if not anonymous or intermediate type.
1021 if (!Name.empty())
1022 addString(Buffer, dwarf::DW_AT_name, Name);
1023
1024 addAnnotation(Buffer, CTy->getAnnotations());
1025
1026 if (Tag == dwarf::DW_TAG_enumeration_type ||
1027 Tag == dwarf::DW_TAG_class_type || Tag == dwarf::DW_TAG_structure_type ||
1028 Tag == dwarf::DW_TAG_union_type) {
1029 // Add size if non-zero (derived types might be zero-sized.)
1030 // Ignore the size if it's a non-enum forward decl.
1031 // TODO: Do we care about size for enum forward declarations?
1032 if (Size &&
1033 (!CTy->isForwardDecl() || Tag == dwarf::DW_TAG_enumeration_type))
1034 addUInt(Buffer, dwarf::DW_AT_byte_size, std::nullopt, Size);
1035 else if (!CTy->isForwardDecl())
1036 // Add zero size if it is not a forward declaration.
1037 addUInt(Buffer, dwarf::DW_AT_byte_size, std::nullopt, 0);
1038
1039 // If we're a forward decl, say so.
1040 if (CTy->isForwardDecl())
1041 addFlag(Buffer, dwarf::DW_AT_declaration);
1042
1043 // Add accessibility info if available.
1044 addAccess(Buffer, CTy->getFlags());
1045
1046 // Add source line info if available.
1047 if (!CTy->isForwardDecl())
1048 addSourceLine(Buffer, CTy);
1049
1050 // No harm in adding the runtime language to the declaration.
1051 unsigned RLang = CTy->getRuntimeLang();
1052 if (RLang)
1053 addUInt(Buffer, dwarf::DW_AT_APPLE_runtime_class, dwarf::DW_FORM_data1,
1054 RLang);
1055
1056 // Add align info if available.
1057 if (uint32_t AlignInBytes = CTy->getAlignInBytes())
1058 addUInt(Buffer, dwarf::DW_AT_alignment, dwarf::DW_FORM_udata,
1059 AlignInBytes);
1060 }
1061}
1062
1063void DwarfUnit::constructTemplateTypeParameterDIE(
1064 DIE &Buffer, const DITemplateTypeParameter *TP) {
1065 DIE &ParamDIE =
1066 createAndAddDIE(dwarf::DW_TAG_template_type_parameter, Buffer);
1067 // Add the type if it exists, it could be void and therefore no type.
1068 if (TP->getType())
1069 addType(ParamDIE, TP->getType());
1070 if (!TP->getName().empty())
1071 addString(ParamDIE, dwarf::DW_AT_name, TP->getName());
1072 if (TP->isDefault() && isCompatibleWithVersion(5))
1073 addFlag(ParamDIE, dwarf::DW_AT_default_value);
1074}
1075
1076void DwarfUnit::constructTemplateValueParameterDIE(
1077 DIE &Buffer, const DITemplateValueParameter *VP) {
1078 DIE &ParamDIE = createAndAddDIE(VP->getTag(), Buffer);
1079
1080 // Add the type if there is one, template template and template parameter
1081 // packs will not have a type.
1082 if (VP->getTag() == dwarf::DW_TAG_template_value_parameter)
1083 addType(ParamDIE, VP->getType());
1084 if (!VP->getName().empty())
1085 addString(ParamDIE, dwarf::DW_AT_name, VP->getName());
1086 if (VP->isDefault() && isCompatibleWithVersion(5))
1087 addFlag(ParamDIE, dwarf::DW_AT_default_value);
1088 if (Metadata *Val = VP->getValue()) {
1089 if (ConstantInt *CI = mdconst::dyn_extract<ConstantInt>(Val))
1090 addConstantValue(ParamDIE, CI, VP->getType());
1091 else if (GlobalValue *GV = mdconst::dyn_extract<GlobalValue>(Val)) {
1092 // We cannot describe the location of dllimport'd entities: the
1093 // computation of their address requires loads from the IAT.
1094 if (!GV->hasDLLImportStorageClass()) {
1095 // For declaration non-type template parameters (such as global values
1096 // and functions)
1097 DIELoc *Loc = new (DIEValueAllocator) DIELoc;
1098 addOpAddress(*Loc, Asm->getSymbol(GV));
1099 // Emit DW_OP_stack_value to use the address as the immediate value of
1100 // the parameter, rather than a pointer to it.
1101 addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_stack_value);
1102 addBlock(ParamDIE, dwarf::DW_AT_location, Loc);
1103 }
1104 } else if (VP->getTag() == dwarf::DW_TAG_GNU_template_template_param) {
1105 assert(isa<MDString>(Val));
1106 addString(ParamDIE, dwarf::DW_AT_GNU_template_name,
1107 cast<MDString>(Val)->getString());
1108 } else if (VP->getTag() == dwarf::DW_TAG_GNU_template_parameter_pack) {
1109 addTemplateParams(ParamDIE, cast<MDTuple>(Val));
1110 }
1111 }
1112}
1113
1115 // Construct the context before querying for the existence of the DIE in case
1116 // such construction creates the DIE.
1117 DIE *ContextDIE = getOrCreateContextDIE(NS->getScope());
1118
1119 if (DIE *NDie = getDIE(NS))
1120 return NDie;
1121 DIE &NDie = createAndAddDIE(dwarf::DW_TAG_namespace, *ContextDIE, NS);
1122
1123 StringRef Name = NS->getName();
1124 if (!Name.empty())
1125 addString(NDie, dwarf::DW_AT_name, NS->getName());
1126 else
1127 Name = "(anonymous namespace)";
1128 DD->addAccelNamespace(*this, CUNode->getNameTableKind(), Name, NDie);
1129 addGlobalName(Name, NDie, NS->getScope());
1130 if (NS->getExportSymbols())
1131 addFlag(NDie, dwarf::DW_AT_export_symbols);
1132 return &NDie;
1133}
1134
1136 // Construct the context before querying for the existence of the DIE in case
1137 // such construction creates the DIE.
1138 DIE *ContextDIE = getOrCreateContextDIE(M->getScope());
1139
1140 if (DIE *MDie = getDIE(M))
1141 return MDie;
1142 DIE &MDie = createAndAddDIE(dwarf::DW_TAG_module, *ContextDIE, M);
1143
1144 if (!M->getName().empty()) {
1145 addString(MDie, dwarf::DW_AT_name, M->getName());
1146 addGlobalName(M->getName(), MDie, M->getScope());
1147 }
1148 if (!M->getConfigurationMacros().empty())
1149 addString(MDie, dwarf::DW_AT_LLVM_config_macros,
1150 M->getConfigurationMacros());
1151 if (!M->getIncludePath().empty())
1152 addString(MDie, dwarf::DW_AT_LLVM_include_path, M->getIncludePath());
1153 if (!M->getAPINotesFile().empty())
1154 addString(MDie, dwarf::DW_AT_LLVM_apinotes, M->getAPINotesFile());
1155 if (M->getFile())
1156 addUInt(MDie, dwarf::DW_AT_decl_file, std::nullopt,
1157 getOrCreateSourceID(M->getFile()));
1158 if (M->getLineNo())
1159 addUInt(MDie, dwarf::DW_AT_decl_line, std::nullopt, M->getLineNo());
1160 if (M->getIsDecl())
1161 addFlag(MDie, dwarf::DW_AT_declaration);
1162
1163 return &MDie;
1164}
1165
1167 // Construct the context before querying for the existence of the DIE in case
1168 // such construction creates the DIE (as is the case for member function
1169 // declarations).
1170 DIE *ContextDIE =
1171 Minimal ? &getUnitDie() : getOrCreateContextDIE(SP->getScope());
1172
1173 if (DIE *SPDie = getDIE(SP))
1174 return SPDie;
1175
1176 if (auto *SPDecl = SP->getDeclaration()) {
1177 if (!Minimal) {
1178 // Add subprogram definitions to the CU die directly.
1179 ContextDIE = &getUnitDie();
1180 // Build the decl now to ensure it precedes the definition.
1182 }
1183 }
1184
1185 // DW_TAG_inlined_subroutine may refer to this DIE.
1186 DIE &SPDie = createAndAddDIE(dwarf::DW_TAG_subprogram, *ContextDIE, SP);
1187
1188 // Stop here and fill this in later, depending on whether or not this
1189 // subprogram turns out to have inlined instances or not.
1190 if (SP->isDefinition())
1191 return &SPDie;
1192
1193 static_cast<DwarfUnit *>(SPDie.getUnit())
1194 ->applySubprogramAttributes(SP, SPDie);
1195 return &SPDie;
1196}
1197
1199 DIE &SPDie, bool Minimal) {
1200 DIE *DeclDie = nullptr;
1201 StringRef DeclLinkageName;
1202 if (auto *SPDecl = SP->getDeclaration()) {
1203 if (!Minimal) {
1204 DITypeRefArray DeclArgs, DefinitionArgs;
1205 DeclArgs = SPDecl->getType()->getTypeArray();
1206 DefinitionArgs = SP->getType()->getTypeArray();
1207
1208 if (DeclArgs.size() && DefinitionArgs.size())
1209 if (DefinitionArgs[0] != nullptr && DeclArgs[0] != DefinitionArgs[0])
1210 addType(SPDie, DefinitionArgs[0]);
1211
1212 DeclDie = getDIE(SPDecl);
1213 assert(DeclDie && "This DIE should've already been constructed when the "
1214 "definition DIE was created in "
1215 "getOrCreateSubprogramDIE");
1216 // Look at the Decl's linkage name only if we emitted it.
1217 if (DD->useAllLinkageNames())
1218 DeclLinkageName = SPDecl->getLinkageName();
1219 unsigned DeclID = getOrCreateSourceID(SPDecl->getFile());
1220 unsigned DefID = getOrCreateSourceID(SP->getFile());
1221 if (DeclID != DefID)
1222 addUInt(SPDie, dwarf::DW_AT_decl_file, std::nullopt, DefID);
1223
1224 if (SP->getLine() != SPDecl->getLine())
1225 addUInt(SPDie, dwarf::DW_AT_decl_line, std::nullopt, SP->getLine());
1226 }
1227 }
1228
1229 // Add function template parameters.
1230 addTemplateParams(SPDie, SP->getTemplateParams());
1231
1232 // Add the linkage name if we have one and it isn't in the Decl.
1233 StringRef LinkageName = SP->getLinkageName();
1234 assert(((LinkageName.empty() || DeclLinkageName.empty()) ||
1235 LinkageName == DeclLinkageName) &&
1236 "decl has a linkage name and it is different");
1237 if (DeclLinkageName.empty() &&
1238 // Always emit it for abstract subprograms.
1239 (DD->useAllLinkageNames() || DU->getAbstractScopeDIEs().lookup(SP)))
1241
1242 if (!DeclDie)
1243 return false;
1244
1245 // Refer to the function declaration where all the other attributes will be
1246 // found.
1247 addDIEEntry(SPDie, dwarf::DW_AT_specification, *DeclDie);
1248 return true;
1249}
1250
1252 bool SkipSPAttributes) {
1253 // If -fdebug-info-for-profiling is enabled, need to emit the subprogram
1254 // and its source location.
1255 bool SkipSPSourceLocation = SkipSPAttributes &&
1257 if (!SkipSPSourceLocation)
1258 if (applySubprogramDefinitionAttributes(SP, SPDie, SkipSPAttributes))
1259 return;
1260
1261 // Constructors and operators for anonymous aggregates do not have names.
1262 if (!SP->getName().empty())
1263 addString(SPDie, dwarf::DW_AT_name, SP->getName());
1264
1265 addAnnotation(SPDie, SP->getAnnotations());
1266
1267 if (!SkipSPSourceLocation)
1268 addSourceLine(SPDie, SP);
1269
1270 // Skip the rest of the attributes under -gmlt to save space.
1271 if (SkipSPAttributes)
1272 return;
1273
1274 // Add the prototype if we have a prototype and we have a C like
1275 // language.
1276 if (SP->isPrototyped() && dwarf::isC((dwarf::SourceLanguage)getLanguage()))
1277 addFlag(SPDie, dwarf::DW_AT_prototyped);
1278
1279 if (SP->isObjCDirect())
1280 addFlag(SPDie, dwarf::DW_AT_APPLE_objc_direct);
1281
1282 unsigned CC = 0;
1283 DITypeRefArray Args;
1284 if (const DISubroutineType *SPTy = SP->getType()) {
1285 Args = SPTy->getTypeArray();
1286 CC = SPTy->getCC();
1287 }
1288
1289 // Add a DW_AT_calling_convention if this has an explicit convention.
1290 if (CC && CC != dwarf::DW_CC_normal)
1291 addUInt(SPDie, dwarf::DW_AT_calling_convention, dwarf::DW_FORM_data1, CC);
1292
1293 // Add a return type. If this is a type like a C/C++ void type we don't add a
1294 // return type.
1295 if (Args.size())
1296 if (auto Ty = Args[0])
1297 addType(SPDie, Ty);
1298
1299 unsigned VK = SP->getVirtuality();
1300 if (VK) {
1301 addUInt(SPDie, dwarf::DW_AT_virtuality, dwarf::DW_FORM_data1, VK);
1302 if (SP->getVirtualIndex() != -1u) {
1303 DIELoc *Block = getDIELoc();
1304 addUInt(*Block, dwarf::DW_FORM_data1, dwarf::DW_OP_constu);
1305 addUInt(*Block, dwarf::DW_FORM_udata, SP->getVirtualIndex());
1306 addBlock(SPDie, dwarf::DW_AT_vtable_elem_location, Block);
1307 }
1308 ContainingTypeMap.insert(std::make_pair(&SPDie, SP->getContainingType()));
1309 }
1310
1311 if (!SP->isDefinition()) {
1312 addFlag(SPDie, dwarf::DW_AT_declaration);
1313
1314 // Add arguments. Do not add arguments for subprogram definition. They will
1315 // be handled while processing variables.
1316 constructSubprogramArguments(SPDie, Args);
1317 }
1318
1319 addThrownTypes(SPDie, SP->getThrownTypes());
1320
1321 if (SP->isArtificial())
1322 addFlag(SPDie, dwarf::DW_AT_artificial);
1323
1324 if (!SP->isLocalToUnit())
1325 addFlag(SPDie, dwarf::DW_AT_external);
1326
1328 if (SP->isOptimized())
1329 addFlag(SPDie, dwarf::DW_AT_APPLE_optimized);
1330
1331 if (unsigned isa = Asm->getISAEncoding())
1332 addUInt(SPDie, dwarf::DW_AT_APPLE_isa, dwarf::DW_FORM_flag, isa);
1333 }
1334
1335 if (SP->isLValueReference())
1336 addFlag(SPDie, dwarf::DW_AT_reference);
1337
1338 if (SP->isRValueReference())
1339 addFlag(SPDie, dwarf::DW_AT_rvalue_reference);
1340
1341 if (SP->isNoReturn())
1342 addFlag(SPDie, dwarf::DW_AT_noreturn);
1343
1344 addAccess(SPDie, SP->getFlags());
1345
1346 if (SP->isExplicit())
1347 addFlag(SPDie, dwarf::DW_AT_explicit);
1348
1349 if (SP->isMainSubprogram())
1350 addFlag(SPDie, dwarf::DW_AT_main_subprogram);
1351 if (SP->isPure())
1352 addFlag(SPDie, dwarf::DW_AT_pure);
1353 if (SP->isElemental())
1354 addFlag(SPDie, dwarf::DW_AT_elemental);
1355 if (SP->isRecursive())
1356 addFlag(SPDie, dwarf::DW_AT_recursive);
1357
1358 if (!SP->getTargetFuncName().empty())
1359 addString(SPDie, dwarf::DW_AT_trampoline, SP->getTargetFuncName());
1360
1361 if (DD->getDwarfVersion() >= 5 && SP->isDeleted())
1362 addFlag(SPDie, dwarf::DW_AT_deleted);
1363}
1364
1365void DwarfUnit::constructSubrangeDIE(DIE &Buffer, const DISubrange *SR,
1366 DIE *IndexTy) {
1367 DIE &DW_Subrange = createAndAddDIE(dwarf::DW_TAG_subrange_type, Buffer);
1368 addDIEEntry(DW_Subrange, dwarf::DW_AT_type, *IndexTy);
1369
1370 // The LowerBound value defines the lower bounds which is typically zero for
1371 // C/C++. The Count value is the number of elements. Values are 64 bit. If
1372 // Count == -1 then the array is unbounded and we do not emit
1373 // DW_AT_lower_bound and DW_AT_count attributes.
1374 int64_t DefaultLowerBound = getDefaultLowerBound();
1375
1376 auto AddBoundTypeEntry = [&](dwarf::Attribute Attr,
1377 DISubrange::BoundType Bound) -> void {
1378 if (auto *BV = dyn_cast_if_present<DIVariable *>(Bound)) {
1379 if (auto *VarDIE = getDIE(BV))
1380 addDIEEntry(DW_Subrange, Attr, *VarDIE);
1381 } else if (auto *BE = dyn_cast_if_present<DIExpression *>(Bound)) {
1382 DIELoc *Loc = new (DIEValueAllocator) DIELoc;
1383 DIEDwarfExpression DwarfExpr(*Asm, getCU(), *Loc);
1384 DwarfExpr.setMemoryLocationKind();
1385 DwarfExpr.addExpression(BE);
1386 addBlock(DW_Subrange, Attr, DwarfExpr.finalize());
1387 } else if (auto *BI = dyn_cast_if_present<ConstantInt *>(Bound)) {
1388 if (Attr == dwarf::DW_AT_count) {
1389 if (BI->getSExtValue() != -1)
1390 addUInt(DW_Subrange, Attr, std::nullopt, BI->getSExtValue());
1391 } else if (Attr != dwarf::DW_AT_lower_bound || DefaultLowerBound == -1 ||
1392 BI->getSExtValue() != DefaultLowerBound)
1393 addSInt(DW_Subrange, Attr, dwarf::DW_FORM_sdata, BI->getSExtValue());
1394 }
1395 };
1396
1397 AddBoundTypeEntry(dwarf::DW_AT_lower_bound, SR->getLowerBound());
1398
1399 AddBoundTypeEntry(dwarf::DW_AT_count, SR->getCount());
1400
1401 AddBoundTypeEntry(dwarf::DW_AT_upper_bound, SR->getUpperBound());
1402
1403 AddBoundTypeEntry(dwarf::DW_AT_byte_stride, SR->getStride());
1404}
1405
1406void DwarfUnit::constructGenericSubrangeDIE(DIE &Buffer,
1407 const DIGenericSubrange *GSR,
1408 DIE *IndexTy) {
1409 DIE &DwGenericSubrange =
1410 createAndAddDIE(dwarf::DW_TAG_generic_subrange, Buffer);
1411 addDIEEntry(DwGenericSubrange, dwarf::DW_AT_type, *IndexTy);
1412
1413 int64_t DefaultLowerBound = getDefaultLowerBound();
1414
1415 auto AddBoundTypeEntry = [&](dwarf::Attribute Attr,
1416 DIGenericSubrange::BoundType Bound) -> void {
1417 if (auto *BV = dyn_cast_if_present<DIVariable *>(Bound)) {
1418 if (auto *VarDIE = getDIE(BV))
1419 addDIEEntry(DwGenericSubrange, Attr, *VarDIE);
1420 } else if (auto *BE = dyn_cast_if_present<DIExpression *>(Bound)) {
1421 if (BE->isConstant() &&
1423 *BE->isConstant()) {
1424 if (Attr != dwarf::DW_AT_lower_bound || DefaultLowerBound == -1 ||
1425 static_cast<int64_t>(BE->getElement(1)) != DefaultLowerBound)
1426 addSInt(DwGenericSubrange, Attr, dwarf::DW_FORM_sdata,
1427 BE->getElement(1));
1428 } else {
1429 DIELoc *Loc = new (DIEValueAllocator) DIELoc;
1430 DIEDwarfExpression DwarfExpr(*Asm, getCU(), *Loc);
1431 DwarfExpr.setMemoryLocationKind();
1432 DwarfExpr.addExpression(BE);
1433 addBlock(DwGenericSubrange, Attr, DwarfExpr.finalize());
1434 }
1435 }
1436 };
1437
1438 AddBoundTypeEntry(dwarf::DW_AT_lower_bound, GSR->getLowerBound());
1439 AddBoundTypeEntry(dwarf::DW_AT_count, GSR->getCount());
1440 AddBoundTypeEntry(dwarf::DW_AT_upper_bound, GSR->getUpperBound());
1441 AddBoundTypeEntry(dwarf::DW_AT_byte_stride, GSR->getStride());
1442}
1443
1444DIE *DwarfUnit::getIndexTyDie() {
1445 if (IndexTyDie)
1446 return IndexTyDie;
1447 // Construct an integer type to use for indexes.
1448 IndexTyDie = &createAndAddDIE(dwarf::DW_TAG_base_type, getUnitDie());
1449 StringRef Name = "__ARRAY_SIZE_TYPE__";
1450 addString(*IndexTyDie, dwarf::DW_AT_name, Name);
1451 addUInt(*IndexTyDie, dwarf::DW_AT_byte_size, std::nullopt, sizeof(int64_t));
1452 addUInt(*IndexTyDie, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1,
1456 /*Flags*/ 0);
1457 return IndexTyDie;
1458}
1459
1460/// Returns true if the vector's size differs from the sum of sizes of elements
1461/// the user specified. This can occur if the vector has been rounded up to
1462/// fit memory alignment constraints.
1463static bool hasVectorBeenPadded(const DICompositeType *CTy) {
1464 assert(CTy && CTy->isVector() && "Composite type is not a vector");
1465 const uint64_t ActualSize = CTy->getSizeInBits();
1466
1467 // Obtain the size of each element in the vector.
1468 DIType *BaseTy = CTy->getBaseType();
1469 assert(BaseTy && "Unknown vector element type.");
1470 const uint64_t ElementSize = BaseTy->getSizeInBits();
1471
1472 // Locate the number of elements in the vector.
1473 const DINodeArray Elements = CTy->getElements();
1474 assert(Elements.size() == 1 &&
1475 Elements[0]->getTag() == dwarf::DW_TAG_subrange_type &&
1476 "Invalid vector element array, expected one element of type subrange");
1477 const auto Subrange = cast<DISubrange>(Elements[0]);
1478 const auto NumVecElements =
1479 Subrange->getCount()
1480 ? cast<ConstantInt *>(Subrange->getCount())->getSExtValue()
1481 : 0;
1482
1483 // Ensure we found the element count and that the actual size is wide
1484 // enough to contain the requested size.
1485 assert(ActualSize >= (NumVecElements * ElementSize) && "Invalid vector size");
1486 return ActualSize != (NumVecElements * ElementSize);
1487}
1488
1489void DwarfUnit::constructArrayTypeDIE(DIE &Buffer, const DICompositeType *CTy) {
1490 if (CTy->isVector()) {
1491 addFlag(Buffer, dwarf::DW_AT_GNU_vector);
1492 if (hasVectorBeenPadded(CTy))
1493 addUInt(Buffer, dwarf::DW_AT_byte_size, std::nullopt,
1494 CTy->getSizeInBits() / CHAR_BIT);
1495 }
1496
1497 if (DIVariable *Var = CTy->getDataLocation()) {
1498 if (auto *VarDIE = getDIE(Var))
1499 addDIEEntry(Buffer, dwarf::DW_AT_data_location, *VarDIE);
1500 } else if (DIExpression *Expr = CTy->getDataLocationExp()) {
1501 DIELoc *Loc = new (DIEValueAllocator) DIELoc;
1502 DIEDwarfExpression DwarfExpr(*Asm, getCU(), *Loc);
1503 DwarfExpr.setMemoryLocationKind();
1504 DwarfExpr.addExpression(Expr);
1505 addBlock(Buffer, dwarf::DW_AT_data_location, DwarfExpr.finalize());
1506 }
1507
1508 if (DIVariable *Var = CTy->getAssociated()) {
1509 if (auto *VarDIE = getDIE(Var))
1510 addDIEEntry(Buffer, dwarf::DW_AT_associated, *VarDIE);
1511 } else if (DIExpression *Expr = CTy->getAssociatedExp()) {
1512 DIELoc *Loc = new (DIEValueAllocator) DIELoc;
1513 DIEDwarfExpression DwarfExpr(*Asm, getCU(), *Loc);
1514 DwarfExpr.setMemoryLocationKind();
1515 DwarfExpr.addExpression(Expr);
1516 addBlock(Buffer, dwarf::DW_AT_associated, DwarfExpr.finalize());
1517 }
1518
1519 if (DIVariable *Var = CTy->getAllocated()) {
1520 if (auto *VarDIE = getDIE(Var))
1521 addDIEEntry(Buffer, dwarf::DW_AT_allocated, *VarDIE);
1522 } else if (DIExpression *Expr = CTy->getAllocatedExp()) {
1523 DIELoc *Loc = new (DIEValueAllocator) DIELoc;
1524 DIEDwarfExpression DwarfExpr(*Asm, getCU(), *Loc);
1525 DwarfExpr.setMemoryLocationKind();
1526 DwarfExpr.addExpression(Expr);
1527 addBlock(Buffer, dwarf::DW_AT_allocated, DwarfExpr.finalize());
1528 }
1529
1530 if (auto *RankConst = CTy->getRankConst()) {
1531 addSInt(Buffer, dwarf::DW_AT_rank, dwarf::DW_FORM_sdata,
1532 RankConst->getSExtValue());
1533 } else if (auto *RankExpr = CTy->getRankExp()) {
1534 DIELoc *Loc = new (DIEValueAllocator) DIELoc;
1535 DIEDwarfExpression DwarfExpr(*Asm, getCU(), *Loc);
1536 DwarfExpr.setMemoryLocationKind();
1537 DwarfExpr.addExpression(RankExpr);
1538 addBlock(Buffer, dwarf::DW_AT_rank, DwarfExpr.finalize());
1539 }
1540
1541 // Emit the element type.
1542 addType(Buffer, CTy->getBaseType());
1543
1544 // Get an anonymous type for index type.
1545 // FIXME: This type should be passed down from the front end
1546 // as different languages may have different sizes for indexes.
1547 DIE *IdxTy = getIndexTyDie();
1548
1549 // Add subranges to array type.
1550 DINodeArray Elements = CTy->getElements();
1551 for (DINode *E : Elements) {
1552 // FIXME: Should this really be such a loose cast?
1553 if (auto *Element = dyn_cast_or_null<DINode>(E)) {
1554 if (Element->getTag() == dwarf::DW_TAG_subrange_type)
1555 constructSubrangeDIE(Buffer, cast<DISubrange>(Element), IdxTy);
1556 else if (Element->getTag() == dwarf::DW_TAG_generic_subrange)
1557 constructGenericSubrangeDIE(Buffer, cast<DIGenericSubrange>(Element),
1558 IdxTy);
1559 }
1560 }
1561}
1562
1563void DwarfUnit::constructEnumTypeDIE(DIE &Buffer, const DICompositeType *CTy) {
1564 const DIType *DTy = CTy->getBaseType();
1565 bool IsUnsigned = DTy && DD->isUnsignedDIType(DTy);
1566 if (DTy) {
1567 if (DD->getDwarfVersion() >= 3)
1568 addType(Buffer, DTy);
1569 if (DD->getDwarfVersion() >= 4 && (CTy->getFlags() & DINode::FlagEnumClass))
1570 addFlag(Buffer, dwarf::DW_AT_enum_class);
1571 }
1572
1573 auto *Context = CTy->getScope();
1574 bool IndexEnumerators = !Context || isa<DICompileUnit>(Context) || isa<DIFile>(Context) ||
1575 isa<DINamespace>(Context) || isa<DICommonBlock>(Context);
1576 DINodeArray Elements = CTy->getElements();
1577
1578 // Add enumerators to enumeration type.
1579 for (const DINode *E : Elements) {
1580 auto *Enum = dyn_cast_or_null<DIEnumerator>(E);
1581 if (Enum) {
1582 DIE &Enumerator = createAndAddDIE(dwarf::DW_TAG_enumerator, Buffer);
1583 StringRef Name = Enum->getName();
1584 addString(Enumerator, dwarf::DW_AT_name, Name);
1585 addConstantValue(Enumerator, Enum->getValue(), IsUnsigned);
1586 if (IndexEnumerators)
1587 addGlobalName(Name, Enumerator, Context);
1588 }
1589 }
1590}
1591
1593 for (auto &P : ContainingTypeMap) {
1594 DIE &SPDie = *P.first;
1595 const DINode *D = P.second;
1596 if (!D)
1597 continue;
1598 DIE *NDie = getDIE(D);
1599 if (!NDie)
1600 continue;
1601 addDIEEntry(SPDie, dwarf::DW_AT_containing_type, *NDie);
1602 }
1603}
1604
1605DIE &DwarfUnit::constructMemberDIE(DIE &Buffer, const DIDerivedType *DT) {
1606 DIE &MemberDie = createAndAddDIE(DT->getTag(), Buffer);
1607 StringRef Name = DT->getName();
1608 if (!Name.empty())
1609 addString(MemberDie, dwarf::DW_AT_name, Name);
1610
1611 addAnnotation(MemberDie, DT->getAnnotations());
1612
1613 if (DIType *Resolved = DT->getBaseType())
1614 addType(MemberDie, Resolved);
1615
1616 addSourceLine(MemberDie, DT);
1617
1618 if (DT->getTag() == dwarf::DW_TAG_inheritance && DT->isVirtual()) {
1619
1620 // For C++, virtual base classes are not at fixed offset. Use following
1621 // expression to extract appropriate offset from vtable.
1622 // BaseAddr = ObAddr + *((*ObAddr) - Offset)
1623
1624 DIELoc *VBaseLocationDie = new (DIEValueAllocator) DIELoc;
1625 addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_dup);
1626 addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_deref);
1627 addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_constu);
1628 addUInt(*VBaseLocationDie, dwarf::DW_FORM_udata, DT->getOffsetInBits());
1629 addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_minus);
1630 addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_deref);
1631 addUInt(*VBaseLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_plus);
1632
1633 addBlock(MemberDie, dwarf::DW_AT_data_member_location, VBaseLocationDie);
1634 } else {
1635 uint64_t Size = DT->getSizeInBits();
1636 uint64_t FieldSize = DD->getBaseTypeSize(DT);
1637 uint32_t AlignInBytes = DT->getAlignInBytes();
1638 uint64_t OffsetInBytes;
1639
1640 bool IsBitfield = DT->isBitField();
1641 if (IsBitfield) {
1642 // Handle bitfield, assume bytes are 8 bits.
1643 if (DD->useDWARF2Bitfields())
1644 addUInt(MemberDie, dwarf::DW_AT_byte_size, std::nullopt, FieldSize / 8);
1645 addUInt(MemberDie, dwarf::DW_AT_bit_size, std::nullopt, Size);
1646
1647 uint64_t Offset = DT->getOffsetInBits();
1648 // We can't use DT->getAlignInBits() here: AlignInBits for member type
1649 // is non-zero if and only if alignment was forced (e.g. _Alignas()),
1650 // which can't be done with bitfields. Thus we use FieldSize here.
1651 uint32_t AlignInBits = FieldSize;
1652 uint32_t AlignMask = ~(AlignInBits - 1);
1653 // The bits from the start of the storage unit to the start of the field.
1654 uint64_t StartBitOffset = Offset - (Offset & AlignMask);
1655 // The byte offset of the field's aligned storage unit inside the struct.
1656 OffsetInBytes = (Offset - StartBitOffset) / 8;
1657
1658 if (DD->useDWARF2Bitfields()) {
1659 uint64_t HiMark = (Offset + FieldSize) & AlignMask;
1660 uint64_t FieldOffset = (HiMark - FieldSize);
1661 Offset -= FieldOffset;
1662
1663 // Maybe we need to work from the other end.
1665 Offset = FieldSize - (Offset + Size);
1666
1667 addUInt(MemberDie, dwarf::DW_AT_bit_offset, std::nullopt, Offset);
1668 OffsetInBytes = FieldOffset >> 3;
1669 } else {
1670 addUInt(MemberDie, dwarf::DW_AT_data_bit_offset, std::nullopt, Offset);
1671 }
1672 } else {
1673 // This is not a bitfield.
1674 OffsetInBytes = DT->getOffsetInBits() / 8;
1675 if (AlignInBytes)
1676 addUInt(MemberDie, dwarf::DW_AT_alignment, dwarf::DW_FORM_udata,
1677 AlignInBytes);
1678 }
1679
1680 if (DD->getDwarfVersion() <= 2) {
1681 DIELoc *MemLocationDie = new (DIEValueAllocator) DIELoc;
1682 addUInt(*MemLocationDie, dwarf::DW_FORM_data1, dwarf::DW_OP_plus_uconst);
1683 addUInt(*MemLocationDie, dwarf::DW_FORM_udata, OffsetInBytes);
1684 addBlock(MemberDie, dwarf::DW_AT_data_member_location, MemLocationDie);
1685 } else if (!IsBitfield || DD->useDWARF2Bitfields()) {
1686 // In DWARF v3, DW_FORM_data4/8 in DW_AT_data_member_location are
1687 // interpreted as location-list pointers. Interpreting constants as
1688 // pointers is not expected, so we use DW_FORM_udata to encode the
1689 // constants here.
1690 if (DD->getDwarfVersion() == 3)
1691 addUInt(MemberDie, dwarf::DW_AT_data_member_location,
1692 dwarf::DW_FORM_udata, OffsetInBytes);
1693 else
1694 addUInt(MemberDie, dwarf::DW_AT_data_member_location, std::nullopt,
1695 OffsetInBytes);
1696 }
1697 }
1698
1699 addAccess(MemberDie, DT->getFlags());
1700
1701 if (DT->isVirtual())
1702 addUInt(MemberDie, dwarf::DW_AT_virtuality, dwarf::DW_FORM_data1,
1703 dwarf::DW_VIRTUALITY_virtual);
1704
1705 // Objective-C properties.
1706 if (DINode *PNode = DT->getObjCProperty())
1707 if (DIE *PDie = getDIE(PNode))
1708 addAttribute(MemberDie, dwarf::DW_AT_APPLE_property,
1709 dwarf::DW_FORM_ref4, DIEEntry(*PDie));
1710
1711 if (DT->isArtificial())
1712 addFlag(MemberDie, dwarf::DW_AT_artificial);
1713
1714 return MemberDie;
1715}
1716
1718 if (!DT)
1719 return nullptr;
1720
1721 // Construct the context before querying for the existence of the DIE in case
1722 // such construction creates the DIE.
1723 DIE *ContextDIE = getOrCreateContextDIE(DT->getScope());
1724 assert(dwarf::isType(ContextDIE->getTag()) &&
1725 "Static member should belong to a type.");
1726
1727 if (DIE *StaticMemberDIE = getDIE(DT))
1728 return StaticMemberDIE;
1729
1730 DIE &StaticMemberDIE = createAndAddDIE(DT->getTag(), *ContextDIE, DT);
1731
1732 const DIType *Ty = DT->getBaseType();
1733
1734 addString(StaticMemberDIE, dwarf::DW_AT_name, DT->getName());
1735 addType(StaticMemberDIE, Ty);
1736 addSourceLine(StaticMemberDIE, DT);
1737 addFlag(StaticMemberDIE, dwarf::DW_AT_external);
1738 addFlag(StaticMemberDIE, dwarf::DW_AT_declaration);
1739
1740 // FIXME: We could omit private if the parent is a class_type, and
1741 // public if the parent is something else.
1742 addAccess(StaticMemberDIE, DT->getFlags());
1743
1744 if (const ConstantInt *CI = dyn_cast_or_null<ConstantInt>(DT->getConstant()))
1745 addConstantValue(StaticMemberDIE, CI, Ty);
1746 if (const ConstantFP *CFP = dyn_cast_or_null<ConstantFP>(DT->getConstant()))
1747 addConstantFPValue(StaticMemberDIE, CFP);
1748
1749 if (uint32_t AlignInBytes = DT->getAlignInBytes())
1750 addUInt(StaticMemberDIE, dwarf::DW_AT_alignment, dwarf::DW_FORM_udata,
1751 AlignInBytes);
1752
1753 return &StaticMemberDIE;
1754}
1755
1757 // Emit size of content not including length itself
1760 isDwoUnit() ? "debug_info_dwo" : "debug_info", "Length of Unit");
1761 else
1763 "Length of Unit");
1764
1765 Asm->OutStreamer->AddComment("DWARF version number");
1766 unsigned Version = DD->getDwarfVersion();
1767 Asm->emitInt16(Version);
1768
1769 // DWARF v5 reorders the address size and adds a unit type.
1770 if (Version >= 5) {
1771 Asm->OutStreamer->AddComment("DWARF Unit Type");
1772 Asm->emitInt8(UT);
1773 Asm->OutStreamer->AddComment("Address Size (in bytes)");
1775 }
1776
1777 // We share one abbreviations table across all units so it's always at the
1778 // start of the section. Use a relocatable offset where needed to ensure
1779 // linking doesn't invalidate that offset.
1780 Asm->OutStreamer->AddComment("Offset Into Abbrev. Section");
1782 if (UseOffsets)
1784 else
1786 TLOF.getDwarfAbbrevSection()->getBeginSymbol(), false);
1787
1788 if (Version <= 4) {
1789 Asm->OutStreamer->AddComment("Address Size (in bytes)");
1791 }
1792}
1793
1794void DwarfTypeUnit::emitHeader(bool UseOffsets) {
1795 if (!DD->useSplitDwarf()) {
1796 LabelBegin = Asm->createTempSymbol("tu_begin");
1797 Asm->OutStreamer->emitLabel(LabelBegin);
1798 }
1799 DwarfUnit::emitCommonHeader(UseOffsets,
1800 DD->useSplitDwarf() ? dwarf::DW_UT_split_type
1801 : dwarf::DW_UT_type);
1802 Asm->OutStreamer->AddComment("Type Signature");
1803 Asm->OutStreamer->emitIntValue(TypeSignature, sizeof(TypeSignature));
1804 Asm->OutStreamer->AddComment("Type DIE Offset");
1805 // In a skeleton type unit there is no type DIE so emit a zero offset.
1806 Asm->emitDwarfLengthOrOffset(Ty ? Ty->getOffset() : 0);
1807}
1808
1810 const MCSymbol *Hi, const MCSymbol *Lo) {
1813}
1814
1816 const MCSymbol *Label, const MCSymbol *Sec) {
1819 else
1820 addSectionDelta(Die, Attribute, Label, Sec);
1821}
1822
1823bool DwarfTypeUnit::isDwoUnit() const {
1824 // Since there are no skeleton type units, all type units are dwo type units
1825 // when split DWARF is being used.
1826 return DD->useSplitDwarf();
1827}
1828
1830 const DIScope *Context) {
1832}
1833
1834void DwarfTypeUnit::addGlobalType(const DIType *Ty, const DIE &Die,
1835 const DIScope *Context) {
1837}
1838
1839const MCSymbol *DwarfUnit::getCrossSectionRelativeBaseAddress() const {
1841 return nullptr;
1842 if (isDwoUnit())
1843 return nullptr;
1844 return getSection()->getBeginSymbol();
1845}
1846
1849 addSectionLabel(getUnitDie(), dwarf::DW_AT_str_offsets_base,
1852}
1853
1855 assert(DD->getDwarfVersion() >= 5 &&
1856 "DW_AT_rnglists_base requires DWARF version 5 or later");
1858 addSectionLabel(getUnitDie(), dwarf::DW_AT_rnglists_base,
1861}
1862
1863void DwarfTypeUnit::finishNonUnitTypeDIE(DIE& D, const DICompositeType *CTy) {
1865}
1866
1867bool DwarfUnit::isCompatibleWithVersion(uint16_t Version) const {
1868 return !Asm->TM.Options.DebugStrictDwarf || DD->getDwarfVersion() >= Version;
1869}
This file declares a class to represent arbitrary precision floating point values and provide a varie...
This file implements a class to represent arbitrary precision integral constant values and operations...
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
static bool hasVectorBeenPadded(const DICompositeType *CTy)
Returns true if the vector's size differs from the sum of sizes of elements the user specified.
Definition: DwarfUnit.cpp:1463
std::string Name
uint64_t Size
Symbol * Sym
Definition: ELF_riscv.cpp:479
#define G(x, y, z)
Definition: MD5.cpp:56
unsigned const TargetRegisterInfo * TRI
This file contains the declarations for metadata subclasses.
LLVMContext & Context
#define P(N)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static enum BaseType getBaseType(const Value *Val)
Return the baseType for Val which states whether Val is exclusively derived from constant/null,...
static unsigned getSize(unsigned Kind)
APInt bitcastToAPInt() const
Definition: APFloat.h:1210
Class for arbitrary precision integers.
Definition: APInt.h:76
uint64_t getZExtValue() const
Get zero extended value.
Definition: APInt.h:1491
unsigned getBitWidth() const
Return the number of bits in the APInt.
Definition: APInt.h:1439
const uint64_t * getRawData() const
This function returns a pointer to the internal storage of the APInt.
Definition: APInt.h:547
int64_t getSExtValue() const
Get sign extended value.
Definition: APInt.h:1513
unsigned getIndex(const MCSymbol *Sym, bool TLS=false)
Returns the index into the address pool with the given label/symbol.
Definition: AddressPool.cpp:20
void resetUsedFlag(bool HasBeenUsed=false)
Definition: AddressPool.h:51
Annotations lets you mark points and ranges inside source code, for tests:
Definition: Annotations.h:53
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:84
const TargetLoweringObjectFile & getObjFileLowering() const
Return information about object file lowering.
Definition: AsmPrinter.cpp:398
MCSymbol * getSymbol(const GlobalValue *GV) const
Definition: AsmPrinter.cpp:700
void emitDwarfSymbolReference(const MCSymbol *Label, bool ForceOffset=false) const
Emit a reference to a symbol for use in dwarf.
void emitDwarfLengthOrOffset(uint64_t Value) const
Emit 32- or 64-bit value depending on the DWARF format.
TargetMachine & TM
Target machine description.
Definition: AsmPrinter.h:87
const MCAsmInfo * MAI
Target Asm Printer information.
Definition: AsmPrinter.h:90
MachineFunction * MF
The current machine function.
Definition: AsmPrinter.h:102
void emitInt8(int Value) const
Emit a byte directive and value.
void emitDwarfUnitLength(uint64_t Length, const Twine &Comment) const
Emit a unit length field.
MCContext & OutContext
This is the context for the output file that we are streaming.
Definition: AsmPrinter.h:94
MCSymbol * createTempSymbol(const Twine &Name) const
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
Definition: AsmPrinter.h:99
virtual unsigned getISAEncoding()
Get the value for DW_AT_APPLE_isa. Zero if no isa encoding specified.
Definition: AsmPrinter.h:755
void emitInt16(int Value) const
Emit a short directive and value.
const DataLayout & getDataLayout() const
Return information about data layout.
Definition: AsmPrinter.cpp:402
dwarf::FormParams getDwarfFormParams() const
Returns information about the byte size of DW_FORM values.
bool doesDwarfUseRelocationsAcrossSections() const
Definition: AsmPrinter.h:330
ConstantFP - Floating Point Values [float, double].
Definition: Constants.h:268
const APFloat & getValueAPF() const
Definition: Constants.h:311
This is the shared class of boolean and integer constants.
Definition: Constants.h:80
const APInt & getValue() const
Return the constant as an APInt value reference.
Definition: Constants.h:145
Basic type, like 'int' or 'float'.
unsigned getEncoding() const
bool getDebugInfoForProfiling() const
bool isDebugDirectivesOnly() const
static std::optional< DebugNameTableKind > getNameTableKind(StringRef Str)
DIExpression * getRankExp() const
DIExpression * getAssociatedExp() const
DIVariable * getAllocated() const
DIExpression * getDataLocationExp() const
DIVariable * getAssociated() const
DIDerivedType * getDiscriminator() const
DIVariable * getDataLocation() const
unsigned getRuntimeLang() const
DINodeArray getElements() const
DITemplateParameterArray getTemplateParams() const
DIExpression * getAllocatedExp() const
DIType * getVTableHolder() const
DINodeArray getAnnotations() const
ConstantInt * getRankConst() const
DIType * getBaseType() const
DINodeArray getAnnotations() const
Get annotations associated with this derived type.
DIObjCProperty * getObjCProperty() const
Constant * getConstant() const
DIEBlock - Represents a block of values.
Definition: DIE.h:1046
A simple label difference DIE.
Definition: DIE.h:261
DwarfExpression implementation for singular DW_AT_location.
DIEDwarfExpression(const AsmPrinter &AP, DwarfCompileUnit &CU, DIELoc &DIE)
Definition: DwarfUnit.cpp:40
A pointer to another debug information entry.
Definition: DIE.h:319
A container for inline string values.
Definition: DIE.h:297
An integer value DIE.
Definition: DIE.h:168
static dwarf::Form BestForm(bool IsSigned, uint64_t Int)
Choose the best form for integer.
Definition: DIE.h:175
A label DIE.
Definition: DIE.h:223
DIELoc - Represents an expression location.
Definition: DIE.h:1010
unsigned computeSize(const dwarf::FormParams &FormParams) const
Calculate the size of the location expression.
Definition: DIE.cpp:710
dwarf::Form BestForm(unsigned DwarfVersion) const
BestForm - Choose the best form for data.
Definition: DIE.h:1024
A container for string pool string values.
Definition: DIE.h:278
Represents a compile or type unit.
Definition: DIE.h:960
MCSection * getSection() const
Return the section that this DIEUnit will be emitted into.
Definition: DIE.h:996
DIE & getUnitDie()
Definition: DIE.h:999
A list of DIE values.
Definition: DIE.h:689
void takeValues(DIEValueList &Other)
Take ownership of the nodes in Other, and append them to the back of the list.
Definition: DIE.h:805
A structured debug information entry.
Definition: DIE.h:819
DIE & addChild(DIE *Child)
Add a child to the DIE.
Definition: DIE.h:934
static DIE * get(BumpPtrAllocator &Alloc, dwarf::Tag Tag)
Definition: DIE.h:849
DIEUnit * getUnit() const
Climb up the parent chain to get the compile unit or type unit that this DIE belongs to.
Definition: DIE.cpp:207
dwarf::Tag getTag() const
Definition: DIE.h:855
DWARF expression.
BoundType getLowerBound() const
BoundType getUpperBound() const
Represents a module in the programming language, for example, a Clang module, or a Fortran module.
Debug lexical block.
DIScope * getScope() const
StringRef getName() const
bool getExportSymbols() const
Tagged DWARF-like metadata node.
dwarf::Tag getTag() const
DIFlags
Debug info flags.
unsigned getLine() const
DIFile * getFile() const
Base class for scope-like contexts.
StringRef getName() const
DIFile * getFile() const
DIScope * getScope() const
String type, Fortran CHARACTER(n)
unsigned getEncoding() const
DIExpression * getStringLengthExp() const
DIVariable * getStringLength() const
DIExpression * getStringLocationExp() const
Subprogram description.
Array subrange.
BoundType getUpperBound() const
BoundType getStride() const
BoundType getLowerBound() const
BoundType getCount() const
Type array for a subprogram.
unsigned size() const
Base class for types.
bool isLittleEndian() const
bool isBigEndian() const
bool isLValueReference() const
bool isBitField() const
bool isVirtual() const
bool isObjcClassComplete() const
MDString * getRawName() const
bool isAppleBlockExtension() const
uint64_t getOffsetInBits() const
bool isVector() const
DIFlags getFlags() const
StringRef getName() const
bool isForwardDecl() const
bool isTypePassByValue() const
uint64_t getSizeInBits() const
uint32_t getAlignInBytes() const
unsigned getLine() const
bool isRValueReference() const
bool isArtificial() const
bool getExportSymbols() const
DIScope * getScope() const
bool isTypePassByReference() const
Base class for variables.
This class represents an Operation in the Expression.
bool isLittleEndian() const
Layout endianness...
Definition: DataLayout.h:238
static bool isUnsignedDIType(const DIType *Ty)
Return true if type encoding is unsigned.
static uint64_t getBaseTypeSize(const DIType *Ty)
If this type is derived from a base type then return base type size.
void addGlobalNameForTypeUnit(StringRef Name, const DIScope *Context)
Add a new global name present in a type unit to this compile unit.
unsigned getOrCreateSourceID(const DIFile *File) override
Look up the source ID for the given file.
void addGlobalTypeUnitType(const DIType *Ty, const DIScope *Context)
Add a new global type present in a type unit to this compile unit.
Collects and handles dwarf debug information.
Definition: DwarfDebug.h:351
std::optional< MD5::MD5Result > getMD5AsBytes(const DIFile *File) const
If the File has an MD5 checksum, return it as an MD5Result allocated in the MCContext.
bool useAddrOffsetForm() const
Definition: DwarfDebug.h:777
uint16_t getDwarfVersion() const
Returns the Dwarf Version.
void addAccelNamespace(const DwarfUnit &Unit, const DICompileUnit::DebugNameTableKind NameTableKind, StringRef Name, const DIE &Die)
bool useAllLinkageNames() const
Returns whether we should emit all DW_AT_[MIPS_]linkage_name.
Definition: DwarfDebug.h:749
dwarf::Form getDwarfSectionOffsetForm() const
Returns a suitable DWARF form to represent a section offset, i.e.
bool useAppleExtensionAttributes() const
Definition: DwarfDebug.h:800
bool useInlineStrings() const
Returns whether to use inline strings.
Definition: DwarfDebug.h:760
bool generateTypeUnits() const
Returns whether to generate DWARF v4 type units.
Definition: DwarfDebug.h:790
AddressPool & getAddressPool()
Definition: DwarfDebug.h:861
bool useSectionsAsReferences() const
Returns whether to use sections as labels rather than temp symbols.
Definition: DwarfDebug.h:782
bool shareAcrossDWOCUs() const
Definition: DwarfDebug.cpp:537
const MCSymbol * getSectionLabel(const MCSection *S)
bool useSplitDwarf() const
Returns whether or not to change the current debug info for the split dwarf proposal support.
Definition: DwarfDebug.h:806
bool useDWARF2Bitfields() const
Returns whether to use the DWARF2 format for bitfields instyead of the DWARF4 format.
Definition: DwarfDebug.h:757
bool useAddrOffsetExpressions() const
Definition: DwarfDebug.h:771
void addDwarfTypeUnitType(DwarfCompileUnit &CU, StringRef Identifier, DIE &Die, const DICompositeType *CTy)
Add a DIE to the set of types that we're going to pull into type units.
void addAccelType(const DwarfUnit &Unit, const DICompileUnit::DebugNameTableKind NameTableKind, StringRef Name, const DIE &Die, char Flags)
Base class containing the logic for constructing DWARF expressions independently of whether they are ...
MCSymbol * getStringOffsetsStartSym() const
Definition: DwarfFile.h:147
MCSymbol * getRnglistsTableBaseSym() const
Definition: DwarfFile.h:150
DwarfStringPool & getStringPool()
Returns the string pool.
Definition: DwarfFile.h:145
DenseMap< const DILocalScope *, DIE * > & getAbstractScopeDIEs()
Definition: DwarfFile.h:165
void insertDIE(const MDNode *TypeMD, DIE *Die)
Definition: DwarfFile.h:173
DIE * getDIE(const MDNode *TypeMD)
Definition: DwarfFile.h:177
EntryRef getEntry(AsmPrinter &Asm, StringRef Str)
Get a reference to an entry in the string pool.
EntryRef getIndexedEntry(AsmPrinter &Asm, StringRef Str)
Same as getEntry, except that you can use EntryRef::getIndex to obtain a unique ID of this entry (e....
DwarfTypeUnit(DwarfCompileUnit &CU, AsmPrinter *A, DwarfDebug *DW, DwarfFile *DWU, unsigned UniqueID, MCDwarfDwoLineTable *SplitLineTable=nullptr)
Definition: DwarfUnit.cpp:88
void addGlobalType(const DIType *Ty, const DIE &Die, const DIScope *Context) override
Add a new global type to the compile unit.
Definition: DwarfUnit.cpp:1834
DwarfCompileUnit & getCU() override
Definition: DwarfUnit.h:402
void emitHeader(bool UseOffsets) override
Emit the header for this unit, not including the initial length field.
Definition: DwarfUnit.cpp:1794
void addGlobalName(StringRef Name, const DIE &Die, const DIScope *Context) override
Add a new global name to the compile unit.
Definition: DwarfUnit.cpp:1829
This dwarf writer support class manages information associated with a source file.
Definition: DwarfUnit.h:35
virtual DIE * getOrCreateTypeDIE(const MDNode *TyNode)
Find existing DIE or create new DIE for the given type.
Definition: DwarfUnit.cpp:606
void addThrownTypes(DIE &Die, DINodeArray ThrownTypes)
Add thrown types.
Definition: DwarfUnit.cpp:526
void addStringOffsetsStart()
Add the DW_AT_str_offsets_base attribute to the unit DIE.
Definition: DwarfUnit.cpp:1847
void addAnnotation(DIE &Buffer, DINodeArray Annotations)
Add DW_TAG_LLVM_annotation.
Definition: DwarfUnit.cpp:865
std::vector< DIEBlock * > DIEBlocks
A list of all the DIEBlocks in use.
Definition: DwarfUnit.h:66
std::vector< DIELoc * > DIELocs
A list of all the DIELocs in use.
Definition: DwarfUnit.h:69
uint16_t getLanguage() const
Definition: DwarfUnit.h:110
void addBlock(DIE &Die, dwarf::Attribute Attribute, DIELoc *Loc)
Add block data.
Definition: DwarfUnit.cpp:390
void addTemplateParams(DIE &Buffer, DINodeArray TParams)
Add template parameters in buffer.
Definition: DwarfUnit.cpp:515
virtual DIE * getOrCreateContextDIE(const DIScope *Context)
Get context owner's DIE.
Definition: DwarfUnit.cpp:545
bool useSegmentedStringOffsetsTable() const
Definition: DwarfUnit.h:275
bool applySubprogramDefinitionAttributes(const DISubprogram *SP, DIE &SPDie, bool Minimal)
Definition: DwarfUnit.cpp:1198
DIELoc * getDIELoc()
Returns a fresh newly allocated DIELoc.
Definition: DwarfUnit.h:142
void addAttribute(DIEValueList &Die, dwarf::Attribute Attribute, dwarf::Form Form, T &&Value)
Definition: DwarfUnit.h:84
void addOpAddress(DIELoc &Die, const MCSymbol *Sym)
Add a dwarf op address data and value using the form given and an op of either DW_FORM_addr or DW_FOR...
Definition: DwarfUnit.cpp:331
void addUInt(DIEValueList &Die, dwarf::Attribute Attribute, std::optional< dwarf::Form > Form, uint64_t Integer)
Add an unsigned integer attribute data and value.
Definition: DwarfUnit.cpp:220
void addString(DIE &Die, dwarf::Attribute Attribute, StringRef Str)
Add a string attribute data and value.
Definition: DwarfUnit.cpp:246
void addConstantValue(DIE &Die, const ConstantInt *CI, const DIType *Ty)
Add constant value entry in variable DIE.
Definition: DwarfUnit.cpp:458
DIE * getOrCreateNameSpace(const DINamespace *NS)
Definition: DwarfUnit.cpp:1114
void insertDIE(const DINode *Desc, DIE *D)
Insert DIE into the map.
Definition: DwarfUnit.cpp:201
void addAccess(DIE &Die, DINode::DIFlags Flags)
Add the accessibility attribute.
Definition: DwarfUnit.cpp:533
void addSectionDelta(DIE &Die, dwarf::Attribute Attribute, const MCSymbol *Hi, const MCSymbol *Lo)
addSectionDelta - Add a label delta attribute data and value.
Definition: DwarfUnit.cpp:1809
DIE * createTypeDIE(const DIScope *Context, DIE &ContextDIE, const DIType *Ty)
Creates type DIE with specific context.
Definition: DwarfUnit.cpp:575
DwarfDebug * DD
Definition: DwarfUnit.h:55
DenseMap< DIE *, const DINode * > ContainingTypeMap
This map is used to keep track of subprogram DIEs that need DW_AT_containing_type attribute.
Definition: DwarfUnit.h:74
const DICompileUnit * CUNode
MDNode for the compile unit.
Definition: DwarfUnit.h:40
virtual unsigned getOrCreateSourceID(const DIFile *File)=0
Look up the source ID for the given file.
void addDIETypeSignature(DIE &Die, uint64_t Signature)
Add a type's DW_AT_signature and set the declaration flag.
Definition: DwarfUnit.cpp:356
virtual void addGlobalType(const DIType *Ty, const DIE &Die, const DIScope *Context)=0
Add a new global type to the compile unit.
virtual DwarfCompileUnit & getCU()=0
DIE * getDIE(const DINode *D) const
Returns the DIE map slot for the specified debug variable.
Definition: DwarfUnit.cpp:195
virtual unsigned getHeaderSize() const
Compute the size of a header for this unit, not including the initial length field.
Definition: DwarfUnit.h:281
void constructSubprogramArguments(DIE &Buffer, DITypeRefArray Args)
Construct function argument DIEs.
Definition: DwarfUnit.cpp:820
MCSymbol * LabelBegin
The start of the unit within its section.
Definition: DwarfUnit.h:49
void addSInt(DIEValueList &Die, dwarf::Attribute Attribute, std::optional< dwarf::Form > Form, int64_t Integer)
Add an signed integer attribute data and value.
Definition: DwarfUnit.cpp:234
DwarfUnit(dwarf::Tag, const DICompileUnit *Node, AsmPrinter *A, DwarfDebug *DW, DwarfFile *DWU, unsigned UniqueID=0)
Definition: DwarfUnit.cpp:82
void addLabelDelta(DIEValueList &Die, dwarf::Attribute Attribute, const MCSymbol *Hi, const MCSymbol *Lo)
Add a label delta attribute data and value.
Definition: DwarfUnit.cpp:346
void addLinkageName(DIE &Die, StringRef LinkageName)
Add a linkage name, if it isn't empty.
Definition: DwarfUnit.cpp:507
std::string getParentContextString(const DIScope *Context) const
Get string containing language specific context for a global name.
Definition: DwarfUnit.cpp:658
void addSourceLine(DIE &Die, unsigned Line, const DIFile *File)
Add location information to specified debug information entry.
Definition: DwarfUnit.cpp:408
void emitCommonHeader(bool UseOffsets, dwarf::UnitType UT)
Emit the common part of the header for this unit.
Definition: DwarfUnit.cpp:1756
BumpPtrAllocator DIEValueAllocator
Definition: DwarfUnit.h:43
DIE * IndexTyDie
An anonymous type for index type. Owned by DIEUnit.
Definition: DwarfUnit.h:59
void addRnglistsBase()
Add the DW_AT_rnglists_base attribute to the unit DIE.
Definition: DwarfUnit.cpp:1854
DIE * getOrCreateModule(const DIModule *M)
Definition: DwarfUnit.cpp:1135
DIE & createAndAddDIE(dwarf::Tag Tag, DIE &Parent, const DINode *N=nullptr)
Create a DIE with the given Tag, add the DIE to its parent, and call insertDIE if MD is not null.
Definition: DwarfUnit.cpp:383
DwarfFile * DU
Definition: DwarfUnit.h:56
void addSectionOffset(DIE &Die, dwarf::Attribute Attribute, uint64_t Integer)
Add an offset into a section attribute data and value.
Definition: DwarfUnit.cpp:288
DIE * getOrCreateStaticMemberDIE(const DIDerivedType *DT)
Create new static data member DIE.
Definition: DwarfUnit.cpp:1717
void addLabel(DIEValueList &Die, dwarf::Attribute Attribute, dwarf::Form Form, const MCSymbol *Label)
Add a Dwarf label attribute data and value.
Definition: DwarfUnit.cpp:279
void addConstantFPValue(DIE &Die, const ConstantFP *CFP)
Add constant value entry in variable DIE.
Definition: DwarfUnit.cpp:453
void constructContainingTypeDIEs()
Construct DIEs for types that contain vtables.
Definition: DwarfUnit.cpp:1592
DIE * getOrCreateSubprogramDIE(const DISubprogram *SP, bool Minimal=false)
Definition: DwarfUnit.cpp:1166
void addSectionLabel(DIE &Die, dwarf::Attribute Attribute, const MCSymbol *Label, const MCSymbol *Sec)
Add a Dwarf section label attribute data and value.
Definition: DwarfUnit.cpp:1815
bool isShareableAcrossCUs(const DINode *D) const
Check whether the DIE for this MDNode can be shared across CUs.
Definition: DwarfUnit.cpp:180
void addPoolOpAddress(DIEValueList &Die, const MCSymbol *Label)
Definition: DwarfUnit.cpp:306
DenseMap< const MDNode *, DIE * > MDNodeToDieMap
Tracks the mapping of unit level debug information variables to debug information entries.
Definition: DwarfUnit.h:63
void constructTypeDIE(DIE &Buffer, const DICompositeType *CTy)
Definition: DwarfUnit.cpp:886
virtual void addGlobalName(StringRef Name, const DIE &Die, const DIScope *Context)=0
Add a new global name to the compile unit.
MCSymbol * EndLabel
Emitted at the end of the CU and used to compute the CU Length field.
Definition: DwarfUnit.h:52
void addFlag(DIE &Die, dwarf::Attribute Attribute)
Add a flag that is true to the DIE.
Definition: DwarfUnit.cpp:213
AsmPrinter * Asm
Target of Dwarf emission.
Definition: DwarfUnit.h:46
void addType(DIE &Entity, const DIType *Ty, dwarf::Attribute Attribute=dwarf::DW_AT_type)
Add a new type attribute to the specified entity.
Definition: DwarfUnit.cpp:652
void applySubprogramAttributes(const DISubprogram *SP, DIE &SPDie, bool SkipSPAttributes=false)
Definition: DwarfUnit.cpp:1251
void addDIEEntry(DIE &Die, dwarf::Attribute Attribute, DIE &Entry)
Add a DIE attribute data and value.
Definition: DwarfUnit.cpp:352
static StringRef dropLLVMManglingEscape(StringRef Name)
If the given string begins with the GlobalValue name mangling escape character '\1',...
Definition: GlobalValue.h:566
unsigned getCodePointerSize() const
Get the code pointer size in bytes.
Definition: MCAsmInfo.h:546
uint16_t getDwarfVersion() const
Definition: MCContext.h:833
unsigned getFile(StringRef Directory, StringRef FileName, std::optional< MD5::MD5Result > Checksum, uint16_t DwarfVersion, std::optional< StringRef > Source)
Definition: MCDwarf.h:339
MCSection * getDwarfStrOffSection() const
MCSection * getDwarfRnglistsSection() const
MCSection * getDwarfAbbrevSection() const
MCSymbol * getBeginSymbol()
Definition: MCSection.h:129
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:40
Metadata node.
Definition: Metadata.h:1067
const MDOperand & getOperand(unsigned I) const
Definition: Metadata.h:1428
A single uniqued string.
Definition: Metadata.h:720
Root of the metadata hierarchy.
Definition: Metadata.h:62
A discriminated union of two or more pointer types, with the discriminator in the low bit of the poin...
Definition: PointerUnion.h:118
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1209
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
constexpr bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:134
TargetOptions Options
unsigned DebugStrictDwarf
When set to true, don't use DWARF extensions in later DWARF versions.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
LLVM Value Representation.
Definition: Value.h:74
@ DW_ACCESS_private
Definition: Dwarf.h:182
@ DW_ACCESS_protected
Definition: Dwarf.h:181
@ DW_ACCESS_public
Definition: Dwarf.h:180
Attribute
Attributes.
Definition: Dwarf.h:123
UnitType
Constants for unit types in DWARF v5.
Definition: Dwarf.h:551
bool isType(Tag T)
Definition: Dwarf.h:111
SourceLanguage
Definition: Dwarf.h:204
bool isCPlusPlus(SourceLanguage S)
Definition: Dwarf.h:212
TypeKind getArrayIndexTypeEncoding(SourceLanguage S)
Definition: Dwarf.h:409
@ DW_FLAG_type_implementation
Definition: Dwarf.h:608
bool isC(SourceLanguage S)
Definition: Dwarf.h:346
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
auto reverse(ContainerTy &&C)
Definition: STLExtras.h:428
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition: Casting.h:548
#define N
Description of the encoding of one expression Op.