41 #include "llvm/Config/llvm-config.h" 102 : OS(&OS), TypeTable(TypeTable) {}
104 void EmitBytes(
StringRef Data) { OS->EmitBytes(Data); }
106 void EmitIntValue(uint64_t
Value,
unsigned Size) {
107 OS->EmitIntValueInHex(Value, Size);
110 void EmitBinaryData(
StringRef Data) { OS->EmitBinaryData(Data); }
112 void AddComment(
const Twine &
T) { OS->AddComment(T); }
114 void AddRawComment(
const Twine &T) { OS->emitRawComment(T); }
116 bool isVerboseAsm() {
return OS->isVerboseAsm(); }
124 TypeName = TypeTable.getTypeName(TI);
137 case Triple::ArchType::x86:
139 case Triple::ArchType::x86_64:
141 case Triple::ArchType::thumb:
143 case Triple::ArchType::aarch64:
166 collectGlobalVariableInfo();
169 ConstantInt *GH = mdconst::extract_or_null<ConstantInt>(
171 EmitDebugGlobalHashes = GH && !GH->
isZero();
175 std::string &Filepath = FileToFilepathMap[
File];
176 if (!Filepath.empty())
183 if (Dir.
startswith(
"/") || Filename.startswith(
"/")) {
187 if (Dir.
back() !=
'/')
189 Filepath += Filename;
197 if (Filename.find(
':') == 1)
200 Filepath = (Dir +
"\\" + Filename).str();
205 std::replace(Filepath.begin(), Filepath.end(),
'/',
'\\');
209 while ((Cursor = Filepath.find(
"\\.\\", Cursor)) != std::string::npos)
210 Filepath.erase(Cursor, 2);
215 while ((Cursor = Filepath.find(
"\\..\\", Cursor)) != std::string::npos) {
220 size_t PrevSlash = Filepath.rfind(
'\\', Cursor - 1);
221 if (PrevSlash == std::string::npos)
225 Filepath.erase(PrevSlash, Cursor + 3 - PrevSlash);
232 while ((Cursor = Filepath.find(
"\\\\", Cursor)) != std::string::npos)
233 Filepath.erase(Cursor, 1);
238 unsigned CodeViewDebug::maybeRecordFile(
const DIFile *
F) {
240 unsigned NextId = FileIdMap.size() + 1;
241 auto Insertion = FileIdMap.insert(std::make_pair(FullPath, NextId));
242 if (Insertion.second) {
246 if (F->getChecksum()) {
247 std::string Checksum =
fromHex(F->getChecksum()->Value);
249 memcpy(CKMem, Checksum.data(), Checksum.size());
251 reinterpret_cast<const uint8_t *
>(CKMem), Checksum.size());
252 switch (F->getChecksum()->Kind) {
258 static_cast<unsigned>(CSKind));
260 assert(Success &&
".cv_file directive failed");
262 return Insertion.first->second;
265 CodeViewDebug::InlineSite &
266 CodeViewDebug::getInlineSite(
const DILocation *InlinedAt,
268 auto SiteInsertion = CurFn->InlineSites.insert({InlinedAt, InlineSite()});
269 InlineSite *Site = &SiteInsertion.first->second;
270 if (SiteInsertion.second) {
271 unsigned ParentFuncId = CurFn->FuncId;
272 if (
const DILocation *OuterIA = InlinedAt->getInlinedAt())
274 getInlineSite(OuterIA, InlinedAt->getScope()->getSubprogram())
277 Site->SiteFuncId = NextFuncId++;
279 Site->SiteFuncId, ParentFuncId, maybeRecordFile(InlinedAt->getFile()),
280 InlinedAt->getLine(), InlinedAt->getColumn(),
SMLoc());
281 Site->Inlinee = Inlinee;
282 InlinedSubprograms.insert(Inlinee);
283 getFuncIdForSubprogram(Inlinee);
290 if (!ScopeName.
empty())
293 switch (Scope->
getTag()) {
294 case dwarf::DW_TAG_enumeration_type:
295 case dwarf::DW_TAG_class_type:
296 case dwarf::DW_TAG_structure_type:
297 case dwarf::DW_TAG_union_type:
298 return "<unnamed-tag>";
299 case dwarf::DW_TAG_namespace:
300 return "`anonymous namespace'";
309 while (Scope !=
nullptr) {
310 if (ClosestSubprogram ==
nullptr)
313 if (!ScopeName.empty())
314 QualifiedNameComponents.
push_back(ScopeName);
317 return ClosestSubprogram;
322 std::string FullyQualifiedName;
325 FullyQualifiedName.append(QualifiedNameComponent);
326 FullyQualifiedName.append(
"::");
328 FullyQualifiedName.append(TypeName);
329 return FullyQualifiedName;
343 if (CVD.TypeEmissionLevel == 1)
344 CVD.emitDeferredCompleteTypes();
345 --CVD.TypeEmissionLevel;
357 if (!Scope || isa<DIFile>(Scope))
360 assert(!isa<DIType>(Scope) &&
"shouldn't make a namespace scope for a type");
363 auto I = TypeIndices.find({
Scope,
nullptr});
364 if (
I != TypeIndices.end())
370 auto TI = TypeTable.writeLeafType(SID);
371 return recordTypeIndexForDINode(Scope, TI);
378 auto I = TypeIndices.find({SP,
nullptr});
379 if (
I != TypeIndices.end())
388 if (
const auto *Class = dyn_cast_or_null<DICompositeType>(Scope)) {
392 TypeIndex ClassType = getTypeIndex(Class);
395 TI = TypeTable.writeLeafType(MFuncId);
398 TypeIndex ParentScope = getScopeIndex(Scope);
400 TI = TypeTable.writeLeafType(FuncId);
403 return recordTypeIndexForDINode(SP, TI);
407 return ((DCTy->
getFlags() & DINode::FlagNonTrivial) == DINode::FlagNonTrivial);
415 const DIType *ReturnTy =
nullptr;
417 if (TypeArray.size())
418 ReturnTy = TypeArray[0];
421 if (
auto *ReturnDCTy = dyn_cast_or_null<DICompositeType>(ReturnTy)) {
423 FO |= FunctionOptions::CxxReturnUdt;
427 if (ClassTy &&
isNonTrivial(ClassTy) && SPName == ClassTy->getName()) {
428 FO |= FunctionOptions::Constructor;
440 if (SP->getDeclaration())
441 SP = SP->getDeclaration();
442 assert(!SP->getDeclaration() &&
"should use declaration as key");
446 auto I = TypeIndices.find({SP, Class});
447 if (I != TypeIndices.end())
453 TypeLoweringScope S(*
this);
454 const bool IsStaticMethod = (SP->getFlags() & DINode::FlagStaticMember) != 0;
458 SP->getType(), Class, SP->getThisAdjustment(), IsStaticMethod, FO);
459 return recordTypeIndexForDINode(SP, TI, Class);
465 auto InsertResult = TypeIndices.insert({{Node, ClassTy}, TI});
467 assert(InsertResult.second &&
"DINode was already assigned a type index");
471 unsigned CodeViewDebug::getPointerSizeInBytes() {
475 void CodeViewDebug::recordLocalVariable(LocalVariable &&Var,
480 InlineSite &Site = getInlineSite(InlinedAt, Inlinee);
481 Site.InlinedLocals.emplace_back(Var);
484 ScopeVariables[
LS].emplace_back(Var);
495 void CodeViewDebug::maybeRecordLocation(
const DebugLoc &DL,
507 if (LI.getStartLine() != DL.
getLine() || LI.isAlwaysStepInto() ||
508 LI.isNeverStepInto())
512 if (CI.getStartColumn() != DL.
getCol())
515 if (!CurFn->HaveLineInfo)
516 CurFn->HaveLineInfo =
true;
519 FileId = CurFn->LastFileId;
521 FileId = CurFn->LastFileId = maybeRecordFile(DL->getFile());
524 unsigned FuncId = CurFn->FuncId;
525 if (
const DILocation *SiteLoc = DL->getInlinedAt()) {
531 getInlineSite(SiteLoc, Loc->getScope()->getSubprogram()).SiteFuncId;
534 bool FirstLoc =
true;
535 while ((SiteLoc = Loc->getInlinedAt())) {
537 getInlineSite(SiteLoc, Loc->getScope()->getSubprogram());
546 OS.EmitCVLocDirective(FuncId, FileId, DL.
getLine(), DL.
getCol(),
548 DL->getFilename(),
SMLoc());
551 void CodeViewDebug::emitCodeViewMagicVersion() {
552 OS.EmitValueToAlignment(4);
553 OS.AddComment(
"Debug section magic");
570 switchToDebugSectionForSymbol(
nullptr);
572 MCSymbol *CompilerInfo = beginCVSubsection(DebugSubsectionKind::Symbols);
573 emitCompilerInformation();
574 endCVSubsection(CompilerInfo);
576 emitInlineeLinesSubsection();
579 for (
auto &
P : FnDebugInfo)
580 if (!
P.first->isDeclarationForLinker())
581 emitDebugInfoForFunction(
P.first, *
P.second);
584 setCurrentSubprogram(
nullptr);
585 emitDebugInfoForGlobals();
588 emitDebugInfoForRetainedTypes();
592 switchToDebugSectionForSymbol(
nullptr);
595 if (!GlobalUDTs.empty()) {
596 MCSymbol *SymbolsEnd = beginCVSubsection(DebugSubsectionKind::Symbols);
597 emitDebugInfoForUDTs(GlobalUDTs);
598 endCVSubsection(SymbolsEnd);
602 OS.AddComment(
"File index to string table offset subsection");
603 OS.EmitCVFileChecksumsDirective();
606 OS.AddComment(
"String table");
607 OS.EmitCVStringTableDirective();
616 emitTypeInformation();
618 if (EmitDebugGlobalHashes)
619 emitTypeGlobalHashes();
626 unsigned MaxFixedRecordLength = 0xF00) {
637 void CodeViewDebug::emitTypeInformation() {
638 if (TypeTable.empty())
643 emitCodeViewMagicVersion();
649 CVMCAdapter CVMCOS(OS, Table);
651 Pipeline.addCallbackToPipeline(typeMapping);
665 B = Table.getNext(*B);
669 void CodeViewDebug::emitTypeGlobalHashes() {
670 if (TypeTable.empty())
677 OS.EmitValueToAlignment(4);
678 OS.AddComment(
"Magic");
680 OS.AddComment(
"Section Version");
681 OS.EmitIntValue(0, 2);
682 OS.AddComment(
"Hash Algorithm");
683 OS.EmitIntValue(
uint16_t(GlobalTypeHashAlg::SHA1_8), 2);
685 TypeIndex TI(TypeIndex::FirstNonSimpleIndex);
686 for (
const auto &GHR : TypeTable.hashes()) {
687 if (OS.isVerboseAsm()) {
693 OS.AddComment(Comment);
696 assert(GHR.Hash.size() == 8);
697 StringRef S(reinterpret_cast<const char *>(GHR.Hash.data()),
699 OS.EmitBinaryData(S);
705 case dwarf::DW_LANG_C:
706 case dwarf::DW_LANG_C89:
707 case dwarf::DW_LANG_C99:
708 case dwarf::DW_LANG_C11:
709 case dwarf::DW_LANG_ObjC:
711 case dwarf::DW_LANG_C_plus_plus:
712 case dwarf::DW_LANG_C_plus_plus_03:
713 case dwarf::DW_LANG_C_plus_plus_11:
714 case dwarf::DW_LANG_C_plus_plus_14:
716 case dwarf::DW_LANG_Fortran77:
717 case dwarf::DW_LANG_Fortran90:
718 case dwarf::DW_LANG_Fortran03:
719 case dwarf::DW_LANG_Fortran08:
721 case dwarf::DW_LANG_Pascal83:
723 case dwarf::DW_LANG_Cobol74:
724 case dwarf::DW_LANG_Cobol85:
726 case dwarf::DW_LANG_Java:
728 case dwarf::DW_LANG_D:
730 case dwarf::DW_LANG_Swift:
751 for (
const char C : Name) {
754 V.Part[
N] +=
C -
'0';
755 }
else if (
C ==
'.') {
765 void CodeViewDebug::emitCompilerInformation() {
766 MCSymbol *CompilerEnd = beginSymbolRecord(SymbolKind::S_COMPILE3);
771 const auto *
CU = cast<DICompileUnit>(Node);
777 OS.AddComment(
"Flags and language");
778 OS.EmitIntValue(Flags, 4);
780 OS.AddComment(
"CPUType");
781 OS.EmitIntValue(static_cast<uint64_t>(TheCPU), 2);
785 OS.AddComment(
"Frontend version");
786 for (
int N = 0;
N < 4; ++
N)
787 OS.EmitIntValue(FrontVer.Part[
N], 2);
792 int Major = 1000 * LLVM_VERSION_MAJOR +
793 10 * LLVM_VERSION_MINOR +
797 Version BackVer = {{ Major, 0, 0, 0 }};
798 OS.AddComment(
"Backend version");
799 for (
int N = 0;
N < 4; ++
N)
800 OS.EmitIntValue(BackVer.Part[
N], 2);
802 OS.AddComment(
"Null-terminated compiler version string");
805 endSymbolRecord(CompilerEnd);
814 void CodeViewDebug::emitBuildInfo() {
825 TypeIndex BuildInfoArgs[BuildInfoRecord::MaxArgs] = {};
828 const auto *
CU = cast<DICompileUnit>(Node);
829 const DIFile *MainSourceFile =
CU->getFile();
830 BuildInfoArgs[BuildInfoRecord::CurrentDirectory] =
832 BuildInfoArgs[BuildInfoRecord::SourceFile] =
837 TypeIndex BuildInfoIndex = TypeTable.writeLeafType(BIR);
841 MCSymbol *BISubsecEnd = beginCVSubsection(DebugSubsectionKind::Symbols);
842 MCSymbol *BIEnd = beginSymbolRecord(SymbolKind::S_BUILDINFO);
843 OS.AddComment(
"LF_BUILDINFO index");
844 OS.EmitIntValue(BuildInfoIndex.
getIndex(), 4);
845 endSymbolRecord(BIEnd);
846 endCVSubsection(BISubsecEnd);
849 void CodeViewDebug::emitInlineeLinesSubsection() {
850 if (InlinedSubprograms.empty())
853 OS.AddComment(
"Inlinee lines subsection");
854 MCSymbol *InlineEnd = beginCVSubsection(DebugSubsectionKind::InlineeLines);
860 OS.AddComment(
"Inlinee lines signature");
861 OS.EmitIntValue(
unsigned(InlineeLinesSignature::Normal), 4);
864 assert(TypeIndices.count({SP, nullptr}));
865 TypeIndex InlineeIdx = TypeIndices[{SP,
nullptr}];
868 unsigned FileId = maybeRecordFile(SP->
getFile());
869 OS.AddComment(
"Inlined function " + SP->
getName() +
" starts at " +
872 OS.AddComment(
"Type index of inlined function");
873 OS.EmitIntValue(InlineeIdx.getIndex(), 4);
874 OS.AddComment(
"Offset into filechecksum table");
875 OS.EmitCVFileChecksumOffsetDirective(FileId);
876 OS.AddComment(
"Starting line number");
877 OS.EmitIntValue(SP->getLine(), 4);
880 endCVSubsection(InlineEnd);
883 void CodeViewDebug::emitInlinedCallSite(
const FunctionInfo &FI,
885 const InlineSite &Site) {
886 assert(TypeIndices.count({Site.Inlinee, nullptr}));
887 TypeIndex InlineeIdx = TypeIndices[{Site.Inlinee,
nullptr}];
890 MCSymbol *InlineEnd = beginSymbolRecord(SymbolKind::S_INLINESITE);
892 OS.AddComment(
"PtrParent");
893 OS.EmitIntValue(0, 4);
894 OS.AddComment(
"PtrEnd");
895 OS.EmitIntValue(0, 4);
896 OS.AddComment(
"Inlinee type index");
897 OS.EmitIntValue(InlineeIdx.getIndex(), 4);
899 unsigned FileId = maybeRecordFile(Site.Inlinee->getFile());
900 unsigned StartLineNum = Site.Inlinee->getLine();
902 OS.EmitCVInlineLinetableDirective(Site.SiteFuncId, FileId, StartLineNum,
905 endSymbolRecord(InlineEnd);
907 emitLocalVariableList(FI, Site.InlinedLocals);
910 for (
const DILocation *ChildSite : Site.ChildSites) {
911 auto I = FI.InlineSites.find(ChildSite);
912 assert(
I != FI.InlineSites.end() &&
913 "child site not in function inline site map");
914 emitInlinedCallSite(FI, ChildSite,
I->second);
918 emitEndSymbolRecord(SymbolKind::S_INLINESITE_END);
921 void CodeViewDebug::switchToDebugSectionForSymbol(
const MCSymbol *GVSym) {
931 DebugSec = OS.getContext().getAssociativeCOFFSection(DebugSec, KeySym);
933 OS.SwitchSection(DebugSec);
937 if (ComdatDebugSections.insert(DebugSec).second)
938 emitCodeViewMagicVersion();
943 void CodeViewDebug::emitDebugInfoForThunk(
const Function *GV,
949 OS.AddComment(
"Symbol subsection for " +
Twine(FuncName));
950 MCSymbol *SymbolsEnd = beginCVSubsection(DebugSubsectionKind::Symbols);
953 MCSymbol *ThunkRecordEnd = beginSymbolRecord(SymbolKind::S_THUNK32);
954 OS.AddComment(
"PtrParent");
955 OS.EmitIntValue(0, 4);
956 OS.AddComment(
"PtrEnd");
957 OS.EmitIntValue(0, 4);
958 OS.AddComment(
"PtrNext");
959 OS.EmitIntValue(0, 4);
960 OS.AddComment(
"Thunk section relative address");
961 OS.EmitCOFFSecRel32(Fn, 0);
962 OS.AddComment(
"Thunk section index");
963 OS.EmitCOFFSectionIndex(Fn);
964 OS.AddComment(
"Code size");
965 OS.emitAbsoluteSymbolDiff(FI.End, Fn, 2);
966 OS.AddComment(
"Ordinal");
967 OS.EmitIntValue(
unsigned(ordinal), 1);
968 OS.AddComment(
"Function name");
971 endSymbolRecord(ThunkRecordEnd);
977 emitEndSymbolRecord(SymbolKind::S_PROC_ID_END);
979 endCVSubsection(SymbolsEnd);
982 void CodeViewDebug::emitDebugInfoForFunction(
const Function *GV,
990 switchToDebugSectionForSymbol(Fn);
992 std::string FuncName;
995 setCurrentSubprogram(SP);
998 emitDebugInfoForThunk(GV, FI, Fn);
1008 if (FuncName.empty())
1013 OS.EmitCVFPOData(Fn);
1016 OS.AddComment(
"Symbol subsection for " +
Twine(FuncName));
1017 MCSymbol *SymbolsEnd = beginCVSubsection(DebugSubsectionKind::Symbols);
1020 : SymbolKind::S_GPROC32_ID;
1021 MCSymbol *ProcRecordEnd = beginSymbolRecord(ProcKind);
1024 OS.AddComment(
"PtrParent");
1025 OS.EmitIntValue(0, 4);
1026 OS.AddComment(
"PtrEnd");
1027 OS.EmitIntValue(0, 4);
1028 OS.AddComment(
"PtrNext");
1029 OS.EmitIntValue(0, 4);
1032 OS.AddComment(
"Code size");
1033 OS.emitAbsoluteSymbolDiff(FI.End, Fn, 4);
1034 OS.AddComment(
"Offset after prologue");
1035 OS.EmitIntValue(0, 4);
1036 OS.AddComment(
"Offset before epilogue");
1037 OS.EmitIntValue(0, 4);
1038 OS.AddComment(
"Function type index");
1039 OS.EmitIntValue(getFuncIdForSubprogram(GV->
getSubprogram()).getIndex(), 4);
1040 OS.AddComment(
"Function section relative address");
1041 OS.EmitCOFFSecRel32(Fn, 0);
1042 OS.AddComment(
"Function section index");
1043 OS.EmitCOFFSectionIndex(Fn);
1044 OS.AddComment(
"Flags");
1045 OS.EmitIntValue(0, 1);
1047 OS.AddComment(
"Function name");
1050 endSymbolRecord(ProcRecordEnd);
1052 MCSymbol *FrameProcEnd = beginSymbolRecord(SymbolKind::S_FRAMEPROC);
1054 OS.AddComment(
"FrameSize");
1055 OS.EmitIntValue(FI.FrameSize - FI.CSRSize, 4);
1056 OS.AddComment(
"Padding");
1057 OS.EmitIntValue(0, 4);
1058 OS.AddComment(
"Offset of padding");
1059 OS.EmitIntValue(0, 4);
1060 OS.AddComment(
"Bytes of callee saved registers");
1061 OS.EmitIntValue(FI.CSRSize, 4);
1062 OS.AddComment(
"Exception handler offset");
1063 OS.EmitIntValue(0, 4);
1064 OS.AddComment(
"Exception handler section");
1065 OS.EmitIntValue(0, 2);
1066 OS.AddComment(
"Flags (defines frame register)");
1067 OS.EmitIntValue(
uint32_t(FI.FrameProcOpts), 4);
1068 endSymbolRecord(FrameProcEnd);
1070 emitLocalVariableList(FI, FI.Locals);
1071 emitGlobalVariableList(FI.Globals);
1072 emitLexicalBlockList(FI.ChildBlocks, FI);
1077 for (
const DILocation *InlinedAt : FI.ChildSites) {
1078 auto I = FI.InlineSites.find(InlinedAt);
1079 assert(
I != FI.InlineSites.end() &&
1080 "child site not in function inline site map");
1081 emitInlinedCallSite(FI, InlinedAt,
I->second);
1084 for (
auto Annot : FI.Annotations) {
1086 MDTuple *Strs = cast<MDTuple>(Annot.second);
1087 MCSymbol *AnnotEnd = beginSymbolRecord(SymbolKind::S_ANNOTATION);
1088 OS.EmitCOFFSecRel32(Label, 0);
1090 OS.EmitCOFFSectionIndex(Label);
1095 StringRef Str = cast<MDString>(MD)->getString();
1096 assert(Str.
data()[Str.
size()] ==
'\0' &&
"non-nullterminated MDString");
1099 endSymbolRecord(AnnotEnd);
1102 for (
auto HeapAllocSite : FI.HeapAllocSites) {
1103 const MCSymbol *BeginLabel = std::get<0>(HeapAllocSite);
1104 const MCSymbol *EndLabel = std::get<1>(HeapAllocSite);
1105 const DIType *DITy = std::get<2>(HeapAllocSite);
1106 MCSymbol *HeapAllocEnd = beginSymbolRecord(SymbolKind::S_HEAPALLOCSITE);
1107 OS.AddComment(
"Call site offset");
1108 OS.EmitCOFFSecRel32(BeginLabel, 0);
1109 OS.AddComment(
"Call site section index");
1110 OS.EmitCOFFSectionIndex(BeginLabel);
1111 OS.AddComment(
"Call instruction length");
1112 OS.emitAbsoluteSymbolDiff(EndLabel, BeginLabel, 2);
1113 OS.AddComment(
"Type index");
1114 OS.EmitIntValue(getCompleteTypeIndex(DITy).getIndex(), 4);
1115 endSymbolRecord(HeapAllocEnd);
1119 emitDebugInfoForUDTs(LocalUDTs);
1122 emitEndSymbolRecord(SymbolKind::S_PROC_ID_END);
1124 endCVSubsection(SymbolsEnd);
1127 OS.EmitCVLinetableDirective(FI.FuncId, Fn, FI.End);
1130 CodeViewDebug::LocalVarDefRange
1131 CodeViewDebug::createDefRangeMem(
uint16_t CVRegister,
int Offset) {
1132 LocalVarDefRange DR;
1135 assert(DR.DataOffset == Offset &&
"truncation");
1137 DR.StructOffset = 0;
1138 DR.CVRegister = CVRegister;
1142 void CodeViewDebug::collectVariableInfoFromMFTable(
1152 assert(
VI.Var->isValidLocationForIntrinsic(
VI.Loc) &&
1153 "Expected inlined-at fields to agree");
1155 Processed.
insert(InlinedEntity(
VI.Var,
VI.Loc->getInlinedAt()));
1164 int64_t ExprOffset = 0;
1168 if (
VI.Expr->getNumElements() == 1 &&
1169 VI.Expr->getElement(0) == llvm::dwarf::DW_OP_deref)
1171 else if (!
VI.Expr->extractIfOffset(ExprOffset))
1176 unsigned FrameReg = 0;
1181 LocalVarDefRange DefRange =
1182 createDefRangeMem(CVReg, FrameOffset + ExprOffset);
1188 DefRange.Ranges.emplace_back(Begin, End);
1193 Var.DefRanges.emplace_back(std::move(DefRange));
1195 Var.UseReferenceType =
true;
1197 recordLocalVariable(std::move(Var), Scope);
1209 void CodeViewDebug::calculateRanges(
1214 for (
auto I = Entries.
begin(),
E = Entries.
end();
I !=
E; ++
I) {
1216 if (!
Entry.isDbgValue())
1234 if (Var.UseReferenceType) {
1237 Location->LoadChain.pop_back();
1243 Var.UseReferenceType =
true;
1244 Var.DefRanges.clear();
1245 calculateRanges(Var, Entries);
1250 if (Location->Register == 0 || Location->LoadChain.size() > 1)
1253 LocalVarDefRange DR;
1255 DR.InMemory = !Location->LoadChain.empty();
1257 !Location->LoadChain.empty() ? Location->LoadChain.back() : 0;
1258 if (Location->FragmentInfo) {
1259 DR.IsSubfield =
true;
1260 DR.StructOffset = Location->FragmentInfo->OffsetInBits / 8;
1262 DR.IsSubfield =
false;
1263 DR.StructOffset = 0;
1266 if (Var.DefRanges.empty() ||
1267 Var.DefRanges.back().isDifferentLocation(DR)) {
1268 Var.DefRanges.emplace_back(std::move(DR));
1276 auto &EndingEntry = Entries[
Entry.getEndIndex()];
1277 End = EndingEntry.isDbgValue()
1286 Var.DefRanges.back().Ranges;
1287 if (!R.
empty() && R.
back().second == Begin)
1288 R.
back().second = End;
1296 void CodeViewDebug::collectVariableInfo(
const DISubprogram *SP) {
1299 collectVariableInfoFromMFTable(Processed);
1302 InlinedEntity IV =
I.first;
1303 if (Processed.
count(IV))
1309 const auto &Entries =
I.second;
1323 calculateRanges(Var, Entries);
1324 recordLocalVariable(std::move(Var), Scope);
1333 auto Insertion = FnDebugInfo.insert({&GV, std::make_unique<FunctionInfo>()});
1334 assert(Insertion.second &&
"function already has info");
1335 CurFn = Insertion.first->second.get();
1336 CurFn->FuncId = NextFuncId++;
1351 if (CurFn->FrameSize > 0) {
1353 CurFn->EncodedLocalFramePtrReg = EncodedFramePtrReg::StackPtr;
1354 CurFn->EncodedParamFramePtrReg = EncodedFramePtrReg::StackPtr;
1358 if (CurFn->HasStackRealignment) {
1360 CurFn->EncodedLocalFramePtrReg = EncodedFramePtrReg::StackPtr;
1372 FPO |= FrameProcedureOptions::HasAlloca;
1374 FPO |= FrameProcedureOptions::HasSetJmp;
1377 FPO |= FrameProcedureOptions::HasInlineAssembly;
1381 FPO |= FrameProcedureOptions::HasStructuredExceptionHandling;
1383 FPO |= FrameProcedureOptions::HasExceptionHandling;
1386 FPO |= FrameProcedureOptions::MarkedInline;
1388 FPO |= FrameProcedureOptions::Naked;
1390 FPO |= FrameProcedureOptions::SecurityChecks;
1395 FPO |= FrameProcedureOptions::OptimizedForSpeed;
1397 CurFn->FrameProcOpts = FPO;
1399 OS.EmitCVFuncIdDirective(CurFn->FuncId);
1406 bool EmptyPrologue =
true;
1407 for (
const auto &MBB : *MF) {
1408 for (
const auto &
MI : MBB) {
1411 PrologEndLoc =
MI.getDebugLoc();
1413 }
else if (!
MI.isMetaInstruction()) {
1414 EmptyPrologue =
false;
1420 if (PrologEndLoc && !EmptyPrologue) {
1422 maybeRecordLocation(FnStartDL, MF);
1426 for (
const auto &MBB : *MF) {
1427 for (
const auto &
MI : MBB) {
1428 if (
MI.getHeapAllocMarker()) {
1441 if (T->
getTag() == dwarf::DW_TAG_typedef) {
1443 switch (Scope->
getTag()) {
1444 case dwarf::DW_TAG_structure_type:
1445 case dwarf::DW_TAG_class_type:
1446 case dwarf::DW_TAG_union_type:
1459 T = DT->getBaseType();
1464 void CodeViewDebug::addToUDTs(
const DIType *Ty) {
1475 std::string FullyQualifiedName =
1478 if (ClosestSubprogram ==
nullptr) {
1479 GlobalUDTs.emplace_back(std::move(FullyQualifiedName), Ty);
1480 }
else if (ClosestSubprogram == CurrentSubprogram) {
1481 LocalUDTs.emplace_back(std::move(FullyQualifiedName), Ty);
1495 case dwarf::DW_TAG_array_type:
1496 return lowerTypeArray(cast<DICompositeType>(Ty));
1497 case dwarf::DW_TAG_typedef:
1498 return lowerTypeAlias(cast<DIDerivedType>(Ty));
1499 case dwarf::DW_TAG_base_type:
1500 return lowerTypeBasic(cast<DIBasicType>(Ty));
1501 case dwarf::DW_TAG_pointer_type:
1502 if (cast<DIDerivedType>(Ty)->
getName() ==
"__vtbl_ptr_type")
1503 return lowerTypeVFTableShape(cast<DIDerivedType>(Ty));
1505 case dwarf::DW_TAG_reference_type:
1506 case dwarf::DW_TAG_rvalue_reference_type:
1507 return lowerTypePointer(cast<DIDerivedType>(Ty));
1508 case dwarf::DW_TAG_ptr_to_member_type:
1509 return lowerTypeMemberPointer(cast<DIDerivedType>(Ty));
1510 case dwarf::DW_TAG_restrict_type:
1511 case dwarf::DW_TAG_const_type:
1512 case dwarf::DW_TAG_volatile_type:
1514 return lowerTypeModifier(cast<DIDerivedType>(Ty));
1515 case dwarf::DW_TAG_subroutine_type:
1519 return lowerTypeMemberFunction(cast<DISubroutineType>(Ty), ClassTy,
1523 return lowerTypeFunction(cast<DISubroutineType>(Ty));
1524 case dwarf::DW_TAG_enumeration_type:
1525 return lowerTypeEnum(cast<DICompositeType>(Ty));
1526 case dwarf::DW_TAG_class_type:
1527 case dwarf::DW_TAG_structure_type:
1528 return lowerTypeClass(cast<DICompositeType>(Ty));
1529 case dwarf::DW_TAG_union_type:
1530 return lowerTypeUnion(cast<DICompositeType>(Ty));
1531 case dwarf::DW_TAG_unspecified_type:
1532 if (Ty->
getName() ==
"decltype(nullptr)")
1533 return TypeIndex::NullptrT();
1542 TypeIndex UnderlyingTypeIndex = getTypeIndex(Ty->getBaseType());
1547 if (UnderlyingTypeIndex ==
TypeIndex(SimpleTypeKind::Int32Long) &&
1548 TypeName ==
"HRESULT")
1549 return TypeIndex(SimpleTypeKind::HResult);
1550 if (UnderlyingTypeIndex ==
TypeIndex(SimpleTypeKind::UInt16Short) &&
1551 TypeName ==
"wchar_t")
1552 return TypeIndex(SimpleTypeKind::WideCharacter);
1554 return UnderlyingTypeIndex;
1559 TypeIndex ElementTypeIndex = getTypeIndex(ElementType);
1561 TypeIndex IndexType = getPointerSizeInBytes() == 8
1563 :
TypeIndex(SimpleTypeKind::UInt32Long);
1569 for (
int i = Elements.size() - 1; i >= 0; --i) {
1570 const DINode *Element = Elements[i];
1571 assert(Element->
getTag() == dwarf::DW_TAG_subrange_type);
1573 const DISubrange *Subrange = cast<DISubrange>(Element);
1574 assert(Subrange->getLowerBound() == 0 &&
1575 "codeview doesn't support subranges with lower bounds");
1577 if (
auto *CI = Subrange->getCount().dyn_cast<
ConstantInt*>())
1578 Count = CI->getSExtValue();
1588 ElementSize *= Count;
1592 uint64_t ArraySize =
1593 (i == 0 && ElementSize == 0) ? Ty->
getSizeInBits() / 8 : ElementSize;
1596 ArrayRecord AR(ElementTypeIndex, IndexType, ArraySize, Name);
1597 ElementTypeIndex = TypeTable.writeLeafType(AR);
1600 return ElementTypeIndex;
1613 case dwarf::DW_ATE_address:
1616 case dwarf::DW_ATE_boolean:
1618 case 1: STK = SimpleTypeKind::Boolean8;
break;
1619 case 2: STK = SimpleTypeKind::Boolean16;
break;
1620 case 4: STK = SimpleTypeKind::Boolean32;
break;
1621 case 8: STK = SimpleTypeKind::Boolean64;
break;
1622 case 16: STK = SimpleTypeKind::Boolean128;
break;
1625 case dwarf::DW_ATE_complex_float:
1627 case 2: STK = SimpleTypeKind::Complex16;
break;
1628 case 4: STK = SimpleTypeKind::Complex32;
break;
1629 case 8: STK = SimpleTypeKind::Complex64;
break;
1630 case 10: STK = SimpleTypeKind::Complex80;
break;
1631 case 16: STK = SimpleTypeKind::Complex128;
break;
1634 case dwarf::DW_ATE_float:
1636 case 2: STK = SimpleTypeKind::Float16;
break;
1637 case 4: STK = SimpleTypeKind::Float32;
break;
1638 case 6: STK = SimpleTypeKind::Float48;
break;
1639 case 8: STK = SimpleTypeKind::Float64;
break;
1640 case 10: STK = SimpleTypeKind::Float80;
break;
1641 case 16: STK = SimpleTypeKind::Float128;
break;
1644 case dwarf::DW_ATE_signed:
1646 case 1: STK = SimpleTypeKind::SignedCharacter;
break;
1647 case 2: STK = SimpleTypeKind::Int16Short;
break;
1649 case 8: STK = SimpleTypeKind::Int64Quad;
break;
1650 case 16: STK = SimpleTypeKind::Int128Oct;
break;
1653 case dwarf::DW_ATE_unsigned:
1655 case 1: STK = SimpleTypeKind::UnsignedCharacter;
break;
1656 case 2: STK = SimpleTypeKind::UInt16Short;
break;
1658 case 8: STK = SimpleTypeKind::UInt64Quad;
break;
1659 case 16: STK = SimpleTypeKind::UInt128Oct;
break;
1662 case dwarf::DW_ATE_UTF:
1664 case 2: STK = SimpleTypeKind::Character16;
break;
1665 case 4: STK = SimpleTypeKind::Character32;
break;
1668 case dwarf::DW_ATE_signed_char:
1670 STK = SimpleTypeKind::SignedCharacter;
1672 case dwarf::DW_ATE_unsigned_char:
1674 STK = SimpleTypeKind::UnsignedCharacter;
1682 STK = SimpleTypeKind::Int32Long;
1684 STK = SimpleTypeKind::UInt32Long;
1685 if (STK == SimpleTypeKind::UInt16Short &&
1687 STK = SimpleTypeKind::WideCharacter;
1688 if ((STK == SimpleTypeKind::SignedCharacter ||
1689 STK == SimpleTypeKind::UnsignedCharacter) &&
1691 STK = SimpleTypeKind::NarrowCharacter;
1698 TypeIndex PointeeTI = getTypeIndex(Ty->getBaseType());
1704 Ty->
getTag() == dwarf::DW_TAG_pointer_type) {
1706 ? SimpleTypeMode::NearPointer64
1707 : SimpleTypeMode::NearPointer32;
1712 Ty->
getSizeInBits() == 64 ? PointerKind::Near64 : PointerKind::Near32;
1716 case dwarf::DW_TAG_pointer_type:
1717 PM = PointerMode::Pointer;
1719 case dwarf::DW_TAG_reference_type:
1720 PM = PointerMode::LValueReference;
1722 case dwarf::DW_TAG_rvalue_reference_type:
1723 PM = PointerMode::RValueReference;
1728 PO |= PointerOptions::Const;
1731 return TypeTable.writeLeafType(PR);
1743 : PointerToMemberRepresentation::GeneralFunction;
1744 case DINode::FlagSingleInheritance:
1745 return PointerToMemberRepresentation::SingleInheritanceFunction;
1746 case DINode::FlagMultipleInheritance:
1747 return PointerToMemberRepresentation::MultipleInheritanceFunction;
1748 case DINode::FlagVirtualInheritance:
1749 return PointerToMemberRepresentation::VirtualInheritanceFunction;
1755 : PointerToMemberRepresentation::GeneralData;
1756 case DINode::FlagSingleInheritance:
1757 return PointerToMemberRepresentation::SingleInheritanceData;
1758 case DINode::FlagMultipleInheritance:
1759 return PointerToMemberRepresentation::MultipleInheritanceData;
1760 case DINode::FlagVirtualInheritance:
1761 return PointerToMemberRepresentation::VirtualInheritanceData;
1769 assert(Ty->
getTag() == dwarf::DW_TAG_ptr_to_member_type);
1770 TypeIndex ClassTI = getTypeIndex(Ty->getClassType());
1771 TypeIndex PointeeTI = getTypeIndex(Ty->getBaseType(), Ty->getClassType());
1772 PointerKind PK = getPointerSizeInBytes() == 8 ? PointerKind::Near64
1773 : PointerKind::Near32;
1774 bool IsPMF = isa<DISubroutineType>(Ty->getBaseType());
1775 PointerMode PM = IsPMF ? PointerMode::PointerToMemberFunction
1776 : PointerMode::PointerToDataMember;
1783 return TypeTable.writeLeafType(PR);
1790 case dwarf::DW_CC_normal:
return CallingConvention::NearC;
1791 case dwarf::DW_CC_BORLAND_msfastcall:
return CallingConvention::NearFast;
1792 case dwarf::DW_CC_BORLAND_thiscall:
return CallingConvention::ThisCall;
1793 case dwarf::DW_CC_BORLAND_stdcall:
return CallingConvention::NearStdCall;
1794 case dwarf::DW_CC_BORLAND_pascal:
return CallingConvention::NearPascal;
1795 case dwarf::DW_CC_LLVM_vectorcall:
return CallingConvention::NearVector;
1797 return CallingConvention::NearC;
1803 bool IsModifier =
true;
1804 const DIType *BaseTy = Ty;
1805 while (IsModifier && BaseTy) {
1807 switch (BaseTy->
getTag()) {
1808 case dwarf::DW_TAG_const_type:
1809 Mods |= ModifierOptions::Const;
1810 PO |= PointerOptions::Const;
1812 case dwarf::DW_TAG_volatile_type:
1813 Mods |= ModifierOptions::Volatile;
1814 PO |= PointerOptions::Volatile;
1816 case dwarf::DW_TAG_restrict_type:
1819 PO |= PointerOptions::Restrict;
1826 BaseTy = cast<DIDerivedType>(BaseTy)->
getBaseType();
1834 switch (BaseTy->
getTag()) {
1835 case dwarf::DW_TAG_pointer_type:
1836 case dwarf::DW_TAG_reference_type:
1837 case dwarf::DW_TAG_rvalue_reference_type:
1838 return lowerTypePointer(cast<DIDerivedType>(BaseTy), PO);
1839 case dwarf::DW_TAG_ptr_to_member_type:
1840 return lowerTypeMemberPointer(cast<DIDerivedType>(BaseTy), PO);
1846 TypeIndex ModifiedTI = getTypeIndex(BaseTy);
1854 return TypeTable.writeLeafType(MR);
1860 ReturnAndArgTypeIndices.
push_back(getTypeIndex(ArgType));
1863 if (ReturnAndArgTypeIndices.
size() > 1 &&
1864 ReturnAndArgTypeIndices.
back() == TypeIndex::Void()) {
1867 TypeIndex ReturnTypeIndex = TypeIndex::Void();
1869 if (!ReturnAndArgTypeIndices.
empty()) {
1870 auto ReturnAndArgTypesRef =
makeArrayRef(ReturnAndArgTypeIndices);
1871 ReturnTypeIndex = ReturnAndArgTypesRef.front();
1872 ArgTypeIndices = ReturnAndArgTypesRef.
drop_front();
1875 ArgListRecord ArgListRec(TypeRecordKind::ArgList, ArgTypeIndices);
1876 TypeIndex ArgListIndex = TypeTable.writeLeafType(ArgListRec);
1883 return TypeTable.writeLeafType(Procedure);
1889 bool IsStaticMethod,
1892 TypeIndex ClassType = getTypeIndex(ClassTy);
1898 TypeIndex ReturnTypeIndex = TypeIndex::Void();
1900 ReturnTypeIndex = getTypeIndex(ReturnAndArgs[Index++]);
1907 if (!IsStaticMethod && ReturnAndArgs.
size() >
Index) {
1909 dyn_cast_or_null<DIDerivedType>(ReturnAndArgs[Index])) {
1910 if (PtrTy->getTag() == dwarf::DW_TAG_pointer_type) {
1911 ThisTypeIndex = getTypeIndexForThisPtr(PtrTy, Ty);
1917 while (Index < ReturnAndArgs.
size())
1918 ArgTypeIndices.
push_back(getTypeIndex(ReturnAndArgs[Index++]));
1921 if (!ArgTypeIndices.
empty() && ArgTypeIndices.
back() == TypeIndex::Void())
1924 ArgListRecord ArgListRec(TypeRecordKind::ArgList, ArgTypeIndices);
1925 TypeIndex ArgListIndex = TypeTable.writeLeafType(ArgListRec);
1930 ArgTypeIndices.
size(), ArgListIndex, ThisAdjustment);
1931 return TypeTable.writeLeafType(MFR);
1935 unsigned VSlotCount =
1940 return TypeTable.writeLeafType(VFTSR);
1945 case DINode::FlagPrivate:
return MemberAccess::Private;
1946 case DINode::FlagPublic:
return MemberAccess::Public;
1947 case DINode::FlagProtected:
return MemberAccess::Protected;
1950 return RecordTag == dwarf::DW_TAG_class_type ? MemberAccess::Private
1951 : MemberAccess::Public;
1957 if (SP->isArtificial())
1958 return MethodOptions::CompilerGenerated;
1967 if (SP->getFlags() & DINode::FlagStaticMember)
1970 switch (SP->getVirtuality()) {
1971 case dwarf::DW_VIRTUALITY_none:
1973 case dwarf::DW_VIRTUALITY_virtual:
1974 return Introduced ? MethodKind::IntroducingVirtual : MethodKind::Virtual;
1975 case dwarf::DW_VIRTUALITY_pure_virtual:
1976 return Introduced ? MethodKind::PureIntroducingVirtual
1977 : MethodKind::PureVirtual;
1982 return MethodKind::Vanilla;
1988 case dwarf::DW_TAG_structure_type:
return TypeRecordKind::Struct;
2002 CO |= ClassOptions::HasUniqueName;
2008 if (ImmediateScope && isa<DICompositeType>(ImmediateScope))
2009 CO |= ClassOptions::Nested;
2015 if (Ty->
getTag() == dwarf::DW_TAG_enumeration_type) {
2016 if (ImmediateScope && isa<DISubprogram>(ImmediateScope))
2017 CO |= ClassOptions::Scoped;
2019 for (
const DIScope *Scope = ImmediateScope; Scope !=
nullptr;
2021 if (isa<DISubprogram>(Scope)) {
2022 CO |= ClassOptions::Scoped;
2033 case dwarf::DW_TAG_class_type:
2034 case dwarf::DW_TAG_structure_type:
2035 case dwarf::DW_TAG_union_type:
2036 case dwarf::DW_TAG_enumeration_type:
2042 if (
const auto *File = Ty->
getFile()) {
2044 TypeIndex SIDI = TypeTable.writeLeafType(SIDR);
2047 TypeTable.writeLeafType(USLR);
2054 unsigned EnumeratorCount = 0;
2057 CO |= ClassOptions::ForwardReference;
2060 ContinuationBuilder.
begin(ContinuationRecordKind::FieldList);
2064 if (
auto *
Enumerator = dyn_cast_or_null<DIEnumerator>(Element)) {
2072 FTI = TypeTable.insertRecord(ContinuationBuilder);
2079 TypeIndex EnumTI = TypeTable.writeLeafType(ER);
2081 addUDTSrcLine(Ty, EnumTI);
2115 void CodeViewDebug::clear() {
2116 assert(CurFn ==
nullptr);
2118 FnDebugInfo.clear();
2119 FileToFilepathMap.clear();
2122 TypeIndices.clear();
2123 CompleteTypeIndices.clear();
2124 ScopeGlobals.clear();
2130 Info.
Members.push_back({DDTy, 0});
2140 const DIType *Ty = DDTy->getBaseType();
2141 bool FullyResolved =
false;
2142 while (!FullyResolved) {
2144 case dwarf::DW_TAG_const_type:
2145 case dwarf::DW_TAG_volatile_type:
2151 FullyResolved =
true;
2160 ClassInfo NestedInfo = collectClassInfo(DCTy);
2170 for (
auto *Element : Elements) {
2175 if (
auto *SP = dyn_cast<DISubprogram>(Element)) {
2176 Info.
Methods[SP->getRawName()].push_back(SP);
2177 }
else if (
auto *DDTy = dyn_cast<DIDerivedType>(Element)) {
2178 if (DDTy->
getTag() == dwarf::DW_TAG_member) {
2179 collectMemberInfo(Info, DDTy);
2180 }
else if (DDTy->
getTag() == dwarf::DW_TAG_inheritance) {
2182 }
else if (DDTy->
getTag() == dwarf::DW_TAG_pointer_type &&
2183 DDTy->
getName() ==
"__vtbl_ptr_type") {
2184 Info.
VShapeTI = getTypeIndex(DDTy);
2185 }
else if (DDTy->
getTag() == dwarf::DW_TAG_typedef) {
2187 }
else if (DDTy->
getTag() == dwarf::DW_TAG_friend) {
2191 }
else if (
auto *Composite = dyn_cast<DICompositeType>(Element)) {
2215 auto I = CompleteTypeIndices.find(Ty);
2216 if (
I != CompleteTypeIndices.end() &&
I->second ==
TypeIndex())
2218 return getCompleteTypeIndex(Ty);
2229 TypeIndex FwdDeclTI = TypeTable.writeLeafType(CR);
2231 DeferredCompleteTypes.push_back(Ty);
2241 unsigned FieldCount;
2243 std::tie(FieldTI, VShapeTI, FieldCount, ContainsNestedClass) =
2244 lowerRecordFieldList(Ty);
2246 if (ContainsNestedClass)
2247 CO |= ClassOptions::ContainsNestedClass;
2255 CO |= ClassOptions::HasConstructorOrDestructor;
2263 TypeIndex ClassTI = TypeTable.writeLeafType(CR);
2265 addUDTSrcLine(Ty, ClassTI);
2275 return getCompleteTypeIndex(Ty);
2281 TypeIndex FwdDeclTI = TypeTable.writeLeafType(UR);
2283 DeferredCompleteTypes.push_back(Ty);
2290 unsigned FieldCount;
2292 std::tie(FieldTI, std::ignore, FieldCount, ContainsNestedClass) =
2293 lowerRecordFieldList(Ty);
2295 if (ContainsNestedClass)
2296 CO |= ClassOptions::ContainsNestedClass;
2301 UnionRecord UR(FieldCount, CO, FieldTI, SizeInBytes, FullName,
2303 TypeIndex UnionTI = TypeTable.writeLeafType(UR);
2305 addUDTSrcLine(Ty, UnionTI);
2312 std::tuple<TypeIndex, TypeIndex, unsigned, bool>
2318 unsigned MemberCount = 0;
2321 ContinuationBuilder.
begin(ContinuationRecordKind::FieldList);
2325 if (I->
getFlags() & DINode::FlagVirtual) {
2327 unsigned VBPtrOffset = I->getVBPtrOffset();
2330 auto RecordKind = (I->
getFlags() & DINode::FlagIndirectVirtualBase) == DINode::FlagIndirectVirtualBase
2331 ? TypeRecordKind::IndirectVirtualBaseClass
2332 : TypeRecordKind::VirtualBaseClass;
2335 getTypeIndex(I->getBaseType()), getVBPTypeIndex(), VBPtrOffset,
2342 "bases must be on byte boundaries");
2344 getTypeIndex(I->getBaseType()),
2354 TypeIndex MemberBaseType = getTypeIndex(Member->getBaseType());
2367 if ((Member->
getFlags() & DINode::FlagArtificial) &&
2369 VFPtrRecord VFPR(getTypeIndex(Member->getBaseType()));
2376 uint64_t MemberOffsetInBits =
2379 uint64_t StartBitOffset = MemberOffsetInBits;
2380 if (
const auto *CI =
2381 dyn_cast_or_null<ConstantInt>(Member->getStorageOffsetInBits())) {
2382 MemberOffsetInBits = CI->getZExtValue() + MemberInfo.
BaseOffset;
2384 StartBitOffset -= MemberOffsetInBits;
2387 MemberBaseType = TypeTable.writeLeafType(BFR);
2389 uint64_t MemberOffsetInBytes = MemberOffsetInBits / 8;
2397 for (
auto &MethodItr : Info.
Methods) {
2400 std::vector<OneMethodRecord> Methods;
2402 TypeIndex MethodType = getMemberFunctionType(SP, Ty);
2403 bool Introduced = SP->getFlags() & DINode::FlagIntroducedVirtual;
2405 unsigned VFTableOffset = -1;
2407 VFTableOffset = SP->getVirtualIndex() * getPointerSizeInBytes();
2415 assert(!Methods.empty() &&
"Empty methods map entry");
2416 if (Methods.size() == 1)
2422 TypeIndex MethodList = TypeTable.writeLeafType(MOLR);
2436 TypeIndex FieldTI = TypeTable.insertRecord(ContinuationBuilder);
2437 return std::make_tuple(FieldTI, Info.
VShapeTI, MemberCount,
2441 TypeIndex CodeViewDebug::getVBPTypeIndex() {
2442 if (!VBPType.getIndex()) {
2445 TypeIndex ModifiedTI = TypeTable.writeLeafType(MR);
2447 PointerKind PK = getPointerSizeInBytes() == 8 ? PointerKind::Near64
2448 : PointerKind::Near32;
2451 PointerRecord PR(ModifiedTI, PK, PM, PO, getPointerSizeInBytes());
2452 VBPType = TypeTable.writeLeafType(PR);
2461 return TypeIndex::Void();
2466 auto I = TypeIndices.find({Ty, ClassTy});
2467 if (
I != TypeIndices.end())
2470 TypeLoweringScope S(*
this);
2472 return recordTypeIndexForDINode(Ty, TI, ClassTy);
2476 CodeViewDebug::getTypeIndexForThisPtr(
const DIDerivedType *PtrTy,
2478 assert(PtrTy->
getTag() == dwarf::DW_TAG_pointer_type &&
2479 "this type must be a pointer type");
2482 if (SubroutineTy->
getFlags() & DINode::DIFlags::FlagLValueReference)
2483 Options = PointerOptions::LValueRefThisPointer;
2484 else if (SubroutineTy->
getFlags() & DINode::DIFlags::FlagRValueReference)
2485 Options = PointerOptions::RValueRefThisPointer;
2492 auto I = TypeIndices.find({PtrTy, SubroutineTy});
2493 if (
I != TypeIndices.end())
2496 TypeLoweringScope S(*
this);
2497 TypeIndex TI = lowerTypePointer(PtrTy, Options);
2498 return recordTypeIndexForDINode(PtrTy, TI, SubroutineTy);
2501 TypeIndex CodeViewDebug::getTypeIndexForReferenceTo(
const DIType *Ty) {
2503 getPointerSizeInBytes() == 8 ? PointerKind::Near64
2504 : PointerKind::Near32,
2507 return TypeTable.writeLeafType(PR);
2513 return TypeIndex::Void();
2518 if (Ty->
getTag() == dwarf::DW_TAG_typedef)
2519 (
void)getTypeIndex(Ty);
2520 while (Ty->
getTag() == dwarf::DW_TAG_typedef)
2521 Ty = cast<DIDerivedType>(Ty)->getBaseType();
2526 case dwarf::DW_TAG_class_type:
2527 case dwarf::DW_TAG_structure_type:
2528 case dwarf::DW_TAG_union_type:
2531 return getTypeIndex(Ty);
2534 const auto *CTy = cast<DICompositeType>(Ty);
2536 TypeLoweringScope S(*
this);
2542 if (!CTy->getName().empty() || !CTy->getIdentifier().empty()) {
2543 TypeIndex FwdDeclTI = getTypeIndex(CTy);
2548 if (CTy->isForwardDecl())
2555 auto InsertResult = CompleteTypeIndices.insert({CTy,
TypeIndex()});
2556 if (!InsertResult.second)
2557 return InsertResult.first->second;
2560 switch (CTy->getTag()) {
2561 case dwarf::DW_TAG_class_type:
2562 case dwarf::DW_TAG_structure_type:
2563 TI = lowerCompleteTypeClass(CTy);
2565 case dwarf::DW_TAG_union_type:
2566 TI = lowerCompleteTypeUnion(CTy);
2576 CompleteTypeIndices[CTy] = TI;
2584 void CodeViewDebug::emitDeferredCompleteTypes() {
2586 while (!DeferredCompleteTypes.empty()) {
2587 std::swap(DeferredCompleteTypes, TypesToEmit);
2589 getCompleteTypeIndex(RecordTy);
2590 TypesToEmit.clear();
2594 void CodeViewDebug::emitLocalVariableList(
const FunctionInfo &FI,
2598 for (
const LocalVariable &L : Locals)
2599 if (L.DIVar->isParameter())
2601 llvm::sort(Params, [](
const LocalVariable *L,
const LocalVariable *R) {
2602 return L->DIVar->getArg() < R->DIVar->getArg();
2604 for (
const LocalVariable *L : Params)
2605 emitLocalVariable(FI, *L);
2608 for (
const LocalVariable &L : Locals)
2609 if (!L.DIVar->isParameter())
2610 emitLocalVariable(FI, L);
2613 void CodeViewDebug::emitLocalVariable(
const FunctionInfo &FI,
2614 const LocalVariable &Var) {
2616 MCSymbol *LocalEnd = beginSymbolRecord(SymbolKind::S_LOCAL);
2619 if (Var.DIVar->isParameter())
2620 Flags |= LocalSymFlags::IsParameter;
2621 if (Var.DefRanges.empty())
2622 Flags |= LocalSymFlags::IsOptimizedOut;
2624 OS.AddComment(
"TypeIndex");
2626 ? getTypeIndexForReferenceTo(Var.DIVar->getType())
2627 : getCompleteTypeIndex(Var.DIVar->getType());
2629 OS.AddComment(
"Flags");
2630 OS.EmitIntValue(static_cast<uint16_t>(Flags), 2);
2633 endSymbolRecord(LocalEnd);
2639 for (
const LocalVarDefRange &DefRange : Var.DefRanges) {
2641 if (DefRange.InMemory) {
2642 int Offset = DefRange.DataOffset;
2643 unsigned Reg = DefRange.CVRegister;
2649 Reg =
unsigned(RegisterId::VFRAME);
2650 Offset += FI.OffsetAdjustment;
2658 (
bool(Flags & LocalSymFlags::IsParameter)
2659 ? (EncFP == FI.EncodedParamFramePtrReg)
2660 : (EncFP == FI.EncodedLocalFramePtrReg))) {
2663 OS.EmitCVDefRangeDirective(DefRange.Ranges, DRHdr);
2666 if (DefRange.IsSubfield) {
2667 RegRelFlags = DefRangeRegisterRelSym::IsSubfieldFlag |
2668 (DefRange.StructOffset
2669 << DefRangeRegisterRelSym::OffsetInParentShift);
2673 DRHdr.
Flags = RegRelFlags;
2675 OS.EmitCVDefRangeDirective(DefRange.Ranges, DRHdr);
2678 assert(DefRange.DataOffset == 0 &&
"unexpected offset into register");
2679 if (DefRange.IsSubfield) {
2681 DRHdr.
Register = DefRange.CVRegister;
2684 OS.EmitCVDefRangeDirective(DefRange.Ranges, DRHdr);
2687 DRHdr.
Register = DefRange.CVRegister;
2689 OS.EmitCVDefRangeDirective(DefRange.Ranges, DRHdr);
2696 const FunctionInfo& FI) {
2697 for (LexicalBlock *Block : Blocks)
2698 emitLexicalBlock(*Block, FI);
2703 void CodeViewDebug::emitLexicalBlock(
const LexicalBlock &Block,
2704 const FunctionInfo& FI) {
2705 MCSymbol *RecordEnd = beginSymbolRecord(SymbolKind::S_BLOCK32);
2706 OS.AddComment(
"PtrParent");
2707 OS.EmitIntValue(0, 4);
2708 OS.AddComment(
"PtrEnd");
2709 OS.EmitIntValue(0, 4);
2710 OS.AddComment(
"Code size");
2711 OS.emitAbsoluteSymbolDiff(Block.End, Block.Begin, 4);
2712 OS.AddComment(
"Function section relative address");
2713 OS.EmitCOFFSecRel32(Block.Begin, 0);
2714 OS.AddComment(
"Function section index");
2715 OS.EmitCOFFSectionIndex(FI.Begin);
2716 OS.AddComment(
"Lexical block name");
2718 endSymbolRecord(RecordEnd);
2721 emitLocalVariableList(FI, Block.Locals);
2722 emitGlobalVariableList(Block.Globals);
2725 emitLexicalBlockList(Block.Children, FI);
2728 emitEndSymbolRecord(SymbolKind::S_END);
2733 void CodeViewDebug::collectLexicalBlockInfo(
2739 collectLexicalBlockInfo(*Scope, Blocks, Locals, Globals);
2744 void CodeViewDebug::collectLexicalBlockInfo(
2754 bool IgnoreScope =
false;
2755 auto LI = ScopeVariables.find(&Scope);
2757 LI != ScopeVariables.
end() ? &LI->second :
nullptr;
2760 GI != ScopeGlobals.
end() ? GI->second.get() :
nullptr;
2765 if (!Locals && !Globals)
2805 auto BlockInsertion = CurFn->LexicalBlocks.insert({DILB, LexicalBlock()});
2806 if (!BlockInsertion.second)
2811 const InsnRange &Range = Ranges.front();
2812 assert(Range.first && Range.second);
2813 LexicalBlock &Block = BlockInsertion.first->second;
2816 assert(Block.Begin &&
"missing label for scope begin");
2817 assert(Block.End &&
"missing label for scope end");
2820 Block.Locals = std::move(*Locals);
2822 Block.Globals = std::move(*Globals);
2832 assert(FnDebugInfo.count(&GV));
2833 assert(CurFn == FnDebugInfo[&GV].
get());
2839 collectLexicalBlockInfo(*CFS,
2847 ScopeVariables.clear();
2851 if (!CurFn->HaveLineInfo && !GV.
getSubprogram()->isThunk()) {
2852 FnDebugInfo.erase(&GV);
2858 for (
const auto &MBB : *MF) {
2859 for (
const auto &
MI : MBB) {
2860 if (
MDNode *MD =
MI.getHeapAllocMarker()) {
2863 dyn_cast<DIType>(MD)));
2868 CurFn->Annotations = MF->getCodeViewAnnotations();
2880 return DL && DL.
getLine() != 0;
2895 for (
const auto &NextMI : *MI->
getParent()) {
2896 if (NextMI.isDebugInstr())
2898 DL = NextMI.getDebugLoc();
2911 maybeRecordLocation(DL,
Asm->
MF);
2917 OS.EmitIntValue(
unsigned(Kind), 4);
2918 OS.AddComment(
"Subsection size");
2919 OS.emitAbsoluteSymbolDiff(EndLabel, BeginLabel, 4);
2920 OS.EmitLabel(BeginLabel);
2924 void CodeViewDebug::endCVSubsection(
MCSymbol *EndLabel) {
2925 OS.EmitLabel(EndLabel);
2927 OS.EmitValueToAlignment(4);
2932 if (EE.Value == SymKind)
2940 OS.AddComment(
"Record length");
2941 OS.emitAbsoluteSymbolDiff(EndLabel, BeginLabel, 2);
2942 OS.EmitLabel(BeginLabel);
2943 if (OS.isVerboseAsm())
2945 OS.EmitIntValue(
unsigned(SymKind), 2);
2949 void CodeViewDebug::endSymbolRecord(
MCSymbol *SymEnd) {
2954 OS.EmitValueToAlignment(4);
2955 OS.EmitLabel(SymEnd);
2958 void CodeViewDebug::emitEndSymbolRecord(
SymbolKind EndKind) {
2959 OS.AddComment(
"Record length");
2960 OS.EmitIntValue(2, 2);
2961 if (OS.isVerboseAsm())
2963 OS.EmitIntValue(
unsigned(EndKind), 2);
2966 void CodeViewDebug::emitDebugInfoForUDTs(
2967 ArrayRef<std::pair<std::string, const DIType *>> UDTs) {
2968 for (
const auto &UDT : UDTs) {
2969 const DIType *T = UDT.second;
2972 MCSymbol *UDTRecordEnd = beginSymbolRecord(SymbolKind::S_UDT);
2973 OS.AddComment(
"Type");
2974 OS.EmitIntValue(getCompleteTypeIndex(T).getIndex(), 4);
2976 endSymbolRecord(UDTRecordEnd);
2980 void CodeViewDebug::collectGlobalVariableInfo() {
2985 GV.getDebugInfo(GVEs);
2986 for (
const auto *GVE : GVEs)
2987 GlobalMap[GVE] = &GV;
2992 const auto *
CU = cast<DICompileUnit>(Node);
2993 for (
const auto *GVE :
CU->getGlobalVariables()) {
2999 CVGlobalVariable CVGV = {DIGV, DIE};
3000 GlobalVariables.emplace_back(std::move(CVGV));
3003 const auto *GV = GlobalMap.
lookup(GVE);
3009 if (Scope && isa<DILocalScope>(Scope)) {
3012 auto Insertion = ScopeGlobals.
insert(
3013 {
Scope, std::unique_ptr<GlobalVariableList>()});
3014 if (Insertion.second)
3015 Insertion.first->second = std::make_unique<GlobalVariableList>();
3016 VariableList = Insertion.first->second.get();
3019 VariableList = &ComdatVariables;
3022 VariableList = &GlobalVariables;
3023 CVGlobalVariable CVGV = {DIGV, GV};
3029 void CodeViewDebug::emitDebugInfoForGlobals() {
3033 switchToDebugSectionForSymbol(
nullptr);
3034 if (!GlobalVariables.empty()) {
3035 OS.AddComment(
"Symbol subsection for globals");
3036 MCSymbol *EndLabel = beginCVSubsection(DebugSubsectionKind::Symbols);
3037 emitGlobalVariableList(GlobalVariables);
3038 endCVSubsection(EndLabel);
3043 for (
const CVGlobalVariable &CVGV : ComdatVariables) {
3046 OS.AddComment(
"Symbol subsection for " +
3048 switchToDebugSectionForSymbol(GVSym);
3049 MCSymbol *EndLabel = beginCVSubsection(DebugSubsectionKind::Symbols);
3051 emitDebugInfoForGlobal(CVGV);
3052 endCVSubsection(EndLabel);
3056 void CodeViewDebug::emitDebugInfoForRetainedTypes() {
3059 for (
auto *Ty : cast<DICompileUnit>(Node)->getRetainedTypes()) {
3060 if (
DIType *RT = dyn_cast<DIType>(Ty)) {
3070 for (
const CVGlobalVariable &CVGV : Globals) {
3072 emitDebugInfoForGlobal(CVGV);
3076 void CodeViewDebug::emitDebugInfoForGlobal(
const CVGlobalVariable &CVGV) {
3085 : SymbolKind::S_GTHREAD32)
3087 : SymbolKind::S_GDATA32);
3088 MCSymbol *DataEnd = beginSymbolRecord(DataSym);
3089 OS.AddComment(
"Type");
3090 OS.EmitIntValue(getCompleteTypeIndex(DIGV->
getType()).getIndex(), 4);
3091 OS.AddComment(
"DataOffset");
3092 OS.EmitCOFFSecRel32(GVSym, 0);
3093 OS.AddComment(
"Segment");
3094 OS.EmitCOFFSectionIndex(GVSym);
3095 OS.AddComment(
"Name");
3096 const unsigned LengthOfDataRecord = 12;
3098 endSymbolRecord(DataEnd);
3104 "Global constant variables must contain a constant expression.");
3107 MCSymbol *SConstantEnd = beginSymbolRecord(SymbolKind::S_CONSTANT);
3108 OS.AddComment(
"Type");
3109 OS.EmitIntValue(getTypeIndex(DIGV->
getType()).getIndex(), 4);
3110 OS.AddComment(
"Value");
3118 OS.EmitBinaryData(SRef);
3120 OS.AddComment(
"Name");
3123 if (
const auto *MemberDecl = dyn_cast_or_null<DIDerivedType>(
3128 endSymbolRecord(SConstantEnd);
Scope
Defines the scope in which this symbol should be visible: Default – Visible in the public interface ...
bool isDeclarationForLinker() const
bool isObjectPointer() const
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
PointerKind
Equivalent to CV_ptrtype_e.
TypeLoweringScope(CodeViewDebug &CVD)
const TargetLoweringObjectFile & getObjFileLowering() const
Return information about object file lowering.
LLVM_NODISCARD StringRef take_front(size_t N=1) const
Return a StringRef equal to 'this' but with only the first N elements remaining.
reference emplace_back(ArgTypes &&... Args)
const DILocalScope * getScopeNode() const
const std::string & getTargetTriple() const
Get the target triple which is a string describing the target host.
bool isConstant() const
Determine whether this represents a standalone constant value.
uint64_t getOffsetInBits() const
static bool shouldAlwaysEmitCompleteClassType(const DICompositeType *Ty)
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
bool hasLocalLinkage() const
DILocation * get() const
Get the underlying DILocation.
bool hasDebugInfo() const
Returns true if valid debug info is present.
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
This class represents lattice values for constants.
bool isAbstractScope() const
bool hasOptNone() const
Do not optimize this function (-O0).
MCSection * getCOFFDebugTypesSection() const
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
bool hasStackProtectorIndex() const
bool hasOptSize() const
Optimize this function for size (-Os) or minimum size (-Oz).
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
virtual int getFrameIndexReference(const MachineFunction &MF, int FI, unsigned &FrameReg) const
getFrameIndexReference - This method should return the base register and offset used to reference a f...
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
LLVM_NODISCARD bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
Implements a dense probed hash-table based set.
StringRef getTypeName()
We provide a function which tries to compute the (demangled) name of a type statically.
void push_back(const T &Elt)
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
SimpleTypeKind getSimpleKind() const
virtual void EmitBytes(StringRef Data)
Emit the bytes in Data into the output.
void writeMemberType(RecordType &Record)
void endModule() override
Emit the COFF section that holds the line table information.
TypeIndex writeLeafType(T &Record)
SmallVectorImpl< InsnRange > & getRanges()
static enum BaseType getBaseType(const Value *Val)
Return the baseType for Val which states whether Val is exclusively derived from constant/null, or not exclusively derived from constant.
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
A raw_ostream that writes to an SmallVector or SmallString.
auto formatv(const char *Fmt, Ts &&... Vals) -> formatv_object< decltype(std::make_tuple(detail::build_format_adapter(std::forward< Ts >(Vals))...))>
unsigned getPointerSizeInBits(unsigned AS=0) const
Layout pointer size, in bits FIXME: The defaults need to be removed once all of the backends/clients ...
unsigned const TargetRegisterInfo * TRI
MachineFunction * MF
The current machine function.
bool isForwardDecl() const
LexicalScope - This class is used to track scope information.
TinyPtrVector - This class is specialized for cases where there are normally 0 or 1 element in a vect...
void endFunctionImpl(const MachineFunction *) override
Gather post-function debug information.
MCSection * getCOFFGlobalTypeHashesSection() const
StringRef getName() const
VariableDbgInfoMapTy & getVariableDbgInfo()
Tagged DWARF-like metadata node.
std::string fromHex(StringRef Input)
Convert hexadecimal string Input to its binary representation.
DINodeArray getElements() const
SimpleTypeMode getSimpleMode() const
This represents a section on Windows.
MCContext & getContext() const
DebugLoc PrevInstLoc
Previous instruction's location information.
StringRef getName() const
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
bool isStaticMember() const
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
SmallVectorImpl< LexicalScope * > & getChildren()
DbgValueHistoryMap DbgValues
History of DBG_VALUE and clobber instructions for each user variable.
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
static StringRef getSymbolName(SymbolKind SymKind)
virtual bool hasFP(const MachineFunction &MF) const =0
hasFP - Return true if the specified function should have a dedicated frame pointer register...
static StringRef getName(Value *V)
bool is_absolute(const Twine &path, Style style=Style::native)
Is path absolute?
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 ...
static std::string getFullyQualifiedName(const DIScope *Scope, StringRef Name)
static FunctionOptions getFunctionOptions(const DISubroutineType *Ty, const DICompositeType *ClassTy=nullptr, StringRef SPName=StringRef(""))
uint64_t getSizeInBits() const
void * allocate(unsigned Size, unsigned Align=8)
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
StringRef getFilename() const
static StringRef getPrettyScopeName(const DIScope *Scope)
auto reverse(ContainerTy &&C, typename std::enable_if< has_rbegin< ContainerTy >::value >::type *=nullptr) -> decltype(make_range(C.rbegin(), C.rend()))
bool isLocalToUnit() const
virtual bool EmitCVFileDirective(unsigned FileNo, StringRef Filename, ArrayRef< uint8_t > Checksum, unsigned ChecksumKind)
Associate a filename with a specified logical file number, and also specify that file's checksum info...
DIType * getBaseType() const
static bool canUseReferenceType(const DbgVariableLocation &Loc)
ModifierOptions
Equivalent to CV_modifier_t.
static bool isUsableDebugLoc(DebugLoc DL)
MCSymbol * getFunctionBegin() const
op_range operands() const
static SourceLanguage MapDWLangToCVLang(unsigned DWLang)
static void addLocIfNotPresent(SmallVectorImpl< const DILocation *> &Locs, const DILocation *Loc)
static const EntryIndex NoEntry
Special value to indicate that an entry is valid until the end of the function.
const MCContext & getContext() const
MCSection * getCOFFDebugSymbolsSection() const
NamedMDNode * getNamedMetadata(const Twine &Name) const
Return the first NamedMDNode in the module with the specified name.
LLVM_NODISCARD size_t size() const
size - Get the string size.
LexicalScope * findLexicalScope(const DILocation *DL)
findLexicalScope - Find lexical scope, either regular or inlined, for the given DebugLoc.
bool hasPersonalityFn() const
Check whether this function has a personality function.
MethodKind
Part of member attribute flags. (CV_methodprop_e)
DIScope * getScope() const
void requestLabelBeforeInsn(const MachineInstr *MI)
Ensure that a label will be emitted before MI.
iterator_range< op_iterator > operands()
Analysis containing CSE Info
TypeRecordKind
Distinguishes individual records in .debug$T or .debug$P section or PDB type stream.
static DIE * get(BumpPtrAllocator &Alloc, dwarf::Tag Tag)
unsigned getCVBytesOfCalleeSavedRegisters() const
Returns how many bytes of callee-saved registers the target pushed in the prologue.
void beginInstruction(const MachineInstr *MI) override
Process beginning of an instruction.
Streaming machine code generation interface.
EncodedFramePtrReg
Two-bit value indicating which register is the designated frame pointer register. ...
MCSymbol * createTempSymbol(bool CanBeUnnamed=true)
Create and return a new assembler temporary symbol with a unique but unspecified name.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
CodeGenOpt::Level getOptLevel() const
Returns the optimization level: None, Less, Default, or Aggressive.
static MemberAccess translateAccessFlags(unsigned RecordTag, unsigned Flags)
const MachineBasicBlock * PrevInstBB
const MCAsmInfo * MAI
Target Asm Printer information.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
The instances of the Type class are immutable: once they are created, they are never changed...
DISubprogram * getSubprogram() const
Get the attached subprogram.
static StringRef simpleTypeName(TypeIndex TI)
Metadata * getModuleFlag(StringRef Key) const
Return the corresponding value if Key appears in module flags, otherwise return null.
uint32_t getOffset() const
const DILocation * getInlinedAt() const
Instrumentation for Order File
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
size_t size() const
size - Get the array size.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static CPUType mapArchToCVCPUType(Triple::ArchType Type)
A structured debug information entry.
std::vector< MemberInfo > MemberList
AsmPrinter * Asm
Target of debug info emission.
std::pair< iterator, bool > insert(const ValueT &V)
TargetMachine & TM
Target machine description.
This class is intended to be used as a driving class for all asm writers.
EHPersonality classifyEHPersonality(const Value *Pers)
See if the given exception handling personality function is one that we understand.
For method overload sets. LF_METHOD.
Provides write only access to a subclass of WritableBinaryStream.
static void replace(Module &M, GlobalVariable *Old, GlobalVariable *New)
constexpr char TypeName[]
Key for Kernel::Arg::Metadata::mTypeName.
static uint64_t getBaseTypeSize(const DIType *Ty)
If this type is derived from a base type then return base type size.
void beginInstruction(const MachineInstr *MI) override
Process beginning of an instruction.
Error visitTypeRecord(CVType &Record, TypeIndex Index, TypeVisitorCallbacks &Callbacks, VisitorDataSource Source=VDS_BytesPresent)
void beginFunctionImpl(const MachineFunction *MF) override
Gather pre-function debug information.
DIScope * getScope() const
StringRef getDirectory() const
MCSymbol * getLabelAfterInsn(const MachineInstr *MI)
Return Label immediately following the instruction.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
LLVM_NODISCARD char back() const
back - Get the last character in the string.
auto find(R &&Range, const T &Val) -> decltype(adl_begin(Range))
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly...
uint64_t getElement(unsigned I) const
void logAllUnhandledErrors(Error E, raw_ostream &OS, Twine ErrorBanner={})
Log all errors (if any) in E to OS.
bool isDebugInstr() const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Triple - Helper class for working with autoconf configuration names.
static TypeIndex getStringIdTypeIdx(GlobalTypeTableBuilder &TypeTable, StringRef S)
Base class for scope-like contexts.
uint32_t getIndex() const
void sort(IteratorTy Start, IteratorTy End)
PointerOptions
Equivalent to misc lfPointerAttr bitfields.
LexicalScope * findInlinedScope(const DILocalScope *N, const DILocation *IA)
findInlinedScope - Find an inlined scope for the given scope/inlined-at.
Represents the location at which a variable is stored.
SourceLanguage
These values correspond to the CV_CFL_LANG enumeration, and are documented here: https://msdn.microsoft.com/en-us/library/bw3aekw6.aspx.
static Optional< DbgVariableLocation > extractFromMachineInstruction(const MachineInstr &Instruction)
Extract a VariableLocation from a MachineInstr.
This is the shared class of boolean and integer constants.
ArrayRef< EnumEntry< SymbolKind > > getSymbolTypeNames()
void setDebugInfoAvailability(bool avail)
static TypeRecordKind getRecordKind(const DICompositeType *Ty)
Align max(MaybeAlign Lhs, Align Rhs)
StringRef getName() const
MCSymbol * getSymbol(const GlobalValue *GV) const
MCSymbol * getCOMDATSymbol() const
bool isDebugValue() const
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Error mapEncodedInteger(int64_t &Value, const Twine &Comment="")
Module.h This file contains the declarations for the Module class.
LLVM_NODISCARD std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
CPUType
These values correspond to the CV_CPU_TYPE_e enumeration, and are documented here: https://msdn...
Information about stack frame layout on the target.
DIScope * getScope() const
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
DebugLoc getFnDebugLoc() const
Find the debug info location for the start of the function.
MCSymbol * getFunctionEnd() const
const Function & getFunction() const
Return the LLVM function that this machine code represents.
Collects and handles line tables information in a CodeView format.
PointerMode
Equivalent to CV_ptrmode_e.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
This file contains constants used for implementing Dwarf debug support.
static StringRef dropLLVMManglingEscape(StringRef Name)
If the given string begins with the GlobalValue name mangling escape character '\1', drop it.
MCSection & getSection() const
Get the section associated with a defined, non-absolute symbol.
DebugLoc PrologEndLoc
This location indicates end of function prologue and beginning of function body.
iterator insert(iterator I, T &&Elt)
MethodOptions
Equivalent to CV_fldattr_t bitfield.
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
static const DISubprogram * getQualifiedNameComponents(const DIScope *Scope, SmallVectorImpl< StringRef > &QualifiedNameComponents)
const MachineBasicBlock * getParent() const
TargetSubtargetInfo - Generic base class for all target subtargets.
StringRef getIdentifier() const
static MethodKind translateMethodKindFlags(const DISubprogram *SP, bool Introduced)
void requestLabelAfterInsn(const MachineInstr *MI)
Ensure that a label will be emitted after MI.
Type array for a subprogram.
Representation of each machine instruction.
const DIDerivedType * MemberTypeNode
EncodedFramePtrReg encodeFramePtrReg(RegisterId Reg, CPUType CPU)
unsigned getEncoding() const
LLVM_NODISCARD bool empty() const
bool exposesReturnsTwice() const
exposesReturnsTwice - Returns true if the function calls setjmp or any other similar functions with a...
ArrayRef< T > drop_front(size_t N=1) const
Drop the first N elements of the array.
StringRef getName() const
Return a constant reference to the value's name.
static void emitNullTerminatedSymbolName(MCStreamer &OS, StringRef S, unsigned MaxFixedRecordLength=0xF00)
bool hasInlineAsm() const
Returns true if the function contains any inline assembly.
virtual const TargetFrameLowering * getFrameLowering() const
bool isZero() const
This is just a convenience method to make client code smaller for a common code.
int getCodeViewRegNum(MCRegister RegNum) const
Map a target register to an equivalent CodeView register number.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Base class for debug information backends.
int getOffsetAdjustment() const
Return the correction for frame offsets.
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
static std::string getQualifiedName(ArrayRef< StringRef > QualifiedNameComponents, StringRef TypeName)
SymbolKind
Duplicate copy of the above enum, but using the official CV names.
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
const Module * getModule() const
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
PointerToMemberRepresentation
Equivalent to CV_pmtype_e.
ThunkOrdinal
These values correspond to the THUNK_ORDINAL enumeration.
Metadata * getRawStaticDataMemberDeclaration() const
static Version parseVersion(StringRef Name)
unsigned getCodePointerSize() const
Get the code pointer size in bytes.
MCSymbol * getLabelBeforeInsn(const MachineInstr *MI)
Return Label preceding the instruction.
LLVM_NODISCARD const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
MemberAccess
Source-level access specifier. (CV_access_e)
SmallVector< int64_t, 1 > LoadChain
Chain of offsetted loads necessary to load the value if it lives in memory.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static APSInt getUnsigned(uint64_t X)
bool isAsynchronousEHPersonality(EHPersonality Pers)
Returns true if this personality function catches asynchronous exceptions.
static MethodOptions translateMethodOptionFlags(const DISubprogram *SP)
std::vector< const DIType * > NestedTypes
virtual bool EmitCVInlineSiteIdDirective(unsigned FunctionId, unsigned IAFunc, unsigned IAFile, unsigned IALine, unsigned IACol, SMLoc Loc)
Introduces an inline call site id for use with .cv_loc.
bool needsStackRealignment(const MachineFunction &MF) const
True if storage within the function requires the stack pointer to be aligned more than the normal cal...
LLVM Value Representation.
Constant * getPersonalityFn() const
Get the personality function associated with this function.
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
Lightweight error class with error context and mandatory checking.
static bool shouldEmitUdt(const DIType *T)
CallingConvention
These values correspond to the CV_call_e enumeration, and are documented at the following locations: ...
DITypeRefArray getTypeArray() const
static const unsigned FramePtr
MachineModuleInfo * MMI
Collected machine module information.
bool isThreadLocal() const
If the value is "Thread Local", its value isn't shared by the threads.
iterator_range< global_iterator > globals()
StringRef - Represent a constant reference to a string, i.e.
static PointerToMemberRepresentation translatePtrToMemberRep(unsigned SizeInBytes, bool IsPMF, unsigned Flags)
static CallingConvention dwarfCCToCodeView(unsigned DwarfCC)
Given a DWARF calling convention, get the CodeView equivalent.
Represents a location in source code.
DILocalScope * getScope() const
Get the local scope for this variable.
unsigned getNumOperands() const
Return number of MDNode operands.
LocalSymFlags
Corresponds to CV_LVARFLAGS bitfield.
uint64_t getStackSize() const
Return the number of bytes that must be allocated to hold all of the fixed size frame objects...
static ClassOptions getCommonClassOptions(const DICompositeType *Ty)
Return ClassOptions that should be present on both the forward declaration and the defintion of a tag...
bool getFlag(MIFlag Flag) const
Return whether an MI flag is set.
void begin(ContinuationRecordKind RecordKind)
CodeViewDebug(AsmPrinter *AP)
MemberList Members
Direct members.
std::pair< const MachineInstr *, const MachineInstr * > InsnRange
InsnRange - This is used to track range of instructions with identical lexical scope.
std::vector< const DIDerivedType * > Inheritance
Base classes.
static bool needsReferenceType(const DbgVariableLocation &Loc)
LexicalScope * getCurrentFunctionScope() const
getCurrentFunctionScope - Return lexical scope for the current function.
Basic type, like 'int' or 'float'.
static bool isNonTrivial(const DICompositeType *DCTy)