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;
257 SmallVector<CVGlobalVariable, 1> ComdatVariables;
260 SmallVector<CVGlobalVariable, 1> GlobalVariables;
263 SmallVector<const DIDerivedType *, 4> StaticConstMembers;
268 DenseSet<MCSectionCOFF *> ComdatDebugSections;
275 void switchToDebugSectionForSymbol(
const MCSymbol *GVSym);
279 unsigned NextFuncId = 0;
281 InlineSite &getInlineSite(
const DILocation *InlinedAt,
282 const DISubprogram *Inlinee);
284 codeview::TypeIndex getFuncIdForSubprogram(
const DISubprogram *SP);
286 void calculateRanges(LocalVariable &Var,
287 const DbgValueHistoryMap::Entries &Entries);
291 MapVector<const Function *, std::unique_ptr<FunctionInfo>> FnDebugInfo;
295 DenseMap<StringRef, unsigned> FileIdMap;
298 SmallSetVector<const DISubprogram *, 4> InlinedSubprograms;
306 DenseMap<std::pair<const DINode *, const DIType *>, codeview::TypeIndex>
311 DenseMap<const DICompositeType *, codeview::TypeIndex> CompleteTypeIndices;
315 SmallVector<const DICompositeType *, 4> DeferredCompleteTypes;
318 unsigned TypeEmissionLevel = 0;
320 codeview::TypeIndex VBPType;
322 const DISubprogram *CurrentSubprogram =
nullptr;
326 std::vector<std::pair<std::string, const DIType *>> LocalUDTs;
327 std::vector<std::pair<std::string, const DIType *>> GlobalUDTs;
329 using FileToFilepathMapTy = std::map<const DIFile *, std::string>;
330 FileToFilepathMapTy FileToFilepathMap;
332 StringRef getFullFilepath(
const DIFile *File);
334 unsigned maybeRecordFile(
const DIFile *
F);
336 void maybeRecordLocation(
const DebugLoc &
DL,
const MachineFunction *MF);
340 void setCurrentSubprogram(
const DISubprogram *SP) {
341 CurrentSubprogram =
SP;
348 void emitCodeViewMagicVersion();
350 void emitTypeInformation();
352 void emitTypeGlobalHashes();
356 void emitCompilerInformation();
358 void emitSecureHotPatchInformation();
360 void emitBuildInfo();
362 void emitInlineeLinesSubsection();
364 void emitDebugInfoForThunk(
const Function *GV,
368 void emitDebugInfoForFunction(
const Function *GV, FunctionInfo &FI);
370 void emitDebugInfoForRetainedTypes();
372 void emitDebugInfoForUDTs(
373 const std::vector<std::pair<std::string, const DIType *>> &UDTs);
375 void collectDebugInfoForGlobals();
376 void emitDebugInfoForGlobals();
377 void emitGlobalVariableList(ArrayRef<CVGlobalVariable> Globals);
378 void emitConstantSymbolRecord(
const DIType *DTy, APSInt &
Value,
379 const std::string &QualifiedName);
380 void emitDebugInfoForGlobal(
const CVGlobalVariable &CVGV);
381 void emitStaticConstMemberList();
386 MCSymbol *beginCVSubsection(codeview::DebugSubsectionKind Kind);
387 void endCVSubsection(MCSymbol *EndLabel);
391 MCSymbol *beginSymbolRecord(codeview::SymbolKind Kind);
392 void endSymbolRecord(MCSymbol *SymEnd);
397 void emitEndSymbolRecord(codeview::SymbolKind EndKind);
399 void emitInlinedCallSite(
const FunctionInfo &FI,
const DILocation *InlinedAt,
400 const InlineSite &Site);
402 void emitInlinees(
const SmallSet<codeview::TypeIndex, 1> &Inlinees);
404 using InlinedEntity = DbgValueHistoryMap::InlinedEntity;
406 void collectGlobalVariableInfo();
407 void collectVariableInfo(
const DISubprogram *SP);
409 void collectVariableInfoFromMFTable(DenseSet<InlinedEntity> &Processed);
413 void collectLexicalBlockInfo(SmallVectorImpl<LexicalScope *> &Scopes,
414 SmallVectorImpl<LexicalBlock *> &Blocks,
415 SmallVectorImpl<LocalVariable> &Locals,
416 SmallVectorImpl<CVGlobalVariable> &Globals);
417 void collectLexicalBlockInfo(LexicalScope &Scope,
418 SmallVectorImpl<LexicalBlock *> &ParentBlocks,
419 SmallVectorImpl<LocalVariable> &ParentLocals,
420 SmallVectorImpl<CVGlobalVariable> &ParentGlobals);
424 void recordLocalVariable(LocalVariable &&Var,
const LexicalScope *LS);
427 void emitLocalVariableList(
const FunctionInfo &FI,
428 ArrayRef<LocalVariable> Locals);
431 void emitLocalVariable(
const FunctionInfo &FI,
const LocalVariable &Var);
434 void emitLexicalBlockList(ArrayRef<LexicalBlock *> Blocks,
435 const FunctionInfo& FI);
438 void emitLexicalBlock(
const LexicalBlock &Block,
const FunctionInfo& FI);
442 codeview::TypeIndex getTypeIndex(
const DIType *Ty,
443 const DIType *ClassTy =
nullptr);
446 getTypeIndexForThisPtr(
const DIDerivedType *PtrTy,
447 const DISubroutineType *SubroutineTy);
449 codeview::TypeIndex getMemberFunctionType(
const DISubprogram *SP,
450 const DICompositeType *Class);
452 codeview::TypeIndex getScopeIndex(
const DIScope *Scope);
454 codeview::TypeIndex getVBPTypeIndex();
456 void addToUDTs(
const DIType *Ty);
458 void addUDTSrcLine(
const DIType *Ty, codeview::TypeIndex TI);
460 codeview::TypeIndex lowerType(
const DIType *Ty,
const DIType *ClassTy);
461 codeview::TypeIndex lowerTypeAlias(
const DIDerivedType *Ty);
462 codeview::TypeIndex lowerTypeArray(
const DICompositeType *Ty);
463 codeview::TypeIndex lowerTypeString(
const DIStringType *Ty);
464 codeview::TypeIndex lowerTypeBasic(
const DIBasicType *Ty);
465 codeview::TypeIndex lowerTypePointer(
466 const DIDerivedType *Ty,
467 codeview::PointerOptions PO = codeview::PointerOptions::None);
468 codeview::TypeIndex lowerTypeMemberPointer(
469 const DIDerivedType *Ty,
470 codeview::PointerOptions PO = codeview::PointerOptions::None);
471 codeview::TypeIndex lowerTypeModifier(
const DIDerivedType *Ty);
472 codeview::TypeIndex lowerTypeFunction(
const DISubroutineType *Ty);
473 codeview::TypeIndex lowerTypeVFTableShape(
const DIDerivedType *Ty);
474 codeview::TypeIndex lowerTypeMemberFunction(
475 const DISubroutineType *Ty,
const DIType *ClassTy,
int ThisAdjustment,
477 codeview::FunctionOptions FO = codeview::FunctionOptions::None);
478 codeview::TypeIndex lowerTypeEnum(
const DICompositeType *Ty);
479 codeview::TypeIndex lowerTypeClass(
const DICompositeType *Ty);
480 codeview::TypeIndex lowerTypeUnion(
const DICompositeType *Ty);
487 codeview::TypeIndex getCompleteTypeIndex(
const DIType *Ty);
489 codeview::TypeIndex lowerCompleteTypeClass(
const DICompositeType *Ty);
490 codeview::TypeIndex lowerCompleteTypeUnion(
const DICompositeType *Ty);
492 struct TypeLoweringScope;
494 void emitDeferredCompleteTypes();
496 void collectMemberInfo(ClassInfo &Info,
const DIDerivedType *DDTy);
497 ClassInfo collectClassInfo(
const DICompositeType *Ty);
502 std::tuple<codeview::TypeIndex, codeview::TypeIndex, unsigned, bool>
503 lowerRecordFieldList(
const DICompositeType *Ty);
506 codeview::TypeIndex recordTypeIndexForDINode(
const DINode *Node,
507 codeview::TypeIndex TI,
508 const DIType *ClassTy =
nullptr);
514 collectParentScopeNames(
const DIScope *Scope,
515 SmallVectorImpl<StringRef> &ParentScopeNames);
516 std::string getFullyQualifiedName(
const DIScope *Scope, StringRef Name);
517 std::string getFullyQualifiedName(
const DIScope *Scope);
519 unsigned getPointerSizeInBytes();
521 void discoverJumpTableBranches(
const MachineFunction *MF,
bool isThumb);
522 void collectDebugInfoForJumpTables(
const MachineFunction *MF,
bool isThumb);
523 void emitDebugInfoForJumpTables(
const FunctionInfo &FI);
527 void beginFunctionImpl(
const MachineFunction *MF)
override;
530 void endFunctionImpl(
const MachineFunction *)
override;
534 return CurrentSourceLanguage == codeview::SourceLanguage::Fortran;
540 void beginModule(
Module *M)
override;
543 void endModule()
override;