1 //===- llvm/CodeGen/DwarfDebug.h - Dwarf Debug Framework --------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This file contains support for writing dwarf debug info into asm files. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DWARFDEBUG_H 14 #define LLVM_LIB_CODEGEN_ASMPRINTER_DWARFDEBUG_H 15 16 #include "AddressPool.h" 17 #include "DebugLocStream.h" 18 #include "DebugLocEntry.h" 19 #include "DwarfFile.h" 20 #include "llvm/ADT/ArrayRef.h" 21 #include "llvm/ADT/DenseMap.h" 22 #include "llvm/ADT/DenseSet.h" 23 #include "llvm/ADT/MapVector.h" 24 #include "llvm/ADT/STLExtras.h" 25 #include "llvm/ADT/SetVector.h" 26 #include "llvm/ADT/SmallPtrSet.h" 27 #include "llvm/ADT/SmallVector.h" 28 #include "llvm/ADT/StringMap.h" 29 #include "llvm/ADT/StringRef.h" 30 #include "llvm/BinaryFormat/Dwarf.h" 31 #include "llvm/CodeGen/AccelTable.h" 32 #include "llvm/CodeGen/DbgEntityHistoryCalculator.h" 33 #include "llvm/CodeGen/DebugHandlerBase.h" 34 #include "llvm/CodeGen/MachineInstr.h" 35 #include "llvm/IR/DebugInfoMetadata.h" 36 #include "llvm/IR/DebugLoc.h" 37 #include "llvm/IR/Metadata.h" 38 #include "llvm/MC/MCDwarf.h" 39 #include "llvm/Support/Allocator.h" 40 #include "llvm/Target/TargetOptions.h" 41 #include <cassert> 42 #include <cstdint> 43 #include <limits> 44 #include <memory> 45 #include <utility> 46 #include <vector> 47 48 namespace llvm { 49 50 class AsmPrinter; 51 class ByteStreamer; 52 class DebugLocEntry; 53 class DIE; 54 class DwarfCompileUnit; 55 class DwarfExpression; 56 class DwarfTypeUnit; 57 class DwarfUnit; 58 class LexicalScope; 59 class MachineFunction; 60 class MCSection; 61 class MCSymbol; 62 class MDNode; 63 class Module; 64 65 //===----------------------------------------------------------------------===// 66 /// This class is defined as the common parent of DbgVariable and DbgLabel 67 /// such that it could levarage polymorphism to extract common code for 68 /// DbgVariable and DbgLabel. 69 class DbgEntity { 70 const DINode *Entity; 71 const DILocation *InlinedAt; 72 DIE *TheDIE = nullptr; 73 unsigned SubclassID; 74 75 public: 76 enum DbgEntityKind { 77 DbgVariableKind, 78 DbgLabelKind 79 }; 80 81 DbgEntity(const DINode *N, const DILocation *IA, unsigned ID) 82 : Entity(N), InlinedAt(IA), SubclassID(ID) {} 83 virtual ~DbgEntity() {} 84 85 /// Accessors. 86 /// @{ 87 const DINode *getEntity() const { return Entity; } 88 const DILocation *getInlinedAt() const { return InlinedAt; } 89 DIE *getDIE() const { return TheDIE; } 90 unsigned getDbgEntityID() const { return SubclassID; } 91 /// @} 92 93 void setDIE(DIE &D) { TheDIE = &D; } 94 95 static bool classof(const DbgEntity *N) { 96 switch (N->getDbgEntityID()) { 97 default: 98 return false; 99 case DbgVariableKind: 100 case DbgLabelKind: 101 return true; 102 } 103 } 104 }; 105 106 //===----------------------------------------------------------------------===// 107 /// This class is used to track local variable information. 108 /// 109 /// Variables can be created from allocas, in which case they're generated from 110 /// the MMI table. Such variables can have multiple expressions and frame 111 /// indices. 112 /// 113 /// Variables can be created from \c DBG_VALUE instructions. Those whose 114 /// location changes over time use \a DebugLocListIndex, while those with a 115 /// single location use \a ValueLoc and (optionally) a single entry of \a Expr. 116 /// 117 /// Variables that have been optimized out use none of these fields. 118 class DbgVariable : public DbgEntity { 119 /// Offset in DebugLocs. 120 unsigned DebugLocListIndex = ~0u; 121 /// DW_OP_LLVM_tag_offset value from DebugLocs. 122 Optional<uint8_t> DebugLocListTagOffset; 123 124 /// Single value location description. 125 std::unique_ptr<DbgValueLoc> ValueLoc = nullptr; 126 127 struct FrameIndexExpr { 128 int FI; 129 const DIExpression *Expr; 130 }; 131 mutable SmallVector<FrameIndexExpr, 1> 132 FrameIndexExprs; /// Frame index + expression. 133 134 public: 135 /// Construct a DbgVariable. 136 /// 137 /// Creates a variable without any DW_AT_location. Call \a initializeMMI() 138 /// for MMI entries, or \a initializeDbgValue() for DBG_VALUE instructions. 139 DbgVariable(const DILocalVariable *V, const DILocation *IA) 140 : DbgEntity(V, IA, DbgVariableKind) {} 141 142 /// Initialize from the MMI table. 143 void initializeMMI(const DIExpression *E, int FI) { 144 assert(FrameIndexExprs.empty() && "Already initialized?"); 145 assert(!ValueLoc.get() && "Already initialized?"); 146 147 assert((!E || E->isValid()) && "Expected valid expression"); 148 assert(FI != std::numeric_limits<int>::max() && "Expected valid index"); 149 150 FrameIndexExprs.push_back({FI, E}); 151 } 152 153 // Initialize variable's location. 154 void initializeDbgValue(DbgValueLoc Value) { 155 assert(FrameIndexExprs.empty() && "Already initialized?"); 156 assert(!ValueLoc && "Already initialized?"); 157 assert(!Value.getExpression()->isFragment() && "Fragments not supported."); 158 159 ValueLoc = std::make_unique<DbgValueLoc>(Value); 160 if (auto *E = ValueLoc->getExpression()) 161 if (E->getNumElements()) 162 FrameIndexExprs.push_back({0, E}); 163 } 164 165 /// Initialize from a DBG_VALUE instruction. 166 void initializeDbgValue(const MachineInstr *DbgValue); 167 168 // Accessors. 169 const DILocalVariable *getVariable() const { 170 return cast<DILocalVariable>(getEntity()); 171 } 172 173 const DIExpression *getSingleExpression() const { 174 assert(ValueLoc.get() && FrameIndexExprs.size() <= 1); 175 return FrameIndexExprs.size() ? FrameIndexExprs[0].Expr : nullptr; 176 } 177 178 void setDebugLocListIndex(unsigned O) { DebugLocListIndex = O; } 179 unsigned getDebugLocListIndex() const { return DebugLocListIndex; } 180 void setDebugLocListTagOffset(uint8_t O) { DebugLocListTagOffset = O; } 181 Optional<uint8_t> getDebugLocListTagOffset() const { return DebugLocListTagOffset; } 182 StringRef getName() const { return getVariable()->getName(); } 183 const DbgValueLoc *getValueLoc() const { return ValueLoc.get(); } 184 /// Get the FI entries, sorted by fragment offset. 185 ArrayRef<FrameIndexExpr> getFrameIndexExprs() const; 186 bool hasFrameIndexExprs() const { return !FrameIndexExprs.empty(); } 187 void addMMIEntry(const DbgVariable &V); 188 189 // Translate tag to proper Dwarf tag. 190 dwarf::Tag getTag() const { 191 // FIXME: Why don't we just infer this tag and store it all along? 192 if (getVariable()->isParameter()) 193 return dwarf::DW_TAG_formal_parameter; 194 195 return dwarf::DW_TAG_variable; 196 } 197 198 /// Return true if DbgVariable is artificial. 199 bool isArtificial() const { 200 if (getVariable()->isArtificial()) 201 return true; 202 if (getType()->isArtificial()) 203 return true; 204 return false; 205 } 206 207 bool isObjectPointer() const { 208 if (getVariable()->isObjectPointer()) 209 return true; 210 if (getType()->isObjectPointer()) 211 return true; 212 return false; 213 } 214 215 bool hasComplexAddress() const { 216 assert(ValueLoc.get() && "Expected DBG_VALUE, not MMI variable"); 217 assert((FrameIndexExprs.empty() || 218 (FrameIndexExprs.size() == 1 && 219 FrameIndexExprs[0].Expr->getNumElements())) && 220 "Invalid Expr for DBG_VALUE"); 221 return !FrameIndexExprs.empty(); 222 } 223 224 const DIType *getType() const; 225 226 static bool classof(const DbgEntity *N) { 227 return N->getDbgEntityID() == DbgVariableKind; 228 } 229 }; 230 231 //===----------------------------------------------------------------------===// 232 /// This class is used to track label information. 233 /// 234 /// Labels are collected from \c DBG_LABEL instructions. 235 class DbgLabel : public DbgEntity { 236 const MCSymbol *Sym; /// Symbol before DBG_LABEL instruction. 237 238 public: 239 /// We need MCSymbol information to generate DW_AT_low_pc. 240 DbgLabel(const DILabel *L, const DILocation *IA, const MCSymbol *Sym = nullptr) 241 : DbgEntity(L, IA, DbgLabelKind), Sym(Sym) {} 242 243 /// Accessors. 244 /// @{ 245 const DILabel *getLabel() const { return cast<DILabel>(getEntity()); } 246 const MCSymbol *getSymbol() const { return Sym; } 247 248 StringRef getName() const { return getLabel()->getName(); } 249 /// @} 250 251 /// Translate tag to proper Dwarf tag. 252 dwarf::Tag getTag() const { 253 return dwarf::DW_TAG_label; 254 } 255 256 static bool classof(const DbgEntity *N) { 257 return N->getDbgEntityID() == DbgLabelKind; 258 } 259 }; 260 261 /// Used for tracking debug info about call site parameters. 262 class DbgCallSiteParam { 263 private: 264 unsigned Register; ///< Parameter register at the callee entry point. 265 DbgValueLoc Value; ///< Corresponding location for the parameter value at 266 ///< the call site. 267 public: 268 DbgCallSiteParam(unsigned Reg, DbgValueLoc Val) 269 : Register(Reg), Value(Val) { 270 assert(Reg && "Parameter register cannot be undef"); 271 } 272 273 unsigned getRegister() const { return Register; } 274 DbgValueLoc getValue() const { return Value; } 275 }; 276 277 /// Collection used for storing debug call site parameters. 278 using ParamSet = SmallVector<DbgCallSiteParam, 4>; 279 280 /// Helper used to pair up a symbol and its DWARF compile unit. 281 struct SymbolCU { 282 SymbolCU(DwarfCompileUnit *CU, const MCSymbol *Sym) : Sym(Sym), CU(CU) {} 283 284 const MCSymbol *Sym; 285 DwarfCompileUnit *CU; 286 }; 287 288 /// The kind of accelerator tables we should emit. 289 enum class AccelTableKind { 290 Default, ///< Platform default. 291 None, ///< None. 292 Apple, ///< .apple_names, .apple_namespaces, .apple_types, .apple_objc. 293 Dwarf, ///< DWARF v5 .debug_names. 294 }; 295 296 /// Collects and handles dwarf debug information. 297 class DwarfDebug : public DebugHandlerBase { 298 /// All DIEValues are allocated through this allocator. 299 BumpPtrAllocator DIEValueAllocator; 300 301 /// Maps MDNode with its corresponding DwarfCompileUnit. 302 MapVector<const MDNode *, DwarfCompileUnit *> CUMap; 303 304 /// Maps a CU DIE with its corresponding DwarfCompileUnit. 305 DenseMap<const DIE *, DwarfCompileUnit *> CUDieMap; 306 307 /// List of all labels used in aranges generation. 308 std::vector<SymbolCU> ArangeLabels; 309 310 /// Size of each symbol emitted (for those symbols that have a specific size). 311 DenseMap<const MCSymbol *, uint64_t> SymSize; 312 313 /// Collection of abstract variables/labels. 314 SmallVector<std::unique_ptr<DbgEntity>, 64> ConcreteEntities; 315 316 /// Collection of DebugLocEntry. Stored in a linked list so that DIELocLists 317 /// can refer to them in spite of insertions into this list. 318 DebugLocStream DebugLocs; 319 320 /// This is a collection of subprogram MDNodes that are processed to 321 /// create DIEs. 322 SetVector<const DISubprogram *, SmallVector<const DISubprogram *, 16>, 323 SmallPtrSet<const DISubprogram *, 16>> 324 ProcessedSPNodes; 325 326 /// If nonnull, stores the current machine function we're processing. 327 const MachineFunction *CurFn = nullptr; 328 329 /// If nonnull, stores the CU in which the previous subprogram was contained. 330 const DwarfCompileUnit *PrevCU; 331 332 /// As an optimization, there is no need to emit an entry in the directory 333 /// table for the same directory as DW_AT_comp_dir. 334 StringRef CompilationDir; 335 336 /// Holder for the file specific debug information. 337 DwarfFile InfoHolder; 338 339 /// Holders for the various debug information flags that we might need to 340 /// have exposed. See accessor functions below for description. 341 342 /// Map from MDNodes for user-defined types to their type signatures. Also 343 /// used to keep track of which types we have emitted type units for. 344 DenseMap<const MDNode *, uint64_t> TypeSignatures; 345 346 DenseMap<const MCSection *, const MCSymbol *> SectionLabels; 347 348 SmallVector< 349 std::pair<std::unique_ptr<DwarfTypeUnit>, const DICompositeType *>, 1> 350 TypeUnitsUnderConstruction; 351 352 /// Whether to use the GNU TLS opcode (instead of the standard opcode). 353 bool UseGNUTLSOpcode; 354 355 /// Whether to use DWARF 2 bitfields (instead of the DWARF 4 format). 356 bool UseDWARF2Bitfields; 357 358 /// Whether to emit all linkage names, or just abstract subprograms. 359 bool UseAllLinkageNames; 360 361 /// Use inlined strings. 362 bool UseInlineStrings = false; 363 364 /// Allow emission of .debug_ranges section. 365 bool UseRangesSection = true; 366 367 /// True if the sections itself must be used as references and don't create 368 /// temp symbols inside DWARF sections. 369 bool UseSectionsAsReferences = false; 370 371 ///Allow emission of the .debug_loc section. 372 bool UseLocSection = true; 373 374 /// Generate DWARF v4 type units. 375 bool GenerateTypeUnits; 376 377 /// DWARF5 Experimental Options 378 /// @{ 379 AccelTableKind TheAccelTableKind; 380 bool HasAppleExtensionAttributes; 381 bool HasSplitDwarf; 382 383 /// Whether to generate the DWARF v5 string offsets table. 384 /// It consists of a series of contributions, each preceded by a header. 385 /// The pre-DWARF v5 string offsets table for split dwarf is, in contrast, 386 /// a monolithic sequence of string offsets. 387 bool UseSegmentedStringOffsetsTable; 388 389 /// Enable production of call site parameters needed to print the debug entry 390 /// values. Useful for testing purposes when a debugger does not support the 391 /// feature yet. 392 bool EmitDebugEntryValues; 393 394 /// Separated Dwarf Variables 395 /// In general these will all be for bits that are left in the 396 /// original object file, rather than things that are meant 397 /// to be in the .dwo sections. 398 399 /// Holder for the skeleton information. 400 DwarfFile SkeletonHolder; 401 402 /// Store file names for type units under fission in a line table 403 /// header that will be emitted into debug_line.dwo. 404 // FIXME: replace this with a map from comp_dir to table so that we 405 // can emit multiple tables during LTO each of which uses directory 406 // 0, referencing the comp_dir of all the type units that use it. 407 MCDwarfDwoLineTable SplitTypeUnitFileTable; 408 /// @} 409 410 /// True iff there are multiple CUs in this module. 411 bool SingleCU; 412 bool IsDarwin; 413 414 AddressPool AddrPool; 415 416 /// Accelerator tables. 417 AccelTable<DWARF5AccelTableData> AccelDebugNames; 418 AccelTable<AppleAccelTableOffsetData> AccelNames; 419 AccelTable<AppleAccelTableOffsetData> AccelObjC; 420 AccelTable<AppleAccelTableOffsetData> AccelNamespace; 421 AccelTable<AppleAccelTableTypeData> AccelTypes; 422 423 // Identify a debugger for "tuning" the debug info. 424 DebuggerKind DebuggerTuning = DebuggerKind::Default; 425 426 MCDwarfDwoLineTable *getDwoLineTable(const DwarfCompileUnit &); 427 428 const SmallVectorImpl<std::unique_ptr<DwarfCompileUnit>> &getUnits() { 429 return InfoHolder.getUnits(); 430 } 431 432 using InlinedEntity = DbgValueHistoryMap::InlinedEntity; 433 434 void ensureAbstractEntityIsCreated(DwarfCompileUnit &CU, 435 const DINode *Node, 436 const MDNode *Scope); 437 void ensureAbstractEntityIsCreatedIfScoped(DwarfCompileUnit &CU, 438 const DINode *Node, 439 const MDNode *Scope); 440 441 DbgEntity *createConcreteEntity(DwarfCompileUnit &TheCU, 442 LexicalScope &Scope, 443 const DINode *Node, 444 const DILocation *Location, 445 const MCSymbol *Sym = nullptr); 446 447 /// Construct a DIE for this abstract scope. 448 void constructAbstractSubprogramScopeDIE(DwarfCompileUnit &SrcCU, LexicalScope *Scope); 449 450 /// Construct a DIE for the subprogram definition \p SP and return it. 451 DIE &constructSubprogramDefinitionDIE(const DISubprogram *SP); 452 453 /// Construct DIEs for call site entries describing the calls in \p MF. 454 void constructCallSiteEntryDIEs(const DISubprogram &SP, DwarfCompileUnit &CU, 455 DIE &ScopeDIE, const MachineFunction &MF); 456 457 template <typename DataT> 458 void addAccelNameImpl(const DICompileUnit &CU, AccelTable<DataT> &AppleAccel, 459 StringRef Name, const DIE &Die); 460 461 void finishEntityDefinitions(); 462 463 void finishSubprogramDefinitions(); 464 465 /// Finish off debug information after all functions have been 466 /// processed. 467 void finalizeModuleInfo(); 468 469 /// Emit the debug info section. 470 void emitDebugInfo(); 471 472 /// Emit the abbreviation section. 473 void emitAbbreviations(); 474 475 /// Emit the string offsets table header. 476 void emitStringOffsetsTableHeader(); 477 478 /// Emit a specified accelerator table. 479 template <typename AccelTableT> 480 void emitAccel(AccelTableT &Accel, MCSection *Section, StringRef TableName); 481 482 /// Emit DWARF v5 accelerator table. 483 void emitAccelDebugNames(); 484 485 /// Emit visible names into a hashed accelerator table section. 486 void emitAccelNames(); 487 488 /// Emit objective C classes and categories into a hashed 489 /// accelerator table section. 490 void emitAccelObjC(); 491 492 /// Emit namespace dies into a hashed accelerator table. 493 void emitAccelNamespaces(); 494 495 /// Emit type dies into a hashed accelerator table. 496 void emitAccelTypes(); 497 498 /// Emit visible names and types into debug pubnames and pubtypes sections. 499 void emitDebugPubSections(); 500 501 void emitDebugPubSection(bool GnuStyle, StringRef Name, 502 DwarfCompileUnit *TheU, 503 const StringMap<const DIE *> &Globals); 504 505 /// Emit null-terminated strings into a debug str section. 506 void emitDebugStr(); 507 508 /// Emit variable locations into a debug loc section. 509 void emitDebugLoc(); 510 511 /// Emit variable locations into a debug loc dwo section. 512 void emitDebugLocDWO(); 513 514 void emitDebugLocImpl(MCSection *Sec); 515 516 /// Emit address ranges into a debug aranges section. 517 void emitDebugARanges(); 518 519 /// Emit address ranges into a debug ranges section. 520 void emitDebugRanges(); 521 void emitDebugRangesDWO(); 522 void emitDebugRangesImpl(const DwarfFile &Holder, MCSection *Section); 523 524 /// Emit macros into a debug macinfo section. 525 void emitDebugMacinfo(); 526 /// Emit macros into a debug macinfo.dwo section. 527 void emitDebugMacinfoDWO(); 528 void emitDebugMacinfoImpl(MCSection *Section); 529 void emitMacro(DIMacro &M); 530 void emitMacroFile(DIMacroFile &F, DwarfCompileUnit &U); 531 void handleMacroNodes(DIMacroNodeArray Nodes, DwarfCompileUnit &U); 532 533 /// DWARF 5 Experimental Split Dwarf Emitters 534 535 /// Initialize common features of skeleton units. 536 void initSkeletonUnit(const DwarfUnit &U, DIE &Die, 537 std::unique_ptr<DwarfCompileUnit> NewU); 538 539 /// Construct the split debug info compile unit for the debug info section. 540 /// In DWARF v5, the skeleton unit DIE may have the following attributes: 541 /// DW_AT_addr_base, DW_AT_comp_dir, DW_AT_dwo_name, DW_AT_high_pc, 542 /// DW_AT_low_pc, DW_AT_ranges, DW_AT_stmt_list, and DW_AT_str_offsets_base. 543 /// Prior to DWARF v5 it may also have DW_AT_GNU_dwo_id. DW_AT_GNU_dwo_name 544 /// is used instead of DW_AT_dwo_name, Dw_AT_GNU_addr_base instead of 545 /// DW_AT_addr_base, and DW_AT_GNU_ranges_base instead of DW_AT_rnglists_base. 546 DwarfCompileUnit &constructSkeletonCU(const DwarfCompileUnit &CU); 547 548 /// Emit the debug info dwo section. 549 void emitDebugInfoDWO(); 550 551 /// Emit the debug abbrev dwo section. 552 void emitDebugAbbrevDWO(); 553 554 /// Emit the debug line dwo section. 555 void emitDebugLineDWO(); 556 557 /// Emit the dwo stringoffsets table header. 558 void emitStringOffsetsTableHeaderDWO(); 559 560 /// Emit the debug str dwo section. 561 void emitDebugStrDWO(); 562 563 /// Emit DWO addresses. 564 void emitDebugAddr(); 565 566 /// Flags to let the linker know we have emitted new style pubnames. Only 567 /// emit it here if we don't have a skeleton CU for split dwarf. 568 void addGnuPubAttributes(DwarfCompileUnit &U, DIE &D) const; 569 570 /// Create new DwarfCompileUnit for the given metadata node with tag 571 /// DW_TAG_compile_unit. 572 DwarfCompileUnit &getOrCreateDwarfCompileUnit(const DICompileUnit *DIUnit); 573 void finishUnitAttributes(const DICompileUnit *DIUnit, 574 DwarfCompileUnit &NewCU); 575 576 /// Construct imported_module or imported_declaration DIE. 577 void constructAndAddImportedEntityDIE(DwarfCompileUnit &TheCU, 578 const DIImportedEntity *N); 579 580 /// Register a source line with debug info. Returns the unique 581 /// label that was emitted and which provides correspondence to the 582 /// source line list. 583 void recordSourceLine(unsigned Line, unsigned Col, const MDNode *Scope, 584 unsigned Flags); 585 586 /// Populate LexicalScope entries with variables' info. 587 void collectEntityInfo(DwarfCompileUnit &TheCU, const DISubprogram *SP, 588 DenseSet<InlinedEntity> &ProcessedVars); 589 590 /// Build the location list for all DBG_VALUEs in the 591 /// function that describe the same variable. If the resulting 592 /// list has only one entry that is valid for entire variable's 593 /// scope return true. 594 bool buildLocationList(SmallVectorImpl<DebugLocEntry> &DebugLoc, 595 const DbgValueHistoryMap::Entries &Entries); 596 597 /// Collect variable information from the side table maintained by MF. 598 void collectVariableInfoFromMFTable(DwarfCompileUnit &TheCU, 599 DenseSet<InlinedEntity> &P); 600 601 /// Emit the reference to the section. 602 void emitSectionReference(const DwarfCompileUnit &CU); 603 604 protected: 605 /// Gather pre-function debug information. 606 void beginFunctionImpl(const MachineFunction *MF) override; 607 608 /// Gather and emit post-function debug information. 609 void endFunctionImpl(const MachineFunction *MF) override; 610 611 void skippedNonDebugFunction() override; 612 613 public: 614 //===--------------------------------------------------------------------===// 615 // Main entry points. 616 // 617 DwarfDebug(AsmPrinter *A, Module *M); 618 619 ~DwarfDebug() override; 620 621 /// Emit all Dwarf sections that should come prior to the 622 /// content. 623 void beginModule(); 624 625 /// Emit all Dwarf sections that should come after the content. 626 void endModule() override; 627 628 /// Emits inital debug location directive. 629 DebugLoc emitInitialLocDirective(const MachineFunction &MF, unsigned CUID); 630 631 /// Process beginning of an instruction. 632 void beginInstruction(const MachineInstr *MI) override; 633 634 /// Perform an MD5 checksum of \p Identifier and return the lower 64 bits. 635 static uint64_t makeTypeSignature(StringRef Identifier); 636 637 /// Add a DIE to the set of types that we're going to pull into 638 /// type units. 639 void addDwarfTypeUnitType(DwarfCompileUnit &CU, StringRef Identifier, 640 DIE &Die, const DICompositeType *CTy); 641 642 friend class NonTypeUnitContext; 643 class NonTypeUnitContext { 644 DwarfDebug *DD; 645 decltype(DwarfDebug::TypeUnitsUnderConstruction) TypeUnitsUnderConstruction; 646 friend class DwarfDebug; 647 NonTypeUnitContext(DwarfDebug *DD); 648 public: 649 NonTypeUnitContext(NonTypeUnitContext&&) = default; 650 ~NonTypeUnitContext(); 651 }; 652 653 NonTypeUnitContext enterNonTypeUnitContext(); 654 655 /// Add a label so that arange data can be generated for it. 656 void addArangeLabel(SymbolCU SCU) { ArangeLabels.push_back(SCU); } 657 658 /// For symbols that have a size designated (e.g. common symbols), 659 /// this tracks that size. 660 void setSymbolSize(const MCSymbol *Sym, uint64_t Size) override { 661 SymSize[Sym] = Size; 662 } 663 664 /// Returns whether we should emit all DW_AT_[MIPS_]linkage_name. 665 /// If not, we still might emit certain cases. 666 bool useAllLinkageNames() const { return UseAllLinkageNames; } 667 668 /// Returns whether to use DW_OP_GNU_push_tls_address, instead of the 669 /// standard DW_OP_form_tls_address opcode 670 bool useGNUTLSOpcode() const { return UseGNUTLSOpcode; } 671 672 /// Returns whether to use the DWARF2 format for bitfields instyead of the 673 /// DWARF4 format. 674 bool useDWARF2Bitfields() const { return UseDWARF2Bitfields; } 675 676 /// Returns whether to use inline strings. 677 bool useInlineStrings() const { return UseInlineStrings; } 678 679 /// Returns whether ranges section should be emitted. 680 bool useRangesSection() const { return UseRangesSection; } 681 682 /// Returns whether to use sections as labels rather than temp symbols. 683 bool useSectionsAsReferences() const { 684 return UseSectionsAsReferences; 685 } 686 687 /// Returns whether .debug_loc section should be emitted. 688 bool useLocSection() const { return UseLocSection; } 689 690 /// Returns whether to generate DWARF v4 type units. 691 bool generateTypeUnits() const { return GenerateTypeUnits; } 692 693 // Experimental DWARF5 features. 694 695 /// Returns what kind (if any) of accelerator tables to emit. 696 AccelTableKind getAccelTableKind() const { return TheAccelTableKind; } 697 698 bool useAppleExtensionAttributes() const { 699 return HasAppleExtensionAttributes; 700 } 701 702 /// Returns whether or not to change the current debug info for the 703 /// split dwarf proposal support. 704 bool useSplitDwarf() const { return HasSplitDwarf; } 705 706 /// Returns whether to generate a string offsets table with (possibly shared) 707 /// contributions from each CU and type unit. This implies the use of 708 /// DW_FORM_strx* indirect references with DWARF v5 and beyond. Note that 709 /// DW_FORM_GNU_str_index is also an indirect reference, but it is used with 710 /// a pre-DWARF v5 implementation of split DWARF sections, which uses a 711 /// monolithic string offsets table. 712 bool useSegmentedStringOffsetsTable() const { 713 return UseSegmentedStringOffsetsTable; 714 } 715 716 bool emitDebugEntryValues() const { 717 return EmitDebugEntryValues; 718 } 719 720 bool shareAcrossDWOCUs() const; 721 722 /// Returns the Dwarf Version. 723 uint16_t getDwarfVersion() const; 724 725 /// Returns the previous CU that was being updated 726 const DwarfCompileUnit *getPrevCU() const { return PrevCU; } 727 void setPrevCU(const DwarfCompileUnit *PrevCU) { this->PrevCU = PrevCU; } 728 729 /// Returns the entries for the .debug_loc section. 730 const DebugLocStream &getDebugLocs() const { return DebugLocs; } 731 732 /// Emit an entry for the debug loc section. This can be used to 733 /// handle an entry that's going to be emitted into the debug loc section. 734 void emitDebugLocEntry(ByteStreamer &Streamer, 735 const DebugLocStream::Entry &Entry, 736 const DwarfCompileUnit *CU); 737 738 /// Emit the location for a debug loc entry, including the size header. 739 void emitDebugLocEntryLocation(const DebugLocStream::Entry &Entry, 740 const DwarfCompileUnit *CU); 741 742 void addSubprogramNames(const DICompileUnit &CU, const DISubprogram *SP, 743 DIE &Die); 744 745 AddressPool &getAddressPool() { return AddrPool; } 746 747 void addAccelName(const DICompileUnit &CU, StringRef Name, const DIE &Die); 748 749 void addAccelObjC(const DICompileUnit &CU, StringRef Name, const DIE &Die); 750 751 void addAccelNamespace(const DICompileUnit &CU, StringRef Name, 752 const DIE &Die); 753 754 void addAccelType(const DICompileUnit &CU, StringRef Name, const DIE &Die, 755 char Flags); 756 757 const MachineFunction *getCurrentFunction() const { return CurFn; } 758 759 /// A helper function to check whether the DIE for a given Scope is 760 /// going to be null. 761 bool isLexicalScopeDIENull(LexicalScope *Scope); 762 763 /// Find the matching DwarfCompileUnit for the given CU DIE. 764 DwarfCompileUnit *lookupCU(const DIE *Die) { return CUDieMap.lookup(Die); } 765 const DwarfCompileUnit *lookupCU(const DIE *Die) const { 766 return CUDieMap.lookup(Die); 767 } 768 769 /// \defgroup DebuggerTuning Predicates to tune DWARF for a given debugger. 770 /// 771 /// Returns whether we are "tuning" for a given debugger. 772 /// @{ 773 bool tuneForGDB() const { return DebuggerTuning == DebuggerKind::GDB; } 774 bool tuneForLLDB() const { return DebuggerTuning == DebuggerKind::LLDB; } 775 bool tuneForSCE() const { return DebuggerTuning == DebuggerKind::SCE; } 776 /// @} 777 778 void addSectionLabel(const MCSymbol *Sym); 779 const MCSymbol *getSectionLabel(const MCSection *S); 780 void insertSectionLabel(const MCSymbol *S); 781 782 static void emitDebugLocValue(const AsmPrinter &AP, const DIBasicType *BT, 783 const DbgValueLoc &Value, 784 DwarfExpression &DwarfExpr); 785 }; 786 787 } // end namespace llvm 788 789 #endif // LLVM_LIB_CODEGEN_ASMPRINTER_DWARFDEBUG_H 790