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