33#include "llvm/Config/llvm-config.h"
80 "Use the *2 versions for tag records in CodeView (LF_CLASS2, etc.)"),
87 : OS(&OS), TypeTable(TypeTable) {}
89 void emitBytes(StringRef
Data)
override { OS->emitBytes(
Data); }
95 void emitAPSIntValue(
const APSInt &
Value)
override {
96 OS->emitIntValue(
Value);
99 void emitBinaryData(StringRef
Data)
override { OS->emitBinaryData(
Data); }
101 void AddComment(
const Twine &
T)
override { OS->AddComment(
T); }
103 void AddRawComment(
const Twine &
T)
override { OS->emitRawComment(
T); }
105 bool isVerboseAsm()
override {
return OS->isVerboseAsm(); }
113 TypeName = std::string(TypeTable.getTypeName(TI));
119 MCStreamer *OS =
nullptr;
120 TypeCollection &TypeTable;
149 std::string &Filepath = FileToFilepathMap[File];
150 if (!Filepath.empty())
160 Filepath = std::string(Dir);
161 if (Dir.
back() !=
'/')
174 Filepath = (Dir +
"\\" +
Filename).str();
183 while ((Cursor = Filepath.find(
"\\.\\", Cursor)) != std::string::npos)
184 Filepath.erase(Cursor, 2);
189 while ((Cursor = Filepath.find(
"\\..\\", Cursor)) != std::string::npos) {
194 size_t PrevSlash = Filepath.rfind(
'\\', Cursor - 1);
195 if (PrevSlash == std::string::npos)
199 Filepath.erase(PrevSlash, Cursor + 3 - PrevSlash);
206 while ((Cursor = Filepath.find(
"\\\\", Cursor)) != std::string::npos)
207 Filepath.erase(Cursor, 1);
212unsigned CodeViewDebug::maybeRecordFile(
const DIFile *
F) {
213 StringRef FullPath = getFullFilepath(
F);
214 unsigned NextId = FileIdMap.size() + 1;
215 auto Insertion = FileIdMap.insert(std::make_pair(FullPath, NextId));
216 if (Insertion.second) {
218 ArrayRef<uint8_t> ChecksumAsBytes;
220 if (
F->getChecksum()) {
221 std::string Checksum =
fromHex(
F->getChecksum()->Value);
222 void *CKMem = OS.getContext().allocate(Checksum.size(), 1);
223 memcpy(CKMem, Checksum.data(), Checksum.size());
224 ChecksumAsBytes = ArrayRef<uint8_t>(
225 reinterpret_cast<const uint8_t *
>(CKMem), Checksum.size());
226 switch (
F->getChecksum()->Kind) {
228 CSKind = FileChecksumKind::MD5;
231 CSKind = FileChecksumKind::SHA1;
234 CSKind = FileChecksumKind::SHA256;
238 bool Success = OS.emitCVFileDirective(NextId, FullPath, ChecksumAsBytes,
239 static_cast<unsigned>(CSKind));
243 return Insertion.first->second;
246CodeViewDebug::InlineSite &
247CodeViewDebug::getInlineSite(
const DILocation *InlinedAt,
249 auto SiteInsertion = CurFn->InlineSites.try_emplace(InlinedAt);
250 InlineSite *Site = &SiteInsertion.first->second;
251 if (SiteInsertion.second) {
252 unsigned ParentFuncId = CurFn->FuncId;
253 if (
const DILocation *OuterIA = InlinedAt->getInlinedAt())
255 getInlineSite(OuterIA, InlinedAt->getScope()->getSubprogram())
258 Site->SiteFuncId = NextFuncId++;
259 OS.emitCVInlineSiteIdDirective(
260 Site->SiteFuncId, ParentFuncId, maybeRecordFile(InlinedAt->getFile()),
261 InlinedAt->getLine(), InlinedAt->getColumn(), SMLoc());
263 InlinedSubprograms.insert(
Inlinee);
264 auto InlineeIdx = getFuncIdForSubprogram(
Inlinee);
266 if (InlinedAt->getInlinedAt() ==
nullptr)
267 CurFn->Inlinees.insert(InlineeIdx);
274 if (!ScopeName.
empty())
277 switch (Scope->getTag()) {
278 case dwarf::DW_TAG_enumeration_type:
279 case dwarf::DW_TAG_class_type:
280 case dwarf::DW_TAG_structure_type:
281 case dwarf::DW_TAG_union_type:
282 return "<unnamed-tag>";
283 case dwarf::DW_TAG_namespace:
284 return "`anonymous namespace'";
290const DISubprogram *CodeViewDebug::collectParentScopeNames(
292 const DISubprogram *ClosestSubprogram =
nullptr;
293 while (Scope !=
nullptr) {
294 if (ClosestSubprogram ==
nullptr)
301 DeferredCompleteTypes.push_back(Ty);
304 if (!ScopeName.
empty())
305 QualifiedNameComponents.
push_back(ScopeName);
308 return ClosestSubprogram;
313 std::string FullyQualifiedName;
316 FullyQualifiedName.append(std::string(QualifiedNameComponent));
317 FullyQualifiedName.append(
"::");
319 FullyQualifiedName.append(std::string(TypeName));
320 return FullyQualifiedName;
328 if (
CVD.TypeEmissionLevel == 1)
329 CVD.emitDeferredCompleteTypes();
330 --
CVD.TypeEmissionLevel;
335std::string CodeViewDebug::getFullyQualifiedName(
const DIScope *Scope,
342 collectParentScopeNames(Scope, QualifiedNameComponents);
346std::string CodeViewDebug::getFullyQualifiedName(
const DIScope *Ty) {
368 auto I = TypeIndices.find({Scope,
nullptr});
369 if (
I != TypeIndices.end())
373 std::string ScopeName = getFullyQualifiedName(Scope);
374 StringIdRecord SID(TypeIndex(), ScopeName);
375 auto TI = TypeTable.writeLeafType(SID);
376 return recordTypeIndexForDINode(Scope, TI);
382 if (Name.empty() || Name.back() !=
'>')
385 int OpenBrackets = 0;
386 for (
int i = Name.size() - 1; i >= 0; --i) {
389 else if (Name[i] ==
'<') {
391 if (OpenBrackets == 0)
392 return Name.substr(0, i);
398TypeIndex CodeViewDebug::getFuncIdForSubprogram(
const DISubprogram *SP) {
402 auto I = TypeIndices.find({
SP,
nullptr});
403 if (
I != TypeIndices.end())
411 const DIScope *
Scope =
SP->getScope();
417 TypeIndex ClassType = getTypeIndex(Class);
418 MemberFuncIdRecord MFuncId(ClassType, getMemberFunctionType(SP, Class),
420 TI = TypeTable.writeLeafType(MFuncId);
423 TypeIndex ParentScope = getScopeIndex(Scope);
424 FuncIdRecord FuncId(ParentScope, getTypeIndex(
SP->getType()), DisplayName);
425 TI = TypeTable.writeLeafType(FuncId);
428 return recordTypeIndexForDINode(SP, TI);
432 return ((DCTy->
getFlags() & DINode::FlagNonTrivial) == DINode::FlagNonTrivial);
440 const DIType *ReturnTy =
nullptr;
441 if (
auto TypeArray = Ty->getTypeArray()) {
442 if (TypeArray.size())
443 ReturnTy = TypeArray[0];
453 if (ClassTy &&
isNonTrivial(ClassTy) && SPName == ClassTy->getName()) {
462TypeIndex CodeViewDebug::getMemberFunctionType(
const DISubprogram *SP,
466 if (
SP->getDeclaration())
467 SP =
SP->getDeclaration();
468 assert(!
SP->getDeclaration() &&
"should use declaration as key");
472 auto I = TypeIndices.find({
SP,
Class});
473 if (
I != TypeIndices.end())
480 const bool IsStaticMethod = (
SP->getFlags() & DINode::FlagStaticMember) != 0;
483 TypeIndex TI = lowerTypeMemberFunction(
484 SP->getType(), Class,
SP->getThisAdjustment(), IsStaticMethod, FO);
485 return recordTypeIndexForDINode(SP, TI, Class);
488TypeIndex CodeViewDebug::recordTypeIndexForDINode(
const DINode *Node,
491 auto InsertResult = TypeIndices.insert({{
Node, ClassTy}, TI});
493 assert(InsertResult.second &&
"DINode was already assigned a type index");
497unsigned CodeViewDebug::getPointerSizeInBytes() {
498 return MMI->getModule()->getDataLayout().getPointerSizeInBits() / 8;
501void CodeViewDebug::recordLocalVariable(LocalVariable &&Var,
503 if (
const DILocation *InlinedAt =
LS->getInlinedAt()) {
505 const DISubprogram *
Inlinee = Var.DIVar->getScope()->getSubprogram();
506 InlineSite &Site = getInlineSite(InlinedAt,
Inlinee);
507 Site.InlinedLocals.emplace_back(std::move(Var));
510 ScopeVariables[
LS].emplace_back(std::move(Var));
520void CodeViewDebug::maybeRecordLocation(
const DebugLoc &
DL,
526 const DIScope *
Scope =
DL->getScope();
531 LineInfo LI(
DL.getLine(),
DL.getLine(),
true);
532 if (LI.getStartLine() !=
DL.getLine() || LI.isAlwaysStepInto() ||
533 LI.isNeverStepInto())
536 ColumnInfo CI(
DL.getCol(), 0);
537 if (CI.getStartColumn() !=
DL.getCol())
540 if (!CurFn->HaveLineInfo)
541 CurFn->HaveLineInfo =
true;
544 FileId = CurFn->LastFileId;
546 FileId = CurFn->LastFileId = maybeRecordFile(
DL->getFile());
549 unsigned FuncId = CurFn->FuncId;
550 if (
const DILocation *SiteLoc =
DL->getInlinedAt()) {
551 const DILocation *Loc =
DL.get();
556 getInlineSite(SiteLoc, Loc->getScope()->getSubprogram()).SiteFuncId;
559 bool FirstLoc =
true;
560 while ((SiteLoc = Loc->getInlinedAt())) {
562 getInlineSite(SiteLoc, Loc->getScope()->getSubprogram());
571 OS.emitCVLocDirective(FuncId, FileId,
DL.getLine(),
DL.getCol(),
573 DL->getFilename(), SMLoc());
576void CodeViewDebug::emitCodeViewMagicVersion() {
577 OS.emitValueToAlignment(
Align(4));
578 OS.AddComment(
"Debug section magic");
585 case dwarf::DW_LNAME_C:
586 return SourceLanguage::C;
587 case dwarf::DW_LNAME_C_plus_plus:
588 return SourceLanguage::Cpp;
589 case dwarf::DW_LNAME_Fortran:
590 return SourceLanguage::Fortran;
591 case dwarf::DW_LNAME_Pascal:
592 return SourceLanguage::Pascal;
593 case dwarf::DW_LNAME_Cobol:
594 return SourceLanguage::Cobol;
595 case dwarf::DW_LNAME_Java:
596 return SourceLanguage::Java;
597 case dwarf::DW_LNAME_D:
598 return SourceLanguage::D;
599 case dwarf::DW_LNAME_Swift:
600 return SourceLanguage::Swift;
601 case dwarf::DW_LNAME_Rust:
602 return SourceLanguage::Rust;
603 case dwarf::DW_LNAME_ObjC:
604 return SourceLanguage::ObjC;
605 case dwarf::DW_LNAME_ObjC_plus_plus:
606 return SourceLanguage::ObjCpp;
611 return SourceLanguage::Masm;
625 if (!
Asm->getObjFileLowering().getCOFFDebugSymbolsSection()) {
630 CompilerInfoAsm =
Asm;
635 if (
Asm->hasDebugInfo()) {
636 Node = *M->debug_compile_units_begin();
640 NamedMDNode *CUs =
MMI->getModule()->getNamedMetadata(
"llvm.dbg.cu");
650 CurrentSourceLanguage =
656 if (!M->getCodeViewFlag() ||
662 collectGlobalVariableInfo();
667 EmitDebugGlobalHashes = GH && !GH->
isZero();
671 if (!CompilerInfoAsm)
681 switchToDebugSectionForSymbol(
nullptr);
685 emitCompilerInformation();
686 endCVSubsection(CompilerInfo);
690 emitSecureHotPatchInformation();
692 emitInlineeLinesSubsection();
695 for (
auto &
P : FnDebugInfo)
696 if (!
P.first->isDeclarationForLinker())
697 emitDebugInfoForFunction(
P.first, *
P.second);
702 collectDebugInfoForGlobals();
705 emitDebugInfoForRetainedTypes();
708 setCurrentSubprogram(
nullptr);
709 emitDebugInfoForGlobals();
713 switchToDebugSectionForSymbol(
nullptr);
716 if (!GlobalUDTs.empty()) {
718 emitDebugInfoForUDTs(GlobalUDTs);
719 endCVSubsection(SymbolsEnd);
723 OS.AddComment(
"File index to string table offset subsection");
724 OS.emitCVFileChecksumsDirective();
727 OS.AddComment(
"String table");
728 OS.emitCVStringTableDirective();
737 emitTypeInformation();
739 if (EmitDebugGlobalHashes)
740 emitTypeGlobalHashes();
747 unsigned MaxFixedRecordLength = 0xF00) {
758void CodeViewDebug::emitTypeInformation() {
759 if (TypeTable.empty())
763 OS.switchSection(
Asm->getObjFileLowering().getCOFFDebugTypesSection());
764 emitCodeViewMagicVersion();
769 if (!OS.isVerboseAsm()) {
770 for (ArrayRef<uint8_t> Record : TypeTable.records())
775 TypeTableCollection
Table(TypeTable.records());
776 TypeVisitorCallbackPipeline Pipeline;
779 CVMCAdapter CVMCOS(OS,
Table);
780 TypeRecordMapping typeMapping(CVMCOS);
783 std::optional<TypeIndex>
B =
Table.getFirst();
799void CodeViewDebug::emitTypeGlobalHashes() {
800 if (TypeTable.empty())
805 OS.switchSection(
Asm->getObjFileLowering().getCOFFGlobalTypeHashesSection());
807 OS.emitValueToAlignment(
Align(4));
808 OS.AddComment(
"Magic");
810 OS.AddComment(
"Section Version");
812 OS.AddComment(
"Hash Algorithm");
813 OS.emitInt16(uint16_t(GlobalTypeHashAlg::BLAKE3));
816 for (
const auto &GHR : TypeTable.hashes()) {
817 if (OS.isVerboseAsm()) {
821 raw_svector_ostream CommentOS(Comment);
823 OS.AddComment(Comment);
826 assert(GHR.Hash.size() == 8);
827 StringRef S(
reinterpret_cast<const char *
>(GHR.Hash.data()),
829 OS.emitBinaryData(S);
833void CodeViewDebug::emitObjName() {
834 MCSymbol *CompilerEnd = beginSymbolRecord(SymbolKind::S_OBJNAME);
836 StringRef PathRef(CompilerInfoAsm->TM.Options.ObjectFilenameForDebug);
837 llvm::SmallString<256> PathStore(PathRef);
839 if (PathRef.empty() || PathRef ==
"-") {
846 OS.AddComment(
"Signature");
847 OS.emitIntValue(0, 4);
849 OS.AddComment(
"Object name");
852 endSymbolRecord(CompilerEnd);
855void CodeViewDebug::emitSecureHotPatchInformation() {
858 for (
const auto &
F :
MMI->getModule()->functions()) {
859 if (!
F.isDeclarationForLinker() &&
860 F.hasFnAttribute(
"marked_for_windows_hot_patching")) {
861 if (hotPatchInfo ==
nullptr)
862 hotPatchInfo = beginCVSubsection(DebugSubsectionKind::Symbols);
863 MCSymbol *HotPatchEnd = beginSymbolRecord(SymbolKind::S_HOTPATCHFUNC);
864 auto *
SP =
F.getSubprogram();
865 OS.AddComment(
"Function");
866 OS.emitInt32(getFuncIdForSubprogram(SP).getIndex());
867 OS.AddComment(
"Name");
869 endSymbolRecord(HotPatchEnd);
873 if (hotPatchInfo !=
nullptr)
874 endCVSubsection(hotPatchInfo);
888 for (
const char C : Name) {
891 V.Part[
N] +=
C -
'0';
893 std::min<int>(
V.Part[
N], std::numeric_limits<uint16_t>::max());
894 }
else if (
C ==
'.') {
904void CodeViewDebug::emitCompilerInformation() {
905 MCSymbol *CompilerEnd = beginSymbolRecord(SymbolKind::S_COMPILE3);
909 Flags = CurrentSourceLanguage;
911 if (
MMI->getModule()->getProfileSummary(
false) !=
nullptr) {
912 Flags |=
static_cast<uint32_t
>(CompileSym3Flags::PGO);
916 ArchType Arch =
M->getTargetTriple().getArch();
921 if ((HotpatchFlag && HotpatchFlag->isOne()) || Arch == ArchType::thumb ||
922 Arch == ArchType::aarch64) {
923 Flags |=
static_cast<uint32_t
>(CompileSym3Flags::HotPatch);
926 OS.AddComment(
"Flags and language");
929 OS.AddComment(
"CPUType");
930 OS.emitInt16(
static_cast<uint64_t>(TheCPU));
932 StringRef CompilerVersion =
"0";
934 CompilerVersion = TheCU->getProducer();
937 OS.AddComment(
"Frontend version");
938 for (
int N : FrontVer.Part) {
945 int Major = 1000 * LLVM_VERSION_MAJOR +
946 10 * LLVM_VERSION_MINOR +
949 Major = std::min<int>(Major, std::numeric_limits<uint16_t>::max());
950 Version BackVer = {{ Major, 0, 0, 0 }};
951 OS.AddComment(
"Backend version");
952 for (
int N : BackVer.Part)
955 OS.AddComment(
"Null-terminated compiler version string");
958 endSymbolRecord(CompilerEnd);
967void CodeViewDebug::emitBuildInfo() {
979 NamedMDNode *CUs =
MMI->getModule()->getNamedMetadata(
"llvm.dbg.cu");
982 const DIFile *MainSourceFile = CU->getFile();
993 TypeTable,
Asm->TM.Options.MCOptions.CommandlineArgs);
995 BuildInfoRecord BIR(BuildInfoArgs);
996 TypeIndex BuildInfoIndex = TypeTable.writeLeafType(BIR);
1000 MCSymbol *BISubsecEnd = beginCVSubsection(DebugSubsectionKind::Symbols);
1001 MCSymbol *BIEnd = beginSymbolRecord(SymbolKind::S_BUILDINFO);
1002 OS.AddComment(
"LF_BUILDINFO index");
1003 OS.emitInt32(BuildInfoIndex.
getIndex());
1004 endSymbolRecord(BIEnd);
1005 endCVSubsection(BISubsecEnd);
1008void CodeViewDebug::emitInlineeLinesSubsection() {
1009 if (InlinedSubprograms.empty())
1012 OS.AddComment(
"Inlinee lines subsection");
1013 MCSymbol *InlineEnd = beginCVSubsection(DebugSubsectionKind::InlineeLines);
1019 OS.AddComment(
"Inlinee lines signature");
1020 OS.emitInt32(
unsigned(InlineeLinesSignature::Normal));
1022 for (
const DISubprogram *SP : InlinedSubprograms) {
1023 assert(TypeIndices.count({SP, nullptr}));
1024 TypeIndex InlineeIdx = TypeIndices[{
SP,
nullptr}];
1027 unsigned FileId = maybeRecordFile(
SP->getFile());
1028 OS.AddComment(
"Inlined function " +
SP->getName() +
" starts at " +
1029 SP->getFilename() + Twine(
':') + Twine(
SP->getLine()));
1031 OS.AddComment(
"Type index of inlined function");
1032 OS.emitInt32(InlineeIdx.
getIndex());
1033 OS.AddComment(
"Offset into filechecksum table");
1034 OS.emitCVFileChecksumOffsetDirective(FileId);
1035 OS.AddComment(
"Starting line number");
1036 OS.emitInt32(
SP->getLine());
1039 endCVSubsection(InlineEnd);
1042void CodeViewDebug::emitInlinedCallSite(
const FunctionInfo &FI,
1045 assert(TypeIndices.count({Site.Inlinee, nullptr}));
1046 TypeIndex InlineeIdx = TypeIndices[{Site.Inlinee,
nullptr}];
1049 MCSymbol *InlineEnd = beginSymbolRecord(SymbolKind::S_INLINESITE);
1051 OS.AddComment(
"PtrParent");
1053 OS.AddComment(
"PtrEnd");
1055 OS.AddComment(
"Inlinee type index");
1056 OS.emitInt32(InlineeIdx.
getIndex());
1058 unsigned FileId = maybeRecordFile(Site.Inlinee->getFile());
1059 unsigned StartLineNum = Site.Inlinee->getLine();
1061 OS.emitCVInlineLinetableDirective(Site.SiteFuncId, FileId, StartLineNum,
1064 endSymbolRecord(InlineEnd);
1066 emitLocalVariableList(FI, Site.InlinedLocals);
1069 for (
const DILocation *ChildSite : Site.ChildSites) {
1070 auto I = FI.InlineSites.find(ChildSite);
1071 assert(
I != FI.InlineSites.end() &&
1072 "child site not in function inline site map");
1073 emitInlinedCallSite(FI, ChildSite,
I->second);
1077 emitEndSymbolRecord(SymbolKind::S_INLINESITE_END);
1080void CodeViewDebug::switchToDebugSectionForSymbol(
const MCSymbol *GVSym) {
1084 MCSectionCOFF *GVSec =
1085 GVSym ?
static_cast<MCSectionCOFF *
>(&GVSym->
getSection()) : nullptr;
1088 auto *DebugSec =
static_cast<MCSectionCOFF *
>(
1089 CompilerInfoAsm->getObjFileLowering().getCOFFDebugSymbolsSection());
1090 DebugSec = OS.getContext().getAssociativeCOFFSection(DebugSec, KeySym);
1092 OS.switchSection(DebugSec);
1096 if (ComdatDebugSections.insert(DebugSec).second)
1097 emitCodeViewMagicVersion();
1102void CodeViewDebug::emitDebugInfoForThunk(
const Function *GV,
1105 std::string FuncName =
1109 OS.AddComment(
"Symbol subsection for " + Twine(FuncName));
1110 MCSymbol *SymbolsEnd = beginCVSubsection(DebugSubsectionKind::Symbols);
1113 MCSymbol *ThunkRecordEnd = beginSymbolRecord(SymbolKind::S_THUNK32);
1114 OS.AddComment(
"PtrParent");
1116 OS.AddComment(
"PtrEnd");
1118 OS.AddComment(
"PtrNext");
1120 OS.AddComment(
"Thunk section relative address");
1121 OS.emitCOFFSecRel32(Fn, 0);
1122 OS.AddComment(
"Thunk section index");
1123 OS.emitCOFFSectionIndex(Fn);
1124 OS.AddComment(
"Code size");
1125 OS.emitAbsoluteSymbolDiff(FI.End, Fn, 2);
1126 OS.AddComment(
"Ordinal");
1127 OS.emitInt8(
unsigned(ordinal));
1128 OS.AddComment(
"Function name");
1131 endSymbolRecord(ThunkRecordEnd);
1137 emitEndSymbolRecord(SymbolKind::S_PROC_ID_END);
1139 endCVSubsection(SymbolsEnd);
1142void CodeViewDebug::emitDebugInfoForFunction(
const Function *GV,
1150 switchToDebugSectionForSymbol(Fn);
1152 std::string FuncName;
1155 setCurrentSubprogram(SP);
1157 if (
SP->isThunk()) {
1158 emitDebugInfoForThunk(GV, FI, Fn);
1164 if (!
SP->getName().empty())
1165 FuncName = getFullyQualifiedName(
SP->getScope(),
SP->getName());
1168 if (FuncName.empty())
1172 if (
MMI->getModule()->getTargetTriple().getArch() ==
Triple::x86)
1173 OS.emitCVFPOData(Fn);
1176 OS.AddComment(
"Symbol subsection for " + Twine(FuncName));
1177 MCSymbol *SymbolsEnd = beginCVSubsection(DebugSubsectionKind::Symbols);
1180 : SymbolKind::S_GPROC32_ID;
1181 MCSymbol *ProcRecordEnd = beginSymbolRecord(ProcKind);
1184 OS.AddComment(
"PtrParent");
1186 OS.AddComment(
"PtrEnd");
1188 OS.AddComment(
"PtrNext");
1192 OS.AddComment(
"Code size");
1193 OS.emitAbsoluteSymbolDiff(FI.End, Fn, 4);
1194 OS.AddComment(
"Offset after prologue");
1196 OS.AddComment(
"Offset before epilogue");
1198 OS.AddComment(
"Function type index");
1199 OS.emitInt32(getFuncIdForSubprogram(GV->
getSubprogram()).getIndex());
1200 OS.AddComment(
"Function section relative address");
1201 OS.emitCOFFSecRel32(Fn, 0);
1202 OS.AddComment(
"Function section index");
1203 OS.emitCOFFSectionIndex(Fn);
1204 OS.AddComment(
"Flags");
1205 ProcSymFlags ProcFlags = ProcSymFlags::HasOptimizedDebugInfo;
1206 if (FI.HasFramePointer)
1207 ProcFlags |= ProcSymFlags::HasFP;
1209 ProcFlags |= ProcSymFlags::IsNoReturn;
1211 ProcFlags |= ProcSymFlags::IsNoInline;
1212 OS.emitInt8(
static_cast<uint8_t
>(ProcFlags));
1214 OS.AddComment(
"Function name");
1217 endSymbolRecord(ProcRecordEnd);
1219 MCSymbol *FrameProcEnd = beginSymbolRecord(SymbolKind::S_FRAMEPROC);
1221 OS.AddComment(
"FrameSize");
1222 OS.emitInt32(FI.FrameSize - FI.CSRSize);
1223 OS.AddComment(
"Padding");
1225 OS.AddComment(
"Offset of padding");
1227 OS.AddComment(
"Bytes of callee saved registers");
1228 OS.emitInt32(FI.CSRSize);
1229 OS.AddComment(
"Exception handler offset");
1231 OS.AddComment(
"Exception handler section");
1233 OS.AddComment(
"Flags (defines frame register)");
1234 OS.emitInt32(uint32_t(FI.FrameProcOpts));
1235 endSymbolRecord(FrameProcEnd);
1237 emitInlinees(FI.Inlinees);
1238 emitLocalVariableList(FI, FI.Locals);
1239 emitGlobalVariableList(FI.Globals);
1240 emitLexicalBlockList(FI.ChildBlocks, FI);
1245 for (
const DILocation *InlinedAt : FI.ChildSites) {
1246 auto I = FI.InlineSites.find(InlinedAt);
1247 assert(
I != FI.InlineSites.end() &&
1248 "child site not in function inline site map");
1249 emitInlinedCallSite(FI, InlinedAt,
I->second);
1252 for (
auto Annot : FI.Annotations) {
1255 MCSymbol *AnnotEnd = beginSymbolRecord(SymbolKind::S_ANNOTATION);
1256 OS.emitCOFFSecRel32(Label, 0);
1258 OS.emitCOFFSectionIndex(Label);
1264 assert(Str.data()[Str.size()] ==
'\0' &&
"non-nullterminated MDString");
1265 OS.emitBytes(StringRef(Str.data(), Str.size() + 1));
1267 endSymbolRecord(AnnotEnd);
1270 for (
auto HeapAllocSite : FI.HeapAllocSites) {
1271 const MCSymbol *BeginLabel = std::get<0>(HeapAllocSite);
1272 const MCSymbol *EndLabel = std::get<1>(HeapAllocSite);
1273 const DIType *DITy = std::get<2>(HeapAllocSite);
1274 MCSymbol *HeapAllocEnd = beginSymbolRecord(SymbolKind::S_HEAPALLOCSITE);
1275 OS.AddComment(
"Call site offset");
1276 OS.emitCOFFSecRel32(BeginLabel, 0);
1277 OS.AddComment(
"Call site section index");
1278 OS.emitCOFFSectionIndex(BeginLabel);
1279 OS.AddComment(
"Call instruction length");
1280 OS.emitAbsoluteSymbolDiff(EndLabel, BeginLabel, 2);
1281 OS.AddComment(
"Type index");
1282 OS.emitInt32(getCompleteTypeIndex(DITy).getIndex());
1283 endSymbolRecord(HeapAllocEnd);
1287 emitDebugInfoForUDTs(LocalUDTs);
1289 emitDebugInfoForJumpTables(FI);
1292 emitEndSymbolRecord(SymbolKind::S_PROC_ID_END);
1294 endCVSubsection(SymbolsEnd);
1297 OS.emitCVLinetableDirective(FI.FuncId, Fn, FI.End);
1301CodeViewDebug::createDefRangeMem(uint16_t CVRegister,
int Offset,
1302 int32_t DerefOffset) {
1308 DR.StructOffset = 0;
1309 DR.CVRegister = CVRegister;
1310 DR.DerefOffset = DerefOffset;
1314void CodeViewDebug::collectVariableInfoFromMFTable(
1321 for (
const MachineFunction::VariableDbgInfo &VI :
1325 assert(
VI.Var->isValidLocationForIntrinsic(
VI.Loc) &&
1326 "Expected inlined-at fields to agree");
1328 Processed.
insert(InlinedEntity(
VI.Var,
VI.Loc->getInlinedAt()));
1336 int64_t ExprOffset = 0;
1340 if (!
VI.Expr->extractLeadingOffset(ExprOffset, FirstRemaining))
1342 if (!FirstRemaining.
empty()) {
1343 if (FirstRemaining.
front() != dwarf::DW_OP_deref)
1345 SmallVector<uint64_t, 1> LastRemaining;
1347 ArrayRef(FirstRemaining).drop_front(), DerefOffset,
1350 if (!LastRemaining.
empty())
1357 StackOffset FrameOffset =
1359 uint16_t CVReg =
TRI->getCodeViewRegNum(FrameReg);
1365 if (DerefOffset < INT32_MIN || DerefOffset > INT32_MAX)
1370 createDefRangeMem(CVReg, FrameOffset.
getFixed() + ExprOffset,
1371 static_cast<int32_t
>(DerefOffset));
1380 Var.DefRanges[DefRange].emplace_back(Begin,
End);
1383 recordLocalVariable(std::move(Var), Scope);
1387void CodeViewDebug::calculateRanges(
1389 const TargetRegisterInfo *
TRI =
Asm->MF->getSubtarget().getRegisterInfo();
1392 for (
auto I = Entries.
begin(),
E = Entries.
end();
I !=
E; ++
I) {
1394 if (!
Entry.isDbgValue())
1396 const MachineInstr *DVInst =
Entry.getInstr();
1400 std::optional<DbgVariableLocation>
Location =
1411 Var.ConstantValue =
APSInt(APInt(64,
Op.getImm()),
false);
1423 if (
Location->FragmentInfo->OffsetInBits % 8)
1433 DR.InMemory = !
Location->LoadChain.empty();
1436 if (!
Location->LoadChain.empty()) {
1437 DR.DataOffset =
Location->LoadChain[0];
1438 if (
Location->LoadChain.size() >= 2)
1439 DR.DerefOffset =
Location->LoadChain[1];
1442 DR.IsSubfield =
true;
1443 DR.StructOffset =
Location->FragmentInfo->OffsetInBits / 8;
1445 DR.IsSubfield =
false;
1446 DR.StructOffset = 0;
1453 auto &EndingEntry = Entries[
Entry.getEndIndex()];
1454 End = EndingEntry.isDbgValue()
1458 End =
Asm->getFunctionEnd();
1462 SmallVectorImpl<std::pair<const MCSymbol *, const MCSymbol *>> &
R =
1464 if (!
R.empty() &&
R.back().second == Begin)
1465 R.back().second =
End;
1467 R.emplace_back(Begin,
End);
1473void CodeViewDebug::collectVariableInfo(
const DISubprogram *SP) {
1474 DenseSet<InlinedEntity> Processed;
1476 collectVariableInfoFromMFTable(Processed);
1478 for (
const MDNode *
N :
SP->getRetainedNodes())
1480 collectGlobalOrStaticLocalVariableInfo(GVE);
1483 InlinedEntity
IV =
I.first;
1487 const DILocation *InlinedAt =
IV.second;
1490 const auto &Entries =
I.second;
1492 LexicalScope *
Scope =
nullptr;
1504 calculateRanges(Var, Entries);
1505 recordLocalVariable(std::move(Var), Scope);
1514 auto Insertion = FnDebugInfo.
insert({&GV, std::make_unique<FunctionInfo>()});
1515 assert(Insertion.second &&
"function already has info");
1516 CurFn = Insertion.first->second.get();
1517 CurFn->FuncId = NextFuncId++;
1518 CurFn->Begin =
Asm->getFunctionBegin();
1526 CurFn->HasStackRealignment =
TRI->hasStackRealignment(*MF);
1532 if (CurFn->FrameSize > 0) {
1537 CurFn->HasFramePointer =
true;
1540 if (CurFn->HasStackRealignment) {
1591 CurFn->FrameProcOpts = FPO;
1593 OS.emitCVFuncIdDirective(CurFn->FuncId);
1600 bool EmptyPrologue =
true;
1601 for (
const auto &
MBB : *MF) {
1602 for (
const auto &
MI :
MBB) {
1607 }
else if (!
MI.isMetaInstruction()) {
1608 EmptyPrologue =
false;
1616 maybeRecordLocation(FnStartDL, MF);
1620 for (
const auto &
MBB : *MF) {
1621 for (
const auto &
MI :
MBB) {
1622 if (
MI.getHeapAllocMarker()) {
1630 bool isThumb =
MMI->getModule()->getTargetTriple().getArch() ==
1632 discoverJumpTableBranches(MF,
isThumb);
1640 if (
T->getTag() == dwarf::DW_TAG_typedef) {
1641 if (
DIScope *Scope =
T->getScope()) {
1642 switch (Scope->getTag()) {
1643 case dwarf::DW_TAG_structure_type:
1644 case dwarf::DW_TAG_class_type:
1645 case dwarf::DW_TAG_union_type:
1655 if (!
T ||
T->isForwardDecl())
1661 T = DT->getBaseType();
1666void CodeViewDebug::addToUDTs(
const DIType *Ty) {
1674 const DISubprogram *ClosestSubprogram =
1675 collectParentScopeNames(Ty->
getScope(), ParentScopeNames);
1677 std::string FullyQualifiedName =
1680 if (ClosestSubprogram ==
nullptr) {
1681 GlobalUDTs.emplace_back(std::move(FullyQualifiedName), Ty);
1682 }
else if (ClosestSubprogram == CurrentSubprogram) {
1683 LocalUDTs.emplace_back(std::move(FullyQualifiedName), Ty);
1694TypeIndex CodeViewDebug::lowerType(
const DIType *Ty,
const DIType *ClassTy) {
1697 case dwarf::DW_TAG_array_type:
1699 case dwarf::DW_TAG_typedef:
1701 case dwarf::DW_TAG_base_type:
1703 case dwarf::DW_TAG_pointer_type:
1707 case dwarf::DW_TAG_reference_type:
1708 case dwarf::DW_TAG_rvalue_reference_type:
1710 case dwarf::DW_TAG_ptr_to_member_type:
1712 case dwarf::DW_TAG_restrict_type:
1713 case dwarf::DW_TAG_const_type:
1714 case dwarf::DW_TAG_volatile_type:
1717 case dwarf::DW_TAG_subroutine_type:
1726 case dwarf::DW_TAG_enumeration_type:
1728 case dwarf::DW_TAG_class_type:
1729 case dwarf::DW_TAG_structure_type:
1731 case dwarf::DW_TAG_union_type:
1733 case dwarf::DW_TAG_string_type:
1735 case dwarf::DW_TAG_unspecified_type:
1736 if (Ty->
getName() ==
"decltype(nullptr)")
1745TypeIndex CodeViewDebug::lowerTypeAlias(
const DIDerivedType *Ty) {
1746 TypeIndex UnderlyingTypeIndex = getTypeIndex(Ty->getBaseType());
1751 if (UnderlyingTypeIndex == TypeIndex(SimpleTypeKind::Int32Long) &&
1752 TypeName ==
"HRESULT")
1753 return TypeIndex(SimpleTypeKind::HResult);
1754 if (UnderlyingTypeIndex == TypeIndex(SimpleTypeKind::UInt16Short) &&
1755 TypeName ==
"wchar_t")
1756 return TypeIndex(SimpleTypeKind::WideCharacter);
1758 return UnderlyingTypeIndex;
1763 TypeIndex ElementTypeIndex = getTypeIndex(ElementType);
1765 TypeIndex IndexType = getPointerSizeInBytes() == 8
1766 ? TypeIndex(SimpleTypeKind::UInt64Quad)
1773 for (
int i =
Elements.size() - 1; i >= 0; --i) {
1774 const DINode *Element =
Elements[i];
1775 assert(Element->
getTag() == dwarf::DW_TAG_subrange_type);
1785 Count = CI->getSExtValue();
1791 Lowerbound = (LI) ? LI->getSExtValue() : Lowerbound;
1792 Count = UI->getSExtValue() - Lowerbound + 1;
1803 ElementSize *=
Count;
1808 (i == 0 && ElementSize == 0) ? Ty->
getSizeInBits() / 8 : ElementSize;
1811 ArrayRecord AR(ElementTypeIndex, IndexType, ArraySize, Name);
1812 ElementTypeIndex = TypeTable.writeLeafType(AR);
1815 return ElementTypeIndex;
1823TypeIndex CodeViewDebug::lowerTypeString(
const DIStringType *Ty) {
1824 TypeIndex CharType = TypeIndex(SimpleTypeKind::NarrowCharacter);
1828 TypeIndex IndexType = getPointerSizeInBytes() == 8
1829 ? TypeIndex(SimpleTypeKind::UInt64Quad)
1833 ArrayRecord AR(CharType, IndexType, ArraySize, Name);
1835 return TypeTable.writeLeafType(AR);
1838TypeIndex CodeViewDebug::lowerTypeBasic(
const DIBasicType *Ty) {
1848 case dwarf::DW_ATE_address:
1851 case dwarf::DW_ATE_boolean:
1853 case 1: STK = SimpleTypeKind::Boolean8;
break;
1854 case 2: STK = SimpleTypeKind::Boolean16;
break;
1855 case 4: STK = SimpleTypeKind::Boolean32;
break;
1856 case 8: STK = SimpleTypeKind::Boolean64;
break;
1857 case 16: STK = SimpleTypeKind::Boolean128;
break;
1860 case dwarf::DW_ATE_complex_float:
1864 case 4: STK = SimpleTypeKind::Complex16;
break;
1865 case 8: STK = SimpleTypeKind::Complex32;
break;
1866 case 16: STK = SimpleTypeKind::Complex64;
break;
1867 case 20: STK = SimpleTypeKind::Complex80;
break;
1868 case 32: STK = SimpleTypeKind::Complex128;
break;
1871 case dwarf::DW_ATE_float:
1873 case 2: STK = SimpleTypeKind::Float16;
break;
1874 case 4: STK = SimpleTypeKind::Float32;
break;
1875 case 6: STK = SimpleTypeKind::Float48;
break;
1876 case 8: STK = SimpleTypeKind::Float64;
break;
1877 case 10: STK = SimpleTypeKind::Float80;
break;
1878 case 16: STK = SimpleTypeKind::Float128;
break;
1881 case dwarf::DW_ATE_signed:
1883 case 1: STK = SimpleTypeKind::SignedCharacter;
break;
1884 case 2: STK = SimpleTypeKind::Int16Short;
break;
1885 case 4: STK = SimpleTypeKind::Int32;
break;
1886 case 8: STK = SimpleTypeKind::Int64Quad;
break;
1887 case 16: STK = SimpleTypeKind::Int128Oct;
break;
1890 case dwarf::DW_ATE_unsigned:
1892 case 1: STK = SimpleTypeKind::UnsignedCharacter;
break;
1893 case 2: STK = SimpleTypeKind::UInt16Short;
break;
1894 case 4: STK = SimpleTypeKind::UInt32;
break;
1895 case 8: STK = SimpleTypeKind::UInt64Quad;
break;
1896 case 16: STK = SimpleTypeKind::UInt128Oct;
break;
1899 case dwarf::DW_ATE_UTF:
1901 case 1: STK = SimpleTypeKind::Character8;
break;
1902 case 2: STK = SimpleTypeKind::Character16;
break;
1903 case 4: STK = SimpleTypeKind::Character32;
break;
1906 case dwarf::DW_ATE_signed_char:
1908 STK = SimpleTypeKind::SignedCharacter;
1910 case dwarf::DW_ATE_unsigned_char:
1912 STK = SimpleTypeKind::UnsignedCharacter;
1922 if (STK == SimpleTypeKind::Int32 &&
1924 STK = SimpleTypeKind::Int32Long;
1925 if (STK == SimpleTypeKind::UInt32 && (Ty->
getName() ==
"long unsigned int" ||
1926 Ty->
getName() ==
"unsigned long"))
1927 STK = SimpleTypeKind::UInt32Long;
1928 if (STK == SimpleTypeKind::UInt16Short &&
1930 STK = SimpleTypeKind::WideCharacter;
1931 if ((STK == SimpleTypeKind::SignedCharacter ||
1932 STK == SimpleTypeKind::UnsignedCharacter) &&
1934 STK = SimpleTypeKind::NarrowCharacter;
1936 return TypeIndex(STK);
1939TypeIndex CodeViewDebug::lowerTypePointer(
const DIDerivedType *Ty,
1941 TypeIndex PointeeTI = getTypeIndex(Ty->getBaseType());
1945 if (PointeeTI.
isSimple() && PO == PointerOptions::None &&
1947 Ty->
getTag() == dwarf::DW_TAG_pointer_type) {
1949 ? SimpleTypeMode::NearPointer64
1950 : SimpleTypeMode::NearPointer32;
1955 Ty->
getSizeInBits() == 64 ? PointerKind::Near64 : PointerKind::Near32;
1959 case dwarf::DW_TAG_pointer_type:
1960 PM = PointerMode::Pointer;
1962 case dwarf::DW_TAG_reference_type:
1963 PM = PointerMode::LValueReference;
1965 case dwarf::DW_TAG_rvalue_reference_type:
1966 PM = PointerMode::RValueReference;
1971 PO |= PointerOptions::Const;
1973 PointerRecord PR(PointeeTI, PK, PM, PO, Ty->
getSizeInBits() / 8);
1974 return TypeTable.writeLeafType(PR);
1987 case DINode::FlagSingleInheritance:
1989 case DINode::FlagMultipleInheritance:
1991 case DINode::FlagVirtualInheritance:
1999 case DINode::FlagSingleInheritance:
2001 case DINode::FlagMultipleInheritance:
2003 case DINode::FlagVirtualInheritance:
2010TypeIndex CodeViewDebug::lowerTypeMemberPointer(
const DIDerivedType *Ty,
2012 assert(Ty->
getTag() == dwarf::DW_TAG_ptr_to_member_type);
2015 TypeIndex PointeeTI =
2016 getTypeIndex(Ty->getBaseType(), IsPMF ? Ty->
getClassType() :
nullptr);
2017 PointerKind PK = getPointerSizeInBytes() == 8 ? PointerKind::Near64
2018 : PointerKind::Near32;
2019 PointerMode PM = IsPMF ? PointerMode::PointerToMemberFunction
2020 : PointerMode::PointerToDataMember;
2024 MemberPointerInfo MPI(
2026 PointerRecord PR(PointeeTI, PK, PM, PO, SizeInBytes, MPI);
2027 return TypeTable.writeLeafType(PR);
2044TypeIndex CodeViewDebug::lowerTypeModifier(
const DIDerivedType *Ty) {
2048 const DIType *BaseTy = Ty;
2049 while (IsModifier && BaseTy) {
2051 switch (BaseTy->
getTag()) {
2052 case dwarf::DW_TAG_const_type:
2053 Mods |= ModifierOptions::Const;
2054 PO |= PointerOptions::Const;
2056 case dwarf::DW_TAG_volatile_type:
2057 Mods |= ModifierOptions::Volatile;
2058 PO |= PointerOptions::Volatile;
2060 case dwarf::DW_TAG_restrict_type:
2063 PO |= PointerOptions::Restrict;
2078 switch (BaseTy->
getTag()) {
2079 case dwarf::DW_TAG_pointer_type:
2080 case dwarf::DW_TAG_reference_type:
2081 case dwarf::DW_TAG_rvalue_reference_type:
2083 case dwarf::DW_TAG_ptr_to_member_type:
2090 TypeIndex ModifiedTI = getTypeIndex(BaseTy);
2094 if (Mods == ModifierOptions::None)
2097 ModifierRecord MR(ModifiedTI, Mods);
2098 return TypeTable.writeLeafType(MR);
2104 ReturnAndArgTypeIndices.
push_back(getTypeIndex(ArgType));
2107 if (ReturnAndArgTypeIndices.
size() > 1 &&
2113 if (!ReturnAndArgTypeIndices.
empty()) {
2114 auto ReturnAndArgTypesRef =
ArrayRef(ReturnAndArgTypeIndices);
2115 ReturnTypeIndex = ReturnAndArgTypesRef.consume_front();
2116 ArgTypeIndices = ReturnAndArgTypesRef;
2119 ArgListRecord ArgListRec(TypeRecordKind::ArgList, ArgTypeIndices);
2120 TypeIndex ArgListIndex = TypeTable.writeLeafType(ArgListRec);
2125 ProcedureRecord Procedure(ReturnTypeIndex,
CC, FO, ArgTypeIndices.
size(),
2127 return TypeTable.writeLeafType(Procedure);
2130TypeIndex CodeViewDebug::lowerTypeMemberFunction(
const DISubroutineType *Ty,
2133 bool IsStaticMethod,
2136 TypeIndex ClassType = getTypeIndex(ClassTy);
2143 if (ReturnAndArgs.size() > Index) {
2144 ReturnTypeIndex = getTypeIndex(ReturnAndArgs[Index++]);
2150 TypeIndex ThisTypeIndex;
2151 if (!IsStaticMethod && ReturnAndArgs.size() > Index) {
2152 if (
const DIDerivedType *PtrTy =
2154 if (PtrTy->getTag() == dwarf::DW_TAG_pointer_type) {
2155 ThisTypeIndex = getTypeIndexForThisPtr(PtrTy, Ty);
2161 while (Index < ReturnAndArgs.size())
2162 ArgTypeIndices.
push_back(getTypeIndex(ReturnAndArgs[Index++]));
2168 ArgListRecord ArgListRec(TypeRecordKind::ArgList, ArgTypeIndices);
2169 TypeIndex ArgListIndex = TypeTable.writeLeafType(ArgListRec);
2173 MemberFunctionRecord MFR(ReturnTypeIndex, ClassType, ThisTypeIndex,
CC, FO,
2174 ArgTypeIndices.
size(), ArgListIndex, ThisAdjustment);
2175 return TypeTable.writeLeafType(MFR);
2178TypeIndex CodeViewDebug::lowerTypeVFTableShape(
const DIDerivedType *Ty) {
2179 unsigned VSlotCount =
2183 VFTableShapeRecord VFTSR(Slots);
2184 return TypeTable.writeLeafType(VFTSR);
2201 if (SP->isArtificial())
2211 if (SP->getFlags() & DINode::FlagStaticMember)
2214 switch (SP->getVirtuality()) {
2215 case dwarf::DW_VIRTUALITY_none:
2217 case dwarf::DW_VIRTUALITY_virtual:
2219 case dwarf::DW_VIRTUALITY_pure_virtual:
2230 switch (Ty->getTag()) {
2231 case dwarf::DW_TAG_class_type:
2232 return UseTagRecord2 ? TypeRecordKind::Class2 : TypeRecordKind::Class;
2233 case dwarf::DW_TAG_structure_type:
2234 return UseTagRecord2 ? TypeRecordKind::Struct2 : TypeRecordKind::Struct;
2248 if (!Ty->getIdentifier().empty())
2262 if (Ty->getTag() == dwarf::DW_TAG_enumeration_type) {
2266 for (
const DIScope *Scope = ImmediateScope; Scope !=
nullptr;
2278void CodeViewDebug::addUDTSrcLine(
const DIType *Ty, TypeIndex TI) {
2280 case dwarf::DW_TAG_class_type:
2281 case dwarf::DW_TAG_structure_type:
2282 case dwarf::DW_TAG_union_type:
2283 case dwarf::DW_TAG_enumeration_type:
2289 if (
const auto *File = Ty->
getFile()) {
2290 StringIdRecord SIDR(TypeIndex(0x0), getFullFilepath(File));
2291 TypeIndex SIDI = TypeTable.writeLeafType(SIDR);
2293 UdtSourceLineRecord USLR(TI, SIDI, Ty->
getLine());
2294 TypeTable.writeLeafType(USLR);
2301 unsigned EnumeratorCount = 0;
2304 CO |= ClassOptions::ForwardReference;
2306 ContinuationRecordBuilder ContinuationBuilder;
2307 ContinuationBuilder.
begin(ContinuationRecordKind::FieldList);
2312 EnumeratorRecord ER(
2313 MemberAccess::Public,
2320 FTI = TypeTable.insertRecord(ContinuationBuilder);
2323 std::string FullName = getFullyQualifiedName(Ty);
2325 EnumRecord ER(EnumeratorCount, CO, FTI, FullName, Ty->
getIdentifier(),
2327 TypeIndex EnumTI = TypeTable.writeLeafType(ER);
2329 addUDTSrcLine(Ty, EnumTI);
2363void CodeViewDebug::clear() {
2364 assert(CurFn ==
nullptr);
2366 FnDebugInfo.clear();
2367 FileToFilepathMap.clear();
2370 TypeIndices.clear();
2371 CompleteTypeIndices.clear();
2372 ScopeGlobals.clear();
2373 CVGlobalVariableOffsets.clear();
2376void CodeViewDebug::collectMemberInfo(
ClassInfo &Info,
2379 Info.Members.push_back({DDTy, 0});
2382 if ((DDTy->
getFlags() & DINode::FlagStaticMember) ==
2383 DINode::FlagStaticMember) {
2386 StaticConstMembers.push_back(DDTy);
2398 const DIType *Ty = DDTy->getBaseType();
2399 bool FullyResolved =
false;
2400 while (!FullyResolved) {
2402 case dwarf::DW_TAG_const_type:
2403 case dwarf::DW_TAG_volatile_type:
2409 FullyResolved =
true;
2418 ClassInfo NestedInfo = collectClassInfo(DCTy);
2419 for (
const ClassInfo::MemberInfo &IndirectField : NestedInfo.
Members)
2420 Info.Members.push_back(
2428 for (
auto *Element : Elements) {
2434 Info.Methods[
SP->getRawName()].push_back(SP);
2436 if (DDTy->
getTag() == dwarf::DW_TAG_member) {
2437 collectMemberInfo(Info, DDTy);
2438 }
else if (DDTy->
getTag() == dwarf::DW_TAG_inheritance) {
2439 Info.Inheritance.push_back(DDTy);
2440 }
else if (DDTy->
getTag() == dwarf::DW_TAG_pointer_type &&
2441 DDTy->
getName() ==
"__vtbl_ptr_type") {
2442 Info.VShapeTI = getTypeIndex(DDTy);
2443 }
else if (DDTy->
getTag() == dwarf::DW_TAG_typedef) {
2444 Info.NestedTypes.push_back(DDTy);
2445 }
else if (DDTy->
getTag() == dwarf::DW_TAG_friend) {
2450 Info.NestedTypes.push_back(Composite);
2460 return Ty->getName().empty() && Ty->getIdentifier().empty() &&
2461 !Ty->isForwardDecl();
2473 auto I = CompleteTypeIndices.find(Ty);
2474 if (
I != CompleteTypeIndices.end() &&
I->second == TypeIndex())
2476 return getCompleteTypeIndex(Ty);
2484 std::string FullName = getFullyQualifiedName(Ty);
2485 ClassRecord CR(Kind, 0, CO, TypeIndex(), TypeIndex(), TypeIndex(), 0,
2487 TypeIndex FwdDeclTI = TypeTable.writeLeafType(CR);
2489 DeferredCompleteTypes.push_back(Ty);
2493TypeIndex CodeViewDebug::lowerCompleteTypeClass(
const DICompositeType *Ty) {
2499 unsigned FieldCount;
2502 lowerRecordFieldList(Ty);
2505 CO |= ClassOptions::ContainsNestedClass;
2513 CO |= ClassOptions::HasConstructorOrDestructor;
2515 std::string FullName = getFullyQualifiedName(Ty);
2519 ClassRecord CR(Kind, FieldCount, CO, FieldTI, TypeIndex(), VShapeTI,
2521 TypeIndex ClassTI = TypeTable.writeLeafType(CR);
2523 addUDTSrcLine(Ty, ClassTI);
2533 return getCompleteTypeIndex(Ty);
2537 std::string FullName = getFullyQualifiedName(Ty);
2539 UseTagRecord2 ? TypeRecordKind::Union2 : TypeRecordKind::Union;
2540 UnionRecord UR(Kind, 0, CO, TypeIndex(), 0, FullName, Ty->
getIdentifier());
2541 TypeIndex FwdDeclTI = TypeTable.writeLeafType(UR);
2543 DeferredCompleteTypes.push_back(Ty);
2547TypeIndex CodeViewDebug::lowerCompleteTypeUnion(
const DICompositeType *Ty) {
2550 unsigned FieldCount;
2553 lowerRecordFieldList(Ty);
2556 CO |= ClassOptions::ContainsNestedClass;
2559 std::string FullName = getFullyQualifiedName(Ty);
2562 UseTagRecord2 ? TypeRecordKind::Union2 : TypeRecordKind::Union;
2563 UnionRecord UR(Kind, FieldCount, CO, FieldTI, SizeInBytes, FullName,
2565 TypeIndex UnionTI = TypeTable.writeLeafType(UR);
2567 addUDTSrcLine(Ty, UnionTI);
2574std::tuple<TypeIndex, TypeIndex, unsigned, bool>
2580 unsigned MemberCount = 0;
2581 ClassInfo
Info = collectClassInfo(Ty);
2582 ContinuationRecordBuilder ContinuationBuilder;
2583 ContinuationBuilder.
begin(ContinuationRecordKind::FieldList);
2586 for (
const DIDerivedType *
I :
Info.Inheritance) {
2587 if (
I->getFlags() & DINode::FlagVirtual) {
2589 unsigned VBPtrOffset =
I->getVBPtrOffset();
2591 unsigned VBTableIndex =
I->getOffsetInBits() / 4;
2592 auto RecordKind = (
I->getFlags() & DINode::FlagIndirectVirtualBase) == DINode::FlagIndirectVirtualBase
2593 ? TypeRecordKind::IndirectVirtualBaseClass
2594 : TypeRecordKind::VirtualBaseClass;
2595 VirtualBaseClassRecord VBCR(
2597 getTypeIndex(
I->getBaseType()), getVBPTypeIndex(), VBPtrOffset,
2603 assert(
I->getOffsetInBits() % 8 == 0 &&
2604 "bases must be on byte boundaries");
2606 getTypeIndex(
I->getBaseType()),
2607 I->getOffsetInBits() / 8);
2614 for (ClassInfo::MemberInfo &MemberInfo :
Info.Members) {
2616 TypeIndex MemberBaseType = getTypeIndex(
Member->getBaseType());
2617 StringRef MemberName =
Member->getName();
2621 if (
Member->isStaticMember()) {
2622 StaticDataMemberRecord SDMR(
Access, MemberBaseType, MemberName);
2629 if ((
Member->getFlags() & DINode::FlagArtificial) &&
2630 Member->getName().starts_with(
"_vptr$")) {
2631 VFPtrRecord VFPR(getTypeIndex(
Member->getBaseType()));
2640 if (
Member->isBitField()) {
2641 uint64_t StartBitOffset = MemberOffsetInBits;
2642 if (
const auto *CI =
2644 MemberOffsetInBits = CI->getZExtValue() + MemberInfo.
BaseOffset;
2646 StartBitOffset -= MemberOffsetInBits;
2647 BitFieldRecord BFR(MemberBaseType,
Member->getSizeInBits(),
2649 MemberBaseType = TypeTable.writeLeafType(BFR);
2651 uint64_t MemberOffsetInBytes = MemberOffsetInBits / 8;
2652 DataMemberRecord DMR(
Access, MemberBaseType, MemberOffsetInBytes,
2659 for (
auto &MethodItr :
Info.Methods) {
2660 StringRef
Name = MethodItr.first->getString();
2662 std::vector<OneMethodRecord> Methods;
2663 for (
const DISubprogram *SP : MethodItr.second) {
2664 TypeIndex MethodType = getMemberFunctionType(SP, Ty);
2665 bool Introduced =
SP->getFlags() & DINode::FlagIntroducedVirtual;
2667 unsigned VFTableOffset = -1;
2669 VFTableOffset =
SP->getVirtualIndex() * getPointerSizeInBytes();
2671 Methods.push_back(OneMethodRecord(
2677 assert(!Methods.empty() &&
"Empty methods map entry");
2678 if (Methods.size() == 1)
2683 MethodOverloadListRecord MOLR(Methods);
2684 TypeIndex MethodList = TypeTable.writeLeafType(MOLR);
2686 OverloadedMethodRecord OMR(Methods.size(), MethodList, Name);
2692 for (
const DIType *
Nested :
Info.NestedTypes) {
2693 NestedTypeRecord
R(getTypeIndex(
Nested),
Nested->getName());
2698 TypeIndex FieldTI = TypeTable.insertRecord(ContinuationBuilder);
2699 return std::make_tuple(FieldTI,
Info.VShapeTI, MemberCount,
2700 !
Info.NestedTypes.empty());
2703TypeIndex CodeViewDebug::getVBPTypeIndex() {
2704 if (!VBPType.getIndex()) {
2707 TypeIndex ModifiedTI = TypeTable.writeLeafType(MR);
2709 PointerKind PK = getPointerSizeInBytes() == 8 ? PointerKind::Near64
2710 : PointerKind::Near32;
2713 PointerRecord PR(ModifiedTI, PK, PM, PO, getPointerSizeInBytes());
2714 VBPType = TypeTable.writeLeafType(PR);
2720TypeIndex CodeViewDebug::getTypeIndex(
const DIType *Ty,
const DIType *ClassTy) {
2728 auto I = TypeIndices.find({Ty, ClassTy});
2729 if (
I != TypeIndices.end())
2733 TypeIndex TI = lowerType(Ty, ClassTy);
2734 return recordTypeIndexForDINode(Ty, TI, ClassTy);
2738CodeViewDebug::getTypeIndexForThisPtr(
const DIDerivedType *PtrTy,
2740 assert(PtrTy->
getTag() == dwarf::DW_TAG_pointer_type &&
2741 "this type must be a pointer type");
2744 if (SubroutineTy->
getFlags() & DINode::DIFlags::FlagLValueReference)
2745 Options = PointerOptions::LValueRefThisPointer;
2746 else if (SubroutineTy->
getFlags() & DINode::DIFlags::FlagRValueReference)
2747 Options = PointerOptions::RValueRefThisPointer;
2754 auto I = TypeIndices.find({PtrTy, SubroutineTy});
2755 if (
I != TypeIndices.end())
2759 TypeIndex TI = lowerTypePointer(PtrTy,
Options);
2760 return recordTypeIndexForDINode(PtrTy, TI, SubroutineTy);
2763TypeIndex CodeViewDebug::getCompleteTypeIndex(
const DIType *Ty) {
2771 if (Ty->
getTag() == dwarf::DW_TAG_typedef)
2772 (void)getTypeIndex(Ty);
2773 while (Ty->
getTag() == dwarf::DW_TAG_typedef)
2779 case dwarf::DW_TAG_class_type:
2780 case dwarf::DW_TAG_structure_type:
2781 case dwarf::DW_TAG_union_type:
2784 return getTypeIndex(Ty);
2795 if (!CTy->getName().empty() || !CTy->getIdentifier().empty()) {
2796 TypeIndex FwdDeclTI = getTypeIndex(CTy);
2801 if (CTy->isForwardDecl())
2808 auto InsertResult = CompleteTypeIndices.try_emplace(CTy);
2809 if (!InsertResult.second)
2810 return InsertResult.first->second;
2813 switch (CTy->getTag()) {
2814 case dwarf::DW_TAG_class_type:
2815 case dwarf::DW_TAG_structure_type:
2816 TI = lowerCompleteTypeClass(CTy);
2818 case dwarf::DW_TAG_union_type:
2819 TI = lowerCompleteTypeUnion(CTy);
2829 CompleteTypeIndices[CTy] = TI;
2837void CodeViewDebug::emitDeferredCompleteTypes() {
2839 while (!DeferredCompleteTypes.empty()) {
2840 std::swap(DeferredCompleteTypes, TypesToEmit);
2841 for (
const DICompositeType *RecordTy : TypesToEmit)
2842 getCompleteTypeIndex(RecordTy);
2843 TypesToEmit.clear();
2847void CodeViewDebug::emitLocalVariableList(
const FunctionInfo &FI,
2851 for (
const LocalVariable &L : Locals)
2852 if (
L.DIVar->isParameter())
2854 llvm::sort(Params, [](
const LocalVariable *L,
const LocalVariable *R) {
2855 return L->DIVar->getArg() <
R->DIVar->getArg();
2857 for (
const LocalVariable *L : Params)
2858 emitLocalVariable(FI, *L);
2861 for (
const LocalVariable &L : Locals) {
2862 if (!
L.DIVar->isParameter()) {
2863 if (
L.ConstantValue) {
2866 const DIType *Ty =
L.DIVar->getType();
2868 emitConstantSymbolRecord(Ty, Val, std::string(
L.DIVar->getName()));
2870 emitLocalVariable(FI, L);
2876void CodeViewDebug::emitLocalVariable(
const FunctionInfo &FI,
2877 const LocalVariable &Var) {
2879 MCSymbol *LocalEnd = beginSymbolRecord(SymbolKind::S_LOCAL);
2882 if (Var.DIVar->isParameter())
2883 Flags |= LocalSymFlags::IsParameter;
2884 if (Var.DefRanges.empty())
2885 Flags |= LocalSymFlags::IsOptimizedOut;
2887 OS.AddComment(
"TypeIndex");
2888 TypeIndex TI = getCompleteTypeIndex(Var.DIVar->getType());
2890 OS.AddComment(
"Flags");
2891 OS.emitInt16(
static_cast<uint16_t
>(Flags));
2894 endSymbolRecord(LocalEnd);
2899 SmallString<20> BytePrefix;
2900 for (
const auto &Pair : Var.DefRanges) {
2902 const auto &
Ranges = Pair.second;
2904 if (DefRange.InMemory) {
2905 int Offset = DefRange.DataOffset;
2906 unsigned Reg = DefRange.CVRegister;
2912 Reg = unsigned(RegisterId::VFRAME);
2913 Offset += FI.OffsetAdjustment;
2919 uint16_t RegRelFlags = 0;
2920 if (DefRange.IsSubfield) {
2922 (DefRange.StructOffset
2925 DefRangeRegisterRelIndirHeader DRHdr;
2927 DRHdr.
Flags = RegRelFlags;
2930 OS.emitCVDefRangeDirective(Ranges, DRHdr);
2931 }
else if (!DefRange.IsSubfield && EncFP != EncodedFramePtrReg::None &&
2932 (
bool(Flags & LocalSymFlags::IsParameter)
2933 ? (EncFP == FI.EncodedParamFramePtrReg)
2934 : (EncFP == FI.EncodedLocalFramePtrReg))) {
2938 DefRangeFramePointerRelHeader DRHdr;
2940 OS.emitCVDefRangeDirective(Ranges, DRHdr);
2942 uint16_t RegRelFlags = 0;
2943 if (DefRange.IsSubfield) {
2945 (DefRange.StructOffset
2948 DefRangeRegisterRelHeader DRHdr;
2950 DRHdr.
Flags = RegRelFlags;
2952 OS.emitCVDefRangeDirective(Ranges, DRHdr);
2955 assert(DefRange.DataOffset == 0 &&
2957 "unexpected offset into register");
2958 if (DefRange.IsSubfield) {
2959 DefRangeSubfieldRegisterHeader DRHdr;
2960 DRHdr.
Register = DefRange.CVRegister;
2963 OS.emitCVDefRangeDirective(Ranges, DRHdr);
2965 DefRangeRegisterHeader DRHdr;
2966 DRHdr.
Register = DefRange.CVRegister;
2968 OS.emitCVDefRangeDirective(Ranges, DRHdr);
2975 const FunctionInfo& FI) {
2976 for (LexicalBlock *
Block : Blocks)
2977 emitLexicalBlock(*
Block, FI);
2982void CodeViewDebug::emitLexicalBlock(
const LexicalBlock &
Block,
2983 const FunctionInfo& FI) {
2984 MCSymbol *RecordEnd = beginSymbolRecord(SymbolKind::S_BLOCK32);
2985 OS.AddComment(
"PtrParent");
2987 OS.AddComment(
"PtrEnd");
2989 OS.AddComment(
"Code size");
2990 OS.emitAbsoluteSymbolDiff(
Block.End,
Block.Begin, 4);
2991 OS.AddComment(
"Function section relative address");
2992 OS.emitCOFFSecRel32(
Block.Begin, 0);
2993 OS.AddComment(
"Function section index");
2994 OS.emitCOFFSectionIndex(FI.Begin);
2995 OS.AddComment(
"Lexical block name");
2997 endSymbolRecord(RecordEnd);
3000 emitLocalVariableList(FI,
Block.Locals);
3001 emitGlobalVariableList(
Block.Globals);
3004 emitLexicalBlockList(
Block.Children, FI);
3007 emitEndSymbolRecord(SymbolKind::S_END);
3012void CodeViewDebug::collectLexicalBlockInfo(
3017 for (LexicalScope *Scope : Scopes)
3018 collectLexicalBlockInfo(*Scope, Blocks, Locals, Globals);
3023void CodeViewDebug::collectLexicalBlockInfo(
3028 if (
Scope.isAbstractScope())
3033 bool IgnoreScope =
false;
3034 auto LI = ScopeVariables.find(&Scope);
3035 SmallVectorImpl<LocalVariable> *
Locals =
3036 LI != ScopeVariables.end() ? &LI->second :
nullptr;
3037 auto GI = ScopeGlobals.find(
Scope.getScopeNode());
3038 SmallVectorImpl<CVGlobalVariable> *Globals =
3039 GI != ScopeGlobals.
end() ? GI->second.get() :
nullptr;
3041 const SmallVectorImpl<InsnRange> &
Ranges =
Scope.getRanges();
3044 if (!Locals && !Globals)
3074 collectLexicalBlockInfo(
Scope.getChildren(),
3084 auto BlockInsertion = CurFn->LexicalBlocks.try_emplace(DILB);
3085 if (!BlockInsertion.second)
3092 LexicalBlock &
Block = BlockInsertion.first->second;
3095 assert(
Block.Begin &&
"missing label for scope begin");
3096 assert(
Block.End &&
"missing label for scope end");
3099 Block.Locals = std::move(*Locals);
3101 Block.Globals = std::move(*Globals);
3103 collectLexicalBlockInfo(
Scope.getChildren(),
3111 assert(FnDebugInfo.count(&GV));
3112 assert(CurFn == FnDebugInfo[&GV].
get());
3118 collectLexicalBlockInfo(*CFS,
3126 ScopeVariables.clear();
3130 if (!CurFn->HaveLineInfo && !GV.
getSubprogram()->isThunk()) {
3131 FnDebugInfo.erase(&GV);
3137 for (
const auto &
MBB : *MF) {
3138 for (
const auto &
MI :
MBB) {
3139 if (
MDNode *MD =
MI.getHeapAllocMarker()) {
3147 bool isThumb =
MMI->getModule()->getTargetTriple().getArch() ==
3149 collectDebugInfoForJumpTables(MF,
isThumb);
3153 CurFn->End =
Asm->getFunctionEnd();
3170 if (
DL.getLine() != 0)
3173 return Scope->getSubprogram()->isArtificial();
3181 if (!
Asm || !CurFn ||
MI->isDebugInstr() ||
3189 for (
const auto &NextMI : *
MI->getParent()) {
3190 if (NextMI.isDebugInstr())
3192 DL = NextMI.getDebugLoc();
3205 maybeRecordLocation(
DL,
Asm->MF);
3218void CodeViewDebug::endCVSubsection(
MCSymbol *EndLabel) {
3225 MCSymbol *BeginLabel =
MMI->getContext().createTempSymbol(),
3226 *EndLabel =
MMI->getContext().createTempSymbol();
3227 OS.AddComment(
"Record length");
3228 OS.emitAbsoluteSymbolDiff(EndLabel, BeginLabel, 2);
3229 OS.emitLabel(BeginLabel);
3230 if (OS.isVerboseAsm())
3232 OS.emitInt16(
unsigned(SymKind));
3236void CodeViewDebug::endSymbolRecord(
MCSymbol *SymEnd) {
3241 OS.emitValueToAlignment(
Align(4));
3242 OS.emitLabel(SymEnd);
3245void CodeViewDebug::emitEndSymbolRecord(
SymbolKind EndKind) {
3246 OS.AddComment(
"Record length");
3248 if (OS.isVerboseAsm())
3250 OS.emitInt16(uint16_t(EndKind));
3253void CodeViewDebug::emitDebugInfoForUDTs(
3254 const std::vector<std::pair<std::string, const DIType *>> &UDTs) {
3256 size_t OriginalSize = UDTs.size();
3258 for (
const auto &UDT : UDTs) {
3259 const DIType *
T =
UDT.second;
3261 MCSymbol *UDTRecordEnd = beginSymbolRecord(SymbolKind::S_UDT);
3262 OS.AddComment(
"Type");
3263 OS.emitInt32(getCompleteTypeIndex(
T).getIndex());
3264 assert(OriginalSize == UDTs.size() &&
3265 "getCompleteTypeIndex found new UDTs!");
3267 endSymbolRecord(UDTRecordEnd);
3271void CodeViewDebug::collectGlobalOrStaticLocalVariableInfo(
3273 const DIGlobalVariable *DIGV = GVE->
getVariable();
3283 (DIE->
getElement(0) == dwarf::DW_OP_plus_uconst))
3288 CVGlobalVariableOffsets.insert(std::make_pair(DIGV, DIE->
getElement(1)));
3291 if (!GlobalMap.count(GVE) && DIE->
isConstant())
3292 GlobalVariables.emplace_back(CVGlobalVariable{DIGV, DIE});
3294 const auto *GV = GlobalMap.lookup(GVE);
3299 SmallVector<CVGlobalVariable, 1> *VariableList;
3304 ScopeGlobals.insert({
Scope, std::unique_ptr<GlobalVariableList>()});
3305 if (Insertion.second)
3306 Insertion.first->second = std::make_unique<GlobalVariableList>();
3307 VariableList = Insertion.first->second.get();
3310 VariableList = &ComdatVariables;
3313 VariableList = &GlobalVariables;
3315 VariableList->
emplace_back(CVGlobalVariable{DIGV, GV});
3318void CodeViewDebug::collectGlobalVariableInfo() {
3319 for (
const GlobalVariable &GV :
MMI->getModule()->globals()) {
3321 GV.getDebugInfo(GVEs);
3322 for (
const auto *GVE : GVEs)
3323 GlobalMap[GVE] = &GV;
3326 NamedMDNode *CUs =
MMI->getModule()->getNamedMetadata(
"llvm.dbg.cu");
3327 for (
const MDNode *Node : CUs->
operands()) {
3329 for (
const auto *GVE : CU->getGlobalVariables()) {
3330 collectGlobalOrStaticLocalVariableInfo(GVE);
3335void CodeViewDebug::collectDebugInfoForGlobals() {
3336 for (
const CVGlobalVariable &CVGV : GlobalVariables) {
3337 const DIGlobalVariable *DIGV = CVGV.DIGV;
3339 getCompleteTypeIndex(DIGV->
getType());
3340 getFullyQualifiedName(Scope, DIGV->
getName());
3343 for (
const CVGlobalVariable &CVGV : ComdatVariables) {
3344 const DIGlobalVariable *DIGV = CVGV.DIGV;
3346 getCompleteTypeIndex(DIGV->
getType());
3347 getFullyQualifiedName(Scope, DIGV->
getName());
3351void CodeViewDebug::emitDebugInfoForGlobals() {
3355 switchToDebugSectionForSymbol(
nullptr);
3356 if (!GlobalVariables.empty() || !StaticConstMembers.empty()) {
3357 OS.AddComment(
"Symbol subsection for globals");
3358 MCSymbol *EndLabel = beginCVSubsection(DebugSubsectionKind::Symbols);
3359 emitGlobalVariableList(GlobalVariables);
3360 emitStaticConstMemberList();
3361 endCVSubsection(EndLabel);
3366 for (
const CVGlobalVariable &CVGV : ComdatVariables) {
3369 OS.AddComment(
"Symbol subsection for " +
3371 switchToDebugSectionForSymbol(GVSym);
3372 MCSymbol *EndLabel = beginCVSubsection(DebugSubsectionKind::Symbols);
3374 emitDebugInfoForGlobal(CVGV);
3375 endCVSubsection(EndLabel);
3379void CodeViewDebug::emitDebugInfoForRetainedTypes() {
3380 NamedMDNode *CUs =
MMI->getModule()->getNamedMetadata(
"llvm.dbg.cu");
3381 for (
const MDNode *Node : CUs->
operands()) {
3393 for (
const CVGlobalVariable &CVGV : Globals) {
3395 emitDebugInfoForGlobal(CVGV);
3400 const std::string &QualifiedName) {
3401 MCSymbol *SConstantEnd = beginSymbolRecord(SymbolKind::S_CONSTANT);
3402 OS.AddComment(
"Type");
3403 OS.emitInt32(getTypeIndex(DTy).getIndex());
3405 OS.AddComment(
"Value");
3410 CodeViewRecordIO IO(Writer);
3412 StringRef SRef((
char *)
Data, Writer.getOffset());
3413 OS.emitBinaryData(SRef);
3415 OS.AddComment(
"Name");
3417 endSymbolRecord(SConstantEnd);
3420void CodeViewDebug::emitStaticConstMemberList() {
3421 for (
const DIDerivedType *DTy : StaticConstMembers) {
3425 if (
const ConstantInt *CI =
3429 else if (
const ConstantFP *CFP =
3431 Value =
APSInt(CFP->getValueAPF().bitcastToAPInt(),
true);
3435 emitConstantSymbolRecord(DTy->getBaseType(),
Value,
3436 getFullyQualifiedName(Scope, DTy->
getName()));
3446 if (
T == dwarf::DW_TAG_pointer_type ||
3447 T == dwarf::DW_TAG_ptr_to_member_type ||
3448 T == dwarf::DW_TAG_reference_type ||
3449 T == dwarf::DW_TAG_rvalue_reference_type)
3451 assert(DTy->getBaseType() &&
"Expected valid base type");
3456 return (BTy->getEncoding() == dwarf::DW_ATE_float);
3459void CodeViewDebug::emitDebugInfoForGlobal(
const CVGlobalVariable &CVGV) {
3460 const DIGlobalVariable *DIGV = CVGV.DIGV;
3466 Scope = MemberDecl->getScope();
3472 ? std::string(DIGV->
getName())
3475 if (
const GlobalVariable *GV =
3479 MCSymbol *GVSym = Asm->getSymbol(GV);
3480 SymbolKind DataSym = GV->isThreadLocal()
3481 ? (DIGV->isLocalToUnit() ? SymbolKind::S_LTHREAD32
3482 : SymbolKind::S_GTHREAD32)
3483 : (DIGV->isLocalToUnit() ? SymbolKind::S_LDATA32
3484 : SymbolKind::S_GDATA32);
3485 MCSymbol *DataEnd = beginSymbolRecord(DataSym);
3486 OS.AddComment(
"Type");
3487 OS.emitInt32(getCompleteTypeIndex(DIGV->getType()).getIndex());
3488 OS.AddComment(
"DataOffset");
3491 uint64_t Offset = CVGlobalVariableOffsets.lookup(DIGV);
3492 OS.emitCOFFSecRel32(GVSym, Offset);
3494 OS.AddComment(
"Segment");
3495 OS.emitCOFFSectionIndex(GVSym);
3496 OS.AddComment(
"Name");
3497 const unsigned LengthOfDataRecord = 12;
3498 emitNullTerminatedSymbolName(OS, QualifiedName, LengthOfDataRecord);
3499 endSymbolRecord(DataEnd);
3501 const DIExpression *DIE = cast<const DIExpression *>(CVGV.GVInfo);
3502 assert(DIE->isConstant() &&
3503 "Global constant variables must contain a constant expression.");
3506 bool isUnsigned = isFloatDIType(DIGV->getType())
3508 : DebugHandlerBase::isUnsignedDIType(DIGV->getType());
3509 APSInt Value(APInt(64, DIE->getConstantValue()), isUnsigned);
3510 emitConstantSymbolRecord(DIGV->getType(), Value, QualifiedName);
3517 int64_t)> &Callback) {
3519 if (JTI && !JTI->isEmpty()) {
3523 for (
const auto &
MBB : *MF) {
3525 const auto LastMI =
MBB.getFirstTerminator();
3526 if (LastMI !=
MBB.end() && LastMI->isIndirectBranch()) {
3534 for (
const auto &MO : LastMI->operands()) {
3536 unsigned Index = MO.getIndex();
3540 Callback(*JTI, *LastMI, Index);
3548 for (
auto I =
MBB.instr_rbegin(),
E =
MBB.instr_rend();
I !=
E; ++
I) {
3549 if (
I->isJumpTableDebugInfo()) {
3550 unsigned Index =
I->getOperand(0).getImm();
3554 Callback(*JTI, *LastMI, Index);
3563 "Some of jump tables were not used in a debug info instruction");
3568void CodeViewDebug::discoverJumpTableBranches(
const MachineFunction *MF,
3572 [
this](
const MachineJumpTableInfo &,
const MachineInstr &BranchMI,
3576void CodeViewDebug::collectDebugInfoForJumpTables(
const MachineFunction *MF,
3580 [
this, MF](
const MachineJumpTableInfo &JTI,
const MachineInstr &BranchMI,
3581 int64_t JumpTableIndex) {
3594 "EK_Custom32, EK_GPRel32BlockAddress, and "
3595 "EK_GPRel64BlockAddress should never be emitted for COFF");
3598 EntrySize = JumpTableEntrySize::Pointer;
3605 std::tie(
Base, BaseOffset, Branch, EntrySize) =
3606 Asm->getCodeViewJumpTableInfo(JumpTableIndex, &BranchMI, Branch);
3610 const MachineJumpTableEntry &JTE = JTI.
getJumpTables()[JumpTableIndex];
3611 JumpTableInfo CVJTI{EntrySize,
3618 for (
const auto &
MBB : JTE.
MBBs)
3620 CurFn->JumpTables.push_back(std::move(CVJTI));
3624void CodeViewDebug::emitDebugInfoForJumpTables(
const FunctionInfo &FI) {
3626 for (
const auto &JumpTable : FI.JumpTables) {
3627 for (
const auto &CaseSym :
JumpTable.Cases) {
3628 MCSymbol *LabelEnd = beginSymbolRecord(SymbolKind::S_LABEL32);
3629 OS.AddComment(
"Offset and segment");
3630 OS.emitCOFFSecRel32(CaseSym, 0);
3631 OS.AddComment(
"Flags");
3634 endSymbolRecord(LabelEnd);
3638 for (
const auto &JumpTable : FI.JumpTables) {
3639 MCSymbol *JumpTableEnd = beginSymbolRecord(SymbolKind::S_ARMSWITCHTABLE);
3641 OS.AddComment(
"Base offset");
3643 OS.AddComment(
"Base section index");
3644 OS.emitCOFFSectionIndex(
JumpTable.Base);
3646 OS.AddComment(
"Base offset");
3648 OS.AddComment(
"Base section index");
3651 OS.AddComment(
"Switch type");
3652 OS.emitInt16(
static_cast<uint16_t
>(
JumpTable.EntrySize));
3653 OS.AddComment(
"Branch offset");
3654 OS.emitCOFFSecRel32(
JumpTable.Branch, 0);
3655 OS.AddComment(
"Table offset");
3656 OS.emitCOFFSecRel32(
JumpTable.Table, 0);
3657 OS.AddComment(
"Branch section index");
3658 OS.emitCOFFSectionIndex(
JumpTable.Branch);
3659 OS.AddComment(
"Table section index");
3660 OS.emitCOFFSectionIndex(
JumpTable.Table);
3661 OS.AddComment(
"Entries count");
3663 endSymbolRecord(JumpTableEnd);
3667void CodeViewDebug::emitInlinees(
3671 constexpr size_t ChunkSize =
3678 size_t CurrentIndex = 0;
3679 while (CurrentIndex < SortedInlinees.
size()) {
3680 auto Symbol = beginSymbolRecord(SymbolKind::S_INLINEES);
3681 auto CurrentChunkSize =
3682 std::min(ChunkSize, SortedInlinees.
size() - CurrentIndex);
3683 OS.AddComment(
"Count");
3684 OS.emitInt32(CurrentChunkSize);
3686 const size_t CurrentChunkEnd = CurrentIndex + CurrentChunkSize;
3687 for (; CurrentIndex < CurrentChunkEnd; ++CurrentIndex) {
3688 OS.AddComment(
"Inlinee");
3689 OS.emitInt32(SortedInlinees[CurrentIndex].getIndex());
3691 endSymbolRecord(Symbol);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file implements the APSInt class, which is a simple class that represents an arbitrary sized int...
static bool isThumb(const MCSubtargetInfo &STI)
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static MethodKind translateMethodKindFlags(const DISubprogram *SP, bool Introduced)
static bool isUsableDebugLoc(DebugLoc DL)
static TypeIndex getStringIdTypeIdx(GlobalTypeTableBuilder &TypeTable, StringRef S)
static CPUType mapArchToCVCPUType(Triple::ArchType Type)
static void emitNullTerminatedSymbolName(MCStreamer &OS, StringRef S, unsigned MaxFixedRecordLength=0xF00)
static Version parseVersion(StringRef Name)
static MethodOptions translateMethodOptionFlags(const DISubprogram *SP)
static bool isNonTrivial(const DICompositeType *DCTy)
static std::string formatNestedName(ArrayRef< StringRef > QualifiedNameComponents, StringRef TypeName)
static ClassOptions getCommonClassOptions(const DICompositeType *Ty)
Return ClassOptions that should be present on both the forward declaration and the defintion of a tag...
static cl::opt< bool > UseTagRecord2("use-codeview-tagrecord2", cl::Hidden, cl::desc("Use the *2 versions for tag records in CodeView (LF_CLASS2, etc.)"), cl::init(false))
static PointerToMemberRepresentation translatePtrToMemberRep(unsigned SizeInBytes, bool IsPMF, unsigned Flags)
static FunctionOptions getFunctionOptions(const DISubroutineType *Ty, const DICompositeType *ClassTy=nullptr, StringRef SPName=StringRef(""))
static StringRef removeTemplateArgs(StringRef Name)
static TypeRecordKind getRecordKind(const DICompositeType *Ty)
void forEachJumpTableBranch(const MachineFunction *MF, bool isThumb, const std::function< void(const MachineJumpTableInfo &, const MachineInstr &, int64_t)> &Callback)
static CallingConvention dwarfCCToCodeView(unsigned DwarfCC)
Given a DWARF calling convention, get the CodeView equivalent.
static SourceLanguage MapDWARFLanguageToCVLang(dwarf::SourceLanguageName DWLName)
static bool isFloatDIType(const DIType *Ty)
static void addLocIfNotPresent(SmallVectorImpl< const DILocation * > &Locs, const DILocation *Loc)
static bool shouldEmitUdt(const DIType *T)
static StringRef getPrettyScopeName(const DIScope *Scope)
static bool shouldAlwaysEmitCompleteClassType(const DICompositeType *Ty)
static MemberAccess translateAccessFlags(unsigned RecordTag, unsigned Flags)
This file contains the declarations for the subclasses of Constant, which represent the different fla...
This file contains constants used for implementing Dwarf debug support.
Module.h This file contains the declarations for the Module class.
Register const TargetRegisterInfo * TRI
Promote Memory to Register
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
static constexpr StringLiteral Filename
static StringRef getName(Value *V)
static cl::opt< RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode > Mode("regalloc-enable-advisor", cl::Hidden, cl::init(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default), cl::desc("Enable regalloc advisor mode"), cl::values(clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default, "default", "Default"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Release, "release", "precompiled"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Development, "development", "for training")))
This file implements the SmallBitVector class.
This file defines the SmallString class.
This file describes how to lower LLVM code to machine code.
static const uint32_t IV[8]
An arbitrary precision integer that knows its signedness.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
Get the array size.
This class is intended to be used as a driving class for all asm writers.
CodeViewDebug(AsmPrinter *AP)
void beginModule(Module *M) override
bool moduleIsInFortran()
Check if the current module is in Fortran.
void endFunctionImpl(const MachineFunction *) override
Gather post-function debug information.
void endModule() override
Emit the COFF section that holds the line table information.
void beginInstruction(const MachineInstr *MI) override
Process beginning of an instruction.
void beginFunctionImpl(const MachineFunction *MF) override
Gather pre-function debug information.
This is the shared class of boolean and integer constants.
bool isZero() const
This is just a convenience method to make client code smaller for a common code.
Basic type, like 'int' or 'float'.
unsigned getEncoding() const
StringRef getIdentifier() const
DINodeArray getElements() const
DIType * getBaseType() const
LLVM_ABI DIType * getClassType() const
Get casted version of extra data.
LLVM_ABI Constant * getConstant() const
unsigned getNumElements() const
uint64_t getElement(unsigned I) const
static LLVM_ABI bool extractLeadingOffset(ArrayRef< uint64_t > Ops, int64_t &OffsetInBytes, SmallVectorImpl< uint64_t > &RemainingOps)
LLVM_ABI std::optional< SignedOrUnsignedConstant > isConstant() const
Determine whether this represents a constant value, if so.
A pair of DIGlobalVariable and DIExpression.
DIGlobalVariable * getVariable() const
DIExpression * getExpression() const
Metadata * getRawStaticDataMemberDeclaration() const
DILocalScope * getScope() const
Get the local scope for this variable.
Tagged DWARF-like metadata node.
LLVM_ABI dwarf::Tag getTag() const
Base class for scope-like contexts.
StringRef getFilename() const
LLVM_ABI StringRef getName() const
StringRef getDirectory() const
LLVM_ABI DIScope * getScope() 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.
String type, Fortran CHARACTER(n)
Subprogram description. Uses SubclassData1.
Type array for a subprogram.
DITypeArray getTypeArray() const
uint64_t getOffsetInBits() const
bool isObjectPointer() const
StringRef getName() const
bool isForwardDecl() const
uint64_t getSizeInBits() const
DIScope * getScope() const
DIScope * getScope() const
StringRef getName() const
SmallVector< Entry, 4 > Entries
static const EntryIndex NoEntry
Special value to indicate that an entry is valid until the end of the function.
static bool isUnsignedDIType(const DIType *Ty)
Return true if type encoding is unsigned.
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.
void requestLabelBeforeInsn(const MachineInstr *MI)
Ensure that a label will be emitted before MI.
const MachineInstr * PrologEndLoc
This location indicates end of function prologue and beginning of function body.
static uint64_t getBaseTypeSize(const DIType *Ty)
If this type is derived from a base type then return base type size.
Implements a dense probed hash-table based set.
bool isNoInline() const
Determine if this function should not be inlined.
bool hasOptSize() const
Optimize this function for size (-Os) or minimum size (-Oz).
bool hasStackProtectorFnAttr() const
Returns true if the function has ssp, sspstrong, or sspreq fn attrs.
DISubprogram * getSubprogram() const
Get the attached subprogram.
bool hasPersonalityFn() const
Check whether this function has a personality function.
Constant * getPersonalityFn() const
Get the personality function associated with this function.
bool hasOptNone() const
Do not optimize this function (-O0).
bool hasProfileData() const
Return true if the function is annotated with profile data.
Function::iterator insert(Function::iterator Position, BasicBlock *BB)
Insert BB in the basic block list at Position.
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
bool hasLocalLinkage() const
static StringRef dropLLVMManglingEscape(StringRef Name)
If the given string begins with the GlobalValue name mangling escape character '\1',...
bool isDeclarationForLinker() const
This class is used to track scope information.
LLVM_ABI MCSymbol * createTempSymbol()
Create a temporary symbol with a unique name.
MCSymbol * getCOMDATSymbol() const
Streaming machine code generation interface.
virtual void AddComment(const Twine &T, bool EOL=true)
Add a textual comment.
virtual void emitAbsoluteSymbolDiff(const MCSymbol *Hi, const MCSymbol *Lo, unsigned Size)
Emit the absolute difference between two symbols.
virtual void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current section.
virtual void emitValueToAlignment(Align Alignment, int64_t Fill=0, uint8_t FillLen=1, unsigned MaxBytesToEmit=0)
Emit some number of copies of Value until the byte alignment ByteAlignment is reached.
void emitInt32(uint64_t Value)
virtual void emitBytes(StringRef Data)
Emit the bytes in Data into the output.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
MCSection & getSection() const
Get the section associated with a defined, non-absolute symbol.
ArrayRef< MDOperand > operands() const
unsigned getNumOperands() const
Return number of MDNode operands.
LLVM_ABI MCSymbol * getSymbol() const
Return the MCSymbol for this basic block.
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
bool hasVarSizedObjects() const
This method may be called any time after instruction selection is complete to determine if the stack ...
uint64_t getStackSize() const
Return the number of bytes that must be allocated to hold all of the fixed size frame objects.
int64_t getOffsetAdjustment() const
Return the correction for frame offsets.
unsigned getCVBytesOfCalleeSavedRegisters() const
Returns how many bytes of callee-saved registers the target pushed in the prologue.
bool hasStackProtectorIndex() const
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
bool hasInlineAsm() const
Returns true if the function contains any inline assembly.
bool exposesReturnsTwice() const
exposesReturnsTwice - Returns true if the function calls setjmp or any other similar functions with a...
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
MCSymbol * getJTISymbol(unsigned JTI, MCContext &Ctx, bool isLinkerPrivate=false) const
getJTISymbol - Return the MCSymbol for the specified non-empty jump table.
auto getInStackSlotVariableDbgInfo()
Returns the collection of variables for which we have debug info and that have been assigned a stack ...
Function & getFunction()
Return the LLVM function that this machine code represents.
const MachineJumpTableInfo * getJumpTableInfo() const
getJumpTableInfo - Return the jump table info object for the current function.
ArrayRef< std::pair< MCSymbol *, MDNode * > > getCodeViewAnnotations() const
Representation of each machine instruction.
bool isDebugValue() const
MachineOperand & getDebugOperand(unsigned Index)
@ EK_GPRel32BlockAddress
EK_GPRel32BlockAddress - Each entry is an address of block, encoded with a relocation as gp-relative,...
@ EK_Inline
EK_Inline - Jump table entries are emitted inline at their point of use.
@ EK_LabelDifference32
EK_LabelDifference32 - Each entry is the address of the block minus the address of the jump table.
@ EK_Custom32
EK_Custom32 - Each entry is a 32-bit value that is custom lowered by the TargetLowering::LowerCustomJ...
@ EK_LabelDifference64
EK_LabelDifference64 - Each entry is the address of the block minus the address of the jump table.
@ EK_BlockAddress
EK_BlockAddress - Each entry is a plain address of block, e.g.: .word LBB123.
@ EK_GPRel64BlockAddress
EK_GPRel64BlockAddress - Each entry is an address of block, encoded with a relocation as gp-relative,...
JTEntryKind getEntryKind() const
const std::vector< MachineJumpTableEntry > & getJumpTables() const
const MCContext & getContext() const
This class implements a map that also provides access to all stored values in a deterministic order.
A Module instance is used to store all the information related to an LLVM module.
iterator_range< op_iterator > operands()
This is a 'bitvector' (really, a variable-sized bit array), optimized for the case when the array is ...
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
const_iterator begin() const
const_iterator end() const
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...
reference emplace_back(ArgTypes &&... Args)
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
void push_back(const T &Elt)
LLVM_NO_SANITIZE_CFI_UNRELATED_CAST iterator begin()
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
static StackOffset getScalable(int64_t Scalable)
static StackOffset getFixed(int64_t Fixed)
Represent a constant reference to a string, i.e.
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
constexpr bool empty() const
Check if the string is empty.
char back() const
Get the last character in the string.
StringRef take_front(size_t N=1) const
Return a StringRef equal to 'this' but with only the first N elements remaining.
bool hasFP(const MachineFunction &MF) const
hasFP - Return true if the specified function should have a dedicated frame pointer register.
virtual StackOffset getFrameIndexReference(const MachineFunction &MF, int FI, Register &FrameReg) const
getFrameIndexReference - This method should return the base register and offset used to reference a f...
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
TargetSubtargetInfo - Generic base class for all target subtargets.
virtual const TargetFrameLowering * getFrameLowering() const
virtual const TargetRegisterInfo * getRegisterInfo() const =0
Return the target's register information.
TinyPtrVector - This class is specialized for cases where there are normally 0 or 1 element in a vect...
The instances of the Type class are immutable: once they are created, they are never changed.
LLVM Value Representation.
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
@ CurrentDirectory
Absolute CWD path.
@ SourceFile
Path to main source file, relative or absolute.
@ BuildTool
Absolute compiler path.
@ CommandLine
Full canonical command line (maybe -cc1)
@ TypeServerPDB
Absolute path of type server PDB (/Fd)
LLVM_ABI void begin(ContinuationRecordKind RecordKind)
void writeMemberType(RecordType &Record)
TypeIndex writeLeafType(T &Record)
SimpleTypeKind getSimpleKind() const
SimpleTypeMode getSimpleMode() const
static const uint32_t FirstNonSimpleIndex
static LLVM_ABI StringRef simpleTypeName(TypeIndex TI)
uint32_t getIndex() const
static TypeIndex NullptrT()
void addCallbackToPipeline(TypeVisitorCallbacks &Callbacks)
std::pair< iterator, bool > insert(const ValueT &V)
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
constexpr char TypeName[]
Key for Kernel::Arg::Metadata::mTypeName.
@ DEBUG_HASHES_SECTION_MAGIC
initializer< Ty > init(const Ty &Val)
PointerMode
Equivalent to CV_ptrmode_e.
ProcSymFlags
Corresponds to the CV_PROCFLAGS bitfield.
PointerOptions
Equivalent to misc lfPointerAttr bitfields.
LocalSymFlags
Corresponds to CV_LVARFLAGS bitfield.
MethodKind
Part of member attribute flags. (CV_methodprop_e)
CVRecord< TypeLeafKind > CVType
PointerKind
Equivalent to CV_ptrtype_e.
CPUType
These values correspond to the CV_CPU_TYPE_e enumeration, and are documented here: https://msdn....
PointerToMemberRepresentation
Equivalent to CV_pmtype_e.
@ MultipleInheritanceData
@ SingleInheritanceFunction
@ VirtualInheritanceFunction
@ MultipleInheritanceFunction
CallingConvention
These values correspond to the CV_call_e enumeration, and are documented at the following locations: ...
MethodOptions
Equivalent to CV_fldattr_t bitfield.
MemberAccess
Source-level access specifier. (CV_access_e)
ThunkOrdinal
These values correspond to the THUNK_ORDINAL enumeration.
LLVM_ABI EnumStrings< SymbolKind, 1 > getSymbolTypeNames()
EncodedFramePtrReg
Two-bit value indicating which register is the designated frame pointer register.
TypeRecordKind
Distinguishes individual records in .debug$T or .debug$P section or PDB type stream.
SymbolKind
Duplicate copy of the above enum, but using the official CV names.
ModifierOptions
Equivalent to CV_modifier_t.
@ ProfileGuidedOptimization
@ HasStructuredExceptionHandling
LLVM_ABI EncodedFramePtrReg encodeFramePtrReg(RegisterId Reg, CPUType CPU)
LLVM_ABI Error visitTypeRecord(CVType &Record, TypeIndex Index, TypeVisitorCallbacks &Callbacks, VisitorDataSource Source=VDS_BytesPresent)
SourceLanguage
These values correspond to the CV_CFL_LANG enumeration in the Microsoft Debug Interface Access SDK,...
std::optional< std::pair< SourceLanguageName, uint32_t > > toDW_LNAME(SourceLanguage language)
Convert a DWARF 5 DW_LANG to a DWARF 6 pair of language name and version.
ElementType
The element type of an SRV or UAV resource.
Scope
Defines the scope in which this symbol should be visible: Default – Visible in the public interface o...
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > extract_or_null(Y &&MD)
Extract a Value from Metadata, allowing null.
NodeAddr< NodeBase * > Node
LLVM_ABI bool is_absolute(const Twine &path, Style style=Style::native)
Is path absolute?
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI void logAllUnhandledErrors(Error E, raw_ostream &OS, Twine ErrorBanner={})
Log all errors (if any) in E to OS.
std::string fromHex(StringRef Input)
Convert hexadecimal string Input to its binary representation. The return string is half the size of ...
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
auto dyn_cast_if_present(const Y &Val)
dyn_cast_if_present<X> - Functionally identical to dyn_cast, except that a null (or none in the case ...
std::tuple< uint64_t, uint32_t > InlineSite
LLVM_GET_TYPE_NAME_CONSTEXPR StringRef getTypeName()
We provide a function which tries to compute the (demangled) name of a type statically.
std::pair< const MachineInstr *, const MachineInstr * > InsnRange
This is used to track range of instructions with identical lexical scope.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
auto dyn_cast_or_null(const Y &Val)
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
auto reverse(ContainerTy &&C)
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
void sort(IteratorTy Start, IteratorTy End)
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
LLVM_ABI EHPersonality classifyEHPersonality(const Value *Pers)
See if the given exception handling personality function is one that we understand.
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...
@ Success
The lock was released successfully.
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
void replace(R &&Range, const T &OldValue, const T &NewValue)
Provide wrappers to std::replace which take ranges instead of having to pass begin/end explicitly.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Count
DWARFExpression::Operation Op
ArrayRef(const T &OneElt) -> ArrayRef< T >
bool isAsynchronousEHPersonality(EHPersonality Pers)
Returns true if this personality function catches asynchronous exceptions.
std::string toString(const APInt &I, unsigned Radix, bool Signed, bool formatAsCLiteral=false, bool UpperCase=true, bool InsertSeparators=false)
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.
@ End
Run the machine verifier once, at the end of the pipeline.
StringRef toStringRef(bool B)
Construct a string ref from a boolean.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
TypeLoweringScope(CodeViewDebug &CVD)
This struct is a compact representation of a valid (non-zero power of two) alignment.
const DIDerivedType * MemberTypeNode
std::vector< MemberInfo > MemberList
MemberList Members
Direct members.
std::vector< const DIType * > NestedTypes
MapVector< MDString *, MethodsList > MethodsMap
std::vector< const DIDerivedType * > Inheritance
Base classes.
TinyPtrVector< const DISubprogram * > MethodsList
int InMemory
Indicates that variable data is stored in memory relative to the specified register.
uint32_t CVRegister
Register containing the data or the register base of the memory location containing the data.
static constexpr int32_t NoDeref
Value for DerefOffset indicating this is not an indirect load.
static LLVM_ABI std::optional< DbgVariableLocation > extractFromMachineInstruction(const MachineInstr &Instruction)
Extract a VariableLocation from a MachineInstr.
std::vector< MachineBasicBlock * > MBBs
MBBs - The vector of basic blocks from which to create the jump table.