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