76 constexpr static int32_t
NoDeref = INT32_MIN;
111 bool EmitDebugGlobalHashes =
false;
122 static LocalVarDef createDefRangeMem(
uint16_t CVRegister,
int Offset,
123 int32_t DerefOffset);
126 struct LocalVariable {
131 std::optional<APSInt> ConstantValue;
134 struct CVGlobalVariable {
135 const DIGlobalVariable *DIGV;
136 PointerUnion<const GlobalVariable *, const DIExpression *> GVInfo;
140 SmallVector<LocalVariable, 1> InlinedLocals;
141 SmallVector<const DILocation *, 1> ChildSites;
142 const DISubprogram *
Inlinee =
nullptr;
146 unsigned SiteFuncId = 0;
150 struct LexicalBlock {
151 SmallVector<LocalVariable, 1>
Locals;
152 SmallVector<CVGlobalVariable, 1> Globals;
153 SmallVector<LexicalBlock *, 1>
Children;
159 struct JumpTableInfo {
160 codeview::JumpTableEntrySize EntrySize;
166 std::vector<const MCSymbol *> Cases;
179 std::unordered_map<const DILocation *, InlineSite> InlineSites;
182 SmallVector<const DILocation *, 1> ChildSites;
185 SmallSet<codeview::TypeIndex, 1> Inlinees;
187 SmallVector<LocalVariable, 1>
Locals;
188 SmallVector<CVGlobalVariable, 1> Globals;
190 std::unordered_map<const DILexicalBlockBase*, LexicalBlock> LexicalBlocks;
193 SmallVector<LexicalBlock *, 1> ChildBlocks;
195 std::vector<std::pair<MCSymbol *, MDNode *>> Annotations;
196 std::vector<std::tuple<const MCSymbol *, const MCSymbol *, const DIType *>>
199 std::vector<JumpTableInfo> JumpTables;
204 unsigned LastFileId = 0;
207 unsigned FrameSize = 0;
210 unsigned ParamSize = 0;
213 unsigned CSRSize = 0;
216 int OffsetAdjustment = 0;
220 codeview::EncodedFramePtrReg EncodedLocalFramePtrReg =
221 codeview::EncodedFramePtrReg::None;
225 codeview::EncodedFramePtrReg EncodedParamFramePtrReg =
226 codeview::EncodedFramePtrReg::None;
228 codeview::FrameProcedureOptions FrameProcOpts;
230 bool HasStackRealignment =
false;
232 bool HaveLineInfo =
false;
234 bool HasFramePointer =
false;
238 codeview::SourceLanguage CurrentSourceLanguage =
239 codeview::SourceLanguage::Masm;
243 DenseMap<const DIGlobalVariable *, uint64_t> CVGlobalVariableOffsets;
249 DenseMap<const LexicalScope *, SmallVector<LocalVariable, 1>> ScopeVariables;
253 typedef SmallVector<CVGlobalVariable, 1> GlobalVariableList;
254 DenseMap<const DIScope*, std::unique_ptr<GlobalVariableList> > ScopeGlobals;
255 DenseMap<const DIGlobalVariableExpression *, const GlobalVariable *>
259 SmallVector<CVGlobalVariable, 1> ComdatVariables;
262 SmallVector<CVGlobalVariable, 1> GlobalVariables;
265 SmallVector<const DIDerivedType *, 4> StaticConstMembers;
270 DenseSet<MCSectionCOFF *> ComdatDebugSections;
277 void switchToDebugSectionForSymbol(
const MCSymbol *GVSym);
281 unsigned NextFuncId = 0;
283 InlineSite &getInlineSite(
const DILocation *InlinedAt,
284 const DISubprogram *Inlinee);
286 codeview::TypeIndex getFuncIdForSubprogram(
const DISubprogram *SP);
288 void calculateRanges(LocalVariable &Var,
289 const DbgValueHistoryMap::Entries &Entries);
293 MapVector<const Function *, std::unique_ptr<FunctionInfo>> FnDebugInfo;
297 DenseMap<StringRef, unsigned> FileIdMap;
300 SmallSetVector<const DISubprogram *, 4> InlinedSubprograms;
308 DenseMap<std::pair<const DINode *, const DIType *>, codeview::TypeIndex>
313 DenseMap<const DICompositeType *, codeview::TypeIndex> CompleteTypeIndices;
317 SmallVector<const DICompositeType *, 4> DeferredCompleteTypes;
320 unsigned TypeEmissionLevel = 0;
322 codeview::TypeIndex VBPType;
324 const DISubprogram *CurrentSubprogram =
nullptr;
328 std::vector<std::pair<std::string, const DIType *>> LocalUDTs;
329 std::vector<std::pair<std::string, const DIType *>> GlobalUDTs;
331 using FileToFilepathMapTy = std::map<const DIFile *, std::string>;
332 FileToFilepathMapTy FileToFilepathMap;
334 StringRef getFullFilepath(
const DIFile *File);
336 unsigned maybeRecordFile(
const DIFile *
F);
338 void maybeRecordLocation(
const DebugLoc &
DL,
const MachineFunction *MF);
342 void setCurrentSubprogram(
const DISubprogram *SP) {
343 CurrentSubprogram =
SP;
350 void emitCodeViewMagicVersion();
352 void emitTypeInformation();
354 void emitTypeGlobalHashes();
358 void emitCompilerInformation();
360 void emitSecureHotPatchInformation();
362 void emitBuildInfo();
364 void emitInlineeLinesSubsection();
366 void emitDebugInfoForThunk(
const Function *GV,
370 void emitDebugInfoForFunction(
const Function *GV, FunctionInfo &FI);
372 void emitDebugInfoForRetainedTypes();
374 void emitDebugInfoForUDTs(
375 const std::vector<std::pair<std::string, const DIType *>> &UDTs);
377 void collectDebugInfoForGlobals();
378 void emitDebugInfoForGlobals();
379 void emitGlobalVariableList(ArrayRef<CVGlobalVariable> Globals);
380 void emitConstantSymbolRecord(
const DIType *DTy, APSInt &
Value,
381 const std::string &QualifiedName);
382 void emitDebugInfoForGlobal(
const CVGlobalVariable &CVGV);
383 void emitStaticConstMemberList();
388 MCSymbol *beginCVSubsection(codeview::DebugSubsectionKind Kind);
389 void endCVSubsection(MCSymbol *EndLabel);
393 MCSymbol *beginSymbolRecord(codeview::SymbolKind Kind);
394 void endSymbolRecord(MCSymbol *SymEnd);
399 void emitEndSymbolRecord(codeview::SymbolKind EndKind);
401 void emitInlinedCallSite(
const FunctionInfo &FI,
const DILocation *InlinedAt,
402 const InlineSite &Site);
404 void emitInlinees(
const SmallSet<codeview::TypeIndex, 1> &Inlinees);
406 using InlinedEntity = DbgValueHistoryMap::InlinedEntity;
408 void collectGlobalVariableInfo();
410 collectGlobalOrStaticLocalVariableInfo(
const DIGlobalVariableExpression *GVE);
411 void collectVariableInfo(
const DISubprogram *SP);
413 void collectVariableInfoFromMFTable(DenseSet<InlinedEntity> &Processed);
417 void collectLexicalBlockInfo(SmallVectorImpl<LexicalScope *> &Scopes,
418 SmallVectorImpl<LexicalBlock *> &Blocks,
419 SmallVectorImpl<LocalVariable> &Locals,
420 SmallVectorImpl<CVGlobalVariable> &Globals);
421 void collectLexicalBlockInfo(LexicalScope &Scope,
422 SmallVectorImpl<LexicalBlock *> &ParentBlocks,
423 SmallVectorImpl<LocalVariable> &ParentLocals,
424 SmallVectorImpl<CVGlobalVariable> &ParentGlobals);
428 void recordLocalVariable(LocalVariable &&Var,
const LexicalScope *LS);
431 void emitLocalVariableList(
const FunctionInfo &FI,
432 ArrayRef<LocalVariable> Locals);
435 void emitLocalVariable(
const FunctionInfo &FI,
const LocalVariable &Var);
438 void emitLexicalBlockList(ArrayRef<LexicalBlock *> Blocks,
439 const FunctionInfo& FI);
442 void emitLexicalBlock(
const LexicalBlock &Block,
const FunctionInfo& FI);
446 codeview::TypeIndex getTypeIndex(
const DIType *Ty,
447 const DIType *ClassTy =
nullptr);
450 getTypeIndexForThisPtr(
const DIDerivedType *PtrTy,
451 const DISubroutineType *SubroutineTy);
453 codeview::TypeIndex getMemberFunctionType(
const DISubprogram *SP,
454 const DICompositeType *Class);
456 codeview::TypeIndex getScopeIndex(
const DIScope *Scope);
458 codeview::TypeIndex getVBPTypeIndex();
460 void addToUDTs(
const DIType *Ty);
462 void addUDTSrcLine(
const DIType *Ty, codeview::TypeIndex TI);
464 codeview::TypeIndex lowerType(
const DIType *Ty,
const DIType *ClassTy);
465 codeview::TypeIndex lowerTypeAlias(
const DIDerivedType *Ty);
466 codeview::TypeIndex lowerTypeArray(
const DICompositeType *Ty);
467 codeview::TypeIndex lowerTypeString(
const DIStringType *Ty);
468 codeview::TypeIndex lowerTypeBasic(
const DIBasicType *Ty);
469 codeview::TypeIndex lowerTypePointer(
470 const DIDerivedType *Ty,
471 codeview::PointerOptions PO = codeview::PointerOptions::None);
472 codeview::TypeIndex lowerTypeMemberPointer(
473 const DIDerivedType *Ty,
474 codeview::PointerOptions PO = codeview::PointerOptions::None);
475 codeview::TypeIndex lowerTypeModifier(
const DIDerivedType *Ty);
476 codeview::TypeIndex lowerTypeFunction(
const DISubroutineType *Ty);
477 codeview::TypeIndex lowerTypeVFTableShape(
const DIDerivedType *Ty);
478 codeview::TypeIndex lowerTypeMemberFunction(
479 const DISubroutineType *Ty,
const DIType *ClassTy,
int ThisAdjustment,
481 codeview::FunctionOptions FO = codeview::FunctionOptions::None);
482 codeview::TypeIndex lowerTypeEnum(
const DICompositeType *Ty);
483 codeview::TypeIndex lowerTypeClass(
const DICompositeType *Ty);
484 codeview::TypeIndex lowerTypeUnion(
const DICompositeType *Ty);
491 codeview::TypeIndex getCompleteTypeIndex(
const DIType *Ty);
493 codeview::TypeIndex lowerCompleteTypeClass(
const DICompositeType *Ty);
494 codeview::TypeIndex lowerCompleteTypeUnion(
const DICompositeType *Ty);
496 struct TypeLoweringScope;
498 void emitDeferredCompleteTypes();
500 void collectMemberInfo(ClassInfo &Info,
const DIDerivedType *DDTy);
501 ClassInfo collectClassInfo(
const DICompositeType *Ty);
506 std::tuple<codeview::TypeIndex, codeview::TypeIndex, unsigned, bool>
507 lowerRecordFieldList(
const DICompositeType *Ty);
510 codeview::TypeIndex recordTypeIndexForDINode(
const DINode *Node,
511 codeview::TypeIndex TI,
512 const DIType *ClassTy =
nullptr);
518 collectParentScopeNames(
const DIScope *Scope,
519 SmallVectorImpl<StringRef> &ParentScopeNames);
520 std::string getFullyQualifiedName(
const DIScope *Scope, StringRef Name);
521 std::string getFullyQualifiedName(
const DIScope *Scope);
523 unsigned getPointerSizeInBytes();
525 void discoverJumpTableBranches(
const MachineFunction *MF,
bool isThumb);
526 void collectDebugInfoForJumpTables(
const MachineFunction *MF,
bool isThumb);
527 void emitDebugInfoForJumpTables(
const FunctionInfo &FI);
531 void beginFunctionImpl(
const MachineFunction *MF)
override;
534 void endFunctionImpl(
const MachineFunction *)
override;
538 return CurrentSourceLanguage == codeview::SourceLanguage::Fortran;
544 void beginModule(
Module *M)
override;
547 void endModule()
override;