65#define DEBUG_TYPE "dwarfdebug"
67STATISTIC(NumCSParams,
"Number of dbg call site params created");
70 "use-dwarf-ranges-base-address-specifier",
cl::Hidden,
80 cl::desc(
"Generate DWARF4 type units."),
91 cl::desc(
"Make an absence of debug location information explicit."),
99 "Default for platform"),
107 cl::desc(
"Use inlined strings rather than string section."),
115 cl::desc(
"Disable emission .debug_ranges section."),
120 cl::desc(
"Use sections+offset as references rather than labels."),
127 cl::desc(
"Emit the GNU .debug_macro format with DWARF <5"),
132 cl::desc(
"Enable use of the DWARFv5 DW_OP_convert operator"),
145 cl::desc(
"Which DWARF linkage-name attributes to emit."),
147 "Default for platform"),
150 "Abstract subprograms")),
155 cl::desc(
"Always use DW_AT_ranges in DWARFv5 whenever it could allow more "
156 "address pool entry sharing to reduce relocations/object size"),
158 "Default address minimization strategy"),
160 "Use rnglists for contiguous ranges if that allows "
161 "using a pre-existing base address"),
164 "Use exprloc addrx+offset expressions for any "
165 "address with a prior base address"),
167 "Use addrx+offset extension form for any address "
168 "with a prior base address"),
176 cl::desc(
"Set to false to ignore Key Instructions metadata"));
180void DebugLocDwarfExpression::emitOp(
uint8_t Op,
const char *Comment) {
186void DebugLocDwarfExpression::emitSigned(int64_t
Value) {
187 getActiveStreamer().emitSLEB128(
Value, Twine(
Value));
191 getActiveStreamer().emitULEB128(
Value, Twine(
Value));
194void DebugLocDwarfExpression::emitData1(uint8_t
Value) {
195 getActiveStreamer().emitInt8(
Value, Twine(
Value));
198void DebugLocDwarfExpression::emitBaseTypeRef(
uint64_t Idx) {
210 assert(!IsBuffering &&
"Already buffering?");
212 TmpBuf = std::make_unique<TempBuffer>(OutBS.GenerateComments);
219 return TmpBuf ? TmpBuf->Bytes.size() : 0;
225 for (
auto Byte :
enumerate(TmpBuf->Bytes)) {
226 const char *
Comment = (
Byte.index() < TmpBuf->Comments.size())
227 ? TmpBuf->Comments[
Byte.index()].c_str()
229 OutBS.emitInt8(
Byte.value(), Comment);
231 TmpBuf->Bytes.clear();
232 TmpBuf->Comments.clear();
243 const bool IsVariadic = !SingleLocExprOpt;
246 if (!IsVariadic && !
MI->isNonListDebugValue()) {
247 assert(
MI->getNumDebugOperands() == 1 &&
248 "Mismatched DIExpression and debug operands for debug instruction.");
249 Expr = *SingleLocExprOpt;
256 MI->isNonListDebugValue() &&
MI->isDebugOffsetImm());
258 }
else if (
Op.isTargetIndex()) {
261 }
else if (
Op.isImm())
263 else if (
Op.isFPImm())
265 else if (
Op.isCImm())
270 return DbgValueLoc(Expr, DbgValueLocEntries, IsVariadic);
274 std::optional<DIExpression::FragmentInfo> Fragment = Expr.
getFragmentInfo();
275 return Fragment ? Fragment->OffsetInBits : 0;
289 Expr(ValueLoc.getExpression()) {
290 if (!Expr->getNumElements())
306 return FIE.Expr && FIE.Expr->isFragment();
308 "conflicting locations for variable");
312 bool GenerateTypeUnits,
321 if (GenerateTypeUnits && (DwarfVersion < 5 || !TT.isOSBinFormatELF()))
327 if (DwarfVersion >= 5)
337 SkeletonHolder(
A,
"skel_string", DIEValueAllocator),
338 IsDarwin(
A->TM.getTargetTriple().isOSDarwin()),
340 const Triple &TT =
Asm->TM.getTargetTriple();
345 DebuggerTuning =
Asm->TM.Options.DebuggerTuning;
350 else if (TT.isOSAIX())
366 HasSplitDwarf = !
Asm->TM.Options.MCOptions.SplitDwarfFile.empty();
374 unsigned DwarfVersionNumber =
Asm->TM.Options.MCOptions.DwarfVersion;
375 unsigned DwarfVersion = DwarfVersionNumber ? DwarfVersionNumber
376 :
MMI->getModule()->getDwarfVersion();
380 bool Dwarf64 = DwarfVersion >= 3 &&
389 ((
Asm->TM.Options.MCOptions.Dwarf64 ||
MMI->getModule()->isDwarf64()) &&
390 TT.isOSBinFormatELF()) ||
391 TT.isOSBinFormatXCOFF();
393 if (!Dwarf64 && TT.isArch64Bit() && TT.isOSBinFormatXCOFF())
402 GenerateTypeUnits = (
A->TM.getTargetTriple().isOSBinFormatELF() ||
403 A->TM.getTargetTriple().isOSBinFormatWasm()) &&
407 DwarfVersion, GenerateTypeUnits, DebuggerTuning,
A->TM.getTargetTriple());
414 UseGNUTLSOpcode =
tuneForGDB() || DwarfVersion < 3;
416 UseDWARF2Bitfields = DwarfVersion < 4;
422 UseSegmentedStringOffsetsTable = DwarfVersion >= 5;
426 EmitDebugEntryValues =
Asm->TM.Options.ShouldEmitDebugEntryValues();
430 UseDebugMacroSection =
439 if (DwarfVersion >= 5)
442 Asm->OutStreamer->getContext().setDwarfVersion(DwarfVersion);
451 return Name.starts_with(
"+") || Name.starts_with(
"-");
458 return Name.contains(
") ");
464 Class = In.slice(In.find(
'[') + 1, In.find(
' '));
469 Class = In.slice(In.find(
'[') + 1, In.find(
'('));
470 Category = In.slice(In.find(
'[') + 1, In.find(
' '));
474 return In.slice(In.find(
' ') + 1, In.find(
']'));
487 if (!SP->isDefinition())
490 if (SP->getName() !=
"")
521 if (Scope->isAbstractScope())
539 if (
auto *SkelCU =
CU.getSkeleton())
540 if (
CU.getCUNode()->getSplitDebugInlining())
551 auto &
CU = getOrCreateDwarfCompileUnit(SP->getUnit());
552 if (
CU.getSkeleton())
558void DwarfDebug::constructAbstractSubprogramScopeDIE(
DwarfCompileUnit &SrcCU,
560 assert(Scope && Scope->getScopeNode());
561 assert(Scope->isAbstractScope());
562 assert(!Scope->getInlinedAt());
568 auto &
CU = getOrCreateDwarfCompileUnit(SP->getUnit());
570 TargetCU.constructAbstractSubprogramScopeDIE(Scope);
571 if (
auto *SkelCU =
CU.getSkeleton())
572 if (
CU.getCUNode()->getSplitDebugInlining())
573 SkelCU->constructAbstractSubprogramScopeDIE(Scope);
607template <
typename ValT>
611 for (
auto Param : DescribedParams) {
612 bool ShouldCombineExpressions = Expr && Param.Expr->
getNumElements() > 0;
622 "Combined debug expression is invalid");
637 auto &ParamsForFwdReg = Worklist[
Reg];
638 for (
auto Param : ParamsToAdd) {
641 return D.ParamReg == Param.ParamReg;
643 "Same parameter described twice by forwarding reg");
650 ParamsForFwdReg.push_back({Param.ParamReg, CombinedExpr});
670 auto IsRegClobberedInMeantime = [&](
Register Reg) ->
bool {
671 for (
auto &RegUnit : ClobberedRegUnits)
672 if (
TRI.hasRegUnit(
Reg, RegUnit))
677 auto DescribeFwdRegsByCalleeSavedCopy = [&](
const DestSourcePair &CopyInst) {
678 Register CopyDestReg = CopyInst.Destination->getReg();
679 Register CopySrcReg = CopyInst.Source->getReg();
680 if (IsRegClobberedInMeantime(CopyDestReg))
684 if (!
TRI.isCalleeSavedPhysReg(CopyDestReg, *MF))
691 for (
auto FwdRegIt = ForwardedRegWorklist.
begin();
692 FwdRegIt != ForwardedRegWorklist.
end();) {
694 if (FwdRegIt->first == CopySrcReg)
696 else if (
unsigned SubRegIdx =
697 TRI.getSubRegIndex(CopySrcReg, FwdRegIt->first))
698 if (
Register CopyDestSubReg =
TRI.getSubReg(CopyDestReg, SubRegIdx))
708 FwdRegIt = ForwardedRegWorklist.
erase(FwdRegIt);
716 if (
auto CopyInst =
TII.isCopyInstr(*CurMI))
717 DescribeFwdRegsByCalleeSavedCopy(*CopyInst);
745 if (
MI.isDebugInstr())
749 if (MO.getReg().isPhysical()) {
750 for (
auto &FwdReg : ForwardedRegWorklist)
751 if (
TRI.regsOverlap(FwdReg.first, MO.getReg()))
752 Defs.insert(FwdReg.first);
761 getForwardingRegsDefinedByMI(*CurMI, FwdRegDefs);
762 if (FwdRegDefs.
empty()) {
768 for (
auto ParamFwdReg : FwdRegDefs) {
769 if (
auto ParamValue =
TII.describeLoadedValue(*CurMI, ParamFwdReg)) {
770 if (ParamValue->first.isImm()) {
771 int64_t Val = ParamValue->first.getImm();
773 ForwardedRegWorklist[ParamFwdReg], Params);
774 }
else if (ParamValue->first.isReg()) {
775 Register RegLoc = ParamValue->first.getReg();
776 Register SP = TLI.getStackPointerRegisterToSaveRestore();
778 bool IsSPorFP = (RegLoc == SP) || (RegLoc ==
FP);
781 if (!IsRegClobberedInMeantime(RegLoc) &&
782 (
TRI.isCalleeSavedPhysReg(RegLoc, *MF) || IsSPorFP)) {
785 ForwardedRegWorklist[ParamFwdReg], Params);
794 ForwardedRegWorklist[ParamFwdReg]);
801 for (
auto ParamFwdReg : FwdRegDefs)
802 ForwardedRegWorklist.
erase(ParamFwdReg);
809 for (
auto &New : TmpWorklistItems)
811 TmpWorklistItems.
clear();
828 if (ForwardedRegWorklist.
empty())
835 interpretValues(CurMI, ForwardedRegWorklist, Params, ClobberedRegUnits);
846 auto CSInfo = CalleesMap.
find(CallMI);
849 if (CSInfo == CalleesMap.end())
863 for (
const auto &ArgReg : CSInfo->second.ArgRegPairs) {
865 ForwardedRegWorklist.
insert({ArgReg.Reg, {{ArgReg.Reg, EmptyExpr}}})
867 assert(InsertedReg &&
"Single register used to forward two arguments?");
872 for (
const auto &MO : CallMI->
uses())
873 if (MO.isReg() && MO.isUndef())
874 ForwardedRegWorklist.
erase(MO.getReg());
884 bool ShouldTryEmitEntryVals =
MBB->getIterator() == MF->
begin();
893 assert(std::next(Suc) == BundleEnd &&
894 "More than one instruction in call delay slot");
901 for (;
I !=
MBB->rend(); ++
I) {
908 if (ShouldTryEmitEntryVals) {
912 for (
auto &RegEntry : ForwardedRegWorklist) {
919void DwarfDebug::constructCallSiteEntryDIEs(
const DISubprogram &SP,
924 if (!
SP.areAllCallsDescribed() || !
SP.isDefinition())
931 CU.addFlag(ScopeDIE,
CU.getDwarf5OrGNUAttr(dwarf::DW_AT_call_all_calls));
934 assert(
TII &&
"TargetInstrInfo not found: cannot label tail calls");
937 auto delaySlotSupported = [&](
const MachineInstr &
MI) {
938 if (!
MI.isBundledWithSucc())
940 auto Suc = std::next(
MI.getIterator());
942 (void)CallInstrBundle;
944 (void)DelaySlotBundle;
951 "Call and its successor instruction don't have same label after.");
956 auto addCallSiteTargetForIndirectCalls = [&](
const MachineInstr *
MI,
960 auto CSInfo = CalleesMap.
find(
MI);
962 if (CSInfo == CalleesMap.end() || !CSInfo->second.CallTarget)
965 MDNode *CallTarget = CSInfo->second.CallTarget;
967 assert(!CallSiteDIE.findAttribute(dwarf::DW_AT_LLVM_virtual_call_origin) &&
968 "DW_AT_LLVM_virtual_call_origin already exists");
970 DIE *CalleeDIE =
CU.getOrCreateSubprogramDIE(CalleeSP,
nullptr);
971 assert(CalleeDIE &&
"Could not create DIE for call site entry origin");
972 CU.addDIEEntry(CallSiteDIE,
973 CU.getDwarf5OrGNUAttr(dwarf::DW_AT_LLVM_virtual_call_origin),
976 CU.addLinkageNamesToDeclarations(*
this, *CalleeSP, *CalleeDIE);
980 for (
const MachineBasicBlock &
MBB : MF) {
990 if (!
MI.isCandidateForAdditionalCallInfo())
999 if (
MI.hasDelaySlot() && !delaySlotSupported(*&
MI))
1007 const MachineOperand &CalleeOp =
TII->getCalleeOperand(
MI);
1008 bool PhysRegCalleeOperand =
1010 MachineLocation CallTarget{0};
1012 const DISubprogram *CalleeSP =
nullptr;
1013 const Function *CalleeDecl =
nullptr;
1014 if (PhysRegCalleeOperand) {
1015 bool Scalable =
false;
1016 const MachineOperand *BaseOp =
nullptr;
1017 const TargetRegisterInfo &
TRI =
1018 *
Asm->MF->getSubtarget().getRegisterInfo();
1019 if (
TII->getMemOperandWithOffset(
MI, BaseOp,
Offset, Scalable, &
TRI)) {
1020 if (BaseOp && BaseOp->
isReg() && !Scalable)
1021 CallTarget = MachineLocation(BaseOp->
getReg(),
true);
1025 CallTarget = MachineLocation(CalleeOp.
getReg());
1034 if (CalleeSP ==
nullptr && CallTarget.
getReg() == 0 &&
1035 AllocSiteTy ==
nullptr)
1045 const MachineInstr *TopLevelCallMI =
1052 const MCSymbol *PCAddr = (!IsTail ||
CU.useGNUAnalogForDwarf5Feature())
1061 assert((IsTail || PCAddr) &&
"Non-tail call without return PC");
1064 dbgs() <<
"CallSiteEntry: " << MF.getName() <<
" -> "
1068 MF.getSubtarget().getRegisterInfo()->getName(
1070 << (IsTail ?
" [IsTail]" :
"") <<
"\n");
1072 DIE &CallSiteDIE =
CU.constructCallSiteEntryDIE(
1073 ScopeDIE, CalleeSP, CalleeDecl, IsTail, PCAddr, CallAddr, CallTarget,
1077 addCallSiteTargetForIndirectCalls(TopLevelCallMI, CallSiteDIE);
1084 CU.constructCallSiteParmEntryDIEs(CallSiteDIE, Params);
1091 if (!
U.hasDwarfPubSections())
1094 U.addFlag(
D, dwarf::DW_AT_GNU_pubnames);
1100 case dwarf::DW_LNAME_Fortran:
1101 case dwarf::DW_LNAME_Cobol:
1102 case dwarf::DW_LNAME_Pascal:
1109 case dwarf::DW_LANG_Cobol74:
1110 case dwarf::DW_LANG_Cobol85:
1111 case dwarf::DW_LANG_Fortran77:
1112 case dwarf::DW_LANG_Fortran90:
1113 case dwarf::DW_LANG_Fortran95:
1114 case dwarf::DW_LANG_Fortran03:
1115 case dwarf::DW_LANG_Fortran08:
1116 case dwarf::DW_LANG_Fortran18:
1117 case dwarf::DW_LANG_Fortran23:
1118 case dwarf::DW_LANG_Pascal83:
1125void DwarfDebug::finishUnitAttributes(
const DICompileUnit *DIUnit,
1133 std::string ProducerWithFlags =
Producer.str() +
" " +
Flags.str();
1134 NewCU.
addString(Die, dwarf::DW_AT_producer, ProducerWithFlags);
1136 NewCU.
addString(Die, dwarf::DW_AT_producer, Producer);
1139 NewCU.
addUInt(Die, dwarf::DW_AT_language_name, dwarf::DW_FORM_data2,
1142 if (uint32_t LangVersion = Lang.getVersion(); LangVersion != 0)
1143 NewCU.
addUInt(Die, dwarf::DW_AT_language_version, std::nullopt,
1146 NewCU.
addUInt(Die, dwarf::DW_AT_language, dwarf::DW_FORM_data2,
1151 NewCU.
addUInt(Die, dwarf::DW_AT_identifier_case, dwarf::DW_FORM_data1,
1153 NewCU.
addString(Die, dwarf::DW_AT_name, FN);
1158 if (!SysRoot.
empty())
1159 NewCU.
addString(Die, dwarf::DW_AT_LLVM_sysroot, SysRoot);
1160 StringRef SDK = DIUnit->
getSDK();
1162 NewCU.
addString(Die, dwarf::DW_AT_APPLE_sdk, SDK);
1173 if (!CompilationDir.empty())
1174 NewCU.
addString(Die, dwarf::DW_AT_comp_dir, CompilationDir);
1175 addGnuPubAttributes(NewCU, Die);
1179 NewCU.
addFlag(Die, dwarf::DW_AT_APPLE_optimized);
1184 NewCU.
addString(Die, dwarf::DW_AT_APPLE_flags, Flags);
1187 NewCU.
addUInt(Die, dwarf::DW_AT_APPLE_major_runtime_vers,
1188 dwarf::DW_FORM_data1, RVer);
1193 NewCU.
addUInt(Die, dwarf::DW_AT_GNU_dwo_id, dwarf::DW_FORM_data8,
1198 ? dwarf::DW_AT_dwo_name
1199 : dwarf::DW_AT_GNU_dwo_name;
1206 if (
auto *
CU = CUMap.lookup(DIUnit))
1213 return CUMap.begin()->second;
1221DwarfDebug::getOrCreateDwarfCompileUnit(
const DICompileUnit *DIUnit) {
1222 if (
auto *
CU = getDwarfCompileUnit(DIUnit))
1227 auto OwnedUnit = std::make_unique<DwarfCompileUnit>(
1229 DwarfCompileUnit &NewCU = *OwnedUnit;
1236 if (!
Asm->OutStreamer->hasRawTextSupport() || SingleCU)
1237 Asm->OutStreamer->emitDwarfFile0Directive(
1243 NewCU.
setSection(
Asm->getObjFileLowering().getDwarfInfoDWOSection());
1245 finishUnitAttributes(DIUnit, NewCU);
1246 NewCU.
setSection(
Asm->getObjFileLowering().getDwarfInfoSection());
1249 CUMap.insert({DIUnit, &NewCU});
1250 CUDieMap.insert({&NewCU.
getUnitDie(), &NewCU});
1264 if (!
A.Expr || !
B.Expr)
1266 auto FragmentA =
A.Expr->getFragmentInfo();
1267 auto FragmentB =
B.Expr->getFragmentInfo();
1268 if (!FragmentA || !FragmentB)
1270 return FragmentA->OffsetInBits < FragmentB->OffsetInBits;
1275 return A.Expr ==
B.Expr;
1290 unsigned NumDebugCUs = std::distance(M->debug_compile_units_begin(),
1291 M->debug_compile_units_end());
1292 if (NumDebugCUs == 0)
1295 assert(NumDebugCUs > 0 &&
"Asm unexpectedly initialized");
1296 SingleCU = NumDebugCUs == 1;
1303 .setStringOffsetsStartSym(
Asm->createTempSymbol(
"str_offsets_base"));
1311 Asm->createTempSymbol(
"rnglists_table_base"));
1315 Asm->createTempSymbol(
"rnglists_dwo_table_base"));
1320 AddrPool.setLabel(
Asm->createTempSymbol(
"addr_table_base"));
1321 DebugLocs.setSym(
Asm->createTempSymbol(
"loclists_table_base"));
1324 if (CUNode->getImportedEntities().empty() &&
1325 CUNode->getEnumTypes().empty() && CUNode->getRetainedTypes().empty() &&
1326 CUNode->getGlobalVariables().empty() && CUNode->getMacros().empty())
1329 getOrCreateDwarfCompileUnit(CUNode);
1333void DwarfDebug::finishEntityDefinitions() {
1334 for (
const auto &Entity : ConcreteEntities) {
1335 DIE *Die = Entity->getDIE();
1342 Unit->finishEntityDefinition(Entity.get());
1346void DwarfDebug::finishSubprogramDefinitions() {
1347 for (
const DISubprogram *SP : ProcessedSPNodes) {
1350 getOrCreateDwarfCompileUnit(
SP->getUnit()),
1351 [&](DwarfCompileUnit &
CU) { CU.finishSubprogramDefinition(SP); });
1355void DwarfDebug::finalizeModuleInfo() {
1356 const TargetLoweringObjectFile &TLOF =
Asm->getObjFileLowering();
1358 finishSubprogramDefinitions();
1360 finishEntityDefinitions();
1362 bool HasEmittedSplitCU =
false;
1366 for (
const auto &
P : CUMap) {
1367 auto &TheCU = *
P.second;
1368 if (TheCU.getCUNode()->isDebugDirectivesOnly())
1370 TheCU.attachLexicalScopesAbstractOrigins();
1373 TheCU.constructContainingTypeDIEs();
1378 auto *SkCU = TheCU.getSkeleton();
1380 bool HasSplitUnit = SkCU && !TheCU.getUnitDie().children().empty();
1383 (void)HasEmittedSplitCU;
1385 "Multiple CUs emitted into a single dwo file");
1386 HasEmittedSplitCU =
true;
1388 ? dwarf::DW_AT_dwo_name
1389 : dwarf::DW_AT_GNU_dwo_name;
1390 finishUnitAttributes(TheCU.getCUNode(), TheCU);
1391 StringRef DWOName =
Asm->TM.Options.MCOptions.SplitDwarfFile;
1392 TheCU.addString(TheCU.getUnitDie(), attrDWOName, DWOName);
1393 SkCU->addString(SkCU->getUnitDie(), attrDWOName, DWOName);
1399 DIEHash(
Asm, &TheCU).computeCUSignature(DWOName, TheCU.getUnitDie());
1404 TheCU.addUInt(TheCU.getUnitDie(), dwarf::DW_AT_GNU_dwo_id,
1405 dwarf::DW_FORM_data8, ID);
1406 SkCU->addUInt(SkCU->getUnitDie(), dwarf::DW_AT_GNU_dwo_id,
1407 dwarf::DW_FORM_data8, ID);
1410 if (
getDwarfVersion() < 5 && !SkeletonHolder.getRangeLists().empty()) {
1412 SkCU->addSectionLabel(SkCU->getUnitDie(), dwarf::DW_AT_GNU_ranges_base,
1416 finishUnitAttributes(SkCU->getCUNode(), *SkCU);
1425 DwarfCompileUnit &
U = SkCU ? *SkCU : TheCU;
1427 if (
unsigned NumRanges = TheCU.getRanges().size()) {
1434 U.addUInt(
U.getUnitDie(), dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr,
1437 U.setBaseAddress(TheCU.getRanges().front().Begin);
1438 U.attachRangesOrLowHighPC(
U.getUnitDie(), TheCU.takeRanges());
1445 U.addAddrTableBase();
1448 if (
U.hasRangeLists())
1449 U.addRnglistsBase();
1452 U.addSectionLabel(
U.getUnitDie(), dwarf::DW_AT_loclists_base,
1461 if (CUNode->getMacros()) {
1463 if (UseDebugMacroSection) {
1468 ? dwarf::DW_AT_macros
1469 : dwarf::DW_AT_GNU_macros;
1471 U.getMacroLabelBegin(), Section);
1477 dwarf::DW_AT_macro_info,
1478 U.getMacroLabelBegin(), Section);
1484 for (
auto *CUNode :
MMI->getModule()->debug_compile_units())
1485 if (CUNode->getDWOId())
1486 getOrCreateDwarfCompileUnit(CUNode);
1491 SkeletonHolder.computeSizeAndOffsets();
1495 AccelDebugNames.convertDieToOffset();
1504 assert(CurFn ==
nullptr);
1514 Global.getDebugInfo(GVs);
1515 for (
auto *GVE : GVs)
1516 GVMap[GVE->getVariable()].push_back({&
Global, GVE->getExpression()});
1527 for (
auto *GVE : CUNode->getGlobalVariables()) {
1531 auto &GVMapEntry = GVMap[GVE->getVariable()];
1532 auto *Expr = GVE->getExpression();
1533 if (!GVMapEntry.size() || (Expr && Expr->isConstant()))
1534 GVMapEntry.push_back({
nullptr, Expr});
1537 for (
auto *GVE : CUNode->getGlobalVariables()) {
1540 "Unexpected function-local entity in 'globals' CU field.");
1541 if (Processed.
insert(GV).second)
1546 for (
auto *Ty : CUNode->getEnumTypes()) {
1548 "Unexpected function-local entity in 'enums' CU field.");
1552 for (
auto *Ty : CUNode->getRetainedTypes()) {
1555 CU->getOrCreateTypeDIE(RT);
1560 for (
auto *IE : CUNode->getImportedEntities()) {
1562 "Unexpected function-local entity in 'imports' CU field.");
1563 CU->getOrCreateImportedEntityDIE(IE);
1567 const auto Unexpected = [](
const Metadata *
N) {
1570 for (
const auto *
D :
CU->getDeferredLocalDecls())
1571 DISubprogram::visitRetainedNode<void>(
1572 D, Unexpected, Unexpected,
1573 [
CU](
const auto *IE) {
CU->getOrCreateImportedEntityDIE(IE); },
1574 [
CU](
const auto *Ty) {
CU->getOrCreateTypeDIE(Ty); },
1575 [&](
const auto *GVE) {
1577 if (Processed.
insert(GV).second)
1583 CU->createBaseTypeDIEs();
1588 if (!
Asm || !
Asm->hasDebugInfo())
1592 finalizeModuleInfo();
1602 emitAbbreviations();
1608 if (UseARangesSection)
1616 emitDebugMacinfoDWO();
1626 emitDebugAbbrevDWO();
1628 emitDebugRangesDWO();
1638 emitAccelNamespaces();
1642 emitAccelDebugNames();
1651 emitDebugPubSections();
1659 if (
CU.getExistingAbstractEntity(
Node))
1664 CU.createAbstractEntity(
Node, Scope);
1673void DwarfDebug::collectVariableInfoFromMFTable(
1675 SmallDenseMap<InlinedEntity, DbgVariable *> MFVars;
1676 LLVM_DEBUG(
dbgs() <<
"DwarfDebug: collecting variables from MF side table\n");
1677 for (
const auto &VI :
Asm->MF->getVariableDbgInfo()) {
1680 assert(
VI.Var->isValidLocationForIntrinsic(
VI.Loc) &&
1681 "Expected inlined-at fields to agree");
1683 InlinedEntity Var(
VI.Var,
VI.Loc->getInlinedAt());
1690 <<
", no variable scope found\n");
1694 ensureAbstractEntityIsCreatedIfScoped(TheCU, Var.first,
Scope->getScopeNode());
1698 if (DbgVariable *PreviousLoc = MFVars.
lookup(Var)) {
1699 auto *PreviousMMI = std::get_if<Loc::MMI>(PreviousLoc);
1700 auto *PreviousEntryValue = std::get_if<Loc::EntryValue>(PreviousLoc);
1702 if (PreviousMMI &&
VI.inStackSlot())
1703 PreviousMMI->addFrameIndexExpr(
VI.Expr,
VI.getStackSlot());
1705 else if (PreviousEntryValue &&
VI.inEntryValueRegister())
1706 PreviousEntryValue->addExpr(
VI.getEntryValueRegister(), *
VI.Expr);
1711 if (PreviousLoc->holds<Loc::MMI>())
1712 PreviousLoc->emplace<Loc::EntryValue>(
VI.getEntryValueRegister(),
1715 <<
", conflicting fragment location types\n");
1720 auto RegVar = std::make_unique<DbgVariable>(
1722 if (
VI.inStackSlot())
1723 RegVar->emplace<Loc::MMI>(
VI.Expr,
VI.getStackSlot());
1725 RegVar->emplace<Loc::EntryValue>(
VI.getEntryValueRegister(), *
VI.Expr);
1728 InfoHolder.addScopeVariable(Scope, RegVar.get());
1729 MFVars.
insert({Var, RegVar.get()});
1730 ConcreteEntities.push_back(std::move(RegVar));
1742 assert(
DbgValue->getDebugLoc() &&
"DBG_VALUE without a debug location");
1750 if (LSRange.size() == 0)
1753 const MachineInstr *LScopeBegin = LSRange.front().first;
1757 if (!Ordering.isBefore(
DbgValue, LScopeBegin)) {
1763 for (++Pred; Pred !=
MBB->rend(); ++Pred) {
1766 auto PredDL = Pred->getDebugLoc();
1767 if (!PredDL || Pred->isMetaInstruction())
1771 if (
DL->getScope() == PredDL->getScope())
1774 if (!PredScope || LScope->dominates(PredScope))
1787 if (
MBB->pred_empty() &&
1794 if (Ordering.isBefore(RangeEnd, LScopeEnd))
1838 std::pair<DbgValueHistoryMap::EntryIndex, DbgValueLoc>;
1840 bool isSafeForSingleLocation =
true;
1841 const MachineInstr *StartDebugMI =
nullptr;
1842 const MachineInstr *EndMI =
nullptr;
1844 for (
auto EB = Entries.
begin(), EI = EB, EE = Entries.
end(); EI != EE; ++EI) {
1845 const MachineInstr *
Instr = EI->getInstr();
1848 size_t Index = std::distance(EB, EI);
1849 erase_if(OpenRanges, [&](OpenRange &R) {
return R.first <=
Index; });
1856 "Forgot label before/after instruction starting a range!");
1859 if (std::next(EI) == Entries.
end()) {
1860 const MachineBasicBlock &EndMBB =
Asm->MF->back();
1862 if (EI->isClobber())
1863 EndMI = EI->getInstr();
1865 else if (std::next(EI)->isClobber())
1869 assert(EndLabel &&
"Forgot label after instruction ending a range!");
1871 if (EI->isDbgValue())
1877 if (EI->isDbgValue()) {
1884 if (!
Instr->isUndefDebugValue()) {
1889 if (
Instr->getDebugExpression()->isFragment())
1890 isSafeForSingleLocation =
false;
1893 StartDebugMI =
Instr;
1895 isSafeForSingleLocation =
false;
1901 if (OpenRanges.
empty())
1905 if (StartLabel == EndLabel) {
1906 LLVM_DEBUG(
dbgs() <<
"Omitting location list entry with empty range.\n");
1911 for (
auto &R : OpenRanges)
1919 if (
Asm->MF->hasBBSections() && StartLabel ==
Asm->getFunctionBegin() &&
1920 !
Instr->getParent()->sameSection(&
Asm->MF->front())) {
1921 for (
const auto &[MBBSectionId, MBBSectionRange] :
1922 Asm->MBBSectionRanges) {
1923 if (
Instr->getParent()->getSectionID() == MBBSectionId) {
1924 DebugLoc.emplace_back(MBBSectionRange.BeginLabel, EndLabel,
Values);
1927 DebugLoc.emplace_back(MBBSectionRange.BeginLabel,
1928 MBBSectionRange.EndLabel,
Values);
1938 dbgs() << CurEntry->getValues().size() <<
" Values:\n";
1939 for (
auto &
Value : CurEntry->getValues())
1941 dbgs() <<
"-----\n";
1944 auto PrevEntry = std::next(CurEntry);
1945 if (PrevEntry !=
DebugLoc.rend() && PrevEntry->MergeRanges(*CurEntry))
1949 if (!isSafeForSingleLocation ||
1956 if (!
Asm->MF->hasBBSections())
1964 const MachineBasicBlock *RangeMBB =
nullptr;
1965 if (
DebugLoc[0].getBeginSym() ==
Asm->getFunctionBegin())
1966 RangeMBB = &
Asm->MF->front();
1968 RangeMBB = Entries.
begin()->getInstr()->getParent();
1970 assert(RangeIt !=
Asm->MBBSectionRanges.end() &&
1971 "Range MBB not found in MBBSectionRanges!");
1973 auto *NextEntry = std::next(CurEntry);
1974 auto NextRangeIt = std::next(RangeIt);
1975 while (NextEntry !=
DebugLoc.end()) {
1976 if (NextRangeIt ==
Asm->MBBSectionRanges.end())
1983 if ((RangeIt->second.EndLabel !=
Asm->getFunctionEnd() &&
1984 CurEntry->getEndSym() != RangeIt->second.EndLabel) ||
1985 NextEntry->getBeginSym() != NextRangeIt->second.BeginLabel ||
1986 CurEntry->getValues() != NextEntry->getValues())
1988 RangeIt = NextRangeIt;
1989 NextRangeIt = std::next(RangeIt);
1990 CurEntry = NextEntry;
1991 NextEntry = std::next(CurEntry);
2001 ensureAbstractEntityIsCreatedIfScoped(TheCU, Node,
Scope.getScopeNode());
2003 ConcreteEntities.push_back(
2009 ConcreteEntities.push_back(
2015 return ConcreteEntities.back().get();
2023 collectVariableInfoFromMFTable(TheCU, Processed);
2026 InlinedEntity
IV =
I.first;
2031 const auto &HistoryMapEntries =
I.second;
2035 if (!
DbgValues.hasNonEmptyLocation(HistoryMapEntries))
2038 LexicalScope *
Scope =
nullptr;
2040 if (
const DILocation *IA =
IV.second)
2050 *Scope, LocalVar,
IV.second));
2052 const MachineInstr *MInsn = HistoryMapEntries.front().getInstr();
2058 size_t HistSize = HistoryMapEntries.size();
2059 bool SingleValueWithClobber =
2060 HistSize == 2 && HistoryMapEntries[1].isClobber();
2061 if (HistSize == 1 || SingleValueWithClobber) {
2063 SingleValueWithClobber ? HistoryMapEntries[1].getInstr() :
nullptr;
2065 RegVar->emplace<Loc::Single>(MInsn);
2071 DebugLocStream::ListBuilder
List(DebugLocs, TheCU, *
Asm, *RegVar);
2075 bool isValidSingleLocation = buildLocationList(Entries, HistoryMapEntries);
2080 if (isValidSingleLocation) {
2081 RegVar->emplace<Loc::Single>(Entries[0].getValues()[0]);
2092 for (
auto &Entry : Entries)
2099 InlinedEntity IL =
I.first;
2100 const MachineInstr *
MI =
I.second;
2104 LexicalScope *
Scope =
nullptr;
2107 const DILocalScope *LocalScope =
2108 Label->getScope()->getNonLexicalBlockFileScope();
2110 if (
const DILocation *IA = IL.second)
2123 createConcreteEntity(TheCU, *Scope, Label, IL.second, Sym);
2127 for (
const MDNode *
N :
SP->getRetainedNodes()) {
2131 if (!Processed.
insert(InlinedEntity(DN,
nullptr)).second)
2133 LexicalScope *LexS =
LScopes.findLexicalScope(LS);
2135 createConcreteEntity(TheCU, *LexS, DN,
nullptr);
2137 LocalDeclsPerLS[
LS].insert(
N);
2151 if (!
MI.isBundledWithSucc())
2153 auto Suc = std::next(
MI.getIterator());
2158 assert(Suc->isBundledWithPred() &&
2159 "Call bundle instructions are out of order");
2164 if (!NoDebug && SP->areAllCallsDescribed() &&
2166 (!
MI->hasDelaySlot() || delaySlotSupported(*
MI))) {
2168 bool IsTail =
TII->isTailCall(*
MI);
2186 auto RecordLineZero = [&]() {
2190 const MDNode *Scope =
nullptr;
2191 unsigned Column = 0;
2196 recordSourceLine(0, Column, Scope, 0);
2201 unsigned LastAsmLine =
2202 Asm->OutStreamer->getContext().getCurrentDwarfLoc().getLine();
2207 if (
MI->isMetaInstruction())
2228 auto RecordSourceLine = [
this](
auto &
DL,
auto Flags) {
2230 if (
Asm->OutStreamer->isVerboseAsm()) {
2234 recordSourceLine(
DL.getLine(),
DL.getCol(),
DL.getScope(), Flags,
2243 bool ScopeUsesKeyInstructions =
2245 DL->getScope()->getSubprogram()->getKeyInstructionsEnabled();
2248 if (ScopeUsesKeyInstructions &&
DL &&
DL.getLine())
2249 IsKey = KeyInstructions.contains(
MI);
2255 assert(
MI->getParent() == &*
MI->getMF()->begin());
2256 recordSourceLine(SP->getScopeLine(), 0, SP,
2261 bool PrevInstInSameSection =
2263 PrevInstBB->getSectionID() ==
MI->getParent()->getSectionID());
2264 bool ForceIsStmt = ForceIsStmtInstrs.contains(
MI);
2265 if (PrevInstInSameSection && !ForceIsStmt &&
DL.isSameSourceLocation(
PrevInstLoc)) {
2275 if ((LastAsmLine == 0 &&
DL.getLine() != 0) || Flags) {
2277 RecordSourceLine(
DL, Flags);
2290 if (LastAsmLine == 0)
2311 if (
DL.getLine() == 0 && LastAsmLine == 0)
2318 if (ScopeUsesKeyInstructions) {
2325 if (
DL.getLine() && (
DL.getLine() != OldLine || ForceIsStmt))
2340 if (
Asm->OutStreamer->isVerboseAsm()) {
2344 recordSourceLine(
DL.getLine(),
DL.getCol(),
DL.getScope(), Flags,
2353static std::pair<const MachineInstr *, bool>
2364 bool IsEmptyPrologue =
2365 !(
F.hasPrologueData() ||
F.getMetadata(LLVMContext::MD_func_sanitize));
2370 -> std::optional<std::pair<const MachineInstr *, bool>> {
2372 bool isCopy = (
TII.isCopyInstr(
MI) ?
true :
false);
2373 bool isTrivRemat =
TII.isTriviallyReMaterializable(
MI);
2376 if (!isFrameSetup &&
MI.getDebugLoc()) {
2382 if (
MI.getDebugLoc().getLine())
2383 return std::make_pair(&
MI, IsEmptyPrologue);
2388 if (!
isCopy && !isTrivRemat && !isFrameSetup && !NonTrivialInst)
2389 NonTrivialInst = &
MI;
2391 IsEmptyPrologue =
false;
2392 return std::nullopt;
2400 auto CurBlock = MF->
begin();
2401 auto CurInst = CurBlock->begin();
2405 while (CurBlock->empty())
2406 CurInst = (++CurBlock)->begin();
2407 assert(CurInst != CurBlock->end());
2411 auto getNextInst = [&CurBlock, &CurInst, MF]() ->
bool {
2413 if (CurInst->isTerminator()) {
2422 if (CurBlock->pred_size() > 1)
2433 if (CurBlock == MF->
end())
2435 }
while (CurBlock->empty());
2436 CurInst = CurBlock->begin();
2442 if (!CurInst->isMetaInstruction()) {
2443 auto FoundInst = ExamineInst(*CurInst);
2454 if (CurInst->isCall()) {
2456 Loc &&
Loc->getLine() == 0) {
2458 unsigned ScopeLine = SP->getScopeLine();
2461 const_cast<MachineInstr *
>(&*CurInst)->setDebugLoc(ScopeLineDILoc);
2464 return std::make_pair(&*CurInst,
false);
2470 auto NextInst = std::next(CurInst);
2471 if (NextInst != CurInst->getParent()->end()) {
2488 if (NonTrivialInst && NonTrivialInst->
getParent() == &*MF->
begin()) {
2489 IsEmptyPrologue = NonTrivialInst == &*MF->
begin()->begin();
2490 return std::make_pair(NonTrivialInst, IsEmptyPrologue);
2494 return std::make_pair(
nullptr, IsEmptyPrologue);
2500 const MDNode *S,
unsigned Flags,
unsigned CUID,
2502 ArrayRef<std::unique_ptr<DwarfCompileUnit>> DCUs,
2505 unsigned FileNo = 1;
2508 Fn =
Scope->getFilename();
2509 if (Line != 0 && DwarfVersion >= 4)
2514 .getOrCreateSourceID(
Scope->getFile());
2516 Asm.OutStreamer->emitDwarfLocDirective(FileNo, Line, Col, Flags, 0,
2517 Discriminator, Fn, Comment);
2528 bool IsEmptyPrologue = PrologEnd.second;
2531 if (IsEmptyPrologue) {
2539 if (!
DL ||
DL->getLine() != 0)
2550 (void)getOrCreateDwarfCompileUnit(SP->getUnit());
2560 KeyInstructions.clear();
2567 std::pair<uint8_t, SmallVector<const MachineInstr *, 2>>>
2584 for (
auto &
MBB : *MF) {
2594 uint64_t BuoyAtom = 0;
2596 for (
auto &
MI :
MBB) {
2597 if (
MI.isMetaInstruction())
2601 if (!
Loc || !
Loc->getLine())
2612 bool IsCallLike =
MI.isCall() ||
TII.isTailCall(
MI);
2617 KeyInstructions.insert(Buoy);
2623 if (!
Loc->getAtomGroup() || !
Loc->getAtomRank())
2627 auto *InlinedAt = Loc->getInlinedAt();
2630 if (!Group || !Rank)
2634 if (BuoyAtom && BuoyAtom != Group) {
2639 auto &[CandidateRank, CandidateInsts] =
2640 GroupCandidates[{InlinedAt, Group}];
2646 assert((CandidateRank == 0 && CandidateInsts.empty()) ||
2647 (CandidateRank != 0 && !CandidateInsts.empty()));
2649 assert(Rank &&
"expected nonzero rank");
2652 if (CandidateRank && CandidateRank < Rank)
2659 if (CandidateRank == Rank)
2663 else if (CandidateRank > Rank)
2664 CandidateInsts.clear();
2668 CandidateInsts.push_back(Buoy);
2669 CandidateRank = Rank;
2677 if (CandidateInsts.empty())
2683 for (
const auto &[
_, Insts] : GroupCandidates.
values())
2684 for (
auto *
I : Insts)
2685 KeyInstructions.insert(
I);
2693 ForceIsStmtInstrs.clear();
2725 SmallDenseSet<MachineBasicBlock *, 4> PredMBBsToExamine;
2726 SmallDenseMap<MachineBasicBlock *, MachineInstr *> PotentialIsStmtMBBInstrs;
2732 for (
auto &
MI :
MBB) {
2733 if (
MI.getDebugLoc() &&
MI.getDebugLoc()->getLine()) {
2746 for (
auto *
MBB : PredMBBsToExamine) {
2747 auto CheckMBBEdge = [&](MachineBasicBlock *Succ,
unsigned OutgoingLine) {
2748 auto MBBInstrIt = PotentialIsStmtMBBInstrs.
find(Succ);
2749 if (MBBInstrIt == PotentialIsStmtMBBInstrs.
end())
2751 MachineInstr *
MI = MBBInstrIt->second;
2752 if (
MI->getDebugLoc()->getLine() == OutgoingLine)
2754 PotentialIsStmtMBBInstrs.
erase(MBBInstrIt);
2755 ForceIsStmtInstrs.insert(
MI);
2762 CheckMBBEdge(Succ, 0);
2768 return PotentialIsStmtMBBInstrs.contains(SuccMBB);
2776 MachineBasicBlock *
TBB =
nullptr, *FBB =
nullptr;
2783 if (!AnalyzeFailed && !
Cond.empty() && FBB !=
nullptr &&
2786 assert(MIIt->isBranch() &&
"Bad result from analyzeBranch?");
2787 CheckMBBEdge(FBB, FBBLine);
2811 unsigned LastLine = 0;
2813 if (
auto DL = MIIt->getDebugLoc();
DL &&
DL->getLine()) {
2814 LastLine =
DL->getLine();
2819 for (
auto *Succ : SuccessorBBs)
2820 CheckMBBEdge(Succ, LastLine);
2835 FunctionLineTableLabel =
CU.emitFuncLineTableOffsets()
2836 ?
Asm->OutStreamer->emitLineTableLabel()
2839 Asm->OutStreamer->getContext().setDwarfCompileUnitID(
2847 *MF,
Asm->OutStreamer->getContext().getDwarfCompileUnitID());
2853 computeKeyInstructions(MF);
2854 findForceIsStmtInstrs(MF);
2862 if (
Asm->OutStreamer->hasRawTextSupport())
2866 return CU.getUniqueID();
2870 const auto &CURanges =
CU->getRanges();
2871 auto &LineTable =
Asm->OutStreamer->getContext().getMCDwarfLineTable(
2874 LineTable.getMCLineSections().addEndEntry(
2875 const_cast<MCSymbol *
>(CURanges.back().End));
2895 "endFunction should be called with the same function as beginFunction");
2898 Asm->OutStreamer->getContext().setDwarfCompileUnitID(0);
2910 collectEntityInfo(TheCU, SP, Processed);
2914 for (
const auto &R :
Asm->MBBSectionRanges)
2915 TheCU.
addRange({R.second.BeginLabel, R.second.EndLabel});
2922 LScopes.getAbstractScopesList().empty() && !IsDarwin) {
2923 for (
const auto &R :
Asm->MBBSectionRanges)
2933 size_t NumAbstractSubprograms =
LScopes.getAbstractScopesList().size();
2937 for (
const MDNode *
N : SP->getRetainedNodes()) {
2940 auto *LexS =
LScopes.getOrCreateAbstractScope(LS);
2941 assert(LexS &&
"Expected the LexicalScope to be created.");
2945 if (!Processed.
insert(InlinedEntity(DN,
nullptr)).second ||
2951 LocalDeclsPerLS[LS].insert(
N);
2954 LScopes.getAbstractScopesList().size() == NumAbstractSubprograms &&
2955 "getOrCreateAbstractScope() inserted an abstract subprogram scope");
2957 constructAbstractSubprogramScopeDIE(TheCU, AScope);
2960 ProcessedSPNodes.insert(SP);
2964 if (!
LScopes.getAbstractScopesList().empty() &&
2966 SkelCU->constructSubprogramScopeDIE(SP,
F, FnScope,
2967 FunctionLineTableLabel);
2969 FunctionLineTableLabel =
nullptr;
2972 constructCallSiteEntryDIEs(*SP, TheCU, ScopeDIE, *MF);
2980 LocalDeclsPerLS.clear();
2987void DwarfDebug::recordSourceLine(
unsigned Line,
unsigned Col,
const MDNode *S,
2999void DwarfDebug::emitDebugInfo() {
3005void DwarfDebug::emitAbbreviations() {
3008 Holder.
emitAbbrevs(
Asm->getObjFileLowering().getDwarfAbbrevSection());
3011void DwarfDebug::emitStringOffsetsTableHeader() {
3014 *
Asm,
Asm->getObjFileLowering().getDwarfStrOffSection(),
3018template <
typename AccelTableT>
3019void DwarfDebug::emitAccel(AccelTableT &Accel,
MCSection *Section,
3021 Asm->OutStreamer->switchSection(Section);
3027void DwarfDebug::emitAccelDebugNames() {
3036void DwarfDebug::emitAccelNames() {
3037 emitAccel(AccelNames,
Asm->getObjFileLowering().getDwarfAccelNamesSection(),
3043void DwarfDebug::emitAccelObjC() {
3044 emitAccel(AccelObjC,
Asm->getObjFileLowering().getDwarfAccelObjCSection(),
3049void DwarfDebug::emitAccelNamespaces() {
3050 emitAccel(AccelNamespace,
3051 Asm->getObjFileLowering().getDwarfAccelNamespaceSection(),
3056void DwarfDebug::emitAccelTypes() {
3057 emitAccel(AccelTypes,
Asm->getObjFileLowering().getDwarfAccelTypesSection(),
3087 if (Die->
getTag() == dwarf::DW_TAG_compile_unit)
3095 DIE &SpecDIE = SpecVal.getDIEEntry().getEntry();
3102 case dwarf::DW_TAG_class_type:
3103 case dwarf::DW_TAG_structure_type:
3104 case dwarf::DW_TAG_union_type:
3105 case dwarf::DW_TAG_enumeration_type:
3110 case dwarf::DW_TAG_typedef:
3111 case dwarf::DW_TAG_base_type:
3112 case dwarf::DW_TAG_subrange_type:
3113 case dwarf::DW_TAG_template_alias:
3115 case dwarf::DW_TAG_namespace:
3117 case dwarf::DW_TAG_subprogram:
3119 case dwarf::DW_TAG_variable:
3121 case dwarf::DW_TAG_enumerator:
3131void DwarfDebug::emitDebugPubSections() {
3132 for (
const auto &NU : CUMap) {
3133 DwarfCompileUnit *TheU = NU.second;
3140 Asm->OutStreamer->switchSection(
3141 GnuStyle ?
Asm->getObjFileLowering().getDwarfGnuPubNamesSection()
3142 :
Asm->getObjFileLowering().getDwarfPubNamesSection());
3143 emitDebugPubSection(GnuStyle,
"Names", TheU, TheU->
getGlobalNames());
3145 Asm->OutStreamer->switchSection(
3146 GnuStyle ?
Asm->getObjFileLowering().getDwarfGnuPubTypesSection()
3147 :
Asm->getObjFileLowering().getDwarfPubTypesSection());
3148 emitDebugPubSection(GnuStyle,
"Types", TheU, TheU->
getGlobalTypes());
3154 Asm->emitDwarfOffset(
CU.getSection()->getBeginSymbol(),
3155 CU.getDebugSectionOffset());
3157 Asm->emitDwarfSymbolReference(
CU.getLabelBegin());
3160void DwarfDebug::emitDebugPubSection(
bool GnuStyle,
StringRef Name,
3168 "pub" + Name,
"Length of Public " + Name +
" Info");
3170 Asm->OutStreamer->AddComment(
"DWARF Version");
3173 Asm->OutStreamer->AddComment(
"Offset of Compilation Unit Info");
3174 emitSectionReference(*TheU);
3176 Asm->OutStreamer->AddComment(
"Compilation Unit Length");
3181 for (
const auto &GI : Globals)
3184 return A.second->getOffset() <
B.second->getOffset();
3186 for (
const auto &[Name, Entity] : Vec) {
3187 Asm->OutStreamer->AddComment(
"DIE offset");
3188 Asm->emitDwarfLengthOrOffset(Entity->getOffset());
3192 Asm->OutStreamer->AddComment(
3198 Asm->OutStreamer->AddComment(
"External Name");
3199 Asm->OutStreamer->emitBytes(StringRef(
Name.data(),
Name.size() + 1));
3202 Asm->OutStreamer->AddComment(
"End Mark");
3203 Asm->emitDwarfLengthOrOffset(0);
3204 Asm->OutStreamer->emitLabel(EndLabel);
3208void DwarfDebug::emitDebugStr() {
3209 MCSection *StringOffsetsSection =
nullptr;
3211 emitStringOffsetsTableHeader();
3212 StringOffsetsSection =
Asm->getObjFileLowering().getDwarfStrOffSection();
3215 Holder.
emitStrings(
Asm->getObjFileLowering().getDwarfStrSection(),
3216 StringOffsetsSection,
true);
3222 auto &&Comments = DebugLocs.getComments(Entry);
3223 auto Comment = Comments.begin();
3224 auto End = Comments.end();
3231 unsigned PtrSize =
Asm->MAI.getCodePointerSize();
3233 DebugLocs.getBytes(Entry).size()),
3234 Asm->getDataLayout().isLittleEndian(), PtrSize);
3239 for (
const auto &
Op : Expr) {
3240 assert(
Op.getCode() != dwarf::DW_OP_const_type &&
3241 "3 operand ops not yet supported");
3242 assert(!
Op.getSubCode() &&
"SubOps not yet supported");
3243 Streamer.
emitInt8(
Op.getCode(), Comment != End ? *(Comment++) :
"");
3245 for (
unsigned I = 0;
I <
Op.getDescription().
Op.size(); ++
I) {
3246 if (
Op.getDescription().Op[
I] == Encoding::BaseTypeRef) {
3248 Streamer.
emitDIERef(*
CU->ExprRefedBaseTypes[
Op.getRawOperand(
I)].Die);
3250 for (
unsigned J = 0; J <
Length; ++J)
3254 for (uint64_t J =
Offset; J <
Op.getOperandEndOffset(
I); ++J)
3255 Streamer.
emitInt8(
Data.getData()[J], Comment != End ? *(Comment++) :
"");
3266 auto *DIExpr =
Value.getExpression();
3272 if (DIExpr && DIExpr->isEntryValue()) {
3289 auto EmitValueLocEntry = [&DwarfExpr, &
BT,
3292 if (Entry.isInt()) {
3293 if (
BT && (
BT->getEncoding() == dwarf::DW_ATE_boolean)) {
3298 bool IsSigned =
BT && (
BT->getEncoding() == dwarf::DW_ATE_signed ||
3299 BT->getEncoding() == dwarf::DW_ATE_signed_char);
3310 uint64_t TypeBitSize =
BT->getSizeInBits();
3311 bool IsByteSized = TypeBitSize % 8 == 0;
3313 IsSigned ? !
isIntN(GenericBitSize, Entry.getInt())
3315 static_cast<uint64_t
>(Entry.getInt()));
3316 if (TypeBitSize > GenericBitSize && IsByteSized && IsOutOfRange) {
3318 APInt(
static_cast<unsigned>(TypeBitSize),
3319 static_cast<uint64_t
>(Entry.getInt()), IsSigned,
3330 }
else if (Entry.isLocation()) {
3332 if (Location.isIndirect())
3338 }
else if (Entry.isTargetIndexLocation()) {
3344 }
else if (Entry.isConstantFP()) {
3347 DwarfExpr.
addConstantFP(Entry.getConstantFP()->getValueAPF(), AP);
3348 }
else if (Entry.getConstantFP()
3351 .getBitWidth() <= 64 ) {
3353 Entry.getConstantFP()->getValueAPF().bitcastToAPInt());
3356 dbgs() <<
"Skipped DwarfExpression creation for ConstantFP of size"
3357 << Entry.getConstantFP()
3368 if (!
Value.isVariadic()) {
3369 if (!EmitValueLocEntry(
Value.getLocEntries()[0], ExprCursor))
3378 return Entry.isLocation() && !Entry.getLoc().getReg();
3383 std::move(ExprCursor),
3384 [EmitValueLocEntry, &
Value](
unsigned Idx,
3386 return EmitValueLocEntry(
Value.getLocEntries()[Idx], Cursor);
3394 assert(!Values.empty() &&
3395 "location list entries without values are redundant");
3396 assert(Begin != End &&
"unexpected location list entry with empty range");
3401 if (
Value.isFragment()) {
3404 return P.isFragment();
3405 }) &&
"all values are expected to be fragments");
3408 for (
const auto &Fragment : Values)
3412 assert(Values.size() == 1 &&
"only fragments may have >1 value");
3423 Asm->OutStreamer->AddComment(
"Loc expr size");
3425 Asm->emitULEB128(DebugLocs.getBytes(Entry).size());
3426 else if (DebugLocs.getBytes(Entry).size() <= std::numeric_limits<uint16_t>::max())
3427 Asm->emitInt16(DebugLocs.getBytes(Entry).size());
3446 Asm->OutStreamer->AddComment(
"Offset entry count");
3452 Asm->getDwarfOffsetByteSize());
3466 Asm->OutStreamer->AddComment(
"Offset entry count");
3467 Asm->emitInt32(DebugLocs.getLists().size());
3468 Asm->OutStreamer->emitLabel(DebugLocs.getSym());
3470 for (
const auto &List : DebugLocs.getLists())
3471 Asm->emitLabelDifference(List.Label, DebugLocs.getSym(),
3472 Asm->getDwarfOffsetByteSize());
3477template <
typename Ranges,
typename PayloadEmitter>
3481 unsigned OffsetPair,
unsigned StartxLength,
unsigned StartxEndx,
3483 bool ShouldUseBaseAddress, PayloadEmitter EmitPayload) {
3484 auto Size = Asm->MAI.getCodePointerSize();
3488 Asm->OutStreamer->emitLabel(Sym);
3495 for (
const auto &
Range : R)
3496 SectionRanges[&
Range.Begin->getSection()].push_back(&
Range);
3498 const MCSymbol *CUBase =
CU.getBaseAddress();
3499 bool BaseIsSet =
false;
3500 for (
const auto &
P : SectionRanges) {
3501 auto *
Base = CUBase;
3503 (DD.
useSplitDwarf() && UseDwarf5 &&
P.first->isLinkerRelaxable())) {
3506 }
else if (!
Base && ShouldUseBaseAddress) {
3507 const MCSymbol *Begin =
P.second.front()->Begin;
3512 Asm->OutStreamer->emitIntValue(-1,
Size);
3513 Asm->OutStreamer->AddComment(
" base address");
3514 Asm->OutStreamer->emitSymbolValue(
Base,
Size);
3515 }
else if (NewBase != Begin ||
P.second.size() > 1) {
3521 Asm->OutStreamer->AddComment(StringifyEnum(BaseAddressx));
3522 Asm->emitInt8(BaseAddressx);
3523 Asm->OutStreamer->AddComment(
" base address index");
3526 }
else if (BaseIsSet && !UseDwarf5) {
3529 Asm->OutStreamer->emitIntValue(-1,
Size);
3530 Asm->OutStreamer->emitIntValue(0,
Size);
3533 for (
const auto *RS :
P.second) {
3536 assert(Begin &&
"Range without a begin symbol?");
3537 assert(End &&
"Range without an end symbol?");
3541 Asm->OutStreamer->AddComment(StringifyEnum(OffsetPair));
3542 Asm->emitInt8(OffsetPair);
3543 Asm->OutStreamer->AddComment(
" starting offset");
3544 Asm->emitLabelDifferenceAsULEB128(Begin,
Base);
3545 Asm->OutStreamer->AddComment(
" ending offset");
3546 Asm->emitLabelDifferenceAsULEB128(End,
Base);
3548 Asm->emitLabelDifference(Begin,
Base,
Size);
3549 Asm->emitLabelDifference(End,
Base,
Size);
3551 }
else if (UseDwarf5) {
3559 Asm->OutStreamer->AddComment(StringifyEnum(StartxEndx));
3560 Asm->emitInt8(StartxEndx);
3561 Asm->OutStreamer->AddComment(
" start index");
3563 Asm->OutStreamer->AddComment(
" end index");
3566 Asm->OutStreamer->AddComment(StringifyEnum(StartxLength));
3567 Asm->emitInt8(StartxLength);
3568 Asm->OutStreamer->AddComment(
" start index");
3570 Asm->OutStreamer->AddComment(
" length");
3571 Asm->emitLabelDifferenceAsULEB128(End, Begin);
3574 Asm->OutStreamer->emitSymbolValue(Begin,
Size);
3575 Asm->OutStreamer->emitSymbolValue(End,
Size);
3582 Asm->OutStreamer->AddComment(StringifyEnum(
EndOfList));
3586 Asm->OutStreamer->emitIntValue(0,
Size);
3587 Asm->OutStreamer->emitIntValue(0,
Size);
3595 dwarf::DW_LLE_base_addressx, dwarf::DW_LLE_offset_pair,
3596 dwarf::DW_LLE_startx_length, dwarf::DW_LLE_startx_endx,
3599 DD.emitDebugLocEntryLocation(E, List.CU);
3603void DwarfDebug::emitDebugLocImpl(
MCSection *Sec) {
3604 if (DebugLocs.getLists().empty())
3607 Asm->OutStreamer->switchSection(Sec);
3613 for (
const auto &
List : DebugLocs.getLists())
3617 Asm->OutStreamer->emitLabel(TableEnd);
3621void DwarfDebug::emitDebugLoc() {
3624 ?
Asm->getObjFileLowering().getDwarfLoclistsSection()
3625 :
Asm->getObjFileLowering().getDwarfLocSection());
3629void DwarfDebug::emitDebugLocDWO() {
3632 Asm->getObjFileLowering().getDwarfLoclistsDWOSection());
3637 for (
const auto &
List : DebugLocs.getLists()) {
3638 Asm->OutStreamer->switchSection(
3639 Asm->getObjFileLowering().getDwarfLocDWOSection());
3640 Asm->OutStreamer->emitLabel(
List.Label);
3642 for (
const auto &Entry : DebugLocs.getEntries(
List)) {
3651 Asm->emitInt8(dwarf::DW_LLE_startx_length);
3652 unsigned idx = AddrPool.getIndex(
Entry.Begin);
3653 Asm->emitULEB128(idx);
3659 Asm->emitInt8(dwarf::DW_LLE_end_of_list);
3669void DwarfDebug::emitDebugARanges() {
3670 if (ArangeLabels.empty())
3677 for (
const SymbolCU &SCU : ArangeLabels) {
3678 if (SCU.Sym->isInSection()) {
3680 MCSection *Section = &SCU.Sym->getSection();
3681 SectionMap[Section].push_back(SCU);
3686 SectionMap[
nullptr].push_back(SCU);
3690 DenseMap<DwarfCompileUnit *, std::vector<ArangeSpan>> Spans;
3692 for (
auto &
I : SectionMap) {
3700 for (
const SymbolCU &Cur :
List) {
3702 Span.
Start = Cur.Sym;
3705 Spans[Cur.CU].push_back(Span);
3711 List.push_back(SymbolCU(
nullptr,
Asm->OutStreamer->endSection(Section)));
3715 for (
size_t n = 1, e =
List.size(); n < e; n++) {
3716 const SymbolCU &Prev =
List[n - 1];
3717 const SymbolCU &Cur =
List[n];
3720 if (Cur.
CU != Prev.
CU) {
3722 Span.
Start = StartSym;
3725 Spans[Prev.
CU].push_back(Span);
3732 Asm->OutStreamer->switchSection(
3733 Asm->getObjFileLowering().getDwarfARangesSection());
3735 unsigned PtrSize =
Asm->MAI.getCodePointerSize();
3738 std::vector<DwarfCompileUnit *> CUs;
3739 for (
const auto &it : Spans) {
3740 DwarfCompileUnit *
CU = it.first;
3745 llvm::sort(CUs, [](
const DwarfCompileUnit *
A,
const DwarfCompileUnit *
B) {
3746 return A->getUniqueID() <
B->getUniqueID();
3750 for (DwarfCompileUnit *
CU : CUs) {
3751 std::vector<ArangeSpan> &
List = Spans[
CU];
3754 if (
auto *Skel =
CU->getSkeleton())
3758 unsigned ContentSize =
3760 Asm->getDwarfOffsetByteSize() +
3765 unsigned TupleSize = PtrSize * 2;
3769 Asm->getUnitLengthFieldByteSize() + ContentSize,
Align(TupleSize));
3772 ContentSize += (
List.size() + 1) * TupleSize;
3775 Asm->emitDwarfUnitLength(ContentSize,
"Length of ARange Set");
3776 Asm->OutStreamer->AddComment(
"DWARF Arange version number");
3778 Asm->OutStreamer->AddComment(
"Offset Into Debug Info Section");
3779 emitSectionReference(*
CU);
3780 Asm->OutStreamer->AddComment(
"Address Size (in bytes)");
3781 Asm->emitInt8(PtrSize);
3782 Asm->OutStreamer->AddComment(
"Segment Size (in bytes)");
3785 Asm->OutStreamer->emitFill(Padding, 0xff);
3787 for (
const ArangeSpan &Span :
List) {
3788 Asm->emitLabelReference(Span.Start, PtrSize);
3795 auto SizeRef = SymSize.find(Span.Start);
3796 if ((SizeRef == SymSize.end() || SizeRef->second != 0) && Span.End) {
3797 Asm->emitLabelDifference(Span.End, Span.Start, PtrSize);
3802 if (SizeRef == SymSize.end() || SizeRef->second == 0)
3805 Size = SizeRef->second;
3807 Asm->OutStreamer->emitIntValue(
Size, PtrSize);
3811 Asm->OutStreamer->AddComment(
"ARange terminator");
3812 Asm->OutStreamer->emitIntValue(0, PtrSize);
3813 Asm->OutStreamer->emitIntValue(0, PtrSize);
3821 dwarf::DW_RLE_base_addressx, dwarf::DW_RLE_offset_pair,
3822 dwarf::DW_RLE_startx_length, dwarf::DW_RLE_startx_endx,
3824 List.CU->getCUNode()->getRangesBaseAddress() ||
3836 return !Pair.second->getCUNode()->isDebugDirectivesOnly();
3839 Asm->OutStreamer->switchSection(Section);
3849 Asm->OutStreamer->emitLabel(TableEnd);
3854void DwarfDebug::emitDebugRanges() {
3857 emitDebugRangesImpl(Holder,
3859 ?
Asm->getObjFileLowering().getDwarfRnglistsSection()
3860 :
Asm->getObjFileLowering().getDwarfRangesSection());
3863void DwarfDebug::emitDebugRangesDWO() {
3865 Asm->getObjFileLowering().getDwarfRnglistsDWOSection());
3872 enum HeaderFlagMask {
3873#define HANDLE_MACRO_FLAG(ID, NAME) MACRO_FLAG_##NAME = ID,
3874#include "llvm/BinaryFormat/Dwarf.def"
3876 Asm->OutStreamer->AddComment(
"Macro information version");
3877 Asm->emitInt16(DwarfVersion >= 5 ? DwarfVersion : 4);
3880 if (Asm->isDwarf64()) {
3881 Asm->OutStreamer->AddComment(
"Flags: 64 bit, debug_line_offset present");
3882 Asm->emitInt8(MACRO_FLAG_OFFSET_SIZE | MACRO_FLAG_DEBUG_LINE_OFFSET);
3884 Asm->OutStreamer->AddComment(
"Flags: 32 bit, debug_line_offset present");
3885 Asm->emitInt8(MACRO_FLAG_DEBUG_LINE_OFFSET);
3887 Asm->OutStreamer->AddComment(
"debug_line_offset");
3889 Asm->emitDwarfLengthOrOffset(0);
3891 Asm->emitDwarfSymbolReference(
CU.getLineTableStartSym());
3894void DwarfDebug::handleMacroNodes(DIMacroNodeArray Nodes,
DwarfCompileUnit &U) {
3895 for (
auto *MN : Nodes) {
3899 emitMacroFile(*
F, U);
3905void DwarfDebug::emitMacro(
DIMacro &M) {
3906 StringRef
Name =
M.getName();
3907 StringRef
Value =
M.getValue();
3913 if (UseDebugMacroSection) {
3916 ? dwarf::DW_MACRO_define_strx
3917 : dwarf::DW_MACRO_undef_strx;
3920 Asm->OutStreamer->AddComment(
"Line Number");
3921 Asm->emitULEB128(
M.getLine());
3922 Asm->OutStreamer->AddComment(
"Macro String");
3924 InfoHolder.getStringPool().getIndexedEntry(*
Asm, Str).getIndex());
3927 ? dwarf::DW_MACRO_GNU_define_indirect
3928 : dwarf::DW_MACRO_GNU_undef_indirect;
3931 Asm->OutStreamer->AddComment(
"Line Number");
3932 Asm->emitULEB128(
M.getLine());
3933 Asm->OutStreamer->AddComment(
"Macro String");
3934 Asm->emitDwarfSymbolReference(
3935 InfoHolder.getStringPool().getEntry(*
Asm, Str).getSymbol());
3939 Asm->emitULEB128(
M.getMacinfoType());
3940 Asm->OutStreamer->AddComment(
"Line Number");
3941 Asm->emitULEB128(
M.getLine());
3942 Asm->OutStreamer->AddComment(
"Macro String");
3943 Asm->OutStreamer->emitBytes(Str);
3944 Asm->emitInt8(
'\0');
3948void DwarfDebug::emitMacroFileImpl(
3950 StringRef (*MacroFormToString)(
unsigned Form)) {
3952 Asm->OutStreamer->AddComment(MacroFormToString(StartFile));
3953 Asm->emitULEB128(StartFile);
3954 Asm->OutStreamer->AddComment(
"Line Number");
3956 Asm->OutStreamer->AddComment(
"File Number");
3959 Asm->emitULEB128(getDwoLineTable(U)->getFile(
3961 Asm->OutContext.getDwarfVersion(),
F.getSource()));
3963 Asm->emitULEB128(
U.getOrCreateSourceID(&
F));
3965 Asm->OutStreamer->AddComment(MacroFormToString(EndFile));
3966 Asm->emitULEB128(EndFile);
3973 if (UseDebugMacroSection)
3975 F, U, dwarf::DW_MACRO_start_file, dwarf::DW_MACRO_end_file,
3982void DwarfDebug::emitDebugMacinfoImpl(
MCSection *Section) {
3983 for (
const auto &
P : CUMap) {
3984 auto &TheCU = *
P.second;
3986 DwarfCompileUnit &
U = SkCU ? *SkCU : TheCU;
3988 DIMacroNodeArray Macros = CUNode->getMacros();
3991 Asm->OutStreamer->switchSection(Section);
3992 Asm->OutStreamer->emitLabel(
U.getMacroLabelBegin());
3993 if (UseDebugMacroSection)
3995 handleMacroNodes(Macros, U);
3996 Asm->OutStreamer->AddComment(
"End Of Macro List Mark");
4002void DwarfDebug::emitDebugMacinfo() {
4003 auto &ObjLower =
Asm->getObjFileLowering();
4004 emitDebugMacinfoImpl(UseDebugMacroSection
4005 ? ObjLower.getDwarfMacroSection()
4006 : ObjLower.getDwarfMacinfoSection());
4009void DwarfDebug::emitDebugMacinfoDWO() {
4010 auto &ObjLower =
Asm->getObjFileLowering();
4011 emitDebugMacinfoImpl(UseDebugMacroSection
4012 ? ObjLower.getDwarfMacroDWOSection()
4013 : ObjLower.getDwarfMacinfoDWOSection());
4018void DwarfDebug::initSkeletonUnit(
const DwarfUnit &U,
DIE &Die,
4019 std::unique_ptr<DwarfCompileUnit> NewU) {
4021 if (!CompilationDir.empty())
4022 NewU->addString(Die, dwarf::DW_AT_comp_dir, CompilationDir);
4023 addGnuPubAttributes(*NewU, Die);
4025 SkeletonHolder.addUnit(std::move(NewU));
4030 auto OwnedUnit = std::make_unique<DwarfCompileUnit>(
4031 CU.getUniqueID(),
CU.getCUNode(),
Asm,
this, &SkeletonHolder,
4033 DwarfCompileUnit &NewCU = *OwnedUnit;
4034 NewCU.
setSection(
Asm->getObjFileLowering().getDwarfInfoSection());
4041 initSkeletonUnit(
CU, NewCU.
getUnitDie(), std::move(OwnedUnit));
4048void DwarfDebug::emitDebugInfoDWO() {
4056void DwarfDebug::emitDebugAbbrevDWO() {
4058 InfoHolder.emitAbbrevs(
Asm->getObjFileLowering().getDwarfAbbrevDWOSection());
4061void DwarfDebug::emitDebugLineDWO() {
4063 SplitTypeUnitFileTable.Emit(
4064 *
Asm->OutStreamer, MCDwarfLineTableParams(),
4065 Asm->getObjFileLowering().getDwarfLineDWOSection());
4068void DwarfDebug::emitStringOffsetsTableHeaderDWO() {
4070 InfoHolder.getStringPool().emitStringOffsetsTableHeader(
4071 *
Asm,
Asm->getObjFileLowering().getDwarfStrOffDWOSection(),
4078void DwarfDebug::emitDebugStrDWO() {
4080 emitStringOffsetsTableHeaderDWO();
4082 MCSection *OffSec =
Asm->getObjFileLowering().getDwarfStrOffDWOSection();
4083 InfoHolder.emitStrings(
Asm->getObjFileLowering().getDwarfStrDWOSection(),
4088void DwarfDebug::emitDebugAddr() {
4089 AddrPool.emit(*
Asm,
Asm->getObjFileLowering().getDwarfAddrSection());
4095 const DICompileUnit *DIUnit =
CU.getCUNode();
4096 SplitTypeUnitFileTable.maybeSetRootFile(
4099 return &SplitTypeUnitFileTable;
4110 return Result.high();
4119 if (!TypeUnitsUnderConstruction.empty() && AddrPool.hasBeenUsed())
4122 auto Ins = TypeSignatures.try_emplace(CTy);
4124 CU.addDIETypeSignature(RefDie, Ins.first->second);
4129 bool TopLevelType = TypeUnitsUnderConstruction.empty();
4130 AddrPool.resetUsedFlag();
4132 auto OwnedUnit = std::make_unique<DwarfTypeUnit>(
4136 TypeUnitsUnderConstruction.emplace_back(std::move(OwnedUnit), CTy);
4138 NewTU.
addUInt(UnitDie, dwarf::DW_AT_language, dwarf::DW_FORM_data2,
4139 CU.getSourceLanguage());
4143 Ins.first->second = Signature;
4151 if (!CompilationDir.empty())
4152 NewTU.
addString(UnitDie, dwarf::DW_AT_comp_dir, CompilationDir);
4153 NewTU.
addString(UnitDie, dwarf::DW_AT_dwo_name,
4154 Asm->TM.Options.MCOptions.SplitDwarfFile);
4158 ?
Asm->getObjFileLowering().getDwarfTypesDWOSection()
4159 :
Asm->getObjFileLowering().getDwarfInfoDWOSection();
4164 ?
Asm->getObjFileLowering().getDwarfTypesSection(Signature)
4165 :
Asm->getObjFileLowering().getDwarfInfoSection(Signature);
4168 CU.applyStmtList(UnitDie);
4179 auto TypeUnitsToAdd = std::move(TypeUnitsUnderConstruction);
4180 TypeUnitsUnderConstruction.clear();
4184 if (AddrPool.hasBeenUsed()) {
4185 AccelTypeUnitsDebugNames.clear();
4189 for (
const auto &
TU : TypeUnitsToAdd)
4190 TypeSignatures.erase(
TU.second);
4198 CU.updateAcceleratorTables(CTy->
getScope(), CTy, RefDie);
4204 for (
auto &
TU : TypeUnitsToAdd) {
4205 InfoHolder.computeSizeAndOffsetsForUnit(
TU.first.get());
4210 AccelDebugNames.addTypeUnitSignature(*
TU.first);
4212 AccelDebugNames.addTypeUnitSymbol(*
TU.first);
4215 AccelTypeUnitsDebugNames.convertDieToOffset();
4216 AccelDebugNames.addTypeEntries(AccelTypeUnitsDebugNames);
4217 AccelTypeUnitsDebugNames.clear();
4220 CU.addDIETypeSignature(RefDie, Signature);
4227template <
typename DataT>
4228void DwarfDebug::addAccelNameImpl(
4233 Unit.getUnitDie().getTag() == dwarf::DW_TAG_skeleton_unit || Name.empty())
4250 assert(((&Current == &AccelTypeUnitsDebugNames) ||
4251 ((&Current == &AccelDebugNames) &&
4252 (Unit.getUnitDie().getTag() != dwarf::DW_TAG_type_unit))) &&
4253 "Kind is CU but TU is being processed.");
4254 assert(((&Current == &AccelDebugNames) ||
4255 ((&Current == &AccelTypeUnitsDebugNames) &&
4256 (Unit.getUnitDie().getTag() == dwarf::DW_TAG_type_unit))) &&
4257 "Kind is TU but CU is being processed.");
4260 Current.
addName(
Ref, Die, Unit.getUniqueID(),
4261 Unit.getUnitDie().getTag() == dwarf::DW_TAG_type_unit);
4275 addAccelNameImpl(Unit, NameTableKind, AccelNames, Name, Die);
4284 addAccelNameImpl(Unit, NameTableKind, AccelObjC, Name, Die);
4291 addAccelNameImpl(Unit, NameTableKind, AccelNamespace, Name, Die);
4297 const DIE &Die,
char Flags) {
4298 addAccelNameImpl(Unit, NameTableKind, AccelTypes, Name, Die);
4302 return Asm->OutStreamer->getContext().getDwarfVersion();
4306 if (
Asm->getDwarfVersion() >= 4)
4307 return dwarf::Form::DW_FORM_sec_offset;
4308 assert((!
Asm->isDwarf64() || (
Asm->getDwarfVersion() == 3)) &&
4309 "DWARF64 is not defined prior DWARFv3");
4310 return Asm->isDwarf64() ? dwarf::Form::DW_FORM_data8
4311 : dwarf::Form::DW_FORM_data4;
4315 return SectionLabels.lookup(S);
4319 if (SectionLabels.insert(std::make_pair(&S->
getSection(), S)).second)
4324std::optional<MD5::MD5Result>
4328 return std::nullopt;
4329 std::optional<DIFile::ChecksumInfo<StringRef>> Checksum = File->getChecksum();
4331 return std::nullopt;
4336 std::string ChecksumString =
fromHex(Checksum->Value);
4353 if (
MBB.getAlignment() ==
Align(1))
4356 auto *SP =
MBB.getParent()->getFunction().getSubprogram();
4363 auto PrevLoc =
Asm->OutStreamer->getContext().getCurrentDwarfLoc();
4364 if (PrevLoc.getLine()) {
4365 Asm->OutStreamer->emitDwarfLocDirective(
4366 PrevLoc.getFileNum(), 0, PrevLoc.getColumn(), 0, 0, 0,
StringRef());
4368 Asm->OutStreamer->getCurrentSectionOnly());
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file implements a class to represent arbitrary precision integral constant values and operations...
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static Expected< bool > hasObjCCategory(BitstreamCursor &Stream)
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define clEnumValN(ENUMVAL, FLAGNAME, DESC)
#define clEnumVal(ENUMVAL, DESC)
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static bool isObjCClass(StringRef Name)
static cl::opt< bool > NoDwarfRangesSection("no-dwarf-ranges-section", cl::Hidden, cl::desc("Disable emission .debug_ranges section."), cl::init(false))
static void finishCallSiteParams(ValT Val, const DIExpression *Expr, ArrayRef< FwdRegParamInfo > DescribedParams, ParamSet &Params)
Emit call site parameter entries that are described by the given value and debug expression.
static cl::opt< bool > UseGNUDebugMacro("use-gnu-debug-macro", cl::Hidden, cl::desc("Emit the GNU .debug_macro format with DWARF <5"), cl::init(false))
static cl::opt< DefaultOnOff > DwarfInlinedStrings("dwarf-inlined-strings", cl::Hidden, cl::desc("Use inlined strings rather than string section."), cl::values(clEnumVal(Default, "Default for platform"), clEnumVal(Enable, "Enabled"), clEnumVal(Disable, "Disabled")), cl::init(Default))
static bool validThroughout(LexicalScopes &LScopes, const MachineInstr *DbgValue, const MachineInstr *RangeEnd, const InstructionOrdering &Ordering)
Determine whether a singular DBG_VALUE is valid for the entirety of its enclosing lexical scope.
static cl::opt< bool > GenerateARangeSection("generate-arange-section", cl::Hidden, cl::desc("Generate dwarf aranges"), cl::init(false))
static cl::opt< LinkageNameOption > DwarfLinkageNames("dwarf-linkage-names", cl::Hidden, cl::desc("Which DWARF linkage-name attributes to emit."), cl::values(clEnumValN(DefaultLinkageNames, "Default", "Default for platform"), clEnumValN(AllLinkageNames, "All", "All"), clEnumValN(AbstractLinkageNames, "Abstract", "Abstract subprograms")), cl::init(DefaultLinkageNames))
static void addToFwdRegWorklist(FwdRegWorklist &Worklist, unsigned Reg, const DIExpression *Expr, ArrayRef< FwdRegParamInfo > ParamsToAdd)
Add Reg to the worklist, if it's not already present, and mark that the given parameter registers' va...
static cl::opt< bool > GenerateDwarfTypeUnits("generate-type-units", cl::Hidden, cl::desc("Generate DWARF4 type units."), cl::init(false))
SmallSet< MCRegUnit, 16 > ClobberedRegUnitSet
Container for the set of register units known to be clobbered on the path to a call site.
static cl::opt< bool > KeyInstructionsAreStmts("dwarf-use-key-instructions", cl::Hidden, cl::init(true), cl::desc("Set to false to ignore Key Instructions metadata"))
Set to false to ignore Key Instructions metadata.
static bool interpretNextInstr(const MachineInstr *CurMI, FwdRegWorklist &ForwardedRegWorklist, ParamSet &Params, ClobberedRegUnitSet &ClobberedRegUnits)
static SmallVectorImpl< DwarfCompileUnit::GlobalExpr > & sortGlobalExprs(SmallVectorImpl< DwarfCompileUnit::GlobalExpr > &GVEs)
Sort and unique GVEs by comparing their fragment offset.
static bool isLangCaseSensitive(const DISourceLanguageName &Lang)
static dwarf::PubIndexEntryDescriptor computeIndexValue(DwarfUnit *CU, const DIE *Die)
computeIndexValue - Compute the gdb index value for the DIE and CU.
static uint64_t getFragmentOffsetInBits(const DIExpression &Expr)
static cl::opt< DefaultOnOff > DwarfOpConvert("dwarf-op-convert", cl::Hidden, cl::desc("Enable use of the DWARFv5 DW_OP_convert operator"), cl::values(clEnumVal(Default, "Default for platform"), clEnumVal(Enable, "Enabled"), clEnumVal(Disable, "Disabled")), cl::init(Default))
static std::pair< const MachineInstr *, bool > findPrologueEndLoc(const MachineFunction *MF)
static void collectCallSiteParameters(const MachineInstr *CallMI, ParamSet &Params)
Try to interpret values loaded into registers that forward parameters for CallMI.
static MCSymbol * emitRnglistsTableHeader(AsmPrinter *Asm, const DwarfFile &Holder)
static cl::opt< bool > SplitDwarfCrossCuReferences("split-dwarf-cross-cu-references", cl::Hidden, cl::desc("Enable cross-cu references in DWO files"), cl::init(false))
static cl::opt< bool > UseDwarfRangesBaseAddressSpecifier("use-dwarf-ranges-base-address-specifier", cl::Hidden, cl::desc("Use base address specifiers in debug_ranges"), cl::init(false))
MapVector< Register, SmallVector< FwdRegParamInfo, 2 > > FwdRegWorklist
Register worklist for finding call site values.
static void emitLocList(DwarfDebug &DD, AsmPrinter *Asm, const DebugLocStream::List &List)
static constexpr unsigned ULEB128PadSize
static cl::opt< DefaultOnOff > DwarfSectionsAsReferences("dwarf-sections-as-references", cl::Hidden, cl::desc("Use sections+offset as references rather than labels."), cl::values(clEnumVal(Default, "Default for platform"), clEnumVal(Enable, "Enabled"), clEnumVal(Disable, "Disabled")), cl::init(Default))
static AccelTableKind computeAccelTableKind(unsigned DwarfVersion, bool GenerateTypeUnits, DebuggerKind Tuning, const Triple &TT)
static void emitRangeList(DwarfDebug &DD, AsmPrinter *Asm, MCSymbol *Sym, const Ranges &R, const DwarfCompileUnit &CU, unsigned BaseAddressx, unsigned OffsetPair, unsigned StartxLength, unsigned StartxEndx, unsigned EndOfList, StringRef(*StringifyEnum)(unsigned), bool ShouldUseBaseAddress, PayloadEmitter EmitPayload)
static void forBothCUs(DwarfCompileUnit &CU, Func F)
static MCSymbol * emitLoclistsTableHeader(AsmPrinter *Asm, const DwarfDebug &DD)
static const DILocalScope * getRetainedNodeScope(const MDNode *N)
static const DIExpression * combineDIExpressions(const DIExpression *Original, const DIExpression *Addition)
Append the expression Addition to Original and return the result.
static void interpretValues(const MachineInstr *CurMI, FwdRegWorklist &ForwardedRegWorklist, ParamSet &Params, ClobberedRegUnitSet &ClobberedRegUnits)
Interpret values loaded into registers by CurMI.
static cl::opt< DefaultOnOff > UnknownLocations("use-unknown-locations", cl::Hidden, cl::desc("Make an absence of debug location information explicit."), cl::values(clEnumVal(Default, "At top of block or after label"), clEnumVal(Enable, "In all cases"), clEnumVal(Disable, "Never")), cl::init(Default))
static void recordSourceLine(AsmPrinter &Asm, unsigned Line, unsigned Col, const MDNode *S, unsigned Flags, unsigned CUID, uint16_t DwarfVersion, ArrayRef< std::unique_ptr< DwarfCompileUnit > > DCUs, StringRef Comment={})
Register a source line with debug info.
static void emitMacroHeader(AsmPrinter *Asm, const DwarfDebug &DD, const DwarfCompileUnit &CU, uint16_t DwarfVersion)
Emit the header of a DWARF 5 macro section, or the GNU extension for DWARF 4.
static cl::opt< AccelTableKind > AccelTables("accel-tables", cl::Hidden, cl::desc("Output dwarf accelerator tables."), cl::values(clEnumValN(AccelTableKind::Default, "Default", "Default for platform"), clEnumValN(AccelTableKind::None, "Disable", "Disabled."), clEnumValN(AccelTableKind::Apple, "Apple", "Apple"), clEnumValN(AccelTableKind::Dwarf, "Dwarf", "DWARF")), cl::init(AccelTableKind::Default))
static cl::opt< DwarfDebug::MinimizeAddrInV5 > MinimizeAddrInV5Option("minimize-addr-in-v5", cl::Hidden, cl::desc("Always use DW_AT_ranges in DWARFv5 whenever it could allow more " "address pool entry sharing to reduce relocations/object size"), cl::values(clEnumValN(DwarfDebug::MinimizeAddrInV5::Default, "Default", "Default address minimization strategy"), clEnumValN(DwarfDebug::MinimizeAddrInV5::Ranges, "Ranges", "Use rnglists for contiguous ranges if that allows " "using a pre-existing base address"), clEnumValN(DwarfDebug::MinimizeAddrInV5::Expressions, "Expressions", "Use exprloc addrx+offset expressions for any " "address with a prior base address"), clEnumValN(DwarfDebug::MinimizeAddrInV5::Form, "Form", "Use addrx+offset extension form for any address " "with a prior base address"), clEnumValN(DwarfDebug::MinimizeAddrInV5::Disabled, "Disabled", "Stuff")), cl::init(DwarfDebug::MinimizeAddrInV5::Default))
static StringRef getObjCMethodName(StringRef In)
static DbgValueLoc getDebugLocValue(const MachineInstr *MI)
Get .debug_loc entry for the instruction range starting at MI.
static void getObjCClassCategory(StringRef In, StringRef &Class, StringRef &Category)
const HexagonInstrInfo * TII
Module.h This file contains the declarations for the Module class.
#define DWARF2_FLAG_IS_STMT
#define DWARF2_FLAG_PROLOGUE_END
#define DWARF2_FLAG_EPILOGUE_BEGIN
Register const TargetRegisterInfo * TRI
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
static const MCPhysReg CalleeSavedReg
const SmallVectorImpl< MachineOperand > MachineBasicBlock * TBB
const SmallVectorImpl< MachineOperand > & Cond
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
This file describes how to lower LLVM code to machine code.
static bool isCopy(MachineInstr *MI)
static const uint32_t IV[8]
Class recording the (high level) value of a variable.
Class for arbitrary precision integers.
This class holds an abstract representation of an Accelerator Table, consisting of a sequence of buck...
void addName(DwarfStringPoolEntryRef Name, Types &&... Args)
unsigned getIndex(const MCSymbol *Sym, bool TLS=false)
Returns the index into the address pool with the given label/symbol.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
std::vector< T > vec() const
This class is intended to be used as a driving class for all asm writers.
DwarfDebug * getDwarfDebug()
TargetMachine & TM
Target machine description.
MachineFunction * MF
The current machine function.
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
const MCAsmInfo & MAI
Target Asm Printer information.
uint16_t getDwarfVersion() const
virtual void emitInt8(uint8_t Byte, const Twine &Comment="")=0
virtual unsigned emitDIERef(const DIE &D)=0
Basic type, like 'int' or 'float'.
bool getDebugInfoForProfiling() const
bool isDebugDirectivesOnly() const
StringRef getFlags() const
static LLVM_ABI std::optional< DebugNameTableKind > getNameTableKind(StringRef Str)
unsigned getRuntimeVersion() const
bool getSplitDebugInlining() const
StringRef getSysRoot() const
StringRef getProducer() const
DISourceLanguageName getSourceLanguage() const
uint64_t getDWOId() const
StringRef getSplitDebugFilename() const
static LLVM_ABI std::optional< DebugEmissionKind > getEmissionKind(StringRef Str)
void setSection(MCSection *Section)
Set the section that this DIEUnit will be emitted into.
A structured debug information entry.
LLVM_ABI DIEValue findAttribute(dwarf::Attribute Attribute) const
Find a value in the DIE with the attribute given.
LLVM_ABI const DIE * getUnitDie() const
Climb up the parent chain to get the compile unit or type unit DIE that this DIE belongs to.
dwarf::Tag getTag() const
Holds a DIExpression and keeps track of how many operands have been consumed so far.
static LLVM_ABI DIExpression * append(const DIExpression *Expr, ArrayRef< uint64_t > Ops)
Append the opcodes Ops to DIExpr.
unsigned getNumElements() const
LLVM_ABI bool isImplicit() const
Return whether this is an implicit location description.
static LLVM_ABI std::optional< FragmentInfo > getFragmentInfo(expr_op_iterator Start, expr_op_iterator End)
Retrieve the details of this fragment expression.
static LLVM_ABI std::optional< const DIExpression * > convertToNonVariadicExpression(const DIExpression *Expr)
If Expr is a valid single-location expression, i.e.
ArrayRef< uint64_t > getElements() const
LLVM_ABI bool isValid() const
LLVM_ABI DILocalScope * getNonLexicalBlockFileScope() const
Get the first non DILexicalBlockFile scope of this scope.
uint64_t getAtomGroup() const
uint8_t getAtomRank() const
DIMacroNodeArray getElements() const
Tagged DWARF-like metadata node.
StringRef getFilename() const
StringRef getDirectory() const
std::optional< StringRef > getSource() const
Wrapper structure that holds source language identity metadata that includes language name,...
bool hasVersionedName() const
uint16_t getName() const
Returns a versioned or unversioned language name.
Subprogram description. Uses SubclassData1.
static LLVM_ABI DILocalScope * getRetainedNodeScope(MDNode *N)
DIScope * getScope() const
DIScope * getScope() const
Encoding
Size and signedness of expression operations' operands.
Used for tracking debug info about call site parameters.
This class is defined as the common parent of DbgVariable and DbgLabel such that it could levarage po...
SmallVector< Entry, 4 > Entries
A single location or constant within a variable location description, with either a single entry (wit...
The location of a single variable, composed of an expression and 0 or more DbgValueLocEntries.
const DILocalVariable * getVariable() const
const DIType * getType() const
const MachineInstr * CurMI
If nonnull, stores the current machine instruction we're processing.
AsmPrinter * Asm
Target of debug info emission.
MCSymbol * getLabelBeforeInsn(const MachineInstr *MI)
Return Label preceding the instruction.
MachineModuleInfo * MMI
Collected machine module information.
DebugLoc PrevInstLoc
Previous instruction's location information.
MCSymbol * getLabelAfterInsn(const MachineInstr *MI)
Return Label immediately following the instruction.
DebugHandlerBase(AsmPrinter *A)
void beginInstruction(const MachineInstr *MI) override
Process beginning of an instruction.
const MachineBasicBlock * PrevInstBB
void requestLabelAfterInsn(const MachineInstr *MI)
Ensure that a label will be emitted after MI.
DbgValueHistoryMap DbgValues
History of DBG_VALUE and clobber instructions for each user variable.
DbgLabelInstrMap DbgLabels
Mapping of inlined labels and DBG_LABEL machine instruction.
void beginModule(Module *M) override
const InstructionOrdering & getInstOrdering() const
void requestLabelBeforeInsn(const MachineInstr *MI)
Ensure that a label will be emitted before MI.
const MachineBasicBlock * EpilogBeginBlock
This block includes epilogue instructions.
const MachineInstr * PrologEndLoc
This location indicates end of function prologue and beginning of function body.
DwarfExpression implementation for .debug_loc entries.
void finalize(const AsmPrinter &AP, DebugLocStream::ListBuilder &List, const DIBasicType *BT, DwarfCompileUnit &TheCU)
Lower this entry into a DWARF expression.
Builder for DebugLocStream entries.
Builder for DebugLocStream lists.
ArrayRef< Entry > getEntries(const List &L) const
LLVM_ABI unsigned getLine() const
ValueT lookup(const_arg_type_t< KeyT > Val) const
Return the entry for the specified key, or a default constructed value if no such entry exists.
iterator find(const_arg_type_t< KeyT > Val)
bool erase(const KeyT &Val)
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Implements a dense probed hash-table based set.
void addRange(RangeSpan Range)
addRange - Add an address range to the list of ranges for this unit.
DIE & constructSubprogramScopeDIE(const DISubprogram *Sub, const Function &F, LexicalScope *Scope, MCSymbol *LineTableSym)
Construct a DIE for this subprogram scope.
void createAbstractEntity(const DINode *Node, LexicalScope *Scope)
DwarfCompileUnit * getSkeleton() const
void setSkeleton(DwarfCompileUnit &Skel)
Set the skeleton unit associated with this unit.
const StringMap< const DIE * > & getGlobalNames() const
DbgEntity * getExistingAbstractEntity(const DINode *Node)
const StringMap< const DIE * > & getGlobalTypes() const
bool hasDwarfPubSections() const
Collects and handles dwarf debug information.
bool useSegmentedStringOffsetsTable() const
Returns whether to generate a string offsets table with (possibly shared) contributions from each CU ...
virtual bool shouldResetBaseAddress(const MCSection &Section) const
Whether the target requires resetting the base address in range/loc lists.
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.
virtual bool shouldAttachCompileUnitRanges() const
Whether to attach ranges/low_pc to the compile unit DIE in endModule.
bool emitDebugEntryValues() const
uint16_t getDwarfVersion() const
Returns the Dwarf Version.
void emitDebugLocEntry(ByteStreamer &Streamer, const DebugLocStream::Entry &Entry, const DwarfCompileUnit *CU)
Emit an entry for the debug loc section.
void addAccelNamespace(const DwarfUnit &Unit, const DICompileUnit::DebugNameTableKind NameTableKind, StringRef Name, const DIE &Die)
void setCurrentDWARF5AccelTable(const DWARF5AccelTableKind Kind)
Sets the current DWARF5AccelTable to use.
bool alwaysUseRanges(const DwarfCompileUnit &) const
Returns whether range encodings should be used for single entry range lists.
void beginModule(Module *M) override
Emit all Dwarf sections that should come prior to the content.
void addSubprogramNames(const DwarfUnit &Unit, const DICompileUnit::DebugNameTableKind NameTableKind, const DISubprogram *SP, DIE &Die)
bool useAllLinkageNames() const
Returns whether we should emit all DW_AT_[MIPS_]linkage_name.
void insertSectionLabel(const MCSymbol *S)
void addAccelObjC(const DwarfUnit &Unit, const DICompileUnit::DebugNameTableKind NameTableKind, StringRef Name, const DIE &Die)
dwarf::Form getDwarfSectionOffsetForm() const
Returns a suitable DWARF form to represent a section offset, i.e.
bool useAppleExtensionAttributes() const
void skippedNonDebugFunction() override
void addArangeLabel(SymbolCU SCU)
Add a label so that arange data can be generated for it.
virtual void finishTargetUnitAttributes(const DICompileUnit &DIUnit, DwarfCompileUnit &NewCU)
Target-specific compile unit attribute finalization.
void beginInstruction(const MachineInstr *MI) override
Process beginning of an instruction.
AddressPool & getAddressPool()
DWARF5AccelTable & getCurrentDWARF5AccelTable()
Returns either CU or TU DWARF5AccelTable.
bool useSectionsAsReferences() const
Returns whether to use sections as labels rather than temp symbols.
const DebugLocStream & getDebugLocs() const
Returns the entries for the .debug_loc section.
bool shareAcrossDWOCUs() const
void terminateLineTable(const DwarfCompileUnit *CU)
Terminate the line table by adding the last range label.
void endFunctionImpl(const MachineFunction *MF) override
Gather and emit post-function debug information.
DwarfCompileUnit & getOrCreateAbstractSubprogramCU(const DISubprogram *SP, DwarfCompileUnit &SrcCU)
Find the matching DwarfCompileUnit for the given SP referenced from SrcCU.
void emitDebugLocEntryLocation(const DebugLocStream::Entry &Entry, const DwarfCompileUnit *CU)
Emit the location for a debug loc entry, including the size header.
const SmallVectorImpl< std::unique_ptr< DwarfCompileUnit > > & getUnits()
const MCSymbol * getSectionLabel(const MCSection *S)
static void emitDebugLocValue(const AsmPrinter &AP, const DIBasicType *BT, const DbgValueLoc &Value, DwarfExpression &DwarfExpr)
bool useSplitDwarf() const
Returns whether or not to change the current debug info for split DWARF.
virtual void initializeTargetDebugInfo(const MachineFunction &MF)
Target-specific debug info initialization at function start.
unsigned getDwarfCompileUnitIDForLineTable(const DwarfCompileUnit &CU)
Get Dwarf compile unit ID for line table.
const MachineInstr * emitInitialLocDirective(const MachineFunction &MF, unsigned CUID)
Emits inital debug location directive.
bool useRangesSection() const
Returns whether ranges section should be emitted.
void addAccelName(const DwarfUnit &Unit, const DICompileUnit::DebugNameTableKind NameTableKind, StringRef Name, const DIE &Die)
virtual void recordTargetSourceLine(const DebugLoc &DL, unsigned Flags)
Target-specific source line recording.
bool isLexicalScopeDIENull(LexicalScope *Scope)
A helper function to check whether the DIE for a given Scope is going to be null.
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.
DwarfFile InfoHolder
Holder for the file specific debug information.
void endModule() override
Emit all Dwarf sections that should come after the content.
void addAccelType(const DwarfUnit &Unit, const DICompileUnit::DebugNameTableKind NameTableKind, StringRef Name, const DIE &Die, char Flags)
void beginCodeAlignment(const MachineBasicBlock &MBB) override
Process beginning of code alignment.
DwarfDebug(AsmPrinter *A)
void beginFunctionImpl(const MachineFunction *MF) override
Gather pre-function debug information.
AccelTableKind getAccelTableKind() const
Returns what kind (if any) of accelerator tables to emit.
static uint64_t makeTypeSignature(StringRef Identifier)
Perform an MD5 checksum of Identifier and return the lower 64 bits.
Base class containing the logic for constructing DWARF expressions independently of whether they are ...
void setLocation(const MachineLocation &Loc, const DIExpression *DIExpr)
Set the location (Loc) and DIExpression (DIExpr) to describe.
virtual void disableTemporaryBuffer()=0
Disable emission to the temporary buffer.
virtual unsigned getTemporaryBufferSize()=0
Return the emitted size, in number of bytes, for the data stored in the temporary buffer.
void finalize()
This needs to be called last to commit any pending changes.
void addFragmentOffset(const DIExpression *Expr)
If applicable, emit an empty DW_OP_piece / DW_OP_bit_piece to advance to the fragment described by Ex...
void setMemoryLocationKind()
Lock this down to become a memory location description.
std::optional< uint8_t > TagOffset
void addBooleanConstant(int64_t Value)
Emit a boolean constant.
void addConstantFP(const APFloat &Value, const AsmPrinter &AP)
Emit an floating point constant.
bool addMachineRegExpression(const TargetRegisterInfo &TRI, DIExpressionCursor &Expr, llvm::Register MachineReg, unsigned FragmentOffsetInBits=0)
Emit a machine register location.
void addUnsignedConstant(uint64_t Value)
Emit an unsigned constant.
void addExpression(DIExpressionCursor &&Expr)
Emit all remaining operations in the DIExpressionCursor.
void addImplicitValue(const APInt &Value, const AsmPrinter &AP)
Emit an implicit value.
void addSignedConstant(int64_t Value)
Emit a signed constant.
virtual void commitTemporaryBuffer()=0
Commit the data stored in the temporary buffer to the main output.
void addWasmLocation(unsigned Index, uint64_t Offset)
Emit location information expressed via WebAssembly location + offset The Index is an identifier for ...
virtual void enableTemporaryBuffer()=0
Start emitting data to the temporary buffer.
void beginEntryValueExpression(DIExpressionCursor &ExprCursor)
Begin emission of an entry value dwarf operation.
void setRnglistsTableBaseSym(MCSymbol *Sym)
void emitUnits(bool UseOffsets)
Emit all of the units to the section listed with the given abbreviation section.
const SmallVectorImpl< RangeSpanList > & getRangeLists() const
getRangeLists - Get the vector of range lists.
MCSymbol * getStringOffsetsStartSym() const
MCSymbol * getRnglistsTableBaseSym() const
DwarfStringPool & getStringPool()
Returns the string pool.
void emitAbbrevs(MCSection *)
Emit a set of abbreviations to the specific section.
void emitStrings(MCSection *StrSection, MCSection *OffsetSection=nullptr, bool UseRelativeOffsets=false)
Emit all of the strings to the section given.
DwarfStringPoolEntryRef: Dwarf string pool entry reference.
LLVM_ABI_FOR_TEST EntryRef getEntry(AsmPrinter &Asm, StringRef Str)
Get a reference to an entry in the string pool.
LLVM_ABI_FOR_TEST void emitStringOffsetsTableHeader(AsmPrinter &Asm, MCSection *OffsetSection, MCSymbol *StartSym)
void setTypeSignature(uint64_t Signature)
void setType(const DIE *Ty)
This dwarf writer support class manages information associated with a source file.
void addStringOffsetsStart()
Add the DW_AT_str_offsets_base attribute to the unit DIE.
void addUInt(DIEValueList &Die, dwarf::Attribute Attribute, std::optional< dwarf::Form > Form, uint64_t Integer)
Add an unsigned integer attribute data and value.
void addString(DIE &Die, dwarf::Attribute Attribute, StringRef Str)
Add a string attribute data and value.
DIE * createTypeDIE(const DIScope *Context, DIE &ContextDIE, const DIType *Ty)
Creates type DIE with specific context.
const DICompileUnit * getCUNode() const
void addSectionLabel(DIE &Die, dwarf::Attribute Attribute, const MCSymbol *Label, const MCSymbol *Sec)
Add a Dwarf section label attribute data and value.
void addFlag(DIE &Die, dwarf::Attribute Attribute)
Add a flag that is true to the DIE.
unsigned getUniqueID() const
Gets Unique ID for this unit.
DISubprogram * getSubprogram() const
Get the attached subprogram.
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function.
static StringRef dropLLVMManglingEscape(StringRef Name)
If the given string begins with the GlobalValue name mangling escape character '\1',...
bool analyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, MachineBasicBlock *&FBB, SmallVectorImpl< MachineOperand > &Cond, bool AllowModify) const override
Analyze the branching code at the end of MBB, returning true if it cannot be understood (e....
bool isTailCall(const MachineInstr &MI) const override
Record instruction ordering so we can query their relative positions within a function.
This class is used to track scope information.
SmallVectorImpl< InsnRange > & getRanges()
const DILocalScope * getScopeNode() const
This class provides interface to collect and use lexical scoping information from machine instruction...
LLVM_ABI LexicalScope * findLexicalScope(const DILocation *DL)
Find lexical scope, either regular or inlined, for the given DebugLoc.
LexicalScope * findAbstractScope(const DILocalScope *N)
Find an abstract scope or return null.
Single(DbgValueLoc ValueLoc)
unsigned getCodePointerSize() const
Get the code pointer size in bytes.
static LLVM_ABI void make(MCStreamer *MCOS, MCSection *Section)
MCSection * getDwarfLoclistsSection() const
MCSection * getDwarfRangesSection() const
MCSection * getDwarfMacroSection() const
MCSection * getDwarfMacinfoDWOSection() const
MCSection * getDwarfMacinfoSection() const
MCSection * getDwarfMacroDWOSection() const
static constexpr unsigned NoRegister
Instances of this class represent a uniqued identifier for a section in the current translation unit.
MCSymbol * getBeginSymbol()
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
uint32_t getIndex() const
Get the (implementation defined) index.
MCSection & getSection() const
Get the section associated with a defined, non-absolute symbol.
LLVM_ABI void update(ArrayRef< uint8_t > Data)
Updates the hash for the byte stream provided.
LLVM_ABI void final(MD5Result &Result)
Finishes off the hash and puts the result in result.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
succ_iterator succ_begin()
MBBSectionID getSectionID() const
Returns the section ID of this basic block.
iterator_range< succ_iterator > successors()
reverse_iterator rbegin()
iterator_range< pred_iterator > predecessors()
MachineInstrBundleIterator< const MachineInstr, true > const_reverse_iterator
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
const CallSiteInfoMap & getCallSitesInfo() const
Function & getFunction()
Return the LLVM function that this machine code represents.
Representation of each machine instruction.
const MachineBasicBlock * getParent() const
bool isCall(QueryType Type=AnyInBundle) const
unsigned getNumOperands() const
Retuns the total number of operands.
bool hasDelaySlot(QueryType Type=AnyInBundle) const
Returns true if the specified instruction has a delay slot which must be filled by the code generator...
mop_range uses()
Returns all operands which may be register uses.
LLVM_ABI const MachineFunction * getMF() const
Return the function that contains the basic block that this instruction belongs to.
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
bool isDebugValue() const
MachineOperand class - Representation of each machine instruction operand.
const GlobalValue * getGlobal() const
bool isReg() const
isReg - Tests if this is a MO_Register operand.
bool isGlobal() const
isGlobal - Tests if this is a MO_GlobalAddress operand.
Register getReg() const
getReg - Returns the register number.
This class implements a map that also provides access to all stored values in a deterministic order.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
VectorType::iterator erase(typename VectorType::iterator Iterator)
Remove the element given by Iterator.
A Module instance is used to store all the information related to an LLVM module.
Wrapper class representing virtual and physical registers.
constexpr bool isPhysical() const
Return true if the specified register number is in the physical register namespace.
bool empty() const
Determine if the SetVector is empty or not.
A SetVector that performs no allocations if smaller than a certain size.
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
void insert_range(Range &&R)
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void assign(size_type NumElts, ValueParamT Elt)
reference emplace_back(ArgTypes &&... Args)
iterator erase(const_iterator CI)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Represent a constant reference to a string, i.e.
constexpr bool empty() const
Check if the string is empty.
TargetInstrInfo - Interface to description of machine instruction set.
const Triple & getTargetTriple() const
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
virtual const TargetInstrInfo * getInstrInfo() const
virtual const TargetRegisterInfo * getRegisterInfo() const =0
Return the target's register information.
virtual const TargetLowering * getTargetLowering() const
Triple - Helper class for working with autoconf configuration names.
bool isWasm() const
Tests whether the target is wasm (32- and 64-bit).
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
LLVM Value Representation.
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
std::pair< iterator, bool > insert(const ValueT &V)
void insert_range(Range &&R)
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
reverse_self_iterator getReverseIterator()
self_iterator getIterator()
A raw_ostream that writes to an SmallVector or SmallString.
LLVM_ABI StringRef RangeListEncodingString(unsigned Encoding)
LLVM_ABI StringRef GDBIndexEntryLinkageString(GDBIndexEntryLinkage Linkage)
LLVM_ABI StringRef MacroString(unsigned Encoding)
LLVM_ABI StringRef LocListEncodingString(unsigned Encoding)
LLVM_ABI StringRef GnuMacroString(unsigned Encoding)
LLVM_ABI StringRef MacinfoString(unsigned Encoding)
LLVM_ABI StringRef OperationEncodingString(unsigned Encoding)
LLVM_ABI StringRef GDBIndexEntryKindString(GDBIndexEntryKind Kind)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
ValuesClass values(OptsTy... Options)
Helper to build a ValuesClass by forwarding a variable number of arguments as an initializer list to ...
initializer< Ty > init(const Ty &Val)
bool isCPlusPlus(SourceLanguage S)
@ DW_ARANGES_VERSION
Section version number for .debug_aranges.
@ DW_PUBNAMES_VERSION
Section version number for .debug_pubnames.
@ DWARF_VERSION
Other constants.
Scope
Defines the scope in which this symbol should be visible: Default – Visible in the public interface o...
LLVM_ABI MCSymbol * emitListsTableHeaderStart(MCStreamer &S)
NodeAddr< InstrNode * > Instr
This is an optimization pass for GlobalISel generic memory operations.
bool operator<(int64_t V1, const APSInt &V2)
MachineBasicBlock::instr_iterator getBundleStart(MachineBasicBlock::instr_iterator I)
Returns an iterator to the first instruction in the bundle containing I.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
std::string fromHex(StringRef Input)
Convert hexadecimal string Input to its binary representation. The return string is half the size of ...
RelativeUniformCounterPtr Values
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
LLVM_ABI bool isRangeRelaxable(const MCSymbol *Begin, const MCSymbol *End)
constexpr bool isUIntN(unsigned N, uint64_t x)
Checks if an unsigned integer fits into the given (dynamic) bit width.
auto cast_or_null(const Y &Val)
auto unique(Range &&R, Predicate P)
bool isa_and_nonnull(const Y &Val)
SmallVector< DbgCallSiteParam, 4 > ParamSet
Collection used for storing debug call site parameters.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
auto dyn_cast_or_null(const Y &Val)
void erase(Container &C, ValueType V)
Wrapper function to remove a value from a container:
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
void sort(IteratorTy Start, IteratorTy End)
AccelTableKind
The kind of accelerator tables we should emit.
@ Default
Platform default.
@ Apple
.apple_names, .apple_namespaces, .apple_types, .apple_objc.
@ Dwarf
DWARF v5 .debug_names.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
MachineBasicBlock::instr_iterator getBundleEnd(MachineBasicBlock::instr_iterator I)
Returns an iterator pointing beyond the bundle containing I.
bool is_sorted(R &&Range, Compare C)
Wrapper function around std::is_sorted to check if elements in a range R are sorted with respect to a...
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
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...
uint64_t offsetToAlignment(uint64_t Value, Align Alignment)
Returns the offset to the next integer (mod 2**64) that is greater than or equal to Value and is a mu...
@ Ref
The access may reference the value stored in memory.
auto remove_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::remove_if which take ranges instead of having to pass begin/end explicitly.
void emitAppleAccelTable(AsmPrinter *Asm, AccelTable< DataT > &Contents, StringRef Prefix, const MCSymbol *SecBegin)
Emit an Apple Accelerator Table consisting of entries in the specified AccelTable.
DWARFExpression::Operation Op
OutputIt copy(R &&Range, OutputIt Out)
LLVM_ABI void emitDWARF5AccelTable(AsmPrinter *Asm, DWARF5AccelTable &Contents, const DwarfDebug &DD, ArrayRef< std::unique_ptr< DwarfCompileUnit > > CUs)
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
void erase_if(Container &C, UnaryPredicate P)
Provide a container algorithm similar to C++ Library Fundamentals v2's erase_if which is equivalent t...
constexpr bool isIntN(unsigned N, int64_t x)
Checks if an signed integer fits into the given (dynamic) bit width.
DebuggerKind
Identify a debugger for "tuning" the debug info.
@ SCE
Tune debug info for SCE targets (e.g. PS4).
@ DBX
Tune debug info for dbx.
@ Default
No specific tuning requested.
@ GDB
Tune debug info for gdb.
@ LLDB
Tune debug info for lldb.
Implement std::hash so that hash_code can be used in STL containers.
Represents a parameter whose call site value can be described by applying a debug expression to a reg...
uint64_t ParamReg
The described parameter register.
const DIExpression * Expr
Debug expression that has been built up when walking through the instruction chain that produces the ...
This struct is a compact representation of a valid (non-zero power of two) alignment.
A pair of GlobalVariable and DIExpression.
Represents an entry-value location, or a fragment of one.
void addFrameIndexExpr(const DIExpression *Expr, int FI)
std::set< FrameIndexExpr > FrameIndexExprs
const std::set< FrameIndexExpr > & getFrameIndexExprs() const
Get the FI entries, sorted by fragment offset.
A MapVector that performs no allocations if smaller than a certain size.
Helper used to pair up a symbol and its DWARF compile unit.
This struct describes target specific location.
Describes an entry of the various gnu_pub* debug sections.