LLVM: lib/CodeGen/AsmPrinter/CodeViewDebug.h Source File (original) (raw)

56public:

58

59

61

62

64

65

67

68

70

71

72

74

77 std::memcpy(&Val, &DR, sizeof(Val));

78 return Val;

79 }

80

83 std::memcpy(&DR, &Val, sizeof(Val));

84 return DR;

85 }

86 };

87

88 static_assert(sizeof(uint64_t) == sizeof(LocalVarDef));

89

90private:

94

95

96 bool EmitDebugGlobalHashes = false;

97

98

100

102

103

104

105 AsmPrinter *CompilerInfoAsm = nullptr;

106

107 static LocalVarDef createDefRangeMem(uint16_t CVRegister, int Offset);

108

109

110 struct LocalVariable {

114 DefRanges;

115 bool UseReferenceType = false;

116 std::optional ConstantValue;

117 };

118

119 struct CVGlobalVariable {

120 const DIGlobalVariable *DIGV;

121 PointerUnion<const GlobalVariable *, const DIExpression *> GVInfo;

122 };

123

125 SmallVector<LocalVariable, 1> InlinedLocals;

126 SmallVector<const DILocation *, 1> ChildSites;

127 const DISubprogram *Inlinee = nullptr;

128

129

130

131 unsigned SiteFuncId = 0;

132 };

133

134

135 struct LexicalBlock {

136 SmallVector<LocalVariable, 1> Locals;

137 SmallVector<CVGlobalVariable, 1> Globals;

138 SmallVector<LexicalBlock *, 1> Children;

141 StringRef Name;

142 };

143

144 struct JumpTableInfo {

145 codeview::JumpTableEntrySize EntrySize;

147 uint64_t BaseOffset;

150 size_t TableSize;

151 std::vector<const MCSymbol *> Cases;

152 };

153

154

155

156 struct FunctionInfo {

157 FunctionInfo() = default;

158

159

160 FunctionInfo(const FunctionInfo &FI) = delete;

161

162

163

164 std::unordered_map<const DILocation *, InlineSite> InlineSites;

165

166

167 SmallVector<const DILocation *, 1> ChildSites;

168

169

170 SmallSet<codeview::TypeIndex, 1> Inlinees;

171

172 SmallVector<LocalVariable, 1> Locals;

173 SmallVector<CVGlobalVariable, 1> Globals;

174

175 std::unordered_map<const DILexicalBlockBase*, LexicalBlock> LexicalBlocks;

176

177

178 SmallVector<LexicalBlock *, 1> ChildBlocks;

179

180 std::vector<std::pair<MCSymbol *, MDNode *>> Annotations;

181 std::vector<std::tuple<const MCSymbol *, const MCSymbol *, const DIType *>>

182 HeapAllocSites;

183

184 std::vector JumpTables;

185

186 const MCSymbol *Begin = nullptr;

187 const MCSymbol *End = nullptr;

188 unsigned FuncId = 0;

189 unsigned LastFileId = 0;

190

191

192 unsigned FrameSize = 0;

193

194

195 unsigned ParamSize = 0;

196

197

198 unsigned CSRSize = 0;

199

200

201 int OffsetAdjustment = 0;

202

203

204

205 codeview::EncodedFramePtrReg EncodedLocalFramePtrReg =

206 codeview::EncodedFramePtrReg::None;

207

208

209

210 codeview::EncodedFramePtrReg EncodedParamFramePtrReg =

211 codeview::EncodedFramePtrReg::None;

212

213 codeview::FrameProcedureOptions FrameProcOpts;

214

215 bool HasStackRealignment = false;

216

217 bool HaveLineInfo = false;

218

219 bool HasFramePointer = false;

220 };

221 FunctionInfo *CurFn = nullptr;

222

223 codeview::SourceLanguage CurrentSourceLanguage =

224 codeview::SourceLanguage::Masm;

225

226

227

228 DenseMap<const DIGlobalVariable *, uint64_t> CVGlobalVariableOffsets;

229

230

231

232

233

234 DenseMap<const LexicalScope *, SmallVector<LocalVariable, 1>> ScopeVariables;

235

236

237

238 typedef SmallVector<CVGlobalVariable, 1> GlobalVariableList;

239 DenseMap<const DIScope*, std::unique_ptr > ScopeGlobals;

240

241

242 SmallVector<CVGlobalVariable, 1> ComdatVariables;

243

244

245 SmallVector<CVGlobalVariable, 1> GlobalVariables;

246

247

248 SmallVector<const DIDerivedType *, 4> StaticConstMembers;

249

250

251

252

253 DenseSet<MCSectionCOFF *> ComdatDebugSections;

254

255

256

257

258

259

260 void switchToDebugSectionForSymbol(const MCSymbol *GVSym);

261

262

263

264 unsigned NextFuncId = 0;

265

266 InlineSite &getInlineSite(const DILocation *InlinedAt,

267 const DISubprogram *Inlinee);

268

269 codeview::TypeIndex getFuncIdForSubprogram(const DISubprogram *SP);

270

271 void calculateRanges(LocalVariable &Var,

272 const DbgValueHistoryMap::Entries &Entries);

273

274

275

276 MapVector<const Function *, std::unique_ptr> FnDebugInfo;

277

278

279

280 DenseMap<StringRef, unsigned> FileIdMap;

281

282

283 SmallSetVector<const DISubprogram *, 4> InlinedSubprograms;

284

285

286

287

288

289

290

291 DenseMap<std::pair<const DINode *, const DIType *>, codeview::TypeIndex>

292 TypeIndices;

293

294

295

296 DenseMap<const DICompositeType *, codeview::TypeIndex> CompleteTypeIndices;

297

298

299

300 SmallVector<const DICompositeType *, 4> DeferredCompleteTypes;

301

302

303 unsigned TypeEmissionLevel = 0;

304

305 codeview::TypeIndex VBPType;

306

307 const DISubprogram *CurrentSubprogram = nullptr;

308

309

310

311 std::vector<std::pair<std::string, const DIType *>> LocalUDTs;

312 std::vector<std::pair<std::string, const DIType *>> GlobalUDTs;

313

314 using FileToFilepathMapTy = std::map<const DIFile *, std::string>;

315 FileToFilepathMapTy FileToFilepathMap;

316

317 StringRef getFullFilepath(const DIFile *File);

318

319 unsigned maybeRecordFile(const DIFile *F);

320

321 void maybeRecordLocation(const DebugLoc &DL, const MachineFunction *MF);

322

323 void clear();

324

325 void setCurrentSubprogram(const DISubprogram *SP) {

326 CurrentSubprogram = SP;

327 LocalUDTs.clear();

328 }

329

330

331

332

333 void emitCodeViewMagicVersion();

334

335 void emitTypeInformation();

336

337 void emitTypeGlobalHashes();

338

339 void emitObjName();

340

341 void emitCompilerInformation();

342

343 void emitSecureHotPatchInformation();

344

345 void emitBuildInfo();

346

347 void emitInlineeLinesSubsection();

348

349 void emitDebugInfoForThunk(const Function *GV,

350 FunctionInfo &FI,

351 const MCSymbol *Fn);

352

353 void emitDebugInfoForFunction(const Function *GV, FunctionInfo &FI);

354

355 void emitDebugInfoForRetainedTypes();

356

357 void emitDebugInfoForUDTs(

358 const std::vector<std::pair<std::string, const DIType *>> &UDTs);

359

360 void collectDebugInfoForGlobals();

361 void emitDebugInfoForGlobals();

362 void emitGlobalVariableList(ArrayRef Globals);

363 void emitConstantSymbolRecord(const DIType *DTy, APSInt &Value,

364 const std::string &QualifiedName);

365 void emitDebugInfoForGlobal(const CVGlobalVariable &CVGV);

366 void emitStaticConstMemberList();

367

368

369

370

371 MCSymbol *beginCVSubsection(codeview::DebugSubsectionKind Kind);

372 void endCVSubsection(MCSymbol *EndLabel);

373

374

375

376 MCSymbol *beginSymbolRecord(codeview::SymbolKind Kind);

377 void endSymbolRecord(MCSymbol *SymEnd);

378

379

380

381

382 void emitEndSymbolRecord(codeview::SymbolKind EndKind);

383

384 void emitInlinedCallSite(const FunctionInfo &FI, const DILocation *InlinedAt,

385 const InlineSite &Site);

386

387 void emitInlinees(const SmallSet<codeview::TypeIndex, 1> &Inlinees);

388

389 using InlinedEntity = DbgValueHistoryMap::InlinedEntity;

390

391 void collectGlobalVariableInfo();

392 void collectVariableInfo(const DISubprogram *SP);

393

394 void collectVariableInfoFromMFTable(DenseSet &Processed);

395

396

397

398 void collectLexicalBlockInfo(SmallVectorImpl<LexicalScope *> &Scopes,

399 SmallVectorImpl<LexicalBlock *> &Blocks,

400 SmallVectorImpl &Locals,

401 SmallVectorImpl &Globals);

402 void collectLexicalBlockInfo(LexicalScope &Scope,

403 SmallVectorImpl<LexicalBlock *> &ParentBlocks,

404 SmallVectorImpl &ParentLocals,

405 SmallVectorImpl &ParentGlobals);

406

407

408

409 void recordLocalVariable(LocalVariable &&Var, const LexicalScope *LS);

410

411

412 void emitLocalVariableList(const FunctionInfo &FI,

413 ArrayRef Locals);

414

415

416 void emitLocalVariable(const FunctionInfo &FI, const LocalVariable &Var);

417

418

419 void emitLexicalBlockList(ArrayRef<LexicalBlock *> Blocks,

420 const FunctionInfo& FI);

421

422

423 void emitLexicalBlock(const LexicalBlock &Block, const FunctionInfo& FI);

424

425

426

427 codeview::TypeIndex getTypeIndex(const DIType *Ty,

428 const DIType *ClassTy = nullptr);

429

430 codeview::TypeIndex

431 getTypeIndexForThisPtr(const DIDerivedType *PtrTy,

432 const DISubroutineType *SubroutineTy);

433

434 codeview::TypeIndex getTypeIndexForReferenceTo(const DIType *Ty);

435

436 codeview::TypeIndex getMemberFunctionType(const DISubprogram *SP,

437 const DICompositeType *Class);

438

439 codeview::TypeIndex getScopeIndex(const DIScope *Scope);

440

441 codeview::TypeIndex getVBPTypeIndex();

442

443 void addToUDTs(const DIType *Ty);

444

445 void addUDTSrcLine(const DIType *Ty, codeview::TypeIndex TI);

446

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,

463 bool IsStaticMethod,

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);

468

469

470

471

472

473

474 codeview::TypeIndex getCompleteTypeIndex(const DIType *Ty);

475

476 codeview::TypeIndex lowerCompleteTypeClass(const DICompositeType *Ty);

477 codeview::TypeIndex lowerCompleteTypeUnion(const DICompositeType *Ty);

478

479 struct TypeLoweringScope;

480

481 void emitDeferredCompleteTypes();

482

483 void collectMemberInfo(ClassInfo &Info, const DIDerivedType *DDTy);

484 ClassInfo collectClassInfo(const DICompositeType *Ty);

485

486

487

488

489 std::tuple<codeview::TypeIndex, codeview::TypeIndex, unsigned, bool>

490 lowerRecordFieldList(const DICompositeType *Ty);

491

492

493 codeview::TypeIndex recordTypeIndexForDINode(const DINode *Node,

494 codeview::TypeIndex TI,

495 const DIType *ClassTy = nullptr);

496

497

498

499

500 const DISubprogram *

501 collectParentScopeNames(const DIScope *Scope,

502 SmallVectorImpl &ParentScopeNames);

503 std::string getFullyQualifiedName(const DIScope *Scope, StringRef Name);

504 std::string getFullyQualifiedName(const DIScope *Scope);

505

506 unsigned getPointerSizeInBytes();

507

508 void discoverJumpTableBranches(const MachineFunction *MF, bool isThumb);

509 void collectDebugInfoForJumpTables(const MachineFunction *MF, bool isThumb);

510 void emitDebugInfoForJumpTables(const FunctionInfo &FI);

511

512protected:

513

514 void beginFunctionImpl(const MachineFunction *MF) override;

515

516

517 void endFunctionImpl(const MachineFunction *) override;

518

519

521 return CurrentSourceLanguage == codeview::SourceLanguage::Fortran;

522 }

523

524public:

526

527 void beginModule(Module *M) override;

528

529

530 void endModule() override;

531

532

533 void beginInstruction(const MachineInstr *MI) override;

534};