Lines Matching +full:slice +full:- +full:per +full:- +full:line

1 //===- llvm/CodeGen/DwarfDebug.cpp - Dwarf Debug Framework ----------------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
11 //===----------------------------------------------------------------------===//
70 "use-dwarf-ranges-base-address-specifier", cl::Hidden,
73 static cl::opt<bool> GenerateARangeSection("generate-arange-section",
79 GenerateDwarfTypeUnits("generate-type-units", cl::Hidden,
84 "split-dwarf-cross-cu-references", cl::Hidden,
85 cl::desc("Enable cross-cu references in DWO files"), cl::init(false));
90 "use-unknown-locations", cl::Hidden,
97 "accel-tables", cl::Hidden, cl::desc("Output dwarf accelerator tables."),
106 DwarfInlinedStrings("dwarf-inlined-strings", cl::Hidden,
114 NoDwarfRangesSection("no-dwarf-ranges-section", cl::Hidden,
119 "dwarf-sections-as-references", cl::Hidden,
126 UseGNUDebugMacro("use-gnu-debug-macro", cl::Hidden,
131 "dwarf-op-convert", cl::Hidden,
144 DwarfLinkageNames("dwarf-linkage-names", cl::Hidden,
145 cl::desc("Which DWARF linkage-name attributes to emit."),
154 "minimize-addr-in-v5", cl::Hidden,
161 "using a pre-existing base address"),
214 return TmpBuf ? TmpBuf->Bytes.size() : 0;
220 for (auto Byte : enumerate(TmpBuf->Bytes)) {
221 const char *Comment = (Byte.index() < TmpBuf->Comments.size())
222 ? TmpBuf->Comments[Byte.index()].c_str()
226 TmpBuf->Bytes.clear();
227 TmpBuf->Comments.clear();
231 return getVariable()->getType();
236 const DIExpression *Expr = MI->getDebugExpression();
240 // non-variadic instruction, then convert it to non-variadic form here.
241 if (!IsVariadic && !MI->isNonListDebugValue()) {
242 assert(MI->getNumDebugOperands() == 1 &&
246 assert(MI->getNumOperands() >= 3);
248 for (const MachineOperand &Op : MI->debug_operands()) {
251 MI->isNonListDebugValue() && MI->isDebugOffsetImm());
270 return Fragment ? Fragment->OffsetInBits : 0;
285 if (!Expr->getNumElements())
301 return FIE.Expr && FIE.Expr->isFragment();
331 : DebugHandlerBase(A), DebugLocs(A->OutStreamer->isVerboseAsm()),
334 IsDarwin(A->TM.getTargetTriple().isOSDarwin()) {
335 const Triple &TT = Asm->TM.getTargetTriple();
338 // precedence; fall back to triple-based defaults.
339 if (Asm->TM.Options.DebuggerTuning != DebuggerKind::Default)
340 DebuggerTuning = Asm->TM.Options.DebuggerTuning;
360 HasSplitDwarf = !Asm->TM.Options.MCOptions.SplitDwarfFile.empty();
368 unsigned DwarfVersionNumber = Asm->TM.Options.MCOptions.DwarfVersion;
370 : MMI->getModule()->getDwarfVersion();
376 TT.isArch64Bit(); // DWARF64 requires 64-bit relocations.
381 // according to the DWARF64 format for 64-bit assembly, so we must use
382 // DWARF64 in the compiler too for 64-bit mode.
384 ((Asm->TM.Options.MCOptions.Dwarf64 || MMI->getModule()->isDwarf64()) &&
389 report_fatal_error("XCOFF requires DWARF64 for 64-bit mode!");
400 GenerateTypeUnits = (A->TM.getTargetTriple().isOSBinFormatELF() ||
401 A->TM.getTargetTriple().isOSBinFormatWasm()) &&
405 DwarfVersion, GenerateTypeUnits, DebuggerTuning, A->TM.getTargetTriple());
410 // See GDB bug 11616 - DW_OP_form_tls_address is unimplemented
416 // The DWARF v5 string offsets table has - possibly shared - contributions
418 // offsets table used by the pre-DWARF v5 split-DWARF implementation uses
422 // Emit call-site-param debug info for GDB and LLDB, if the target supports
424 EmitDebugEntryValues = Asm->TM.Options.ShouldEmitDebugEntryValues();
426 // It is unclear if the GCC .debug_macro extension is well-specified
440 Asm->OutStreamer->getContext().setDwarfVersion(DwarfVersion);
441 Asm->OutStreamer->getContext().setDwarfFormat(Dwarf64 ? dwarf::DWARF64
445 // Define out of line so we don't have to include DwarfUnit.h in DwarfDebug.h.
449 return Name.starts_with("+") || Name.starts_with("-");
462 Class = In.slice(In.find('[') + 1, In.find(' '));
467 Class = In.slice(In.find('[') + 1, In.find('('));
468 Category = In.slice(In.find('[') + 1, In.find(' '));
472 return In.slice(In.find(' ') + 1, In.find(']'));
485 if (!SP->isDefinition())
488 if (SP->getName() != "")
489 addAccelName(Unit, NameTableKind, SP->getName(), Die);
494 if (SP->getLinkageName() != "" && SP->getName() != SP->getLinkageName() &&
496 addAccelName(Unit, NameTableKind, SP->getLinkageName(), Die);
498 // If this is an Objective-C selector name add it to the ObjC accelerator
500 if (isObjCClass(SP->getName())) {
502 getObjCClassCategory(SP->getName(), Class, Category);
507 addAccelName(Unit, NameTableKind, getObjCMethodName(SP->getName()), Die);
514 if (Scope->isAbstractScope())
518 const SmallVectorImpl<InsnRange> &Ranges = Scope->getRanges();
533 if (CU.getCUNode()->getSplitDebugInlining())
543 assert(Scope && Scope->getScopeNode());
544 assert(Scope->isAbstractScope());
545 assert(!Scope->getInlinedAt());
547 auto *SP = cast<DISubprogram>(Scope->getScopeNode());
551 if (useSplitDwarf() && !shareAcrossDWOCUs() && !SP->getUnit()->getSplitDebugInlining())
555 auto &CU = getOrCreateDwarfCompileUnit(SP->getUnit());
559 if (CU.getCUNode()->getSplitDebugInlining())
560 SkelCU->constructAbstractSubprogramScopeDIE(Scope);
586 std::vector<uint64_t> Elts = Addition->getElements().vec();
588 if (Original->isImplicit() && Addition->isImplicit())
602 bool ShouldCombineExpressions = Expr && Param.Expr->getNumElements() > 0;
606 if (ShouldCombineExpressions && Expr->isEntryValue())
616 assert((!CombinedExpr || CombinedExpr->isValid()) &&
633 auto &ParamsForFwdReg = I.first->second;
656 const MachineFunction *MF = CurMI->getMF();
658 DIExpression::get(MF->getFunction().getContext(), {});
659 const auto &TRI = *MF->getSubtarget().getRegisterInfo();
660 const auto &TII = *MF->getSubtarget().getInstrInfo();
661 const auto &TLI = *MF->getSubtarget().getTargetLowering();
714 // It's possible that we find a copy from a non-volatile register to the param
717 auto IsRegClobberedInMeantime = [&](Register Reg) -> bool {
726 if (ParamValue->first.isImm()) {
727 int64_t Val = ParamValue->first.getImm();
728 finishCallSiteParams(Val, ParamValue->second,
730 } else if (ParamValue->first.isReg()) {
731 Register RegLoc = ParamValue->first.getReg();
738 finishCallSiteParams(MLoc, ParamValue->second,
741 // ParamFwdReg was described by the non-callee saved register
747 addToFwdRegWorklist(TmpWorklistItems, RegLoc, ParamValue->second,
774 if (CurMI->isBundle())
780 if (CurMI->isCall())
787 if (CurMI->getNumOperands() == 0)
799 const MachineFunction *MF = CallMI->getMF();
800 const auto &CalleesMap = MF->getCallSitesInfo();
807 const MachineBasicBlock *MBB = CallMI->getParent();
810 auto I = std::next(CallMI->getReverseIterator());
815 DIExpression::get(MF->getFunction().getContext(), {});
818 for (const auto &ArgReg : CSInfo->second.ArgRegPairs) {
827 for (const auto &MO : CallMI->uses())
839 bool ShouldTryEmitEntryVals = MBB->getIterator() == MF->begin();
843 if (CallMI->hasDelaySlot()) {
844 auto Suc = std::next(CallMI->getIterator());
845 // Only one-instruction delay slot is supported.
846 auto BundleEnd = llvm::getBundleEnd(CallMI->getIterator());
856 for (; I != MBB->rend(); ++I) {
866 MF->getFunction().getContext(), {dwarf::DW_OP_LLVM_entry_value, 1});
877 // Add a call site-related attribute (DWARF5, Sec. 3.3.1.3). Do this only if
883 // for both tail and non-tail calls. Don't use DW_AT_call_all_source_calls
885 // optimized-out calls are elided.
919 // Skip instructions which aren't calls. Both calls and tail-calling jump
936 const MachineOperand &CalleeOp = TII->getCalleeOperand(MI);
950 if (!CalleeDecl || !CalleeDecl->getSubprogram())
952 CalleeSP = CalleeDecl->getSubprogram();
957 bool IsTail = TII->isTailCall(MI);
960 // EmitFunctionBody iterates over top-level MIs. Get that top-level MI
965 // For non-tail calls, the return PC is needed to disambiguate paths in
979 assert((IsTail || PCAddr) && "Non-tail call without return PC");
981 LLVM_DEBUG(dbgs() << "CallSiteEntry: " << MF.getName() << " -> "
982 << (CalleeDecl ? CalleeDecl->getName()
985 ->getName(CallReg)))
991 // Optionally emit call-site-param debug info.
1012 StringRef FN = DIUnit->getFilename();
1014 StringRef Producer = DIUnit->getProducer();
1015 StringRef Flags = DIUnit->getFlags();
1023 DIUnit->getSourceLanguage());
1025 StringRef SysRoot = DIUnit->getSysRoot();
1028 StringRef SDK = DIUnit->getSDK();
1047 if (DIUnit->isOptimized())
1050 StringRef Flags = DIUnit->getFlags();
1054 if (unsigned RVer = DIUnit->getRuntimeVersion())
1059 if (DIUnit->getDWOId()) {
1062 DIUnit->getDWOId());
1063 if (!DIUnit->getSplitDebugFilename().empty()) {
1068 NewCU.addString(Die, attrDWOName, DIUnit->getSplitDebugFilename());
1081 (!DIUnit->getSplitDebugInlining() ||
1082 DIUnit->getEmissionKind() == DICompileUnit::FullDebug) &&
1084 return *CUMap.begin()->second;
1086 CompilationDir = DIUnit->getDirectory();
1093 // LTO with assembly output shares a single line table amongst multiple CUs.
1094 // To avoid the compilation directory being ambiguous, let the line table
1097 if (!Asm->OutStreamer->hasRawTextSupport() || SingleCU)
1098 Asm->OutStreamer->emitDwarfFile0Directive(
1099 CompilationDir, DIUnit->getFilename(), getMD5AsBytes(DIUnit->getFile()),
1100 DIUnit->getSource(), NewCU.getUniqueID());
1104 NewCU.setSection(Asm->getObjFileLowering().getDwarfInfoDWOSection());
1107 NewCU.setSection(Asm->getObjFileLowering().getDwarfInfoSection());
1123 // the sorting isn't non-deterministic, and so the following
1127 auto FragmentA = A.Expr->getFragmentInfo();
1128 auto FragmentB = B.Expr->getFragmentInfo();
1131 return FragmentA->OffsetInBits < FragmentB->OffsetInBits;
1148 if (!Asm || !MMI->hasDebugInfo())
1151 unsigned NumDebugCUs = std::distance(M->debug_compile_units_begin(),
1152 M->debug_compile_units_end());
1154 assert(MMI->hasDebugInfo() &&
1159 for (const GlobalVariable &Global : M->globals()) {
1163 GVMap[GVE->getVariable()].push_back({&Global, GVE->getExpression()});
1171 .setStringOffsetsStartSym(Asm->createTempSymbol("str_offsets_base"));
1179 Asm->createTempSymbol("rnglists_table_base"));
1183 Asm->createTempSymbol("rnglists_dwo_table_base"));
1188 AddrPool.setLabel(Asm->createTempSymbol("addr_table_base"));
1189 DebugLocs.setSym(Asm->createTempSymbol("loclists_table_base"));
1191 for (DICompileUnit *CUNode : M->debug_compile_units()) {
1192 if (CUNode->getImportedEntities().empty() &&
1193 CUNode->getEnumTypes().empty() && CUNode->getRetainedTypes().empty() &&
1194 CUNode->getGlobalVariables().empty() && CUNode->getMacros().empty())
1200 for (auto *GVE : CUNode->getGlobalVariables()) {
1204 auto &GVMapEntry = GVMap[GVE->getVariable()];
1205 auto *Expr = GVE->getExpression();
1206 if (!GVMapEntry.size() || (Expr && Expr->isConstant()))
1211 for (auto *GVE : CUNode->getGlobalVariables()) {
1212 DIGlobalVariable *GV = GVE->getVariable();
1217 for (auto *Ty : CUNode->getEnumTypes())
1220 for (auto *Ty : CUNode->getRetainedTypes()) {
1224 // There is no point in force-emitting a forward declaration.
1232 DIE *Die = Entity->getDIE();
1234 // FIXME: Consider the time-space tradeoff of just storing the unit pointer
1236 // DIE::getUnit isn't simple - it walks parent pointers, etc.
1237 DwarfCompileUnit *Unit = CUDieMap.lookup(Die->getUnitDie());
1239 Unit->finishEntityDefinition(Entity.get());
1245 assert(SP->getUnit()->getEmissionKind() != DICompileUnit::NoDebug);
1247 getOrCreateDwarfCompileUnit(SP->getUnit()),
1253 const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering();
1264 DWOName = Asm->TM.Options.MCOptions.SplitDwarfFile;
1268 // Handle anything that needs to be done on a per-unit basis after
1272 if (TheCU.getCUNode()->isDebugDirectivesOnly())
1295 Asm->TM.Options.MCOptions.SplitDwarfFile);
1296 SkCU->addString(SkCU->getUnitDie(), attrDWOName,
1297 Asm->TM.Options.MCOptions.SplitDwarfFile);
1303 SkCU->setDWOId(ID);
1307 SkCU->addUInt(SkCU->getUnitDie(), dwarf::DW_AT_GNU_dwo_id,
1312 const MCSymbol *Sym = TLOF.getDwarfRangesSection()->getBeginSymbol();
1313 SkCU->addSectionLabel(SkCU->getUnitDie(), dwarf::DW_AT_GNU_ranges_base,
1317 finishUnitAttributes(SkCU->getCUNode(), *SkCU);
1320 // If we have code split among multiple sections or non-contiguous
1324 // .subsections_via_symbols in mach-o. This would mean turning on
1325 // ranges for all subprogram DIEs for mach-o.
1352 TLOF.getDwarfLoclistsSection()->getBeginSymbol());
1359 if (CUNode->getMacros()) {
1364 TLOF.getDwarfMacroDWOSection()->getBeginSymbol());
1370 TLOF.getDwarfMacroSection()->getBeginSymbol());
1377 TLOF.getDwarfMacinfoDWOSection()->getBeginSymbol());
1381 TLOF.getDwarfMacinfoSection()->getBeginSymbol());
1386 // Emit all frontend-produced Skeleton CUs, i.e., Clang modules.
1387 for (auto *CUNode : MMI->getModule()->debug_compile_units())
1388 if (CUNode->getDWOId())
1403 // Terminate the pending line table.
1415 for (auto *IE : CUNode->getImportedEntities()) {
1416 assert(!isa_and_nonnull<DILocalScope>(IE->getScope()) &&
1417 "Unexpected function-local entity in 'imports' CU field.");
1418 CU->getOrCreateImportedEntityDIE(IE);
1420 for (const auto *D : CU->getDeferredLocalDecls()) {
1422 CU->getOrCreateImportedEntityDIE(IE);
1428 CU->createBaseTypeDIEs();
1431 // If we aren't actually generating debug info (check beginModule -
1433 if (!Asm || !MMI->hasDebugInfo())
1515 S = LV->getScope();
1517 S = L->getScope();
1519 S = IE->getScope();
1524 return cast<DILocalScope>(S)->getNonLexicalBlockFileScope();
1532 for (const auto &VI : Asm->MF->getVariableDbgInfo()) {
1535 assert(VI.Var->isValidLocationForIntrinsic(VI.Loc) &&
1536 "Expected inlined-at fields to agree");
1538 InlinedEntity Var(VI.Var, VI.Loc->getInlinedAt());
1544 LLVM_DEBUG(dbgs() << "Dropping debug info for " << VI.Var->getName()
1549 ensureAbstractEntityIsCreatedIfScoped(TheCU, Var.first, Scope->getScopeNode());
1558 PreviousMMI->addFrameIndexExpr(VI.Expr, VI.getStackSlot());
1561 PreviousEntryValue->addExpr(VI.getEntryValueRegister(), *VI.Expr);
1566 if (PreviousLoc->holds<Loc::MMI>())
1567 PreviousLoc->emplace<Loc::EntryValue>(VI.getEntryValueRegister(),
1569 LLVM_DEBUG(dbgs() << "Dropping debug info for " << VI.Var->getName()
1578 RegVar->emplace<Loc::MMI>(VI.Expr, VI.getStackSlot());
1580 RegVar->emplace<Loc::EntryValue>(VI.getEntryValueRegister(), *VI.Expr);
1581 LLVM_DEBUG(dbgs() << "Created DbgVariable for " << VI.Var->getName()
1597 assert(DbgValue->getDebugLoc() && "DBG_VALUE without a debug location");
1598 auto MBB = DbgValue->getParent();
1599 auto DL = DbgValue->getDebugLoc();
1604 auto &LSRange = LScope->getRanges();
1614 if (LScopeBegin->getParent() != MBB)
1618 for (++Pred; Pred != MBB->rend(); ++Pred) {
1619 if (Pred->getFlag(MachineInstr::FrameSetup))
1621 auto PredDL = Pred->getDebugLoc();
1622 if (!PredDL || Pred->isMetaInstruction())
1626 if (DL->getScope() == PredDL->getScope())
1629 if (!PredScope || LScope->dominates(PredScope))
1634 // If the range of the DBG_VALUE is open-ended, report success.
1642 if (MBB->pred_empty() &&
1643 all_of(DbgValue->debug_operands(),
1680 // 2 | | [Clobber, $reg0 = [...], -, -]
1686 // [0-1) [(reg0, fragment 0, 32)]
1687 // [1-3) [(reg0, fragment 0, 32), (reg1, fragment 32, 32)]
1688 // [3-4) [(reg1, fragment 32, 32), (123, fragment 64, 32)]
1689 // [4-) [(@g, fragment 0, 96)]
1700 const MachineInstr *Instr = EI->getInstr();
1709 EI->isClobber() ? getLabelAfterInsn(Instr) : getLabelBeforeInsn(Instr);
1715 const MachineBasicBlock &EndMBB = Asm->MF->back();
1716 EndLabel = Asm->MBBSectionRanges[EndMBB.getSectionID()].EndLabel;
1717 if (EI->isClobber())
1718 EndMI = EI->getInstr();
1720 else if (std::next(EI)->isClobber())
1721 EndLabel = getLabelAfterInsn(std::next(EI)->getInstr());
1723 EndLabel = getLabelBeforeInsn(std::next(EI)->getInstr());
1726 if (EI->isDbgValue())
1732 if (EI->isDbgValue()) {
1735 // description. If there are any non-undef fragments then padding pieces
1739 if (!Instr->isUndefDebugValue()) {
1741 OpenRanges.emplace_back(EI->getEndIndex(), Value);
1744 if (Instr->getDebugExpression()->isFragment())
1774 if (Asm->MF->hasBBSections() && StartLabel == Asm->getFunctionBegin() &&
1775 !Instr->getParent()->sameSection(&Asm->MF->front())) {
1778 for (const MachineBasicBlock &MBB : *Asm->MF) {
1779 if (MBB.isBeginSection() && &MBB != &Asm->MF->front())
1782 if (MBB.sameSection(Instr->getParent())) {
1797 dbgs() << CurEntry->getValues().size() << " Values:\n";
1798 for (auto &Value : CurEntry->getValues())
1800 dbgs() << "-----\n";
1804 if (PrevEntry != DebugLoc.rend() && PrevEntry->MergeRanges(*CurEntry))
1815 if (!Asm->MF->hasBBSections())
1819 // we must keep the split loclists per section. This does exactly what
1824 if (DebugLoc[0].getBeginSym() == Asm->getFunctionBegin())
1825 RangeMBB = &Asm->MF->front();
1827 RangeMBB = Entries.begin()->getInstr()->getParent();
1832 while (!RangeMBB->isEndSection())
1833 RangeMBB = RangeMBB->getNextNode();
1834 if (!RangeMBB->getNextNode())
1839 if (CurEntry->getEndSym() != RangeMBB->getEndSymbol() ||
1840 NextEntry->getBeginSym() != RangeMBB->getNextNode()->getSymbol() ||
1841 CurEntry->getValues() != NextEntry->getValues())
1843 RangeMBB = RangeMBB->getNextNode();
1876 // Grab the variable info that was squirreled away in the MMI side-table.
1887 // Try to find any non-empty variable location. Do not create a concrete
1895 Scope = LScopes.findInlinedScope(LocalVar->getScope(), IA);
1897 Scope = LScopes.findLexicalScope(LocalVar->getScope());
1907 assert(MInsn->isDebugValue() && "History must begin with debug value");
1919 RegVar->emplace<Loc::Single>(MInsn);
1939 RegVar->emplace<Loc::Single>(Entries[0].getValues()[0]);
1947 static_cast<const Metadata *>(LocalVar->getType()));
1955 // DWARF-related DbgLabel.
1966 Label->getScope()->getNonLexicalBlockFileScope();
1985 for (const DINode *DN : SP->getRetainedNodes()) {
2001 const MachineFunction &MF = *MI->getMF();
2004 !SP || SP->getUnit()->getEmissionKind() == DICompileUnit::NoDebug;
2015 assert(Suc->isBundledWithPred() &&
2021 if (!NoDebug && SP->areAllCallsDescribed() &&
2022 MI->isCandidateForCallSiteEntry(MachineInstr::AnyInBundle) &&
2023 (!MI->hasDelaySlot() || delaySlotSupported(*MI))) {
2025 bool IsTail = TII->isTailCall(*MI);
2030 // For non-tail calls, we need the return address for the call for
2045 // any line record, as there is no correspondence with any user code.
2046 if (MI->isMetaInstruction() || MI->getFlag(MachineInstr::FrameSetup))
2048 const DebugLoc &DL = MI->getDebugLoc();
2051 if (MI->getFlag(MachineInstr::FrameDestroy) && DL) {
2052 const MachineBasicBlock *MBB = MI->getParent();
2060 // When we emit a line-0 record, we don't update PrevInstLoc; so look at
2061 // the last line number actually emitted, to see if it was line 0.
2063 Asm->OutStreamer->getContext().getCurrentDwarfLoc().getLine();
2067 PrevInstBB->getSectionID() == MI->getParent()->getSectionID());
2073 // But we might be coming back to it after a line 0 record.
2083 // We have an unspecified location, which might want to be line 0.
2084 // If we have already emitted a line-0 record, don't repeat it.
2090 // See if we have a reason to emit a line-0 record now.
2091 // Reasons to emit a line-0 record include:
2092 // - User asked for it (UnknownLocations).
2093 // - Instruction has a label, so it's referenced from somewhere else,
2095 // - Instruction is at the top of a block; we don't want to inherit the
2098 (PrevInstBB && PrevInstBB != MI->getParent())) {
2100 // the encoded line table.
2101 // Do not update PrevInstLoc, it remembers the last non-0 line.
2108 recordSourceLine(/*Line=*/0, Column, Scope, /*Flags=*/0);
2114 // Don't repeat a line-0 record, but otherwise emit the new location.
2115 // (The new location might be an explicit line 0, which we do emit.)
2122 // If the line changed, we call that a new statement; unless we went to
2123 // line 0 and came back, in which case it is not a new statement.
2131 // If we're not at line 0, remember this location.
2137 // First known non-DBG_VALUE and non-frame setup location marks
2140 const Function &F = MF->getFunction();
2150 // Scan forward to try to find a non-zero line number. The
2152 // frame setup, and a compiler-generated line 0 location is not a
2167 /// Register a source line with debug info. Returns the unique label that was
2168 /// emitted and which provides correspondence to the source line list.
2169 static void recordSourceLine(AsmPrinter &Asm, unsigned Line, unsigned Col,
2177 Fn = Scope->getFilename();
2178 if (Line != 0 && DwarfVersion >= 4)
2180 Discriminator = LBF->getDiscriminator();
2183 .getOrCreateSourceID(Scope->getFile());
2185 Asm.OutStreamer->emitDwarfLocDirective(FileNo, Line, Col, Flags, 0,
2197 // If the prolog is empty, no need to generate scope line for the proc.
2204 MF.getFunction().getSubprogram()->getUnit());
2207 const DISubprogram *SP = PrologEndLoc->getInlinedAtScope()->getSubprogram();
2208 ::recordSourceLine(*Asm, SP->getScopeLine(), 0, SP, DWARF2_FLAG_IS_STMT,
2215 // Gather pre-function debug information. Assumes being called immediately
2220 auto *SP = MF->getFunction().getSubprogram();
2221 assert(LScopes.empty() || SP == LScopes.getCurrentFunctionScope()->getScopeNode());
2222 if (SP->getUnit()->getEmissionKind() == DICompileUnit::NoDebug)
2225 DwarfCompileUnit &CU = getOrCreateDwarfCompileUnit(SP->getUnit());
2227 Asm->OutStreamer->getContext().setDwarfCompileUnitID(
2232 *MF, Asm->OutStreamer->getContext().getDwarfCompileUnitID());
2238 // belongs to so that we add to the correct per-cu line table in the
2239 // non-asm case.
2240 if (Asm->OutStreamer->hasRawTextSupport())
2241 // Use a single line table if we are generating assembly.
2248 const auto &CURanges = CU->getRanges();
2249 auto &LineTable = Asm->OutStreamer->getContext().getMCDwarfLineTable(
2260 // Terminate the pending line table.
2267 // Gather and emit post-function debug information.
2269 const DISubprogram *SP = MF->getFunction().getSubprogram();
2275 Asm->OutStreamer->getContext().setDwarfCompileUnitID(0);
2278 assert(!FnScope || SP == FnScope->getScopeNode());
2279 DwarfCompileUnit &TheCU = getOrCreateDwarfCompileUnit(SP->getUnit());
2280 if (TheCU.getCUNode()->isDebugDirectivesOnly()) {
2291 for (const auto &R : Asm->MBBSectionRanges)
2294 // Under -gmlt, skip building the subprogram if there are no inlined
2295 // subroutines inside it. But with -fdebug-info-for-profiling, the subprogram
2297 if (!TheCU.getCUNode()->getDebugInfoForProfiling() &&
2298 TheCU.getCUNode()->getEmissionKind() == DICompileUnit::LineTablesOnly &&
2300 for (const auto &R : Asm->MBBSectionRanges)
2313 const auto *SP = cast<DISubprogram>(AScope->getScopeNode());
2314 for (const DINode *DN : SP->getRetainedNodes()) {
2340 TheCU.getCUNode()->getSplitDebugInlining())
2341 SkelCU->constructSubprogramScopeDIE(SP, FnScope);
2347 // Ownership of DbgVariables is a bit subtle - ScopeVariables owns all the
2349 // can be used cross-function)
2357 // Register a source line with debug info. Returns the unique label that was
2358 // emitted and which provides correspondence to the source line list.
2359 void DwarfDebug::recordSourceLine(unsigned Line, unsigned Col, const MDNode *S,
2361 ::recordSourceLine(*Asm, Line, Col, S, Flags,
2362 Asm->OutStreamer->getContext().getDwarfCompileUnitID(),
2366 //===----------------------------------------------------------------------===//
2368 //===----------------------------------------------------------------------===//
2380 Holder.emitAbbrevs(Asm->getObjFileLowering().getDwarfAbbrevSection());
2386 *Asm, Asm->getObjFileLowering().getDwarfStrOffSection(),
2393 Asm->OutStreamer->switchSection(Section);
2396 emitAppleAccelTable(Asm, Accel, TableName, Section->getBeginSymbol());
2409 emitAccel(AccelNames, Asm->getObjFileLowering().getDwarfAccelNamesSection(),
2416 emitAccel(AccelObjC, Asm->getObjFileLowering().getDwarfAccelObjCSection(),
2423 Asm->getObjFileLowering().getDwarfAccelNamespaceSection(),
2429 emitAccel(AccelTypes, Asm->getObjFileLowering().getDwarfAccelTypesSection(),
2436 // dwarf pubnames - offset/name pairs where the offset is the offset into the CU
2439 // gnu pubnames - offset/index value/name tuples where the offset is the offset
2447 /// computeIndexValue - Compute the gdb index value for the DIE and CU.
2455 // point at which the entry is added to the index data structure - since by
2459 if (Die->getTag() == dwarf::DW_TAG_compile_unit)
2466 if (DIEValue SpecVal = Die->findAttribute(dwarf::DW_AT_specification)) {
2470 } else if (Die->findAttribute(dwarf::DW_AT_external))
2473 switch (Die->getTag()) {
2480 dwarf::isCPlusPlus((dwarf::SourceLanguage)CU->getLanguage())
2502 /// emitDebugPubSections - Emit visible names and types into debug pubnames and
2507 if (!TheU->hasDwarfPubSections())
2510 bool GnuStyle = TheU->getCUNode()->getNameTableKind() ==
2513 Asm->OutStreamer->switchSection(
2514 GnuStyle ? Asm->getObjFileLowering().getDwarfGnuPubNamesSection()
2515 : Asm->getObjFileLowering().getDwarfPubNamesSection());
2516 emitDebugPubSection(GnuStyle, "Names", TheU, TheU->getGlobalNames());
2518 Asm->OutStreamer->switchSection(
2519 GnuStyle ? Asm->getObjFileLowering().getDwarfGnuPubTypesSection()
2520 : Asm->getObjFileLowering().getDwarfPubTypesSection());
2521 emitDebugPubSection(GnuStyle, "Types", TheU, TheU->getGlobalTypes());
2527 Asm->emitDwarfOffset(CU.getSection()->getBeginSymbol(),
2530 Asm->emitDwarfSymbolReference(CU.getLabelBegin());
2536 if (auto *Skeleton = TheU->getSkeleton())
2540 MCSymbol *EndLabel = Asm->emitDwarfUnitLength(
2543 Asm->OutStreamer->AddComment("DWARF Version");
2544 Asm->emitInt16(dwarf::DW_PUBNAMES_VERSION);
2546 Asm->OutStreamer->AddComment("Offset of Compilation Unit Info");
2549 Asm->OutStreamer->AddComment("Compilation Unit Length");
2550 Asm->emitDwarfLengthOrOffset(TheU->getLength());
2557 return A.second->getOffset() < B.second->getOffset();
2560 Asm->OutStreamer->AddComment("DIE offset");
2561 Asm->emitDwarfLengthOrOffset(Entity->getOffset());
2565 Asm->OutStreamer->AddComment(
2568 Asm->emitInt8(Desc.toBits());
2571 Asm->OutStreamer->AddComment("External Name");
2572 Asm->OutStreamer->emitBytes(StringRef(Name.data(), Name.size() + 1));
2575 Asm->OutStreamer->AddComment("End Mark");
2576 Asm->emitDwarfLengthOrOffset(0);
2577 Asm->OutStreamer->emitLabel(EndLabel);
2580 /// Emit null-terminated strings into a debug str section.
2585 StringOffsetsSection = Asm->getObjFileLowering().getDwarfStrOffSection();
2588 Holder.emitStrings(Asm->getObjFileLowering().getDwarfStrSection(),
2604 unsigned PtrSize = Asm->MAI->getCodePointerSize();
2607 Asm->getDataLayout().isLittleEndian(), PtrSize);
2608 DWARFExpression Expr(Data, PtrSize, Asm->OutContext.getDwarfFormat());
2621 Streamer.emitDIERef(*CU->ExprRefedBaseTypes[Op.getRawOperand(I)].Die);
2645 if (DIExpr && DIExpr->isEntryValue()) {
2655 const TargetRegisterInfo &TRI = *AP.MF->getSubtarget().getRegisterInfo();
2664 DIExpressionCursor &Cursor) -> bool {
2666 if (BT && (BT->getEncoding() == dwarf::DW_ATE_signed ||
2667 BT->getEncoding() == dwarf::DW_ATE_signed_char))
2676 const TargetRegisterInfo &TRI = *AP.MF->getSubtarget().getRegisterInfo();
2681 // TODO TargetIndexLocation is a target-independent. Currently only the
2682 // WebAssembly-specific encoding is supported.
2686 if (AP.getDwarfVersion() >= 4 && !AP.getDwarfDebug()->tuneForSCE() &&
2688 DwarfExpr.addConstantFP(Entry.getConstantFP()->getValueAPF(), AP);
2690 ->getValueAPF()
2694 Entry.getConstantFP()->getValueAPF().bitcastToAPInt());
2699 ->getValueAPF()
2726 DIExpressionCursor &Cursor) -> bool {
2764 Asm->OutStreamer->AddComment("Loc expr size");
2766 Asm->emitULEB128(DebugLocs.getBytes(Entry).size());
2768 Asm->emitInt16(DebugLocs.getBytes(Entry).size());
2772 Asm->emitInt16(0);
2785 MCSymbol *TableEnd = mcdwarf::emitListsTableHeaderStart(*Asm->OutStreamer);
2787 Asm->OutStreamer->AddComment("Offset entry count");
2788 Asm->emitInt32(Holder.getRangeLists().size());
2789 Asm->OutStreamer->emitLabel(Holder.getRnglistsTableBaseSym());
2792 Asm->emitLabelDifference(List.Label, Holder.getRnglistsTableBaseSym(),
2793 Asm->getDwarfOffsetByteSize());
2803 MCSymbol *TableEnd = mcdwarf::emitListsTableHeaderStart(*Asm->OutStreamer);
2807 Asm->OutStreamer->AddComment("Offset entry count");
2808 Asm->emitInt32(DebugLocs.getLists().size());
2809 Asm->OutStreamer->emitLabel(DebugLocs.getSym());
2812 Asm->emitLabelDifference(List.Label, DebugLocs.getSym(),
2813 Asm->getDwarfOffsetByteSize());
2827 auto Size = Asm->MAI->getCodePointerSize();
2831 Asm->OutStreamer->emitLabel(Sym);
2838 SectionRanges[&Range.Begin->getSection()].push_back(&Range);
2845 const MCSymbol *Begin = P.second.front()->Begin;
2846 const MCSymbol *NewBase = DD.getSectionLabel(&Begin->getSection());
2850 Asm->OutStreamer->emitIntValue(-1, Size);
2851 Asm->OutStreamer->AddComment(" base address");
2852 Asm->OutStreamer->emitSymbolValue(Base, Size);
2859 Asm->OutStreamer->AddComment(StringifyEnum(BaseAddressx));
2860 Asm->emitInt8(BaseAddressx);
2861 Asm->OutStreamer->AddComment(" base address index");
2862 Asm->emitULEB128(DD.getAddressPool().getIndex(Base));
2867 Asm->OutStreamer->emitIntValue(-1, Size);
2868 Asm->OutStreamer->emitIntValue(0, Size);
2872 const MCSymbol *Begin = RS->Begin;
2873 const MCSymbol *End = RS->End;
2879 Asm->OutStreamer->AddComment(StringifyEnum(OffsetPair));
2880 Asm->emitInt8(OffsetPair);
2881 Asm->OutStreamer->AddComment(" starting offset");
2882 Asm->emitLabelDifferenceAsULEB128(Begin, Base);
2883 Asm->OutStreamer->AddComment(" ending offset");
2884 Asm->emitLabelDifferenceAsULEB128(End, Base);
2886 Asm->emitLabelDifference(Begin, Base, Size);
2887 Asm->emitLabelDifference(End, Base, Size);
2890 Asm->OutStreamer->AddComment(StringifyEnum(StartxLength));
2891 Asm->emitInt8(StartxLength);
2892 Asm->OutStreamer->AddComment(" start index");
2893 Asm->emitULEB128(DD.getAddressPool().getIndex(Begin));
2894 Asm->OutStreamer->AddComment(" length");
2895 Asm->emitLabelDifferenceAsULEB128(End, Begin);
2897 Asm->OutStreamer->emitSymbolValue(Begin, Size);
2898 Asm->OutStreamer->emitSymbolValue(End, Size);
2905 Asm->OutStreamer->AddComment(StringifyEnum(EndOfList));
2906 Asm->emitInt8(EndOfList);
2909 Asm->OutStreamer->emitIntValue(0, Size);
2910 Asm->OutStreamer->emitIntValue(0, Size);
2930 Asm->OutStreamer->switchSection(Sec);
2940 Asm->OutStreamer->emitLabel(TableEnd);
2947 ? Asm->getObjFileLowering().getDwarfLoclistsSection()
2948 : Asm->getObjFileLowering().getDwarfLocSection());
2955 Asm->getObjFileLowering().getDwarfLoclistsDWOSection());
2961 Asm->OutStreamer->switchSection(
2962 Asm->getObjFileLowering().getDwarfLocDWOSection());
2963 Asm->OutStreamer->emitLabel(List.Label);
2966 // GDB only supports startx_length in pre-standard split-DWARF.
2974 Asm->emitInt8(dwarf::DW_LLE_startx_length);
2976 Asm->emitULEB128(idx);
2977 // Also the pre-standard encoding is slightly different, emitting this as
2978 // an address-length entry here, but its a ULEB128 in DWARFv5 loclists.
2979 Asm->emitLabelDifference(Entry.End, Entry.Begin, 4);
2982 Asm->emitInt8(dwarf::DW_LLE_end_of_list);
2996 // Provides a unique id per text section.
3001 if (SCU.Sym->isInSection()) {
3003 MCSection *Section = &SCU.Sym->getSection();
3006 // Some symbols (e.g. common/bss on mach-o) can have no section but still
3034 List.push_back(SymbolCU(nullptr, Asm->OutStreamer->endSection(Section)));
3039 const SymbolCU &Prev = List[n - 1];
3055 Asm->OutStreamer->switchSection(
3056 Asm->getObjFileLowering().getDwarfARangesSection());
3058 unsigned PtrSize = Asm->MAI->getCodePointerSize();
3069 return A->getUniqueID() < B->getUniqueID();
3077 if (auto *Skel = CU->getSkeleton())
3083 Asm->getDwarfOffsetByteSize() + // Offset of CU in the .debug_info
3092 Asm->getUnitLengthFieldByteSize() + ContentSize, Align(TupleSize));
3098 Asm->emitDwarfUnitLength(ContentSize, "Length of ARange Set");
3099 Asm->OutStreamer->AddComment("DWARF Arange version number");
3100 Asm->emitInt16(dwarf::DW_ARANGES_VERSION);
3101 Asm->OutStreamer->AddComment("Offset Into Debug Info Section");
3103 Asm->OutStreamer->AddComment("Address Size (in bytes)");
3104 Asm->emitInt8(PtrSize);
3105 Asm->OutStreamer->AddComment("Segment Size (in bytes)");
3106 Asm->emitInt8(0);
3108 Asm->OutStreamer->emitFill(Padding, 0xff);
3111 Asm->emitLabelReference(Span.Start, PtrSize);
3119 if ((SizeRef == SymSize.end() || SizeRef->second != 0) && Span.End) {
3120 Asm->emitLabelDifference(Span.End, Span.Start, PtrSize);
3125 if (SizeRef == SymSize.end() || SizeRef->second == 0)
3128 Size = SizeRef->second;
3130 Asm->OutStreamer->emitIntValue(Size, PtrSize);
3134 Asm->OutStreamer->AddComment("ARange terminator");
3135 Asm->OutStreamer->emitIntValue(0, PtrSize);
3136 Asm->OutStreamer->emitIntValue(0, PtrSize);
3147 List.CU->getCUNode()->getRangesBaseAddress() ||
3159 return !Pair.second->getCUNode()->isDebugDirectivesOnly();
3162 Asm->OutStreamer->switchSection(Section);
3172 Asm->OutStreamer->emitLabel(TableEnd);
3182 ? Asm->getObjFileLowering().getDwarfRnglistsSection()
3183 : Asm->getObjFileLowering().getDwarfRangesSection());
3188 Asm->getObjFileLowering().getDwarfRnglistsDWOSection());
3199 Asm->OutStreamer->AddComment("Macro information version");
3200 Asm->emitInt16(DwarfVersion >= 5 ? DwarfVersion : 4);
3201 // We emit the line offset flag unconditionally here, since line offset should
3203 if (Asm->isDwarf64()) {
3204 Asm->OutStreamer->AddComment("Flags: 64 bit, debug_line_offset present");
3205 Asm->emitInt8(MACRO_FLAG_OFFSET_SIZE | MACRO_FLAG_DEBUG_LINE_OFFSET);
3207 Asm->OutStreamer->AddComment("Flags: 32 bit, debug_line_offset present");
3208 Asm->emitInt8(MACRO_FLAG_DEBUG_LINE_OFFSET);
3210 Asm->OutStreamer->AddComment("debug_line_offset");
3212 Asm->emitDwarfLengthOrOffset(0);
3214 Asm->emitDwarfSymbolReference(CU.getLineTableStartSym());
3241 Asm->OutStreamer->AddComment(dwarf::MacroString(Type));
3242 Asm->emitULEB128(Type);
3243 Asm->OutStreamer->AddComment("Line Number");
3244 Asm->emitULEB128(M.getLine());
3245 Asm->OutStreamer->AddComment("Macro String");
3246 Asm->emitULEB128(
3252 Asm->OutStreamer->AddComment(dwarf::GnuMacroString(Type));
3253 Asm->emitULEB128(Type);
3254 Asm->OutStreamer->AddComment("Line Number");
3255 Asm->emitULEB128(M.getLine());
3256 Asm->OutStreamer->AddComment("Macro String");
3257 Asm->emitDwarfSymbolReference(
3261 Asm->OutStreamer->AddComment(dwarf::MacinfoString(M.getMacinfoType()));
3262 Asm->emitULEB128(M.getMacinfoType());
3263 Asm->OutStreamer->AddComment("Line Number");
3264 Asm->emitULEB128(M.getLine());
3265 Asm->OutStreamer->AddComment("Macro String");
3266 Asm->OutStreamer->emitBytes(Str);
3267 Asm->emitInt8('\0');
3275 Asm->OutStreamer->AddComment(MacroFormToString(StartFile));
3276 Asm->emitULEB128(StartFile);
3277 Asm->OutStreamer->AddComment("Line Number");
3278 Asm->emitULEB128(MF.getLine());
3279 Asm->OutStreamer->AddComment("File Number");
3282 Asm->emitULEB128(getDwoLineTable(U)->getFile(
3284 Asm->OutContext.getDwarfVersion(), F.getSource()));
3286 Asm->emitULEB128(U.getOrCreateSourceID(&F));
3288 Asm->OutStreamer->AddComment(MacroFormToString(EndFile));
3289 Asm->emitULEB128(EndFile);
3311 DIMacroNodeArray Macros = CUNode->getMacros();
3314 Asm->OutStreamer->switchSection(Section);
3315 Asm->OutStreamer->emitLabel(U.getMacroLabelBegin());
3319 Asm->OutStreamer->AddComment("End Of Macro List Mark");
3320 Asm->emitInt8(0);
3326 auto &ObjLower = Asm->getObjFileLowering();
3333 auto &ObjLower = Asm->getObjFileLowering();
3345 NewU->addString(Die, dwarf::DW_AT_comp_dir, CompilationDir);
3357 NewCU.setSection(Asm->getObjFileLowering().getDwarfInfoSection());
3381 InfoHolder.emitAbbrevs(Asm->getObjFileLowering().getDwarfAbbrevDWOSection());
3387 *Asm->OutStreamer, MCDwarfLineTableParams(),
3388 Asm->getObjFileLowering().getDwarfLineDWOSection());
3394 *Asm, Asm->getObjFileLowering().getDwarfStrOffDWOSection(),
3405 MCSection *OffSec = Asm->getObjFileLowering().getDwarfStrOffDWOSection();
3406 InfoHolder.emitStrings(Asm->getObjFileLowering().getDwarfStrDWOSection(),
3412 AddrPool.emit(*Asm, Asm->getObjFileLowering().getDwarfAddrSection());
3420 DIUnit->getDirectory(), DIUnit->getFilename(),
3421 getMD5AsBytes(DIUnit->getFile()), DIUnit->getSource());
3447 CU.addDIETypeSignature(RefDie, Ins.first->second);
3466 Ins.first->second = Signature;
3477 Asm->TM.Options.MCOptions.SplitDwarfFile);
3481 ? Asm->getObjFileLowering().getDwarfTypesDWOSection()
3482 : Asm->getObjFileLowering().getDwarfInfoDWOSection();
3487 ? Asm->getObjFileLowering().getDwarfTypesSection(Signature)
3488 : Asm->getObjFileLowering().getDwarfInfoSection(Signature);
3490 // Non-split type units reuse the compile unit's line table.
3624 return Asm->OutStreamer->getContext().getDwarfVersion();
3628 if (Asm->getDwarfVersion() >= 4)
3630 assert((!Asm->isDwarf64() || (Asm->getDwarfVersion() == 3)) &&
3632 return Asm->isDwarf64() ? dwarf::Form::DW_FORM_data8
3641 if (SectionLabels.insert(std::make_pair(&S->getSection(), S)).second)
3651 std::optional<DIFile::ChecksumInfo<StringRef>> Checksum = File->getChecksum();
3652 if (!Checksum || Checksum->Kind != DIFile::CSK_MD5)
3658 std::string ChecksumString = fromHex(Checksum->Value);