33 AcceleratorRecords(&
GlobalData.getAllocator()) {
44 OrigUnit(&OrigUnit), getUnitFromOffset(UnitFromOffset),
46 AcceleratorRecords(&
GlobalData.getAllocator()) {
50 DWARFDie CUDie = OrigUnit.getUnitDIE();
54 if (std::optional<DWARFFormValue> Val = CUDie.
find(dwarf::DW_AT_language))
57 if (!
GlobalData.getOptions().NoODR && Language.has_value() &&
69 LineTablePtr = File.Dwarf->getLineTableForUnit(&
getOrigUnit());
82 for (
DIEInfo &Info : DieInfoArray)
83 Info.unsetFlagsWhichSetDuringLiveAnalysis();
89 Dependencies.reset(
nullptr);
96 AcceleratorRecords.erase();
100 DebugAddrIndexMap.clear();
101 StmtSeqListAttributes.clear();
117 OutDieOffsetArray.resize(
getOrigUnit().getNumDIEs(), 0);
124 bool IsODRUnavailableFunctionScope) {
131 bool ChildIsODRUnavailableFunctionScope = IsODRUnavailableFunctionScope;
133 if (DieInfo.getIsInMouduleScope())
134 ChildInfo.setIsInMouduleScope();
136 if (DieInfo.getIsInFunctionScope())
137 ChildInfo.setIsInFunctionScope();
139 if (DieInfo.getIsInAnonNamespaceScope())
140 ChildInfo.setIsInAnonNamespaceScope();
142 switch (CurChild->getTag()) {
143 case dwarf::DW_TAG_module:
144 ChildInfo.setIsInMouduleScope();
145 if (DieEntry->
getTag() == dwarf::DW_TAG_compile_unit &&
150 case dwarf::DW_TAG_subprogram:
151 ChildInfo.setIsInFunctionScope();
152 if (!ChildIsODRUnavailableFunctionScope &&
153 !ChildInfo.getIsInMouduleScope()) {
155 {dwarf::DW_AT_abstract_origin, dwarf::DW_AT_specification}))
156 ChildIsODRUnavailableFunctionScope =
true;
159 case dwarf::DW_TAG_namespace: {
162 if (
find(CurChild, dwarf::DW_AT_extension))
165 if (!NamespaceEntry.
CU->
find(NamespaceEntry.
DieEntry, dwarf::DW_AT_name))
166 ChildInfo.setIsInAnonNamespaceScope();
173 ChildInfo.setTrackLiveness();
175 if ((!ChildInfo.getIsInAnonNamespaceScope() &&
176 !ChildIsODRUnavailableFunctionScope && !NoODR))
177 ChildInfo.setODRAvailable();
179 if (CurChild->hasChildren())
180 analyzeDWARFStructureRec(CurChild, ChildIsODRUnavailableFunctionScope);
187 if (LineTablePtr->hasFileAtIndex(FileIdx)) {
191 if (It == ResolvedFullPaths.end()) {
192 std::string OrigFileName;
193 bool FoundFileName = LineTablePtr->getFileNameByIndex(
198 assert(FoundFileName &&
"Must get file name from line table");
208 ResolvedParentPaths.find(ParentPath);
209 if (ParentIt == ResolvedParentPaths.end()) {
214 .insert({ParentPath, GlobalStrings.
insert(RealPath).first})
222 It = ResolvedFullPaths
223 .insert(std::make_pair(
224 FileIdx, GlobalStrings.
insert(ResolvedPath).first))
236 if (ObjFileIdx > std::numeric_limits<uint32_t>::max())
238 "object files exceeds UINT32_MAX");
239 if (LocalIdx > std::numeric_limits<uint32_t>::max())
241 "local index exceeds UINT32_MAX");
243 Priority = (ObjFileIdx << 32) | LocalIdx;
249 ResolvedFullPaths.shrink_and_clear();
250 ResolvedParentPaths.clear();
255 Dependencies.reset(
nullptr);
256 StmtSeqListAttributes.clear();
263 if (!Language || Language != dwarf::DW_LANG_Swift)
266 if (!
GlobalData.getOptions().ParseableSwiftInterfaces)
271 if (!Path.ends_with(
".swiftinterface"))
283 if (!DeveloperDir.
empty() && Path.starts_with(DeveloperDir))
287 if (std::optional<DWARFFormValue> Val =
find(DieEntry, dwarf::DW_AT_name)) {
305 PendingSwiftInterfaces.emplace_back(*
Name, ResolvedPath);
311 for (
auto &Pending : PendingSwiftInterfaces) {
312 auto &Entry = Map[Pending.ModuleName];
313 if (!Entry.empty() && Entry != Pending.ResolvedPath)
314 warn(
Twine(
"conflicting parseable interfaces for Swift Module ") +
315 Pending.ModuleName +
": " + Entry +
" and " + Pending.ResolvedPath +
317 Entry = Pending.ResolvedPath;
319 PendingSwiftInterfaces.clear();
340 assert(ChildInfo.getODRAvailable());
343 ChildrenIndexAssigner.getChildIndex(*
this, CurChild)))
346 if (
Error Err = assignTypeNamesRec(CurChild, NameBuilder))
354 if (std::optional<SectionDescriptor *> DebugInfoSection =
361 Patch.
RefCU.getPointer()->getDieOutOffset(
366 ->ListDebugULEB128DieRefPatch.forEach(
370 Patch.
RefCU.getPointer()->getDieOutOffset(
375 if (std::optional<SectionDescriptor *> DebugLocSection =
378 ->ListDebugULEB128DieRefPatch.forEach(
382 Patch.
RefCU.getPointer()->getDieOutOffset(
387 if (std::optional<SectionDescriptor *> DebugLocListsSection =
389 (*DebugLocListsSection)
390 ->ListDebugULEB128DieRefPatch.forEach(
394 Patch.
RefCU.getPointer()->getDieOutOffset(
409 RefCU = getUnitFromOffset(*
Offset);
417 if (std::optional<uint32_t> RefDieIdx =
425 }
else if (RefCU && CanResolveInterCUReferences) {
430 if (ReferredCUStage < Stage::Loaded || ReferredCUStage >
Stage::Cloned)
433 if (std::optional<uint32_t> RefDieIdx =
449 if (std::optional<DWARFFormValue> AttrVal =
find(DieEntry, Attr))
457 std::lock_guard<std::mutex> Guard(RangesMutex);
459 Ranges.
insert({FuncLowPc, FuncHighPc}, PcOffset);
461 LowPc = std::min(*LowPc, FuncLowPc + PcOffset);
463 LowPc = FuncLowPc + PcOffset;
464 this->HighPc = std::max(HighPc, FuncHighPc + PcOffset);
468 std::lock_guard<std::mutex> Guard(LabelsMutex);
469 Labels.
insert({LabelLowPc, PcOffset});
489 if (!DebugInfoSection.ListDebugLocPatch.empty()) {
494 uint64_t OffsetAfterUnitLength = emitLocListHeader(OutLocationSection);
496 DebugInfoSection.ListDebugLocPatch.forEach([&](
DebugLocPatch &Patch) {
505 if (!OriginalLocations) {
510 LinkedLocationExpressionsVector LinkedLocationExpressions;
512 LinkedLocationExpressionsWithOffsetPatches LinkedExpression;
514 if (CurExpression.Range) {
516 LinkedExpression.Expression.Range = {
527 LinkedExpression.Expression.Expr,
529 LinkedExpression.Patches);
531 LinkedLocationExpressions.push_back({LinkedExpression});
536 OutLocationSection.
OS.
tell());
537 emitLocListFragment(LinkedLocationExpressions, OutLocationSection);
540 if (OffsetAfterUnitLength > 0) {
541 assert(OffsetAfterUnitLength -
543 OffsetAfterUnitLength);
544 OutLocationSection.
apply(
545 OffsetAfterUnitLength -
547 dwarf::DW_FORM_sec_offset,
548 OutLocationSection.
OS.
tell() - OffsetAfterUnitLength);
560 uint64_t OffsetAfterUnitLength = OutLocationSection.
OS.
tell();
574 return OffsetAfterUnitLength;
578uint64_t CompileUnit::emitLocListFragment(
579 const LinkedLocationExpressionsVector &LinkedLocationExpression,
581 uint64_t OffsetBeforeLocationExpression = 0;
584 uint64_t BaseAddress = 0;
585 if (std::optional<uint64_t> LowPC =
getLowPc())
586 BaseAddress = *LowPC;
588 for (
const LinkedLocationExpressionsWithOffsetPatches &LocExpression :
589 LinkedLocationExpression) {
590 if (LocExpression.Expression.Range) {
592 LocExpression.Expression.Range->LowPC - BaseAddress,
595 LocExpression.Expression.Range->HighPC - BaseAddress,
599 OutLocationSection.
emitIntVal(LocExpression.Expression.Expr.size(), 2);
600 OffsetBeforeLocationExpression = OutLocationSection.
OS.
tell();
601 for (uint64_t *OffsetPtr : LocExpression.Patches)
602 *OffsetPtr += OffsetBeforeLocationExpression;
604 OutLocationSection.
OS
605 << StringRef((
const char *)LocExpression.Expression.Expr.data(),
606 LocExpression.Expression.Expr.size());
614 return OffsetBeforeLocationExpression;
617 std::optional<uint64_t> BaseAddress;
618 for (
const LinkedLocationExpressionsWithOffsetPatches &LocExpression :
619 LinkedLocationExpression) {
620 if (LocExpression.Expression.Range) {
624 BaseAddress = LocExpression.Expression.Range->LowPC;
627 OutLocationSection.
emitIntVal(dwarf::DW_LLE_base_addressx, 1);
629 OutLocationSection.
OS);
633 OutLocationSection.
emitIntVal(dwarf::DW_LLE_offset_pair, 1);
636 encodeULEB128(LocExpression.Expression.Range->LowPC - *BaseAddress,
637 OutLocationSection.
OS);
640 encodeULEB128(LocExpression.Expression.Range->HighPC - *BaseAddress,
641 OutLocationSection.
OS);
644 OutLocationSection.
emitIntVal(dwarf::DW_LLE_default_location, 1);
646 encodeULEB128(LocExpression.Expression.Expr.size(), OutLocationSection.
OS);
647 OffsetBeforeLocationExpression = OutLocationSection.
OS.
tell();
648 for (uint64_t *OffsetPtr : LocExpression.Patches)
649 *OffsetPtr += OffsetBeforeLocationExpression;
651 OutLocationSection.
OS << StringRef(
652 (
const char *)LocExpression.Expression.Expr.data(),
653 LocExpression.Expression.Expr.size());
657 OutLocationSection.
emitIntVal(dwarf::DW_LLE_end_of_list, 1);
658 return OffsetBeforeLocationExpression;
661Error CompileUnit::emitDebugAddrSection() {
662 if (
GlobalData.getOptions().UpdateIndexTablesOnly)
668 if (DebugAddrIndexMap.empty())
671 SectionDescriptor &OutAddrSection =
678 uint64_t OffsetAfterSectionLength = OutAddrSection.
OS.
tell();
690 for (uint64_t AddrValue : DebugAddrIndexMap.getValues())
694 OutAddrSection.
apply(
695 OffsetAfterSectionLength -
697 dwarf::DW_FORM_sec_offset,
698 OutAddrSection.
OS.
tell() - OffsetAfterSectionLength);
710 LinkedFunctionRanges.
insert(
713 emitAranges(LinkedFunctionRanges);
731 if (!DebugInfoSection.ListDebugRangePatch.empty()) {
732 std::optional<AddressRangeValuePair> CachedRange;
733 uint64_t OffsetAfterUnitLength = emitRangeListHeader(OutRangeSection);
736 DebugInfoSection.ListDebugRangePatch.forEach([&](
DebugRangePatch &Patch) {
738 CompileUnitRangePtr = &Patch;
748 InputDebugRangesSectionOffset)) {
750 for (
const auto &
Range : *InputRanges) {
751 if (!CachedRange || !CachedRange->Range.contains(
Range.LowPC))
757 warn(
"inconsistent range data.");
762 LinkedRanges.
insert({
Range.LowPC + CachedRange->Value,
763 Range.HighPC + CachedRange->Value});
767 warn(
"invalid range list ignored.");
772 OutRangeSection.
OS.
tell());
773 emitRangeListFragment(LinkedRanges, OutRangeSection);
777 if (CompileUnitRangePtr !=
nullptr) {
781 dwarf::DW_FORM_sec_offset,
782 OutRangeSection.
OS.
tell());
783 emitRangeListFragment(LinkedFunctionRanges, OutRangeSection);
786 if (OffsetAfterUnitLength > 0) {
787 assert(OffsetAfterUnitLength -
789 OffsetAfterUnitLength);
790 OutRangeSection.
apply(
791 OffsetAfterUnitLength -
793 dwarf::DW_FORM_sec_offset,
794 OutRangeSection.
OS.
tell() - OffsetAfterUnitLength);
805 uint64_t OffsetAfterUnitLength = OutRangeSection.
OS.
tell();
819 return OffsetAfterUnitLength;
822void CompileUnit::emitRangeListFragment(
const AddressRanges &LinkedRanges,
826 uint64_t BaseAddress = 0;
827 if (std::optional<uint64_t> LowPC =
getLowPc())
828 BaseAddress = *LowPC;
830 for (
const AddressRange &
Range : LinkedRanges) {
843 std::optional<uint64_t> BaseAddress;
844 for (
const AddressRange &
Range : LinkedRanges) {
846 BaseAddress =
Range.start();
849 OutRangeSection.
emitIntVal(dwarf::DW_RLE_base_addressx, 1);
854 OutRangeSection.
emitIntVal(dwarf::DW_RLE_offset_pair, 1);
864 OutRangeSection.
emitIntVal(dwarf::DW_RLE_end_of_list, 1);
867void CompileUnit::emitAranges(AddressRanges &LinkedFunctionRanges) {
868 if (LinkedFunctionRanges.
empty())
871 SectionDescriptor &DebugInfoSection =
873 SectionDescriptor &OutArangesSection =
888 uint64_t OffsetAfterArangesLengthField = OutArangesSection.
OS.
tell();
891 OutArangesSection.notePatch(
892 DebugOffsetPatch{OutArangesSection.
OS.
tell(), &DebugInfoSection});
898 for (
size_t Idx = 0; Idx <
Padding; Idx++)
902 for (
const AddressRange &
Range : LinkedFunctionRanges) {
913 uint64_t OffsetAfterArangesEnd = OutArangesSection.
OS.
tell();
916 OutArangesSection.
apply(
917 OffsetAfterArangesLengthField -
919 dwarf::DW_FORM_sec_offset,
920 OffsetAfterArangesEnd - OffsetAfterArangesLengthField);
928 DWARFDie OrigUnitDie = OrigUnit.getUnitDIE();
931 if (std::optional<uint64_t> MacroAttr =
935 emitMacroTableImpl(Table, *MacroAttr,
true);
940 if (std::optional<uint64_t> MacroAttr =
944 emitMacroTableImpl(Table, *MacroAttr,
false);
953 bool hasDWARFv5Header) {
959 bool DefAttributeIsReported =
false;
960 bool UndefAttributeIsReported =
false;
961 bool ImportAttributeIsReported =
false;
963 for (
const DWARFDebugMacro::MacroList &
List : MacroTable->MacroLists) {
964 if (OffsetToMacroTable == List.Offset) {
966 if (hasDWARFv5Header) {
968 OutSection.emitIntVal(List.Header.Version, sizeof(List.Header.Version));
970 uint8_t Flags = List.Header.Flags;
974 DWARFDebugMacro::HeaderFlagMask::MACRO_OPCODE_OPERANDS_TABLE) {
976 ~DWARFDebugMacro::HeaderFlagMask::MACRO_OPCODE_OPERANDS_TABLE;
977 warn(
"opcode_operands_table is not supported yet.");
981 std::optional<uint64_t> StmtListOffset;
982 if (Flags & DWARFDebugMacro::HeaderFlagMask::MACRO_DEBUG_LINE_OFFSET) {
984 for (auto &V : getOutUnitDIE()->values()) {
985 if (V.getAttribute() == dwarf::DW_AT_stmt_list) {
986 StmtListOffset = V.getDIEInteger().getValue();
991 if (!StmtListOffset) {
992 Flags &= ~DWARFDebugMacro::HeaderFlagMask::MACRO_DEBUG_LINE_OFFSET;
993 warn(
"couldn`t find line table for macro table.");
998 OutSection.emitIntVal(Flags, sizeof(Flags));
1001 if (StmtListOffset) {
1002 OutSection.notePatch(DebugOffsetPatch{
1003 OutSection.OS.tell(),
1004 &getOrCreateSectionDescriptor(DebugSectionKind::DebugLine)});
1007 OutSection.emitIntVal(0xBADDEF, List.Header.getOffsetByteSize());
1012 for (const DWARFDebugMacro::Entry &MacroEntry : List.Macros) {
1013 if (MacroEntry.Type == 0) {
1014 encodeULEB128(MacroEntry.Type, OutSection.OS);
1018 uint8_t MacroType = MacroEntry.Type;
1019 switch (MacroType) {
1021 bool HasVendorSpecificExtension =
1022 (!hasDWARFv5Header &&
1023 MacroType == dwarf::DW_MACINFO_vendor_ext) ||
1024 (hasDWARFv5Header && (MacroType >= dwarf::DW_MACRO_lo_user &&
1025 MacroType <= dwarf::DW_MACRO_hi_user));
1027 if (HasVendorSpecificExtension) {
1029 OutSection.emitIntVal(MacroType, 1);
1032 encodeULEB128(MacroEntry.ExtConstant, OutSection.OS);
1035 OutSection.emitString(dwarf::DW_FORM_string, MacroEntry.ExtStr);
1037 warn(
"unknown macro type. skip.");
1045 case dwarf::DW_MACRO_define:
1046 case dwarf::DW_MACRO_undef: {
1048 OutSection.emitIntVal(MacroType, 1);
1051 encodeULEB128(MacroEntry.Line, OutSection.OS);
1054 OutSection.emitString(dwarf::DW_FORM_string, MacroEntry.MacroStr);
1056 case dwarf::DW_MACRO_define_strp:
1057 case dwarf::DW_MACRO_undef_strp:
1058 case dwarf::DW_MACRO_define_strx:
1059 case dwarf::DW_MACRO_undef_strx: {
1062 switch (MacroType) {
1063 case dwarf::DW_MACRO_define_strx: {
1064 MacroType = dwarf::DW_MACRO_define_strp;
1065 if (!DefAttributeIsReported) {
1066 warn(
"DW_MACRO_define_strx unsupported yet. Convert to "
1067 "DW_MACRO_define_strp.");
1068 DefAttributeIsReported = true;
1071 case dwarf::DW_MACRO_undef_strx: {
1072 MacroType = dwarf::DW_MACRO_undef_strp;
1073 if (!UndefAttributeIsReported) {
1074 warn(
"DW_MACRO_undef_strx unsupported yet. Convert to "
1075 "DW_MACRO_undef_strp.");
1076 UndefAttributeIsReported = true;
1085 OutSection.emitIntVal(MacroType, 1);
1088 encodeULEB128(MacroEntry.Line, OutSection.OS);
1091 OutSection.emitString(dwarf::DW_FORM_strp, MacroEntry.MacroStr);
1094 case dwarf::DW_MACRO_start_file: {
1096 OutSection.emitIntVal(MacroType, 1);
1098 encodeULEB128(MacroEntry.Line, OutSection.OS);
1100 encodeULEB128(MacroEntry.File, OutSection.OS);
1102 case dwarf::DW_MACRO_end_file: {
1104 OutSection.emitIntVal(MacroType, 1);
1106 case dwarf::DW_MACRO_import:
1107 case dwarf::DW_MACRO_import_sup: {
1108 if (!ImportAttributeIsReported) {
1109 warn(
"DW_MACRO_import and DW_MACRO_import_sup are unsupported "
1111 ImportAttributeIsReported = true;
1125 std::optional<int64_t> VarAddressAdjustment,
1130 uint8_t OrigAddressByteSize = OrigUnit.getAddressByteSize();
1133 for (
auto &
Op : InputExpression) {
1134 auto Desc =
Op.getDescription();
1137 if ((
Desc.Op.size() == 2 &&
Desc.Op[0] == Encoding::BaseTypeRef) ||
1138 (
Desc.Op.size() == 2 &&
Desc.Op[1] == Encoding::BaseTypeRef &&
1139 Desc.Op[0] != Encoding::Size1))
1140 warn(
"unsupported DW_OP encoding.");
1142 if ((
Desc.Op.size() == 1 &&
Desc.Op[0] == Encoding::BaseTypeRef) ||
1143 (
Desc.Op.size() == 2 &&
Desc.Op[1] == Encoding::BaseTypeRef &&
1144 Desc.Op[0] == Encoding::Size1)) {
1146 assert(OpOffset <
Op.getEndOffset());
1147 uint32_t ULEBsize =
Op.getEndOffset() - OpOffset - 1;
1151 assert(!
Op.getSubCode() &&
"SubOps not yet supported");
1154 if (
Desc.Op.size() == 1) {
1155 RefOffset =
Op.getRawOperand(0);
1158 RefOffset =
Op.getRawOperand(1);
1162 unsigned RealSize = 0;
1166 if (RefOffset > 0 ||
Op.getCode() != dwarf::DW_OP_convert) {
1167 RefOffset += OrigUnit.getOffset();
1169 if (std::optional<uint32_t> Idx =
1170 OrigUnit.getDIEIndexForOffset(RefOffset))
1179 Section.notePatchWithOffsetUpdate(
1186 if (RealSize > ULEBsize) {
1189 warn(
"base type ref doesn't fit.");
1191 assert(RealSize == ULEBsize &&
"padding failed");
1194 }
else if (!
getGlobalData().getOptions().UpdateIndexTablesOnly &&
1195 Op.getCode() == dwarf::DW_OP_addrx) {
1196 if (std::optional<object::SectionedAddress> SA =
1197 OrigUnit.getAddrOffsetSectionItem(
Op.getRawOperand(0))) {
1202 OutputExpression.
push_back(dwarf::DW_OP_addr);
1203 uint64_t LinkedAddress = SA->Address + VarAddressAdjustment.value_or(0);
1207 reinterpret_cast<const uint8_t *
>(&LinkedAddress),
1208 OrigAddressByteSize);
1209 OutputExpression.
append(AddressBytes.
begin(), AddressBytes.
end());
1211 warn(
"cann't read DW_OP_addrx operand.");
1212 }
else if (!
getGlobalData().getOptions().UpdateIndexTablesOnly &&
1213 Op.getCode() == dwarf::DW_OP_constx) {
1214 if (std::optional<object::SectionedAddress> SA =
1215 OrigUnit.getAddrOffsetSectionItem(
Op.getRawOperand(0))) {
1220 std::optional<uint8_t> OutOperandKind;
1221 switch (OrigAddressByteSize) {
1223 OutOperandKind = dwarf::DW_OP_const2u;
1226 OutOperandKind = dwarf::DW_OP_const4u;
1229 OutOperandKind = dwarf::DW_OP_const8u;
1233 formatv((
"unsupported address size: {0}."), OrigAddressByteSize));
1237 if (OutOperandKind) {
1238 OutputExpression.
push_back(*OutOperandKind);
1240 SA->Address + VarAddressAdjustment.value_or(0);
1244 reinterpret_cast<const uint8_t *
>(&LinkedAddress),
1245 OrigAddressByteSize);
1246 OutputExpression.
append(AddressBytes.
begin(), AddressBytes.
end());
1249 warn(
"cann't read DW_OP_constx operand.");
1256 OpOffset =
Op.getEndOffset();
1261 std::optional<std::reference_wrapper<const Triple>> TargetTriple,
1270 if (ArtificialTypeUnit)
1274 std::pair<DIE *, TypeEntry *> OutCUDie =
cloneDIE(
1276 std::nullopt, std::nullopt, Allocator, ArtificialTypeUnit);
1279 if (!TargetTriple.has_value() || (OutCUDie.first ==
nullptr))
1302 if (
Error Err = emitDebugAddrSection())
1318 uint64_t OutOffset, std::optional<int64_t> FuncAddressAdjustment,
1324 bool NeedToClonePlainDIE = Info.needToKeepInPlainDwarf();
1325 bool NeedToCloneTypeDIE =
1326 (InputDieEntry->
getTag() != dwarf::DW_TAG_compile_unit) &&
1327 Info.needToPlaceInTypeTable();
1328 std::pair<DIE *, TypeEntry *> ClonedDIE;
1332 if (NeedToClonePlainDIE)
1335 ClonedDIE.first = createPlainDIEandCloneAttributes(
1336 InputDieEntry, PlainDIEGenerator, OutOffset, FuncAddressAdjustment,
1337 VarAddressAdjustment);
1338 if (NeedToCloneTypeDIE) {
1341 assert(ArtificialTypeUnit !=
nullptr);
1345 ClonedDIE.second = createTypeDIEandCloneAttributes(
1346 InputDieEntry, TypeDIEGenerator, ClonedParentTypeDIE,
1347 ArtificialTypeUnit);
1350 ClonedDIE.second ? ClonedDIE.second : ClonedParentTypeDIE;
1352 bool HasPlainChildrenToClone =
1353 (ClonedDIE.first && Info.getKeepPlainChildren());
1355 bool HasTypeChildrenToClone =
1356 ((ClonedDIE.second ||
1357 InputDieEntry->
getTag() == dwarf::DW_TAG_compile_unit) &&
1358 Info.getKeepTypeChildren());
1361 if (HasPlainChildrenToClone || HasTypeChildrenToClone) {
1366 std::pair<DIE *, TypeEntry *> ClonedChild =
cloneDIE(
1367 CurChild, TypeParentForChild, OutOffset, FuncAddressAdjustment,
1368 VarAddressAdjustment, Allocator, ArtificialTypeUnit);
1370 if (ClonedChild.first) {
1372 ClonedChild.first->getOffset() + ClonedChild.first->getSize();
1373 PlainDIEGenerator.
addChild(ClonedChild.first);
1376 assert(ClonedDIE.first ==
nullptr ||
1377 HasPlainChildrenToClone == ClonedDIE.first->hasChildren());
1380 if (HasPlainChildrenToClone)
1381 OutOffset +=
sizeof(int8_t);
1385 if (ClonedDIE.first !=
nullptr)
1386 ClonedDIE.first->setSize(OutOffset - ClonedDIE.first->getOffset());
1391DIE *CompileUnit::createPlainDIEandCloneAttributes(
1393 uint64_t &OutOffset, std::optional<int64_t> &FuncAddressAdjustment,
1394 std::optional<int64_t> &VarAddressAdjustment) {
1397 DIE *ClonedDIE =
nullptr;
1398 bool HasLocationExpressionAddress =
false;
1399 if (InputDieEntry->
getTag() == dwarf::DW_TAG_subprogram) {
1401 FuncAddressAdjustment =
1403 getDIE(InputDieEntry),
false);
1404 }
else if (InputDieEntry->
getTag() == dwarf::DW_TAG_label) {
1406 std::optional<uint64_t> lowPC =
1410 if (It != Labels.
end())
1411 FuncAddressAdjustment = It->second;
1413 }
else if (InputDieEntry->
getTag() == dwarf::DW_TAG_variable) {
1415 std::pair<bool, std::optional<int64_t>> LocExprAddrAndRelocAdjustment =
1417 getDIE(InputDieEntry),
false);
1419 HasLocationExpressionAddress = LocExprAddrAndRelocAdjustment.first;
1420 if (LocExprAddrAndRelocAdjustment.first &&
1421 LocExprAddrAndRelocAdjustment.second)
1422 VarAddressAdjustment = *LocExprAddrAndRelocAdjustment.second;
1425 ClonedDIE = PlainDIEGenerator.
createDIE(InputDieEntry->
getTag(), OutOffset);
1432 DIEAttributeCloner AttributesCloner(ClonedDIE, *
this,
this, InputDieEntry,
1433 PlainDIEGenerator, FuncAddressAdjustment,
1434 VarAddressAdjustment,
1435 HasLocationExpressionAddress);
1436 AttributesCloner.clone();
1439 AcceleratorRecordsSaver AccelRecordsSaver(
getGlobalData(), *
this,
this);
1440 AccelRecordsSaver.save(InputDieEntry, ClonedDIE, AttributesCloner.AttrInfo,
1444 AttributesCloner.finalizeAbbreviations(
Info.getKeepPlainChildren());
1450DIE *CompileUnit::allocateTypeDie(
TypeEntryBody *TypeDescriptor,
1453 bool IsParentDeclaration) {
1458 if (!IsDeclaration && !IsParentDeclaration) {
1461 if (Priority >= TypeDescriptor->
DiePriority.load(std::memory_order_relaxed))
1465 if (TypeDescriptor->
Die.load(std::memory_order_relaxed))
1469 while (TypeDescriptor->
Lock.test_and_set(std::memory_order_acquire))
1474 if (!IsDeclaration && !IsParentDeclaration) {
1477 TypeDescriptor->
DiePriority.load(std::memory_order_relaxed)) {
1478 TypeDescriptor->
DiePriority.store(Priority, std::memory_order_relaxed);
1480 TypeDescriptor->
Die.store(Result, std::memory_order_relaxed);
1482 }
else if (!TypeDescriptor->
Die.load(std::memory_order_relaxed)) {
1491 (BetterParent || Priority < TypeDescriptor->DeclarationDiePriority)) {
1495 TypeDescriptor->
DeclarationDie.store(Result, std::memory_order_relaxed);
1499 TypeDescriptor->
Lock.clear(std::memory_order_release);
1503TypeEntry *CompileUnit::createTypeDIEandCloneAttributes(
1504 const DWARFDebugInfoEntry *InputDieEntry,
DIEGenerator &TypeDIEGenerator,
1506 assert(ArtificialTypeUnit !=
nullptr);
1507 uint32_t InputDieIdx =
getDIEIndex(InputDieEntry);
1510 assert(Entry !=
nullptr);
1511 assert(ClonedParentTypeDIE !=
nullptr);
1512 TypeEntryBody *EntryBody =
1514 Entry, ClonedParentTypeDIE);
1517 bool IsDeclaration =
1520 bool ParentIsDeclaration =
false;
1521 if (std::optional<uint32_t> ParentIdx = InputDieEntry->
getParentIdx())
1522 ParentIsDeclaration =
1526 allocateTypeDie(EntryBody, TypeDIEGenerator, InputDieEntry->
getTag(),
1527 IsDeclaration, ParentIsDeclaration);
1529 if (OutDIE !=
nullptr) {
1530 assert(ArtificialTypeUnit !=
nullptr);
1533 DIEAttributeCloner AttributesCloner(OutDIE, *
this, ArtificialTypeUnit,
1534 InputDieEntry, TypeDIEGenerator,
1535 std::nullopt, std::nullopt,
false);
1536 AttributesCloner.clone();
1539 AcceleratorRecordsSaver AccelRecordsSaver(
getGlobalData(), *
this,
1540 ArtificialTypeUnit);
1541 AccelRecordsSaver.save(InputDieEntry, OutDIE, AttributesCloner.AttrInfo,
1546 OutDIE->
setSize(AttributesCloner.getOutOffset() + 1);
1555 if (InputLineTable ==
nullptr) {
1557 warn(
"cann't load line table.");
1569 OutLineTable.
Rows = InputLineTable->
Rows;
1572 if (OutLineTable.
Rows.size() == 1 && OutLineTable.
Rows[0].EndSequence)
1573 OutLineTable.
Rows.clear();
1580 filterLineTableRows(*InputLineTable, OutLineTable.
Rows, OrigRowIndices);
1582 if (StmtSeqListAttributes.empty())
1602 &RowIndexToSeqStartOffset))
1606 buildStmtSeqOffsetToFirstRowIndex(*InputLineTable);
1607 patchStmtSeqAttributes(SeqOffsetToFirstRowIndex, RowIndexToSeqStartOffset);
1611void CompileUnit::filterLineTableRows(
1613 std::vector<DWARFDebugLine::Row> &NewRows,
1615 NewRows.reserve(InputLineTable.
Rows.size());
1616 NewRowIndices.
reserve(InputLineTable.
Rows.size());
1622 std::vector<DWARFDebugLine::Row> Seq;
1624 constexpr uint64_t InvalidRowIndex = std::numeric_limits<uint64_t>::max();
1627 std::optional<AddressRangeValuePair> CurrRange;
1647 if (!CurrRange || !CurrRange->Range.contains(Row.Address.Address)) {
1651 CurrRange ? CurrRange->Range.end() + CurrRange->Value : -1ULL;
1652 CurrRange = FunctionRanges.getRangeThatContains(Row.Address.Address);
1653 if (StopAddress != -1ULL && !Seq.empty()) {
1658 auto NextLine = Seq.back();
1659 NextLine.Address.Address = StopAddress;
1660 NextLine.EndSequence = 1;
1661 NextLine.PrologueEnd = 0;
1662 NextLine.BasicBlock = 0;
1663 NextLine.EpilogueBegin = 0;
1664 Seq.push_back(NextLine);
1674 if (Row.EndSequence && Seq.empty())
1679 Seq.emplace_back(Row);
1682 if (Row.EndSequence)
1687void CompileUnit::patchStmtSeqAttributes(
1688 const DenseMap<uint64_t, uint64_t> &SeqOffsetToFirstRowIndex,
1689 const DenseMap<uint64_t, uint64_t> &RowIndexToSeqStartOffset) {
1692 for (
const CompileUnit::StmtSeqPatch &Patch : StmtSeqListAttributes) {
1693 uint64_t NewStmtSeq = InvalidOffset;
1694 auto RowIt = SeqOffsetToFirstRowIndex.
find(Patch.InputStmtSeqOffset);
1695 if (RowIt != SeqOffsetToFirstRowIndex.
end()) {
1696 auto OffIt = RowIndexToSeqStartOffset.
find(RowIt->second);
1697 if (OffIt != RowIndexToSeqStartOffset.
end())
1698 NewStmtSeq = OffIt->second;
1704 *Patch.Value = DIEValue(Patch.Value->getAttribute(), Patch.Value->getForm(),
1705 DIEInteger(NewStmtSeq));
1709DenseMap<uint64_t, uint64_t> CompileUnit::buildStmtSeqOffsetToFirstRowIndex(
1710 const DWARFDebugLine::LineTable &InputLineTable)
const {
1713 SmallVector<uint64_t> StmtAttrs;
1714 StmtAttrs.
reserve(StmtSeqListAttributes.size());
1715 for (
const StmtSeqPatch &Patch : StmtSeqListAttributes)
1716 StmtAttrs.
push_back(Patch.InputStmtSeqOffset);
1720 DenseMap<uint64_t, uint64_t>
Result;
1726void CompileUnit::insertLineSequence(std::vector<DWARFDebugLine::Row> &Seq,
1727 SmallVectorImpl<uint64_t> &SeqIndices,
1728 std::vector<DWARFDebugLine::Row> &Rows,
1729 SmallVectorImpl<uint64_t> &RowIndices) {
1731 "Seq and SeqIndices must be kept in lockstep");
1733 "Rows and RowIndices must be kept in lockstep");
1737 auto ClearSeq = [&] {
1742 if (!Rows.empty() && Rows.back().Address < Seq.front().Address) {
1749 object::SectionedAddress Front = Seq.front().Address;
1751 Rows, [=](
const DWARFDebugLine::Row &O) {
return O.Address < Front; });
1752 size_t InsertIdx = std::distance(Rows.begin(), InsertPoint);
1758 if (InsertPoint != Rows.end() && InsertPoint->Address == Front &&
1759 InsertPoint->EndSequence) {
1760 *InsertPoint = Seq.front();
1761 RowIndices[InsertIdx] = SeqIndices.
front();
1762 Rows.insert(InsertPoint + 1, Seq.begin() + 1, Seq.end());
1763 RowIndices.
insert(RowIndices.
begin() + InsertIdx + 1,
1764 SeqIndices.
begin() + 1, SeqIndices.
end());
1766 Rows.insert(InsertPoint, Seq.begin(), Seq.end());
1774#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1794 llvm::errs() <<
" KeepPlainChildren: " << getKeepPlainChildren();
1795 llvm::errs() <<
" KeepTypeChildren: " << getKeepTypeChildren();
1796 llvm::errs() <<
" IsInMouduleScope: " << getIsInMouduleScope();
1797 llvm::errs() <<
" IsInFunctionScope: " << getIsInFunctionScope();
1798 llvm::errs() <<
" IsInAnonNamespaceScope: " << getIsInAnonNamespaceScope();
1799 llvm::errs() <<
" ODRAvailable: " << getODRAvailable();
1800 llvm::errs() <<
" TrackLiveness: " << getTrackLiveness();
1805std::optional<std::pair<StringRef, StringRef>>
1816 return std::nullopt;
1821std::optional<std::pair<StringRef, StringRef>>
1823 FileNamesCache::iterator FileData =
FileNames.find(FileIdx);
1825 return std::make_pair(
StringRef(FileData->second.first),
1830 if (LineTable->hasFileAtIndex(FileIdx)) {
1833 LineTable->Prologue.getFileNameEntry(FileIdx);
1838 return std::nullopt;
1841 std::string FileName = *
Name;
1843 FileNamesCache::iterator FileData =
1845 .insert(std::make_pair(
1847 std::make_pair(std::string(
""), std::move(FileName))))
1849 return std::make_pair(
StringRef(FileData->second.first),
1859 if ((Entry.DirIdx != 0) &&
1860 Entry.DirIdx < LineTable->Prologue.IncludeDirectories.size()) {
1862 LineTable->Prologue.IncludeDirectories[Entry.DirIdx]
1865 IncludeDir = *DirName;
1868 return std::nullopt;
1872 if (0 < Entry.DirIdx &&
1873 Entry.DirIdx <= LineTable->Prologue.IncludeDirectories.size()) {
1875 LineTable->Prologue.IncludeDirectories[Entry.DirIdx - 1]
1878 IncludeDir = *DirName;
1881 return std::nullopt;
1894 FileNamesCache::iterator FileData =
1897 std::make_pair(FileIdx, std::make_pair(std::string(FilePath),
1898 std::move(FileName))))
1900 return std::make_pair(
StringRef(FileData->second.first),
1905 return std::nullopt;
1908#define MAX_REFERENCIES_DEPTH 1000
1911 std::optional<UnitEntryPairTy> RefDiePair;
1915 CUDiePair.
DieEntry, dwarf::DW_AT_extension,
1917 if (!RefDiePair || !RefDiePair->DieEntry)
1920 CUDiePair = *RefDiePair;
1927 if (std::optional<uint32_t> ParentIdx =
DieEntry->getParentIdx())
1930 return std::nullopt;
1966 bool InterCUProcessingStarted, std::atomic<bool> &HasNewInterconnectedCUs) {
1970 return Dependencies->resolveDependenciesAndMarkLiveness(
1971 InterCUProcessingStarted, HasNewInterconnectedCUs);
1975 assert(Dependencies.get());
1977 return Dependencies->updateDependenciesCompleteness();
1981 assert(Dependencies.get());
1983 Dependencies->verifyKeepChain();
1988 dwarf::DW_AT_type, dwarf::DW_AT_specification,
1989 dwarf::DW_AT_abstract_origin, dwarf::DW_AT_import};
1991 return ODRAttributes;
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
#define MAX_REFERENCIES_DEPTH
static bool isValid(const char C)
Returns true if C is a valid mangled character: <0-9a-zA-Z_>.
std::optional< T > getRangeThatContains(uint64_t Addr) const
void insert(AddressRange Range, int64_t Value)
The AddressRanges class helps normalize address range collections.
Collection::const_iterator insert(AddressRange Range)
Represent a constant reference to an array (0 or more elements consecutively in memory),...
std::pair< KeyDataTy *, bool > insert(const KeyTy &NewValue)
Insert new value NewValue or return already existing entry.
A structured debug information entry.
DWARFDebugInfoEntry - A DIE with only the minimum required data.
dwarf::Tag getTag() const
std::optional< uint32_t > getParentIdx() const
Returns index of the parent die.
const DWARFAbbreviationDeclaration * getAbbreviationDeclarationPtr() const
Utility class that carries the DWARF compile/type unit and the debug info entry in an object.
LLVM_ABI std::optional< DWARFFormValue > find(dwarf::Attribute Attr) const
Extract the specified attribute from this DIE.
const DWARFDebugInfoEntry * getDebugInfoEntry() const
LLVM_ABI const char * getName(DINameKind Kind) const
Return the DIE name resolving DW_AT_specification or DW_AT_abstract_origin references if necessary.
Encoding
Size and signedness of expression operations' operands.
StringRef getData() const
const dwarf::FormParams & getFormParams() const
DWARFDie getUnitDIE(bool ExtractUnitDIEOnly=true)
uint8_t getAddressByteSize() const
const char * getCompilationDir()
Expected< DWARFLocationExpressionsVector > findLoclistFromOffset(uint64_t Offset)
bool isLittleEndian() const
uint64_t getOffset() const
iterator find(const_arg_type_t< KeyT > Val)
DenseMapIterator< KeyT, ValueT, KeyInfoT, BucketT > iterator
DenseMapIterator< KeyT, ValueT, KeyInfoT, BucketT, true > const_iterator
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
Error takeError()
Take ownership of the stored error.
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 reserve(size_type N)
iterator erase(const_iterator CI)
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
iterator insert(iterator I, T &&Elt)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringMapIterBase< ValueTy, false > iterator
Represent a constant reference to a string, i.e.
std::string str() const
Get the contents as an std::string.
constexpr bool empty() const
Check if the string is empty.
StringRef slice(size_t Start, size_t End) const
Return a reference to the substring from [Start, End).
Triple - Helper class for working with autoconf configuration names.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
This class represents DWARF information for source file and it's address map.
std::unique_ptr< AddressesMap > Addresses
Helpful address information(list of valid address ranges, relocations).
std::unique_ptr< DWARFContext > Dwarf
Source DWARF information.
@ Pub
.debug_pubnames, .debug_pubtypes
std::map< std::string, std::string > SwiftInterfacesMapTy
CompileUnit(DWARFUnit &OrigUnit, unsigned ID, bool CanUseODR, StringRef ClangModuleName)
TypeUnit * getAsTypeUnit()
Returns TypeUnit if applicable.
DwarfUnit * operator->()
Accessor for common functionality.
PointerUnion< CompileUnit *, TypeUnit * > Ptr
CompileUnit * getAsCompileUnit()
Returns CompileUnit if applicable.
OutputUnitVariantPtr(CompileUnit *U)
void addLabelLowPc(uint64_t LabelLowPc, int64_t PcOffset)
Add the low_pc of a label that is relocated by applying offset PCOffset.
Error cloneAndEmitDebugLocations()
Clone and emit debug locations(.debug_loc/.debug_loclists).
void cloneDieAttrExpression(const DWARFExpression &InputExpression, SmallVectorImpl< uint8_t > &OutputExpression, SectionDescriptor &Section, std::optional< int64_t > VarAddressAdjustment, OffsetsPtrVector &PatchesOffsets)
Clone attribute location axpression.
void maybeResetToLoadedStage()
Reset compile units data(results of liveness analysis, clonning) if current stage greater than Stage:...
void addFunctionRange(uint64_t LowPC, uint64_t HighPC, int64_t PCOffset)
Add a function range [LowPC, HighPC) that is relocated by applying offset PCOffset.
void analyzeImportedModule(const DWARFDebugInfoEntry *DieEntry)
Collect references to parseable Swift interfaces in imported DW_TAG_module blocks.
std::pair< DIE *, TypeEntry * > cloneDIE(const DWARFDebugInfoEntry *InputDieEntry, TypeEntry *ClonedParentTypeDIE, uint64_t OutOffset, std::optional< int64_t > FuncAddressAdjustment, std::optional< int64_t > VarAddressAdjustment, BumpPtrAllocator &Allocator, TypeUnit *ArtificialTypeUnit)
void cleanupDataAfterClonning()
Cleanup unneeded resources after compile unit is cloned.
Error assignTypeNames(TypePool &TypePoolRef)
Search for type entries and assign names.
llvm::Error setPriority(uint64_t ObjFileIdx, uint64_t LocalIdx)
Set deterministic priority for type DIE allocation ordering.
@ TypeTable
Corresponding DIE goes to the type table only.
@ PlainDwarf
Corresponding DIE goes to the plain dwarf only.
Error cloneAndEmitLineTable(const Triple &TargetTriple)
Error cloneAndEmitRanges()
Clone and emit ranges.
void mergeSwiftInterfaces(DWARFLinkerBase::SwiftInterfacesMapTy &Map)
Merge the Swift interface entries collected by analyzeImportedModule into Map, emitting a warning for...
void updateDieRefPatchesWithClonedOffsets()
After cloning stage the output DIEs offsets are deallocated.
uint64_t getDebugAddrIndex(uint64_t Addr)
Returns index(inside .debug_addr) of an address.
const DWARFFile & getContaingFile() const
Returns DWARFFile containing this compile unit.
bool resolveDependenciesAndMarkLiveness(bool InterCUProcessingStarted, std::atomic< bool > &HasNewInterconnectedCUs)
Search for subprograms and variables referencing live code and discover dependend DIEs.
bool updateDependenciesCompleteness()
Check dependend DIEs for incompatible placement.
bool loadInputDIEs()
Load DIEs of input compilation unit.
const RangesTy & getFunctionRanges() const
Returns function ranges of this unit.
Error cloneAndEmitDebugMacro()
Clone and emit debug macros(.debug_macinfo/.debug_macro).
Error cloneAndEmit(std::optional< std::reference_wrapper< const Triple > > TargetTriple, TypeUnit *ArtificialTypeUnit)
Clone and emit this compilation unit.
void setStage(Stage Stage)
Set stage of overall processing.
Stage getStage() const
Returns stage of overall processing.
CompileUnit(LinkingGlobalData &GlobalData, unsigned ID, StringRef ClangModuleName, DWARFFile &File, OffsetToUnitTy UnitFromOffset, dwarf::FormParams Format, llvm::endianness Endianess)
void verifyDependencies()
Check DIEs to have a consistent marking(keep marking, placement marking).
Stage
The stages of new compile unit processing.
@ Cloned
Output DWARF is generated.
@ CreatedNotLoaded
Created, linked with input DWARF file.
@ Loaded
Input DWARF is loaded.
std::optional< uint64_t > getLowPc() const
Returns value of DW_AT_low_pc attribute.
std::optional< std::pair< StringRef, StringRef > > getDirAndFilenameFromLineTable(const DWARFFormValue &FileIdxValue)
Returns directory and file from the line table by index.
std::optional< UnitEntryPairTy > resolveDIEReference(const DWARFFormValue &RefValue, ResolveInterCUReferencesMode CanResolveInterCUReferences)
Resolve the DIE attribute reference that has been extracted in RefValue.
void loadLineTable()
Loads unit line table.
uint64_t getPriority() const
StringEntry * getFileName(unsigned FileIdx, StringPool &GlobalStrings)
Returns name of the file for the FileIdx from the unit`s line table.
This class is a helper to create output DIE tree.
void addChild(DIE *Child)
Adds a specified Child to the current DIE.
DIE * createDIE(dwarf::Tag DieTag, uint32_t OutOffset)
Creates a DIE of specified tag DieTag and OutOffset.
This class discovers DIEs dependencies: marks "live" DIEs, marks DIE locations (whether DIE should be...
std::string UnitName
The name of this unit.
LinkingGlobalData & getGlobalData()
Return global data.
std::vector< std::unique_ptr< DIEAbbrev > > Abbreviations
Storage for the unique Abbreviations.
DIE * OutUnitDIE
Output unit DIE.
std::string SysRoot
The DW_AT_LLVM_sysroot of this unit.
bool isClangModule() const
Return true if this compile unit is from Clang module.
unsigned ID
Unique ID for the unit.
const std::string & getClangModuleName() const
Return Clang module name;.
void setOutUnitDIE(DIE *UnitDie)
Set output unit DIE.
DwarfUnit(LinkingGlobalData &GlobalData, unsigned ID, StringRef ClangModuleName)
std::string ClangModuleName
If this is a Clang module, this holds the module's name.
FoldingSet< DIEAbbrev > AbbreviationsSet
FoldingSet that uniques the abbreviations.
StringRef getSysRoot()
Return the DW_AT_LLVM_sysroot of the compile unit or an empty StringRef.
DIE * getOutUnitDIE()
Returns output unit DIE.
This class keeps data and services common for the whole linking process.
This class helps to assign indexes for DIE children.
LinkingGlobalData & GlobalData
dwarf::FormParams Format
Format for sections.
const dwarf::FormParams & getFormParams() const
Return size of address.
void eraseSections()
Erases data of all sections.
std::optional< const SectionDescriptor * > tryGetSectionDescriptor(DebugSectionKind SectionKind) const
Returns descriptor for the specified section of SectionKind.
void setOutputFormat(dwarf::FormParams Format, llvm::endianness Endianness)
Sets output format for all keeping sections.
uint16_t getVersion() const
Return DWARF version.
uint16_t getDebugInfoHeaderSize() const
Return size of header of debug_info table.
llvm::endianness getEndianness() const
Endiannes for the sections.
SectionDescriptor & getOrCreateSectionDescriptor(DebugSectionKind SectionKind)
Returns descriptor for the specified section of SectionKind.
const SectionDescriptor & getSectionDescriptor(DebugSectionKind SectionKind) const
Returns descriptor for the specified section of SectionKind.
The helper class to build type name based on DIE properties.
Error assignName(UnitEntryPairTy InputUnitEntryPair, std::optional< std::pair< size_t, size_t > > ChildIndex)
Create synthetic name for the specified DIE InputUnitEntryPair and assign created name to the DIE typ...
Keeps cloned data for the type DIE.
bool DeclarationParentIsDeclaration
uint64_t DeclarationDiePriority
std::atomic< DIE * > DeclarationDie
std::atomic< DIE * > Die
TypeEntryBody keeps partially cloned DIEs corresponding to this type.
std::atomic< uint64_t > DiePriority
TypePool keeps type descriptors which contain partially cloned DIE correspinding to each type.
BumpPtrAllocator & getThreadLocalAllocator()
Return thread local allocator used by pool.
TypeEntryBody * getOrCreateTypeEntryBody(TypeEntry *Entry, TypeEntry *ParentEntry)
Create or return existing type entry body for the specified Entry.
TypeEntry * getRoot() const
Return root for all type entries.
Type Unit is used to represent an artificial compilation unit which keeps all type information.
TypePool & getTypePool()
Returns global type pool.
uint64_t tell() const
tell - Return the current offset with the file.
void rememberDieOutOffset(uint32_t Idx, uint64_t Offset)
Idx index of the DIE.
TypeEntry * getDieTypeEntry(uint32_t Idx)
Idx index of the DIE.
DIEInfo & getDIEInfo(unsigned Idx)
Idx index of the DIE.
const DWARFDebugInfoEntry * getSiblingEntry(const DWARFDebugInfoEntry *Die) const
const DWARFDebugInfoEntry * getFirstChildEntry(const DWARFDebugInfoEntry *Die) const
std::optional< uint32_t > getDIEIndexForOffset(uint64_t Offset)
DWARFDie getDIE(const DWARFDebugInfoEntry *Die)
const DWARFDebugInfoEntry * getDebugInfoEntry(unsigned Index) const
DWARFUnit & getOrigUnit() const
Returns paired compile unit from input DWARF.
DWARFDie getUnitDIE(bool ExtractUnitDIEOnly=true)
uint32_t getDIEIndex(const DWARFDebugInfoEntry *Die) const
std::optional< DWARFFormValue > find(uint32_t DieIdx, ArrayRef< dwarf::Attribute > Attrs) const
Error emitDebugInfo(const Triple &TargetTriple)
Emit .debug_info section for unit DIEs.
Error emitDebugLine(const Triple &TargetTriple, const DWARFDebugLine::LineTable &OutLineTable, ArrayRef< uint64_t > OrigRowIndices={}, DenseMap< uint64_t, uint64_t > *RowIndexToSeqStartOffset=nullptr)
Emit .debug_line section.
Error emitDebugStringOffsetSection()
Emit the .debug_str_offsets section for current unit.
void emitPubAccelerators()
Emit .debug_pubnames and .debug_pubtypes for Unit.
void warn(const Twine &Warning, const DWARFDie *DIE=nullptr)
Error emitAbbreviations()
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
bool isODRLanguage(uint16_t Language)
function_ref< CompileUnit *(uint64_t Offset)> OffsetToUnitTy
SmallVector< uint64_t * > OffsetsPtrVector
Type for list of pointers to patches offsets.
StringMapEntry< std::atomic< TypeEntryBody * > > TypeEntry
ArrayRef< dwarf::Attribute > getODRAttributes()
ResolveInterCUReferencesMode
StringRef guessDeveloperDir(StringRef SysRoot)
Make a best effort to guess the Xcode.app/Contents/Developer path from an SDK path.
DebugSectionKind
List of tracked debug tables.
void buildStmtSeqOffsetToFirstRowIndex(const DWARFDebugLine::LineTable <, ArrayRef< uint64_t > SortedStmtSeqOffsets, DenseMap< uint64_t, uint64_t > &SeqOffToFirstRow)
Build a map from an input DW_AT_LLVM_stmt_sequence byte offset to the first-row index (in LT....
StringMapEntry< EmptyStringSetTag > StringEntry
StringEntry keeps data of the string: the length, external offset and a string body which is placed r...
bool isInToolchainDir(StringRef Path)
Make a best effort to determine whether Path is inside a toolchain.
bool isPathAbsoluteOnWindowsOrPosix(const Twine &Path)
std::optional< uint64_t > toAddress(const std::optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract an address.
std::optional< const char * > toString(const std::optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract a string value from it.
std::optional< uint64_t > toSectionOffset(const std::optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract an section offset.
StringRef toStringRef(const std::optional< DWARFFormValue > &V, StringRef Default={})
Take an optional DWARFFormValue and try to extract a string value from it.
std::optional< uint64_t > toUnsigned(const std::optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract an unsigned constant.
@ DW_ARANGES_VERSION
Section version number for .debug_aranges.
LLVM_ABI std::error_code real_path(const Twine &path, SmallVectorImpl< char > &output, bool expand_tilde=false)
Collapse all .
LLVM_ABI StringRef parent_path(StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get parent path.
LLVM_ABI bool is_relative(const Twine &path, Style style=Style::native)
Is path relative?
LLVM_ABI StringRef filename(StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get filename.
LLVM_ABI void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
void swapByteOrder(T &Value)
This is an optimization pass for GlobalISel generic memory operations.
auto find(R &&Range, const T &Val)
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly.
void fill(R &&Range, T &&Value)
Provide wrappers to std::fill which take ranges instead of having to pass begin/end explicitly.
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
auto partition_point(R &&Range, Predicate P)
Binary search for the first iterator in a range where a predicate is false.
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
auto unique(Range &&R, Predicate P)
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
static void insertLineSequence(std::vector< TrackedRow > &Seq, std::vector< TrackedRow > &Rows)
Insert the new line info sequence Seq into the current set of already linked line info Rows.
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
void sort(IteratorTy Start, IteratorTy End)
@ Dwarf
DWARF v5 .debug_names.
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...
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
FunctionAddr VTableAddr uintptr_t uintptr_t Data
DWARFExpression::Operation Op
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
unsigned encodeULEB128(uint64_t Value, raw_ostream &OS, unsigned PadTo=0)
Utility function to encode a ULEB128 value to an output stream.
bool isCompileUnit(const std::unique_ptr< DWARFUnit > &U)
BumpPtrAllocatorImpl<> BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
void consumeError(Error Err)
Consume a Error without doing anything.
dwarf::FormParams FormParams
Version, address size (starting in v5), and DWARF32/64 format; these parameters affect interpretation...
Standard .debug_line state machine structure.
object::SectionedAddress Address
The program-counter value corresponding to a machine instruction generated by the compiler and sectio...
Represents a single DWARF expression, whose value is location-dependent.
Information gathered about source DIEs.
LLVM_DUMP_METHOD void dump()
bool needToPlaceInTypeTable() const
DieOutputPlacement getPlacement() const
This structure is used to update reference to the DIE.
uint64_t RefDieIdxOrClonedOffset
PointerIntPair< CompileUnit *, 1 > RefCU
This structure is used to update location list offset into .debug_loc/.debug_loclists.
int64_t AddrAdjustmentValue
This structure is used to update range list offset into .debug_ranges/.debug_rnglists.
bool IsCompileUnitRanges
Indicates patch which points to immediate compile unit's attribute.
This structure is used to update reference to the DIE of ULEB128 form.
uint64_t RefDieIdxOrClonedOffset
PointerIntPair< CompileUnit *, 1 > RefCU
dwarf::FormParams getFormParams() const
Returns FormParams used by section.
This structure is used to keep data of the concrete section.
raw_svector_ostream OS
Stream which stores data to the Contents.
void emitUnitLength(uint64_t Length)
Emit unit length into the current section contents.
void emitOffset(uint64_t Val)
Emit specified offset value into the current section contents.
void emitIntVal(uint64_t Val, unsigned Size)
Emit specified integer value into the current section contents.
void apply(uint64_t PatchOffset, dwarf::Form AttrForm, uint64_t Val)
Write specified Value of AttrForm to the PatchOffset.
uint64_t getIntVal(uint64_t PatchOffset, unsigned Size)
Returns integer value of Size located by specified PatchOffset.
This is a helper structure which keeps a debug info entry with it's containing compilation unit.
UnitEntryPairTy()=default
std::optional< UnitEntryPairTy > getParent()
UnitEntryPairTy getNamespaceOrigin()
const DWARFDebugInfoEntry * DieEntry