77 std::memcpy(&Val, &DR,
sizeof(Val));
83 std::memcpy(&DR, &Val,
sizeof(Val));
88 static_assert(
sizeof(
uint64_t) ==
sizeof(LocalVarDef));
96 bool EmitDebugGlobalHashes =
false;
107 static LocalVarDef createDefRangeMem(
uint16_t CVRegister,
int Offset);
110 struct LocalVariable {
115 bool UseReferenceType =
false;
116 std::optional<APSInt> ConstantValue;
119 struct CVGlobalVariable {
120 const DIGlobalVariable *DIGV;
121 PointerUnion<const GlobalVariable *, const DIExpression *> GVInfo;
125 SmallVector<LocalVariable, 1> InlinedLocals;
126 SmallVector<const DILocation *, 1> ChildSites;
127 const DISubprogram *
Inlinee =
nullptr;
131 unsigned SiteFuncId = 0;
135 struct LexicalBlock {
136 SmallVector<LocalVariable, 1>
Locals;
137 SmallVector<CVGlobalVariable, 1> Globals;
138 SmallVector<LexicalBlock *, 1>
Children;
144 struct JumpTableInfo {
145 codeview::JumpTableEntrySize EntrySize;
151 std::vector<const MCSymbol *> Cases;
156 struct FunctionInfo {
157 FunctionInfo() =
default;
160 FunctionInfo(
const FunctionInfo &FI) =
delete;
164 std::unordered_map<const DILocation *, InlineSite> InlineSites;
167 SmallVector<const DILocation *, 1> ChildSites;
170 SmallSet<codeview::TypeIndex, 1> Inlinees;
172 SmallVector<LocalVariable, 1>
Locals;
173 SmallVector<CVGlobalVariable, 1> Globals;
175 std::unordered_map<const DILexicalBlockBase*, LexicalBlock> LexicalBlocks;
178 SmallVector<LexicalBlock *, 1> ChildBlocks;
180 std::vector<std::pair<MCSymbol *, MDNode *>> Annotations;
181 std::vector<std::tuple<const MCSymbol *, const MCSymbol *, const DIType *>>
184 std::vector<JumpTableInfo> JumpTables;
189 unsigned LastFileId = 0;
192 unsigned FrameSize = 0;
195 unsigned ParamSize = 0;
198 unsigned CSRSize = 0;
201 int OffsetAdjustment = 0;
205 codeview::EncodedFramePtrReg EncodedLocalFramePtrReg =
206 codeview::EncodedFramePtrReg::None;
210 codeview::EncodedFramePtrReg EncodedParamFramePtrReg =
211 codeview::EncodedFramePtrReg::None;
213 codeview::FrameProcedureOptions FrameProcOpts;
215 bool HasStackRealignment =
false;
217 bool HaveLineInfo =
false;
219 bool HasFramePointer =
false;
221 FunctionInfo *CurFn =
nullptr;
223 codeview::SourceLanguage CurrentSourceLanguage =
224 codeview::SourceLanguage::Masm;
228 DenseMap<const DIGlobalVariable *, uint64_t> CVGlobalVariableOffsets;
234 DenseMap<const LexicalScope *, SmallVector<LocalVariable, 1>> ScopeVariables;
238 typedef SmallVector<CVGlobalVariable, 1> GlobalVariableList;
239 DenseMap<const DIScope*, std::unique_ptr<GlobalVariableList> > ScopeGlobals;
242 SmallVector<CVGlobalVariable, 1> ComdatVariables;
245 SmallVector<CVGlobalVariable, 1> GlobalVariables;
248 SmallVector<const DIDerivedType *, 4> StaticConstMembers;
253 DenseSet<MCSectionCOFF *> ComdatDebugSections;
260 void switchToDebugSectionForSymbol(
const MCSymbol *GVSym);
264 unsigned NextFuncId = 0;
266 InlineSite &getInlineSite(
const DILocation *InlinedAt,
267 const DISubprogram *Inlinee);
269 codeview::TypeIndex getFuncIdForSubprogram(
const DISubprogram *SP);
271 void calculateRanges(LocalVariable &Var,
272 const DbgValueHistoryMap::Entries &Entries);
276 MapVector<const Function *, std::unique_ptr<FunctionInfo>> FnDebugInfo;
280 DenseMap<StringRef, unsigned> FileIdMap;
283 SmallSetVector<const DISubprogram *, 4> InlinedSubprograms;
291 DenseMap<std::pair<const DINode *, const DIType *>, codeview::TypeIndex>
296 DenseMap<const DICompositeType *, codeview::TypeIndex> CompleteTypeIndices;
300 SmallVector<const DICompositeType *, 4> DeferredCompleteTypes;
303 unsigned TypeEmissionLevel = 0;
305 codeview::TypeIndex VBPType;
307 const DISubprogram *CurrentSubprogram =
nullptr;
311 std::vector<std::pair<std::string, const DIType *>> LocalUDTs;
312 std::vector<std::pair<std::string, const DIType *>> GlobalUDTs;
314 using FileToFilepathMapTy = std::map<const DIFile *, std::string>;
315 FileToFilepathMapTy FileToFilepathMap;
317 StringRef getFullFilepath(
const DIFile *File);
319 unsigned maybeRecordFile(
const DIFile *
F);
321 void maybeRecordLocation(
const DebugLoc &
DL,
const MachineFunction *MF);
325 void setCurrentSubprogram(
const DISubprogram *SP) {
326 CurrentSubprogram =
SP;
333 void emitCodeViewMagicVersion();
335 void emitTypeInformation();
337 void emitTypeGlobalHashes();
341 void emitCompilerInformation();
343 void emitSecureHotPatchInformation();
345 void emitBuildInfo();
347 void emitInlineeLinesSubsection();
349 void emitDebugInfoForThunk(
const Function *GV,
353 void emitDebugInfoForFunction(
const Function *GV, FunctionInfo &FI);
355 void emitDebugInfoForRetainedTypes();
357 void emitDebugInfoForUDTs(
358 const std::vector<std::pair<std::string, const DIType *>> &UDTs);
360 void collectDebugInfoForGlobals();
361 void emitDebugInfoForGlobals();
362 void emitGlobalVariableList(ArrayRef<CVGlobalVariable> Globals);
363 void emitConstantSymbolRecord(
const DIType *DTy, APSInt &
Value,
364 const std::string &QualifiedName);
365 void emitDebugInfoForGlobal(
const CVGlobalVariable &CVGV);
366 void emitStaticConstMemberList();
371 MCSymbol *beginCVSubsection(codeview::DebugSubsectionKind Kind);
372 void endCVSubsection(MCSymbol *EndLabel);
376 MCSymbol *beginSymbolRecord(codeview::SymbolKind Kind);
377 void endSymbolRecord(MCSymbol *SymEnd);
382 void emitEndSymbolRecord(codeview::SymbolKind EndKind);
384 void emitInlinedCallSite(
const FunctionInfo &FI,
const DILocation *InlinedAt,
385 const InlineSite &Site);
387 void emitInlinees(
const SmallSet<codeview::TypeIndex, 1> &Inlinees);
389 using InlinedEntity = DbgValueHistoryMap::InlinedEntity;
391 void collectGlobalVariableInfo();
392 void collectVariableInfo(
const DISubprogram *SP);
394 void collectVariableInfoFromMFTable(DenseSet<InlinedEntity> &Processed);
398 void collectLexicalBlockInfo(SmallVectorImpl<LexicalScope *> &Scopes,
399 SmallVectorImpl<LexicalBlock *> &Blocks,
400 SmallVectorImpl<LocalVariable> &Locals,
401 SmallVectorImpl<CVGlobalVariable> &Globals);
402 void collectLexicalBlockInfo(LexicalScope &Scope,
403 SmallVectorImpl<LexicalBlock *> &ParentBlocks,
404 SmallVectorImpl<LocalVariable> &ParentLocals,
405 SmallVectorImpl<CVGlobalVariable> &ParentGlobals);
409 void recordLocalVariable(LocalVariable &&Var,
const LexicalScope *LS);
412 void emitLocalVariableList(
const FunctionInfo &FI,
413 ArrayRef<LocalVariable> Locals);
416 void emitLocalVariable(
const FunctionInfo &FI,
const LocalVariable &Var);
419 void emitLexicalBlockList(ArrayRef<LexicalBlock *> Blocks,
420 const FunctionInfo& FI);
423 void emitLexicalBlock(
const LexicalBlock &Block,
const FunctionInfo& FI);
427 codeview::TypeIndex getTypeIndex(
const DIType *Ty,
428 const DIType *ClassTy =
nullptr);
431 getTypeIndexForThisPtr(
const DIDerivedType *PtrTy,
432 const DISubroutineType *SubroutineTy);
434 codeview::TypeIndex getTypeIndexForReferenceTo(
const DIType *Ty);
436 codeview::TypeIndex getMemberFunctionType(
const DISubprogram *SP,
437 const DICompositeType *Class);
439 codeview::TypeIndex getScopeIndex(
const DIScope *Scope);
441 codeview::TypeIndex getVBPTypeIndex();
443 void addToUDTs(
const DIType *Ty);
445 void addUDTSrcLine(
const DIType *Ty, codeview::TypeIndex TI);
447 codeview::TypeIndex lowerType(
const DIType *Ty,
const DIType *ClassTy);
448 codeview::TypeIndex lowerTypeAlias(
const DIDerivedType *Ty);
449 codeview::TypeIndex lowerTypeArray(
const DICompositeType *Ty);
450 codeview::TypeIndex lowerTypeString(
const DIStringType *Ty);
451 codeview::TypeIndex lowerTypeBasic(
const DIBasicType *Ty);
452 codeview::TypeIndex lowerTypePointer(
453 const DIDerivedType *Ty,
454 codeview::PointerOptions PO = codeview::PointerOptions::None);
455 codeview::TypeIndex lowerTypeMemberPointer(
456 const DIDerivedType *Ty,
457 codeview::PointerOptions PO = codeview::PointerOptions::None);
458 codeview::TypeIndex lowerTypeModifier(
const DIDerivedType *Ty);
459 codeview::TypeIndex lowerTypeFunction(
const DISubroutineType *Ty);
460 codeview::TypeIndex lowerTypeVFTableShape(
const DIDerivedType *Ty);
461 codeview::TypeIndex lowerTypeMemberFunction(
462 const DISubroutineType *Ty,
const DIType *ClassTy,
int ThisAdjustment,
464 codeview::FunctionOptions FO = codeview::FunctionOptions::None);
465 codeview::TypeIndex lowerTypeEnum(
const DICompositeType *Ty);
466 codeview::TypeIndex lowerTypeClass(
const DICompositeType *Ty);
467 codeview::TypeIndex lowerTypeUnion(
const DICompositeType *Ty);
474 codeview::TypeIndex getCompleteTypeIndex(
const DIType *Ty);
476 codeview::TypeIndex lowerCompleteTypeClass(
const DICompositeType *Ty);
477 codeview::TypeIndex lowerCompleteTypeUnion(
const DICompositeType *Ty);
479 struct TypeLoweringScope;
481 void emitDeferredCompleteTypes();
483 void collectMemberInfo(ClassInfo &
Info,
const DIDerivedType *DDTy);
484 ClassInfo collectClassInfo(
const DICompositeType *Ty);
489 std::tuple<codeview::TypeIndex, codeview::TypeIndex, unsigned, bool>
490 lowerRecordFieldList(
const DICompositeType *Ty);
493 codeview::TypeIndex recordTypeIndexForDINode(
const DINode *Node,
494 codeview::TypeIndex TI,
495 const DIType *ClassTy =
nullptr);
501 collectParentScopeNames(
const DIScope *Scope,
502 SmallVectorImpl<StringRef> &ParentScopeNames);
503 std::string getFullyQualifiedName(
const DIScope *Scope, StringRef Name);
504 std::string getFullyQualifiedName(
const DIScope *Scope);
506 unsigned getPointerSizeInBytes();
508 void discoverJumpTableBranches(
const MachineFunction *MF,
bool isThumb);
509 void collectDebugInfoForJumpTables(
const MachineFunction *MF,
bool isThumb);
510 void emitDebugInfoForJumpTables(
const FunctionInfo &FI);
514 void beginFunctionImpl(
const MachineFunction *MF)
override;
517 void endFunctionImpl(
const MachineFunction *)
override;
521 return CurrentSourceLanguage == codeview::SourceLanguage::Fortran;
527 void beginModule(
Module *M)
override;
530 void endModule()
override;