Lines Matching +full:on +full:- +full:die
1 //===- llvm/CodeGen/DwarfCompileUnit.cpp - Dwarf Compile Units ------------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
11 //===----------------------------------------------------------------------===//
20 #include "llvm/CodeGen/DIE.h"
48 "add-linkage-names-to-declaration-call-origins", cl::Hidden,
51 "for -gsce debugger tuning."));
54 bool EnabledByDefault = DD->tuneForSCE(); in AddLinkageNamesToDeclCallOriginsForTuning()
65 // on page 187), the compilation unit in the .debug_info section in GetCompileUnitType()
67 if (DW->getDwarfVersion() >= 5 && Kind == UnitKind::Skeleton) in GetCompileUnitType()
78 MacroLabelBegin = Asm->createTempSymbol("cu_macro_begin"); in DwarfCompileUnit()
81 /// addLabelAddress - Add a dwarf label attribute data and value using
83 void DwarfCompileUnit::addLabelAddress(DIE &Die, dwarf::Attribute Attribute, in addLabelAddress() argument
85 if ((Skeleton || !DD->useSplitDwarf()) && Label) in addLabelAddress()
86 DD->addArangeLabel(SymbolCU(this, Label)); in addLabelAddress()
88 // Don't use the address pool in non-fission or in the skeleton unit itself. in addLabelAddress()
89 if ((!DD->useSplitDwarf() || !Skeleton) && DD->getDwarfVersion() < 5) in addLabelAddress()
90 return addLocalLabelAddress(Die, Attribute, Label); in addLabelAddress()
93 DD->useAddrOffsetForm() || DD->useAddrOffsetExpressions(); in addLabelAddress()
96 if (Label->isInSection() && UseAddrOffsetFormOrExpressions) in addLabelAddress()
97 Base = DD->getSectionLabel(&Label->getSection()); in addLabelAddress()
100 unsigned idx = DD->getAddressPool().getIndex(Label); in addLabelAddress()
101 addAttribute(Die, Attribute, in addLabelAddress()
102 DD->getDwarfVersion() >= 5 ? dwarf::DW_FORM_addrx in addLabelAddress()
110 assert(DD->getDwarfVersion() >= 5 && in addLabelAddress()
113 if (DD->useAddrOffsetExpressions()) { in addLabelAddress()
116 addBlock(Die, Attribute, dwarf::DW_FORM_exprloc, Loc); in addLabelAddress()
118 addAttribute(Die, Attribute, dwarf::DW_FORM_LLVM_addrx_offset, in addLabelAddress()
120 DD->getAddressPool().getIndex(Base), Label, Base)); in addLabelAddress()
123 void DwarfCompileUnit::addLocalLabelAddress(DIE &Die, in addLocalLabelAddress() argument
127 addAttribute(Die, Attribute, dwarf::DW_FORM_addr, DIELabel(Label)); in addLocalLabelAddress()
129 addAttribute(Die, Attribute, dwarf::DW_FORM_addr, DIEInteger(0)); in addLocalLabelAddress()
138 unsigned CUID = Asm->OutStreamer->hasRawTextSupport() ? 0 : getUniqueID(); in getOrCreateSourceID()
140 return Asm->OutStreamer->emitDwarfFileDirective(0, "", "", std::nullopt, in getOrCreateSourceID()
145 LastFileID = Asm->OutStreamer->emitDwarfFileDirective( in getOrCreateSourceID()
146 0, File->getDirectory(), File->getFilename(), DD->getMD5AsBytes(File), in getOrCreateSourceID()
147 File->getSource(), CUID); in getOrCreateSourceID()
152 DIE *DwarfCompileUnit::getOrCreateGlobalVariableDIE( in getOrCreateGlobalVariableDIE()
154 // Check for pre-existence. in getOrCreateGlobalVariableDIE()
155 if (DIE *Die = getDIE(GV)) in getOrCreateGlobalVariableDIE() local
156 return Die; in getOrCreateGlobalVariableDIE()
160 auto *GVContext = GV->getScope(); in getOrCreateGlobalVariableDIE()
161 const DIType *GTy = GV->getType(); in getOrCreateGlobalVariableDIE()
164 DIE *ContextDIE = CB ? getOrCreateCommonBlock(CB, GlobalExprs) in getOrCreateGlobalVariableDIE()
168 DIE *VariableDIE = &createAndAddDIE(GV->getTag(), *ContextDIE, GV); in getOrCreateGlobalVariableDIE()
170 if (auto *SDMDecl = GV->getStaticDataMemberDeclaration()) { in getOrCreateGlobalVariableDIE()
171 DeclContext = SDMDecl->getScope(); in getOrCreateGlobalVariableDIE()
172 assert(SDMDecl->isStaticMember() && "Expected static member decl"); in getOrCreateGlobalVariableDIE()
173 assert(GV->isDefinition()); in getOrCreateGlobalVariableDIE()
174 // We need the declaration DIE that is in the static member's class. in getOrCreateGlobalVariableDIE()
175 DIE *VariableSpecDIE = getOrCreateStaticMemberDIE(SDMDecl); in getOrCreateGlobalVariableDIE()
179 if (GTy != SDMDecl->getBaseType()) in getOrCreateGlobalVariableDIE()
182 DeclContext = GV->getScope(); in getOrCreateGlobalVariableDIE()
184 StringRef DisplayName = GV->getDisplayName(); in getOrCreateGlobalVariableDIE()
186 addString(*VariableDIE, dwarf::DW_AT_name, GV->getDisplayName()); in getOrCreateGlobalVariableDIE()
191 if (!GV->isLocalToUnit()) in getOrCreateGlobalVariableDIE()
198 if (!GV->isDefinition()) in getOrCreateGlobalVariableDIE()
201 addGlobalName(GV->getName(), *VariableDIE, DeclContext); in getOrCreateGlobalVariableDIE()
203 addAnnotation(*VariableDIE, GV->getAnnotations()); in getOrCreateGlobalVariableDIE()
205 if (uint32_t AlignInBytes = GV->getAlignInBytes()) in getOrCreateGlobalVariableDIE()
209 if (MDTuple *TP = GV->getTemplateParams()) in getOrCreateGlobalVariableDIE()
219 DIE *VariableDIE, const DIGlobalVariable *GV, ArrayRef<GlobalExpr> GlobalExprs) { in addLocationAttribute()
232 if (GlobalExprs.size() == 1 && Expr && Expr->isConstant()) { in addLocationAttribute()
237 *Expr->isConstant(), in addLocationAttribute()
238 Expr->getElement(1)); in addLocationAttribute()
244 if (Global && Global->hasDLLImportStorageClass()) in addLocationAttribute()
248 if (!Global && (!Expr || !Expr->isConstant())) in addLocationAttribute()
251 if (Global && Global->isThreadLocal() && in addLocationAttribute()
252 !Asm->getObjFileLowering().supportDebugThreadLocalLocation()) in addLocationAttribute()
263 … https://docs.nvidia.com/cuda/archive/10.0/ptx-writers-guide-to-interoperability/index.html#cuda-s… in addLocationAttribute()
264 // cuda-gdb requires DW_AT_address_class for all variables to be able to in addLocationAttribute()
269 if (Asm->TM.getTargetTriple().isNVPTX() && DD->tuneForGDB()) { in addLocationAttribute()
277 DwarfExpr->addFragmentOffset(Expr); in addLocationAttribute()
281 const MCSymbol *Sym = Asm->getSymbol(Global); in addLocationAttribute()
282 // 16-bit platforms like MSP430 and AVR take this path, so sink this in addLocationAttribute()
285 unsigned PointerSize = Asm->MAI->getCodePointerSize(); in addLocationAttribute()
296 if (Global->isThreadLocal()) { in addLocationAttribute()
297 if (Asm->TM.getTargetTriple().isWasm()) { in addLocationAttribute()
302 …// https://github.com/llvm/llvm-project/blob/19afbfe33156d211fa959dadeea46cd17b9c723c/lld/wasm/Dri… in addLocationAttribute()
306 } else if (Asm->TM.useEmulatedTLS()) { in addLocationAttribute()
309 // FIXME: Make this work with -gsplit-dwarf. in addLocationAttribute()
310 // Based on GCC's support for TLS: in addLocationAttribute()
311 if (!DD->useSplitDwarf()) { in addLocationAttribute()
318 Asm->getObjFileLowering().getDebugThreadLocalSymbol(Sym)); in addLocationAttribute()
322 DD->getAddressPool().getIndex(Sym, /* TLS */ true)); in addLocationAttribute()
326 DD->useGNUTLSOpcode() ? dwarf::DW_OP_GNU_push_tls_address in addLocationAttribute()
329 } else if (Asm->TM.getTargetTriple().isWasm() && in addLocationAttribute()
330 Asm->TM.getRelocationModel() == Reloc::PIC_) { in addLocationAttribute()
333 …// https://github.com/llvm/llvm-project/blob/19afbfe33156d211fa959dadeea46cd17b9c723c/lld/wasm/Dri… in addLocationAttribute()
337 } else if ((Asm->TM.getRelocationModel() == Reloc::RWPI || in addLocationAttribute()
338 Asm->TM.getRelocationModel() == Reloc::ROPI_RWPI) && in addLocationAttribute()
339 !Asm->getObjFileLowering() in addLocationAttribute()
340 .getKindForGlobal(Global, Asm->TM) in addLocationAttribute()
347 Asm->getObjFileLowering().getIndirectSymViaRWPI(Sym)); in addLocationAttribute()
349 Register BaseReg = Asm->getObjFileLowering().getStaticBase(); in addLocationAttribute()
350 BaseReg = Asm->TM.getMCRegisterInfo()->getDwarfRegNum(BaseReg, false); in addLocationAttribute()
357 DD->addArangeLabel(SymbolCU(this, Sym)); in addLocationAttribute()
363 // mixes non-fragments and fragments for the same variable is too expensive in addLocationAttribute()
365 if (DwarfExpr->isUnknownLocation()) in addLocationAttribute()
366 DwarfExpr->setMemoryLocationKind(); in addLocationAttribute()
367 DwarfExpr->addExpression(Expr); in addLocationAttribute()
369 if (Asm->TM.getTargetTriple().isNVPTX() && DD->tuneForGDB()) { in addLocationAttribute()
371 … https://docs.nvidia.com/cuda/archive/10.0/ptx-writers-guide-to-interoperability/index.html#cuda-s… in addLocationAttribute()
372 // cuda-gdb requires DW_AT_address_class for all variables to be able to in addLocationAttribute()
379 addBlock(*VariableDIE, dwarf::DW_AT_location, DwarfExpr->finalize()); in addLocationAttribute()
381 if (DD->useAllLinkageNames()) in addLocationAttribute()
382 addLinkageName(*VariableDIE, GV->getLinkageName()); in addLocationAttribute()
385 DD->addAccelName(*this, CUNode->getNameTableKind(), GV->getName(), in addLocationAttribute()
390 if (GV->getLinkageName() != "" && GV->getName() != GV->getLinkageName() && in addLocationAttribute()
391 DD->useAllLinkageNames()) in addLocationAttribute()
392 DD->addAccelName(*this, CUNode->getNameTableKind(), GV->getLinkageName(), in addLocationAttribute()
397 DIE *DwarfCompileUnit::getOrCreateCommonBlock( in getOrCreateCommonBlock()
399 // Check for pre-existence. in getOrCreateCommonBlock()
400 if (DIE *NDie = getDIE(CB)) in getOrCreateCommonBlock()
402 DIE *ContextDIE = getOrCreateContextDIE(CB->getScope()); in getOrCreateCommonBlock()
403 DIE &NDie = createAndAddDIE(dwarf::DW_TAG_common_block, *ContextDIE, CB); in getOrCreateCommonBlock()
404 StringRef Name = CB->getName().empty() ? "_BLNK_" : CB->getName(); in getOrCreateCommonBlock()
406 addGlobalName(Name, NDie, CB->getScope()); in getOrCreateCommonBlock()
407 if (CB->getFile()) in getOrCreateCommonBlock()
408 addSourceLine(NDie, CB->getLineNo(), CB->getFile()); in getOrCreateCommonBlock()
409 if (DIGlobalVariable *V = CB->getDecl()) in getOrCreateCommonBlock()
415 DD->insertSectionLabel(Range.Begin); in addRange()
417 auto *PrevCU = DD->getPrevCU(); in addRange()
419 DD->setPrevCU(this); in addRange()
425 (&CURanges.back().End->getSection() != in addRange()
426 &Range.End->getSection())) { in addRange()
429 DD->terminateLineTable(PrevCU); in addRange()
438 if (CUNode->isDebugDirectivesOnly()) in initStmtList()
441 const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering(); in initStmtList()
442 if (DD->useSectionsAsReferences()) { in initStmtList()
443 LineTableStartSym = TLOF.getDwarfLineSection()->getBeginSymbol(); in initStmtList()
446 Asm->OutStreamer->getDwarfLineTableSymbol(getUniqueID()); in initStmtList()
455 TLOF.getDwarfLineSection()->getBeginSymbol()); in initStmtList()
458 void DwarfCompileUnit::applyStmtList(DIE &D) { in applyStmtList()
459 const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering(); in applyStmtList()
461 TLOF.getDwarfLineSection()->getBeginSymbol()); in applyStmtList()
464 void DwarfCompileUnit::attachLowHighPC(DIE &D, const MCSymbol *Begin, in attachLowHighPC()
468 assert(Begin->isDefined() && "Invalid starting label"); in attachLowHighPC()
469 assert(End->isDefined() && "Invalid end label"); in attachLowHighPC()
472 if (DD->getDwarfVersion() < 4) in attachLowHighPC()
478 // Add info for Wasm-global-based relocation.
479 // 'GlobalIndex' is used for split dwarf, which currently relies on a few
484 // don't want to depend on target specific headers in this code? in addWasmRelocBaseGlobal()
486 unsigned PointerSize = Asm->getDataLayout().getPointerSize(); in addWasmRelocBaseGlobal()
487 auto *Sym = cast<MCSymbolWasm>(Asm->GetExternalSymbolSymbol(GlobalName)); in addWasmRelocBaseGlobal()
491 Sym->setType(wasm::WASM_SYMBOL_TYPE_GLOBAL); in addWasmRelocBaseGlobal()
492 Sym->setGlobalType(wasm::WasmGlobalType{ in addWasmRelocBaseGlobal()
511 // Find DIE for the given subprogram and attach appropriate DW_AT_low_pc
514 DIE &DwarfCompileUnit::updateSubprogramScopeDIE(const DISubprogram *SP) { in updateSubprogramScopeDIE()
515 DIE *SPDie = getOrCreateSubprogramDIE(SP, includeMinimalInlineScopes()); in updateSubprogramScopeDIE()
517 // If basic block sections are on, ranges for each basic block section has in updateSubprogramScopeDIE()
519 for (const auto &R : Asm->MBBSectionRanges) in updateSubprogramScopeDIE()
524 if (DD->useAppleExtensionAttributes() && in updateSubprogramScopeDIE()
525 !DD->getCurrentFunction()->getTarget().Options.DisableFramePointerElim( in updateSubprogramScopeDIE()
526 *DD->getCurrentFunction())) in updateSubprogramScopeDIE()
531 const TargetFrameLowering *TFI = Asm->MF->getSubtarget().getFrameLowering(); in updateSubprogramScopeDIE()
533 TFI->getDwarfFrameBase(*Asm->MF); in updateSubprogramScopeDIE()
560 // For now, since we only ever use index 0, this should work as-is. in updateSubprogramScopeDIE()
581 DD->addSubprogramNames(*this, CUNode->getNameTableKind(), SP, *SPDie); in updateSubprogramScopeDIE()
586 // Construct a DIE for this scope.
588 DIE &ParentScopeDIE) { in constructScopeDIE()
589 if (!Scope || !Scope->getScopeNode()) in constructScopeDIE()
592 auto *DS = Scope->getScopeNode(); in constructScopeDIE()
594 assert((Scope->getInlinedAt() || !isa<DISubprogram>(DS)) && in constructScopeDIE()
596 "constructSubprogramScopeDIE for non-inlined " in constructScopeDIE()
600 if (Scope->getParent() && isa<DISubprogram>(DS)) { in constructScopeDIE()
601 DIE *ScopeDIE = constructInlinedScopeDIE(Scope, ParentScopeDIE); in constructScopeDIE()
602 assert(ScopeDIE && "Scope DIE should not be null."); in constructScopeDIE()
607 // Early exit when we know the scope DIE is going to be null. in constructScopeDIE()
608 if (DD->isLexicalScopeDIENull(Scope)) in constructScopeDIE()
612 DIE *ScopeDIE = constructLexicalScopeDIE(Scope); in constructScopeDIE()
613 assert(ScopeDIE && "Scope DIE should not be null."); in constructScopeDIE()
619 void DwarfCompileUnit::addScopeRangeList(DIE &ScopeDIE, in addScopeRangeList()
626 (DD->getDwarfVersion() < 5 && Skeleton ? Skeleton->DU : DU) in addScopeRangeList()
627 ->addRange(*(Skeleton ? Skeleton : this), std::move(Range)); in addScopeRangeList()
637 if (DD->getDwarfVersion() >= 5) in addScopeRangeList()
640 const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering(); in addScopeRangeList()
642 TLOF.getDwarfRangesSection()->getBeginSymbol(); in addScopeRangeList()
653 DIE &Die, SmallVector<RangeSpan, 2> Ranges) { in attachRangesOrLowHighPC() argument
655 if (!DD->useRangesSection() || in attachRangesOrLowHighPC()
657 (!DD->alwaysUseRanges(*this) || in attachRangesOrLowHighPC()
658 DD->getSectionLabel(&Ranges.front().Begin->getSection()) == in attachRangesOrLowHighPC()
662 attachLowHighPC(Die, Front.Begin, Back.End); in attachRangesOrLowHighPC()
664 addScopeRangeList(Die, std::move(Ranges)); in attachRangesOrLowHighPC()
668 DIE &Die, const SmallVectorImpl<InsnRange> &Ranges) { in attachRangesOrLowHighPC() argument
672 auto *BeginLabel = DD->getLabelBeforeInsn(R.first); in attachRangesOrLowHighPC()
673 auto *EndLabel = DD->getLabelAfterInsn(R.second); in attachRangesOrLowHighPC()
675 const auto *BeginMBB = R.first->getParent(); in attachRangesOrLowHighPC()
676 const auto *EndMBB = R.second->getParent(); in attachRangesOrLowHighPC()
683 // FIXME: Debug Info Emission depends on block order and this assumes that in attachRangesOrLowHighPC()
686 if (MBB->sameSection(EndMBB) || MBB->isEndSection()) { in attachRangesOrLowHighPC()
687 auto MBBSectionRange = Asm->MBBSectionRanges[MBB->getSectionID()]; in attachRangesOrLowHighPC()
689 {MBB->sameSection(BeginMBB) ? BeginLabel in attachRangesOrLowHighPC()
691 MBB->sameSection(EndMBB) ? EndLabel : MBBSectionRange.EndLabel}); in attachRangesOrLowHighPC()
693 if (MBB->sameSection(EndMBB)) in attachRangesOrLowHighPC()
695 MBB = MBB->getNextNode(); in attachRangesOrLowHighPC()
698 attachRangesOrLowHighPC(Die, std::move(List)); in attachRangesOrLowHighPC()
701 DIE *DwarfCompileUnit::constructInlinedScopeDIE(LexicalScope *Scope, in constructInlinedScopeDIE()
702 DIE &ParentScopeDIE) { in constructInlinedScopeDIE()
703 assert(Scope->getScopeNode()); in constructInlinedScopeDIE()
704 auto *DS = Scope->getScopeNode(); in constructInlinedScopeDIE()
708 DIE *OriginDIE = getAbstractScopeDIEs()[InlinedSP]; in constructInlinedScopeDIE()
709 assert(OriginDIE && "Unable to find original DIE for an inlined subprogram."); in constructInlinedScopeDIE()
711 auto ScopeDIE = DIE::get(DIEValueAllocator, dwarf::DW_TAG_inlined_subroutine); in constructInlinedScopeDIE()
715 attachRangesOrLowHighPC(*ScopeDIE, Scope->getRanges()); in constructInlinedScopeDIE()
717 // Add the call site information to the DIE. in constructInlinedScopeDIE()
718 const DILocation *IA = Scope->getInlinedAt(); in constructInlinedScopeDIE()
720 getOrCreateSourceID(IA->getFile())); in constructInlinedScopeDIE()
721 addUInt(*ScopeDIE, dwarf::DW_AT_call_line, std::nullopt, IA->getLine()); in constructInlinedScopeDIE()
722 if (IA->getColumn()) in constructInlinedScopeDIE()
723 addUInt(*ScopeDIE, dwarf::DW_AT_call_column, std::nullopt, IA->getColumn()); in constructInlinedScopeDIE()
724 if (IA->getDiscriminator() && DD->getDwarfVersion() >= 4) in constructInlinedScopeDIE()
726 IA->getDiscriminator()); in constructInlinedScopeDIE()
730 DD->addSubprogramNames(*this, CUNode->getNameTableKind(), InlinedSP, in constructInlinedScopeDIE()
738 DIE *DwarfCompileUnit::constructLexicalScopeDIE(LexicalScope *Scope) { in constructLexicalScopeDIE()
739 if (DD->isLexicalScopeDIENull(Scope)) in constructLexicalScopeDIE()
741 const auto *DS = Scope->getScopeNode(); in constructLexicalScopeDIE()
743 auto ScopeDIE = DIE::get(DIEValueAllocator, dwarf::DW_TAG_lexical_block); in constructLexicalScopeDIE()
744 if (Scope->isAbstractScope()) { in constructLexicalScopeDIE()
746 "Abstract DIE for this scope exists!"); in constructLexicalScopeDIE()
750 if (!Scope->getInlinedAt()) { in constructLexicalScopeDIE()
752 "Concrete out-of-line DIE for this scope exists!"); in constructLexicalScopeDIE()
756 attachRangesOrLowHighPC(*ScopeDIE, Scope->getRanges()); in constructLexicalScopeDIE()
761 DIE *DwarfCompileUnit::constructVariableDIE(DbgVariable &DV, bool Abstract) { in constructVariableDIE()
762 auto *VariableDie = DIE::get(DIEValueAllocator, DV.getTag()); in constructVariableDIE()
779 const Loc::Single &Single, const DbgVariable &DV, DIE &VariableDie) { in applyConcreteDbgVariableAttributes()
781 if (!DVal->isVariadic()) { in applyConcreteDbgVariableAttributes()
782 const DbgValueLocEntry *Entry = DVal->getLocEntries().begin(); in applyConcreteDbgVariableAttributes()
783 if (Entry->isLocation()) { in applyConcreteDbgVariableAttributes()
784 addVariableAddress(DV, VariableDie, Entry->getLoc()); in applyConcreteDbgVariableAttributes()
785 } else if (Entry->isInt()) { in applyConcreteDbgVariableAttributes()
787 if (Expr && Expr->getNumElements()) { in applyConcreteDbgVariableAttributes()
792 DwarfExpr.addUnsignedConstant(Entry->getInt()); in applyConcreteDbgVariableAttributes()
799 addConstantValue(VariableDie, Entry->getInt(), DV.getType()); in applyConcreteDbgVariableAttributes()
800 } else if (Entry->isConstantFP()) { in applyConcreteDbgVariableAttributes()
801 addConstantFPValue(VariableDie, Entry->getConstantFP()); in applyConcreteDbgVariableAttributes()
802 } else if (Entry->isConstantInt()) { in applyConcreteDbgVariableAttributes()
803 addConstantValue(VariableDie, Entry->getConstantInt(), DV.getType()); in applyConcreteDbgVariableAttributes()
804 } else if (Entry->isTargetIndexLocation()) { in applyConcreteDbgVariableAttributes()
808 static_cast<const Metadata *>(DV.getVariable()->getType())); in applyConcreteDbgVariableAttributes()
816 if (any_of(DVal->getLocEntries(), [](const DbgValueLocEntry &Entry) { in applyConcreteDbgVariableAttributes()
826 const TargetRegisterInfo &TRI = *Asm->MF->getSubtarget().getRegisterInfo(); in applyConcreteDbgVariableAttributes()
841 // arguments into separate pointer-sized fragment expressions. in applyConcreteDbgVariableAttributes()
842 APInt RawBytes = Entry.getConstantFP()->getValueAPF().bitcastToAPInt(); in applyConcreteDbgVariableAttributes()
847 APInt RawBytes = Entry.getConstantInt()->getValue(); in applyConcreteDbgVariableAttributes()
853 // TODO TargetIndexLocation is a target-independent. Currently in applyConcreteDbgVariableAttributes()
854 // only the WebAssembly-specific encoding is supported. in applyConcreteDbgVariableAttributes()
855 assert(Asm->TM.getTargetTriple().isWasm()); in applyConcreteDbgVariableAttributes()
865 [&](unsigned Idx, DIExpressionCursor &Cursor) -> bool { in applyConcreteDbgVariableAttributes()
866 return AddEntry(DVal->getLocEntries()[Idx], Cursor); in applyConcreteDbgVariableAttributes()
870 // Now attach the location information to the DIE. in applyConcreteDbgVariableAttributes()
878 const Loc::Multi &Multi, const DbgVariable &DV, DIE &VariableDie) { in applyConcreteDbgVariableAttributes()
889 DIE &VariableDie) { in applyConcreteDbgVariableAttributes()
896 const TargetFrameLowering *TFI = Asm->MF->getSubtarget().getFrameLowering(); in applyConcreteDbgVariableAttributes()
898 TFI->getFrameIndexReference(*Asm->MF, Fragment.FI, FrameReg); in applyConcreteDbgVariableAttributes()
901 auto *TRI = Asm->MF->getSubtarget().getRegisterInfo(); in applyConcreteDbgVariableAttributes()
903 TRI->getOffsetOpcodes(Offset, Ops); in applyConcreteDbgVariableAttributes()
906 … https://docs.nvidia.com/cuda/archive/10.0/ptx-writers-guide-to-interoperability/index.html#cuda-s… in applyConcreteDbgVariableAttributes()
907 // cuda-gdb requires DW_AT_address_class for all variables to be in applyConcreteDbgVariableAttributes()
912 if (Asm->TM.getTargetTriple().isNVPTX() && DD->tuneForGDB()) { in applyConcreteDbgVariableAttributes()
921 Ops.append(Expr->elements_begin(), Expr->elements_end()); in applyConcreteDbgVariableAttributes()
924 if (const MCSymbol *FrameSymbol = Asm->getFunctionFrameSymbol()) in applyConcreteDbgVariableAttributes()
928 *Asm->MF->getSubtarget().getRegisterInfo(), Cursor, FrameReg); in applyConcreteDbgVariableAttributes()
931 if (Asm->TM.getTargetTriple().isNVPTX() && DD->tuneForGDB()) { in applyConcreteDbgVariableAttributes()
933 … https://docs.nvidia.com/cuda/archive/10.0/ptx-writers-guide-to-interoperability/index.html#cuda-s… in applyConcreteDbgVariableAttributes()
934 // cuda-gdb requires DW_AT_address_class for all variables to be in applyConcreteDbgVariableAttributes()
949 DIE &VariableDie) { in applyConcreteDbgVariableAttributes()
958 *Asm->MF->getSubtarget().getRegisterInfo(), Cursor, Register); in applyConcreteDbgVariableAttributes()
965 const std::monostate &, const DbgVariable &DV, DIE &VariableDie) {} in applyConcreteDbgVariableAttributes()
967 DIE *DwarfCompileUnit::constructVariableDIE(DbgVariable &DV, in constructVariableDIE()
969 DIE *&ObjectPointer) { in constructVariableDIE()
976 DIE *DwarfCompileUnit::constructLabelDIE(DbgLabel &DL, in constructLabelDIE()
978 auto LabelDie = DIE::get(DIEValueAllocator, DL.getTag()); in constructLabelDIE()
991 auto *Array = dyn_cast<DICompositeType>(Var->getType()); in dependencies()
992 if (!Array || Array->getTag() != dwarf::DW_TAG_array_type) in dependencies()
994 if (auto *DLVar = Array->getDataLocation()) in dependencies()
996 if (auto *AsVar = Array->getAssociated()) in dependencies()
998 if (auto *AlVar = Array->getAllocated()) in dependencies()
1000 for (auto *El : Array->getElements()) { in dependencies()
1002 if (auto Count = Subrange->getCount()) in dependencies()
1005 if (auto LB = Subrange->getLowerBound()) in dependencies()
1008 if (auto UB = Subrange->getUpperBound()) in dependencies()
1011 if (auto ST = Subrange->getStride()) in dependencies()
1015 if (auto Count = GenericSubrange->getCount()) in dependencies()
1018 if (auto LB = GenericSubrange->getLowerBound()) in dependencies()
1021 if (auto UB = GenericSubrange->getUpperBound()) in dependencies()
1024 if (auto ST = GenericSubrange->getStride()) in dependencies()
1047 DbgVar.insert({Var->getVariable(), Var}); in sortLocalVars()
1091 DIE &DwarfCompileUnit::constructSubprogramScopeDIE(const DISubprogram *Sub, in constructSubprogramScopeDIE()
1093 DIE &ScopeDIE = updateSubprogramScopeDIE(Sub); in constructSubprogramScopeDIE()
1096 assert(!Scope->getInlinedAt()); in constructSubprogramScopeDIE()
1097 assert(!Scope->isAbstractScope()); in constructSubprogramScopeDIE()
1099 // ObjectPointer might be a local (non-argument) local variable if it's a in constructSubprogramScopeDIE()
1101 if (DIE *ObjectPointer = createAndAddScopeChildren(Scope, ScopeDIE)) in constructSubprogramScopeDIE()
1106 DITypeRefArray FnArgs = Sub->getType()->getTypeArray(); in constructSubprogramScopeDIE()
1111 if (FnArgs.size() > 1 && !FnArgs[FnArgs.size() - 1] && in constructSubprogramScopeDIE()
1114 DIE::get(DIEValueAllocator, dwarf::DW_TAG_unspecified_parameters)); in constructSubprogramScopeDIE()
1119 DIE *DwarfCompileUnit::createAndAddScopeChildren(LexicalScope *Scope, in createAndAddScopeChildren()
1120 DIE &ScopeDIE) { in createAndAddScopeChildren()
1121 DIE *ObjectPointer = nullptr; in createAndAddScopeChildren()
1124 auto Vars = DU->getScopeVariables().lookup(Scope); in createAndAddScopeChildren()
1134 for (DbgLabel *DL : DU->getScopeLabels().lookup(Scope)) in createAndAddScopeChildren()
1137 // Track other local entities (skipped in gmlt-like data). in createAndAddScopeChildren()
1140 if (!includeMinimalInlineScopes() && !Scope->getInlinedAt()) { in createAndAddScopeChildren()
1141 auto &LocalDecls = DD->getLocalDeclsForScope(Scope->getScopeNode()); in createAndAddScopeChildren()
1146 auto skipLexicalScope = [this](LexicalScope *S) -> bool { in createAndAddScopeChildren()
1147 if (isa<DISubprogram>(S->getScopeNode())) in createAndAddScopeChildren()
1149 auto Vars = DU->getScopeVariables().lookup(S); in createAndAddScopeChildren()
1153 DD->getLocalDeclsForScope(S->getScopeNode()).empty(); in createAndAddScopeChildren()
1155 for (LexicalScope *LS : Scope->getChildren()) { in createAndAddScopeChildren()
1156 // If the lexical block doesn't have non-scope children, skip in createAndAddScopeChildren()
1169 auto *SP = cast<DISubprogram>(Scope->getScopeNode()); in constructAbstractSubprogramScopeDIE()
1173 DIE *ContextDIE; in constructAbstractSubprogramScopeDIE()
1180 // DIE (since the debug node will be associated with the concrete DIE, if in constructAbstractSubprogramScopeDIE()
1182 else if (auto *SPDecl = SP->getDeclaration()) { in constructAbstractSubprogramScopeDIE()
1186 ContextDIE = getOrCreateContextDIE(SP->getScope()); in constructAbstractSubprogramScopeDIE()
1190 ContextCU = DD->lookupCU(ContextDIE->getUnitDie()); in constructAbstractSubprogramScopeDIE()
1195 DIE &AbsDef = ContextCU->createAndAddDIE(dwarf::DW_TAG_subprogram, in constructAbstractSubprogramScopeDIE()
1198 // Store the DIE before creating children. in constructAbstractSubprogramScopeDIE()
1199 ContextCU->getAbstractScopeDIEs()[SP] = &AbsDef; in constructAbstractSubprogramScopeDIE()
1201 ContextCU->applySubprogramAttributesToDefinition(SP, AbsDef); in constructAbstractSubprogramScopeDIE()
1202 ContextCU->addSInt(AbsDef, dwarf::DW_AT_inline, in constructAbstractSubprogramScopeDIE()
1203 DD->getDwarfVersion() <= 4 ? std::optional<dwarf::Form>() in constructAbstractSubprogramScopeDIE()
1206 if (DIE *ObjectPointer = ContextCU->createAndAddScopeChildren(Scope, AbsDef)) in constructAbstractSubprogramScopeDIE()
1207 ContextCU->addDIEEntry(AbsDef, dwarf::DW_AT_object_pointer, *ObjectPointer); in constructAbstractSubprogramScopeDIE()
1211 return DD->getDwarfVersion() == 4 && !DD->tuneForLLDB(); in useGNUAnalogForDwarf5Feature()
1261 DIE &DwarfCompileUnit::constructCallSiteEntryDIE(DIE &ScopeDIE, in constructCallSiteEntryDIE()
1267 // Insert a call site entry DIE within ScopeDIE. in constructCallSiteEntryDIE()
1268 DIE &CallSiteDIE = createAndAddDIE(getDwarf5OrGNUTag(dwarf::DW_TAG_call_site), in constructCallSiteEntryDIE()
1276 DIE *CalleeDIE = getOrCreateSubprogramDIE(CalleeSP); in constructCallSiteEntryDIE()
1277 assert(CalleeDIE && "Could not create DIE for call site entry origin"); in constructCallSiteEntryDIE()
1279 !CalleeSP->isDefinition() && in constructCallSiteEntryDIE()
1280 !CalleeDIE->findAttribute(dwarf::DW_AT_linkage_name)) { in constructCallSiteEntryDIE()
1281 addLinkageName(*CalleeDIE, CalleeSP->getLinkageName()); in constructCallSiteEntryDIE()
1295 // GDB works backwards from non-standard usage of DW_AT_low_pc (in DWARF4 in constructCallSiteEntryDIE()
1296 // mode -- equivalently, in DWARF5 mode, DW_AT_call_return_pc) at tail-call in constructCallSiteEntryDIE()
1297 // site entries to figure out the PC of tail-calling branch instructions. in constructCallSiteEntryDIE()
1301 // There's no need to tie non-GDB debuggers to this non-standardness, as it in constructCallSiteEntryDIE()
1302 // adds unnecessary complexity to the debugger. For non-GDB debuggers, emit in constructCallSiteEntryDIE()
1324 DIE &CallSiteDIE, SmallVector<DbgCallSiteParam, 4> &Params) { in constructCallSiteParmEntryDIEs()
1328 DIE::get(DIEValueAllocator, in constructCallSiteParmEntryDIEs()
1347 DIE *DwarfCompileUnit::constructImportedEntityDIE( in constructImportedEntityDIE()
1349 DIE *IMDie = DIE::get(DIEValueAllocator, (dwarf::Tag)Module->getTag()); in constructImportedEntityDIE()
1351 DIE *EntityDie; in constructImportedEntityDIE()
1352 auto *Entity = Module->getEntity(); in constructImportedEntityDIE()
1374 addSourceLine(*IMDie, Module->getLine(), Module->getFile()); in constructImportedEntityDIE()
1376 StringRef Name = Module->getName(); in constructImportedEntityDIE()
1385 DD->addAccelNamespace(*this, CUNode->getNameTableKind(), Name, *IMDie); in constructImportedEntityDIE()
1390 DINodeArray Elements = Module->getElements(); in constructImportedEntityDIE()
1394 IMDie->addChild( in constructImportedEntityDIE()
1401 DIE *DwarfCompileUnit::getOrCreateImportedEntityDIE( in getOrCreateImportedEntityDIE()
1404 // Check for pre-existence. in getOrCreateImportedEntityDIE()
1405 if (DIE *Die = getDIE(IE)) in getOrCreateImportedEntityDIE() local
1406 return Die; in getOrCreateImportedEntityDIE()
1408 DIE *ContextDIE = getOrCreateContextDIE(IE->getScope()); in getOrCreateImportedEntityDIE()
1411 DIE *IMDie = constructImportedEntityDIE(IE); in getOrCreateImportedEntityDIE()
1412 ContextDIE->addChild(IMDie); in getOrCreateImportedEntityDIE()
1417 DIE *D = getDIE(SP); in finishSubprogramDefinition()
1418 if (DIE *AbsSPDIE = getAbstractScopeDIEs().lookup(SP)) { in finishSubprogramDefinition()
1431 DbgEntity *AbsEntity = getExistingAbstractEntity(Entity->getEntity()); in finishEntityDefinition()
1433 auto *Die = Entity->getDIE(); in finishEntityDefinition() local
1437 if (AbsEntity && AbsEntity->getDIE()) { in finishEntityDefinition()
1438 addDIEEntry(*Die, dwarf::DW_AT_abstract_origin, *AbsEntity->getDIE()); in finishEntityDefinition()
1442 applyCommonDbgVariableAttributes(*Var, *Die); in finishEntityDefinition()
1444 applyLabelAttributes(*Label, *Die); in finishEntityDefinition()
1452 const auto *Sym = Label->getSymbol(); in finishEntityDefinition()
1456 addLabelAddress(*Die, dwarf::DW_AT_low_pc, Sym); in finishEntityDefinition()
1459 if (StringRef Name = Label->getName(); !Name.empty()) in finishEntityDefinition()
1460 getDwarfDebug().addAccelName(*this, CUNode->getNameTableKind(), Name, *Die); in finishEntityDefinition()
1467 return I->second.get(); in getExistingAbstractEntity()
1473 assert(Scope && Scope->isAbstractScope()); in createAbstractEntity()
1478 DU->addScopeVariable(Scope, cast<DbgVariable>(Entity.get())); in createAbstractEntity()
1482 DU->addScopeLabel(Scope, cast<DbgLabel>(Entity.get())); in createAbstractEntity()
1488 if (!Skeleton && !DD->useSectionsAsReferences()) { in emitHeader()
1489 LabelBegin = Asm->createTempSymbol("cu_begin"); in emitHeader()
1490 Asm->OutStreamer->emitLabel(LabelBegin); in emitHeader()
1494 : DD->useSplitDwarf() ? dwarf::DW_UT_skeleton in emitHeader()
1497 if (DD->getDwarfVersion() >= 5 && UT != dwarf::DW_UT_compile) in emitHeader()
1498 Asm->emitInt64(getDWOId()); in emitHeader()
1502 switch (CUNode->getNameTableKind()) { in hasDwarfPubSections()
1512 return DD->tuneForGDB() && !includeMinimalInlineScopes() && in hasDwarfPubSections()
1513 !CUNode->isDebugDirectivesOnly() && in hasDwarfPubSections()
1514 DD->getAccelTableKind() != AccelTableKind::Apple && in hasDwarfPubSections()
1515 DD->getDwarfVersion() < 5; in hasDwarfPubSections()
1520 /// addGlobalName - Add a new global name to the compile unit.
1521 void DwarfCompileUnit::addGlobalName(StringRef Name, const DIE &Die, in addGlobalName() argument
1526 GlobalNames[FullName] = &Die; in addGlobalName()
1534 // Insert, allowing the entry to remain as-is if it's already present in addGlobalNameForTypeUnit()
1535 // This way the CU-level type DIE is preferred over the "can't describe this in addGlobalNameForTypeUnit()
1542 void DwarfCompileUnit::addGlobalTypeImpl(const DIType *Ty, const DIE &Die, in addGlobalTypeImpl() argument
1546 std::string FullName = getParentContextString(Context) + Ty->getName().str(); in addGlobalTypeImpl()
1547 GlobalTypes[FullName] = &Die; in addGlobalTypeImpl()
1554 std::string FullName = getParentContextString(Context) + Ty->getName().str(); in addGlobalTypeUnitType()
1555 // Insert, allowing the entry to remain as-is if it's already present in addGlobalTypeUnitType()
1556 // This way the CU-level type DIE is preferred over the "can't describe this in addGlobalTypeUnitType()
1562 void DwarfCompileUnit::addVariableAddress(const DbgVariable &DV, DIE &Die, in addVariableAddress() argument
1565 if (Single && Single->getExpr()) in addVariableAddress()
1566 addComplexAddress(Single->getExpr(), Die, dwarf::DW_AT_location, Location); in addVariableAddress()
1568 addAddress(Die, dwarf::DW_AT_location, Location); in addVariableAddress()
1571 /// Add an address attribute to a die based on the location provided.
1572 void DwarfCompileUnit::addAddress(DIE &Die, dwarf::Attribute Attribute, in addAddress() argument
1580 const TargetRegisterInfo &TRI = *Asm->MF->getSubtarget().getRegisterInfo(); in addAddress()
1585 // Now attach the location information to the DIE. in addAddress()
1586 addBlock(Die, Attribute, DwarfExpr.finalize()); in addAddress()
1589 addUInt(Die, dwarf::DW_AT_LLVM_tag_offset, dwarf::DW_FORM_data1, in addAddress()
1593 /// Start with the address based on the location provided, and generate the
1596 /// location. Add the DWARF information to the die.
1597 void DwarfCompileUnit::addComplexAddress(const DIExpression *DIExpr, DIE &Die, in addComplexAddress() argument
1607 if (DIExpr->isEntryValue()) in addComplexAddress()
1610 const TargetRegisterInfo &TRI = *Asm->MF->getSubtarget().getRegisterInfo(); in addComplexAddress()
1615 // Now attach the location information to the DIE. in addComplexAddress()
1616 addBlock(Die, Attribute, DwarfExpr.finalize()); in addComplexAddress()
1619 addUInt(Die, dwarf::DW_AT_LLVM_tag_offset, dwarf::DW_FORM_data1, in addComplexAddress()
1624 void DwarfCompileUnit::addLocationList(DIE &Die, dwarf::Attribute Attribute, in addLocationList() argument
1626 dwarf::Form Form = (DD->getDwarfVersion() >= 5) in addLocationList()
1628 : DD->getDwarfSectionOffsetForm(); in addLocationList()
1629 addAttribute(Die, Attribute, Form, DIELocList(Index)); in addLocationList()
1633 DIE &VariableDie) { in applyCommonDbgVariableAttributes()
1639 if (uint32_t AlignInBytes = DIVar->getAlignInBytes()) in applyCommonDbgVariableAttributes()
1642 addAnnotation(VariableDie, DIVar->getAnnotations()); in applyCommonDbgVariableAttributes()
1652 DIE &LabelDie) { in applyLabelAttributes()
1661 void DwarfCompileUnit::addExpr(DIELoc &Die, dwarf::Form Form, in addExpr() argument
1663 addAttribute(Die, (dwarf::Attribute)0, Form, DIEExpr(Expr)); in addExpr()
1667 const DISubprogram *SP, DIE &SPDie) { in applySubprogramAttributesToDefinition()
1668 auto *SPDecl = SP->getDeclaration(); in applySubprogramAttributesToDefinition()
1669 auto *Context = SPDecl ? SPDecl->getScope() : SP->getScope(); in applySubprogramAttributesToDefinition()
1671 addGlobalName(SP->getName(), SPDie, Context); in applySubprogramAttributesToDefinition()
1675 return DD->useSplitDwarf() && Skeleton; in isDwoUnit()
1678 void DwarfCompileUnit::finishNonUnitTypeDIE(DIE& D, const DICompositeType *CTy) { in finishNonUnitTypeDIE()
1683 return getCUNode()->getEmissionKind() == DICompileUnit::LineTablesOnly || in includeMinimalInlineScopes()
1684 (DD->useSplitDwarf() && !Skeleton); in includeMinimalInlineScopes()
1688 const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering(); in addAddrTableBase()
1689 MCSymbol *Label = DD->getAddressPool().getLabel(); in addAddrTableBase()
1691 DD->getDwarfVersion() >= 5 ? dwarf::DW_AT_addr_base in addAddrTableBase()
1693 Label, TLOF.getDwarfAddrSection()->getBeginSymbol()); in addAddrTableBase()
1696 void DwarfCompileUnit::addBaseTypeRef(DIEValueList &Die, int64_t Idx) { in addBaseTypeRef() argument
1697 addAttribute(Die, (dwarf::Attribute)0, dwarf::DW_FORM_udata, in addBaseTypeRef()
1707 DIE &Die = getUnitDie().addChildFront( in createBaseTypeDIEs() local
1708 DIE::get(DIEValueAllocator, dwarf::DW_TAG_base_type)); in createBaseTypeDIEs()
1710 addString(Die, dwarf::DW_AT_name, in createBaseTypeDIEs()
1713 addUInt(Die, dwarf::DW_AT_encoding, dwarf::DW_FORM_data1, Btr.Encoding); in createBaseTypeDIEs()
1715 addUInt(Die, dwarf::DW_AT_byte_size, std::nullopt, in createBaseTypeDIEs()
1718 Btr.Die = &Die; in createBaseTypeDIEs()
1722 DIE *DwarfCompileUnit::getLexicalBlockDIE(const DILexicalBlock *LB) { in getLexicalBlockDIE()
1724 bool isAbstract = getAbstractScopeDIEs().count(LB->getSubprogram()); in getLexicalBlockDIE()
1727 assert(!isAbstract && "Missed lexical block DIE in abstract tree!"); in getLexicalBlockDIE()
1729 // Return a concrete DIE if it exists or nullptr otherwise. in getLexicalBlockDIE()
1733 DIE *DwarfCompileUnit::getOrCreateContextDIE(const DIScope *Context) { in getOrCreateContextDIE()
1736 Context = LFScope->getNonLexicalBlockFileScope(); in getOrCreateContextDIE()