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