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 CSRSize = 0;
213 int OffsetAdjustment = 0;
217 codeview::EncodedFramePtrReg EncodedLocalFramePtrReg =
218 codeview::EncodedFramePtrReg::None;
222 codeview::EncodedFramePtrReg EncodedParamFramePtrReg =
223 codeview::EncodedFramePtrReg::None;
225 codeview::FrameProcedureOptions FrameProcOpts;
227 bool HasStackRealignment =
false;
229 bool HaveLineInfo =
false;
231 bool HasFramePointer =
false;
235 codeview::SourceLanguage CurrentSourceLanguage =
236 codeview::SourceLanguage::Masm;
240 DenseMap<const DIGlobalVariable *, uint64_t> CVGlobalVariableOffsets;
246 DenseMap<const LexicalScope *, SmallVector<LocalVariable, 1>> ScopeVariables;
250 typedef SmallVector<CVGlobalVariable, 1> GlobalVariableList;
251 DenseMap<const DIScope*, std::unique_ptr<GlobalVariableList> > ScopeGlobals;
252 DenseMap<const DIGlobalVariableExpression *, const GlobalVariable *>
256 SmallVector<CVGlobalVariable, 1> ComdatVariables;
259 SmallVector<CVGlobalVariable, 1> GlobalVariables;
262 SmallVector<const DIDerivedType *, 4> StaticConstMembers;
267 DenseSet<MCSectionCOFF *> ComdatDebugSections;
274 void switchToDebugSectionForSymbol(
const MCSymbol *GVSym);
278 unsigned NextFuncId = 0;
280 InlineSite &getInlineSite(
const DILocation *InlinedAt,
281 const DISubprogram *Inlinee);
283 codeview::TypeIndex getFuncIdForSubprogram(
const DISubprogram *SP);
285 void calculateRanges(LocalVariable &Var,
286 const DbgValueHistoryMap::Entries &Entries);
290 MapVector<const Function *, std::unique_ptr<FunctionInfo>> FnDebugInfo;
294 DenseMap<StringRef, unsigned> FileIdMap;
297 SmallSetVector<const DISubprogram *, 4> InlinedSubprograms;
305 DenseMap<std::pair<const DINode *, const DIType *>, codeview::TypeIndex>
310 DenseMap<const DICompositeType *, codeview::TypeIndex> CompleteTypeIndices;
314 SmallVector<const DICompositeType *, 4> DeferredCompleteTypes;
317 unsigned TypeEmissionLevel = 0;
319 codeview::TypeIndex VBPType;
321 const DISubprogram *CurrentSubprogram =
nullptr;
325 std::vector<std::pair<std::string, const DIType *>> LocalUDTs;
326 std::vector<std::pair<std::string, const DIType *>> GlobalUDTs;
328 using FileToFilepathMapTy = std::map<const DIFile *, std::string>;
329 FileToFilepathMapTy FileToFilepathMap;
331 StringRef getFullFilepath(
const DIFile *File);
333 unsigned maybeRecordFile(
const DIFile *
F);
335 void maybeRecordLocation(
const DebugLoc &
DL,
const MachineFunction *MF);
339 void setCurrentSubprogram(
const DISubprogram *SP) {
340 CurrentSubprogram =
SP;
347 void emitCodeViewMagicVersion();
349 void emitTypeInformation();
351 void emitTypeGlobalHashes();
355 void emitCompilerInformation();
357 void emitSecureHotPatchInformation();
359 void emitBuildInfo();
361 void emitInlineeLinesSubsection();
363 void emitDebugInfoForThunk(
const Function *GV,
367 void emitDebugInfoForFunction(
const Function *GV, FunctionInfo &FI);
369 void emitDebugInfoForRetainedTypes();
371 void emitDebugInfoForUDTs(
372 const std::vector<std::pair<std::string, const DIType *>> &UDTs);
374 void collectDebugInfoForGlobals();
375 void emitDebugInfoForGlobals();
376 void emitGlobalVariableList(ArrayRef<CVGlobalVariable> Globals);
377 void emitConstantSymbolRecord(
const DIType *DTy, APSInt &
Value,
378 const std::string &QualifiedName);
379 void emitDebugInfoForGlobal(
const CVGlobalVariable &CVGV);
380 void emitStaticConstMemberList();
385 MCSymbol *beginCVSubsection(codeview::DebugSubsectionKind Kind);
386 void endCVSubsection(MCSymbol *EndLabel);
390 MCSymbol *beginSymbolRecord(codeview::SymbolKind Kind);
391 void endSymbolRecord(MCSymbol *SymEnd);
396 void emitEndSymbolRecord(codeview::SymbolKind EndKind);
398 void emitInlinedCallSite(
const FunctionInfo &FI,
const DILocation *InlinedAt,
399 const InlineSite &Site);
401 void emitInlinees(
const SmallSet<codeview::TypeIndex, 1> &Inlinees);
403 using InlinedEntity = DbgValueHistoryMap::InlinedEntity;
405 void collectGlobalVariableInfo();
407 collectGlobalOrStaticLocalVariableInfo(
const DIGlobalVariableExpression *GVE);
408 void collectVariableInfo(
const DISubprogram *SP);
410 void collectVariableInfoFromMFTable(DenseSet<InlinedEntity> &Processed);
414 void collectLexicalBlockInfo(SmallVectorImpl<LexicalScope *> &Scopes,
415 SmallVectorImpl<LexicalBlock *> &Blocks,
416 SmallVectorImpl<LocalVariable> &Locals,
417 SmallVectorImpl<CVGlobalVariable> &Globals);
418 void collectLexicalBlockInfo(LexicalScope &Scope,
419 SmallVectorImpl<LexicalBlock *> &ParentBlocks,
420 SmallVectorImpl<LocalVariable> &ParentLocals,
421 SmallVectorImpl<CVGlobalVariable> &ParentGlobals);
425 void recordLocalVariable(LocalVariable &&Var,
const LexicalScope *LS);
428 void emitLocalVariableList(
const FunctionInfo &FI,
429 ArrayRef<LocalVariable> Locals);
432 void emitLocalVariable(
const FunctionInfo &FI,
const LocalVariable &Var);
435 void emitLexicalBlockList(ArrayRef<LexicalBlock *> Blocks,
436 const FunctionInfo& FI);
439 void emitLexicalBlock(
const LexicalBlock &Block,
const FunctionInfo& FI);
443 codeview::TypeIndex getTypeIndex(
const DIType *Ty,
444 const DIType *ClassTy =
nullptr);
447 getTypeIndexForThisPtr(
const DIDerivedType *PtrTy,
448 const DISubroutineType *SubroutineTy);
450 codeview::TypeIndex getMemberFunctionType(
const DISubprogram *SP,
451 const DICompositeType *Class);
453 codeview::TypeIndex getScopeIndex(
const DIScope *Scope);
455 codeview::TypeIndex getVBPTypeIndex();
457 void addToUDTs(
const DIType *Ty);
459 void addUDTSrcLine(
const DIType *Ty, codeview::TypeIndex TI);
461 codeview::TypeIndex lowerType(
const DIType *Ty,
const DIType *ClassTy);
462 codeview::TypeIndex lowerTypeAlias(
const DIDerivedType *Ty);
463 codeview::TypeIndex lowerTypeArray(
const DICompositeType *Ty);
464 codeview::TypeIndex lowerTypeString(
const DIStringType *Ty);
465 codeview::TypeIndex lowerTypeBasic(
const DIBasicType *Ty);
466 codeview::TypeIndex lowerTypePointer(
467 const DIDerivedType *Ty,
468 codeview::PointerOptions PO = codeview::PointerOptions::None);
469 codeview::TypeIndex lowerTypeMemberPointer(
470 const DIDerivedType *Ty,
471 codeview::PointerOptions PO = codeview::PointerOptions::None);
472 codeview::TypeIndex lowerTypeModifier(
const DIDerivedType *Ty);
473 codeview::TypeIndex lowerTypeFunction(
const DISubroutineType *Ty);
474 codeview::TypeIndex lowerTypeVFTableShape(
const DIDerivedType *Ty);
475 codeview::TypeIndex lowerTypeMemberFunction(
476 const DISubroutineType *Ty,
const DIType *ClassTy,
int ThisAdjustment,
478 codeview::FunctionOptions FO = codeview::FunctionOptions::None);
479 codeview::TypeIndex lowerTypeEnum(
const DICompositeType *Ty);
480 codeview::TypeIndex lowerTypeClass(
const DICompositeType *Ty);
481 codeview::TypeIndex lowerTypeUnion(
const DICompositeType *Ty);
488 codeview::TypeIndex getCompleteTypeIndex(
const DIType *Ty);
490 codeview::TypeIndex lowerCompleteTypeClass(
const DICompositeType *Ty);
491 codeview::TypeIndex lowerCompleteTypeUnion(
const DICompositeType *Ty);
493 struct TypeLoweringScope;
495 void emitDeferredCompleteTypes();
497 void collectMemberInfo(ClassInfo &Info,
const DIDerivedType *DDTy);
498 ClassInfo collectClassInfo(
const DICompositeType *Ty);
503 std::tuple<codeview::TypeIndex, codeview::TypeIndex, unsigned, bool>
504 lowerRecordFieldList(
const DICompositeType *Ty);
507 codeview::TypeIndex recordTypeIndexForDINode(
const DINode *Node,
508 codeview::TypeIndex TI,
509 const DIType *ClassTy =
nullptr);
515 collectParentScopeNames(
const DIScope *Scope,
516 SmallVectorImpl<StringRef> &ParentScopeNames);
517 std::string getFullyQualifiedName(
const DIScope *Scope, StringRef Name);
518 std::string getFullyQualifiedName(
const DIScope *Scope);
520 unsigned getPointerSizeInBytes();
522 void discoverJumpTableBranches(
const MachineFunction *MF,
bool isThumb);
523 void collectDebugInfoForJumpTables(
const MachineFunction *MF,
bool isThumb);
524 void emitDebugInfoForJumpTables(
const FunctionInfo &FI);
528 void beginFunctionImpl(
const MachineFunction *MF)
override;
531 void endFunctionImpl(
const MachineFunction *)
override;
535 return CurrentSourceLanguage == codeview::SourceLanguage::Fortran;
541 void beginModule(
Module *M)
override;
544 void endModule()
override;