1 //===-- llvm/CodeGen/DwarfDebug.h - Dwarf Debug Framework ------*- C++ -*--===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This file contains support for writing dwarf debug info into asm files. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #ifndef CODEGEN_ASMPRINTER_DWARFDEBUG_H__ 15 #define CODEGEN_ASMPRINTER_DWARFDEBUG_H__ 16 17 #include "DwarfFile.h" 18 #include "AsmPrinterHandler.h" 19 #include "DIE.h" 20 #include "DbgValueHistoryCalculator.h" 21 #include "DebugLocEntry.h" 22 #include "DebugLocList.h" 23 #include "DwarfAccelTable.h" 24 #include "llvm/ADT/DenseMap.h" 25 #include "llvm/ADT/MapVector.h" 26 #include "llvm/ADT/SmallPtrSet.h" 27 #include "llvm/ADT/StringMap.h" 28 #include "llvm/ADT/FoldingSet.h" 29 #include "llvm/CodeGen/LexicalScopes.h" 30 #include "llvm/CodeGen/MachineInstr.h" 31 #include "llvm/IR/DebugInfo.h" 32 #include "llvm/IR/DebugLoc.h" 33 #include "llvm/MC/MachineLocation.h" 34 #include "llvm/MC/MCDwarf.h" 35 #include "llvm/Support/Allocator.h" 36 37 #include <memory> 38 39 namespace llvm { 40 41 class AsmPrinter; 42 class ByteStreamer; 43 class ConstantInt; 44 class ConstantFP; 45 class DwarfCompileUnit; 46 class DwarfDebug; 47 class DwarfTypeUnit; 48 class DwarfUnit; 49 class MachineModuleInfo; 50 51 //===----------------------------------------------------------------------===// 52 /// \brief This class is used to record source line correspondence. 53 class SrcLineInfo { 54 unsigned Line; // Source line number. 55 unsigned Column; // Source column. 56 unsigned SourceID; // Source ID number. 57 MCSymbol *Label; // Label in code ID number. 58 public: SrcLineInfo(unsigned L,unsigned C,unsigned S,MCSymbol * label)59 SrcLineInfo(unsigned L, unsigned C, unsigned S, MCSymbol *label) 60 : Line(L), Column(C), SourceID(S), Label(label) {} 61 62 // Accessors getLine()63 unsigned getLine() const { return Line; } getColumn()64 unsigned getColumn() const { return Column; } getSourceID()65 unsigned getSourceID() const { return SourceID; } getLabel()66 MCSymbol *getLabel() const { return Label; } 67 }; 68 69 //===----------------------------------------------------------------------===// 70 /// \brief This class is used to track local variable information. 71 class DbgVariable { 72 DIVariable Var; // Variable Descriptor. 73 DIE *TheDIE; // Variable DIE. 74 unsigned DotDebugLocOffset; // Offset in DotDebugLocEntries. 75 const MachineInstr *MInsn; // DBG_VALUE instruction of the variable. 76 int FrameIndex; 77 DwarfDebug *DD; 78 79 public: 80 /// Construct a DbgVariable from a DIVariable. DbgVariable(DIVariable V,DwarfDebug * DD)81 DbgVariable(DIVariable V, DwarfDebug *DD) 82 : Var(V), TheDIE(nullptr), DotDebugLocOffset(~0U), MInsn(nullptr), 83 FrameIndex(~0), DD(DD) {} 84 85 /// Construct a DbgVariable from a DEBUG_VALUE. 86 /// AbstractVar may be NULL. DbgVariable(const MachineInstr * DbgValue,DwarfDebug * DD)87 DbgVariable(const MachineInstr *DbgValue, DwarfDebug *DD) 88 : Var(DbgValue->getDebugVariable()), TheDIE(nullptr), 89 DotDebugLocOffset(~0U), MInsn(DbgValue), FrameIndex(~0), DD(DD) {} 90 91 // Accessors. getVariable()92 DIVariable getVariable() const { return Var; } setDIE(DIE & D)93 void setDIE(DIE &D) { TheDIE = &D; } getDIE()94 DIE *getDIE() const { return TheDIE; } setDotDebugLocOffset(unsigned O)95 void setDotDebugLocOffset(unsigned O) { DotDebugLocOffset = O; } getDotDebugLocOffset()96 unsigned getDotDebugLocOffset() const { return DotDebugLocOffset; } getName()97 StringRef getName() const { return Var.getName(); } getMInsn()98 const MachineInstr *getMInsn() const { return MInsn; } getFrameIndex()99 int getFrameIndex() const { return FrameIndex; } setFrameIndex(int FI)100 void setFrameIndex(int FI) { FrameIndex = FI; } 101 // Translate tag to proper Dwarf tag. getTag()102 dwarf::Tag getTag() const { 103 if (Var.getTag() == dwarf::DW_TAG_arg_variable) 104 return dwarf::DW_TAG_formal_parameter; 105 106 return dwarf::DW_TAG_variable; 107 } 108 /// \brief Return true if DbgVariable is artificial. isArtificial()109 bool isArtificial() const { 110 if (Var.isArtificial()) 111 return true; 112 if (getType().isArtificial()) 113 return true; 114 return false; 115 } 116 isObjectPointer()117 bool isObjectPointer() const { 118 if (Var.isObjectPointer()) 119 return true; 120 if (getType().isObjectPointer()) 121 return true; 122 return false; 123 } 124 variableHasComplexAddress()125 bool variableHasComplexAddress() const { 126 assert(Var.isVariable() && "Invalid complex DbgVariable!"); 127 return Var.hasComplexAddress(); 128 } 129 bool isBlockByrefVariable() const; getNumAddrElements()130 unsigned getNumAddrElements() const { 131 assert(Var.isVariable() && "Invalid complex DbgVariable!"); 132 return Var.getNumAddrElements(); 133 } getAddrElement(unsigned i)134 uint64_t getAddrElement(unsigned i) const { return Var.getAddrElement(i); } 135 DIType getType() const; 136 137 private: 138 /// resolve - Look in the DwarfDebug map for the MDNode that 139 /// corresponds to the reference. 140 template <typename T> T resolve(DIRef<T> Ref) const; 141 }; 142 143 144 /// \brief Helper used to pair up a symbol and its DWARF compile unit. 145 struct SymbolCU { SymbolCUSymbolCU146 SymbolCU(DwarfCompileUnit *CU, const MCSymbol *Sym) : Sym(Sym), CU(CU) {} 147 const MCSymbol *Sym; 148 DwarfCompileUnit *CU; 149 }; 150 151 /// \brief Collects and handles dwarf debug information. 152 class DwarfDebug : public AsmPrinterHandler { 153 // Target of Dwarf emission. 154 AsmPrinter *Asm; 155 156 // Collected machine module information. 157 MachineModuleInfo *MMI; 158 159 // All DIEValues are allocated through this allocator. 160 BumpPtrAllocator DIEValueAllocator; 161 162 // Handle to the compile unit used for the inline extension handling, 163 // this is just so that the DIEValue allocator has a place to store 164 // the particular elements. 165 // FIXME: Store these off of DwarfDebug instead? 166 DwarfCompileUnit *FirstCU; 167 168 // Maps MDNode with its corresponding DwarfCompileUnit. 169 MapVector<const MDNode *, DwarfCompileUnit *> CUMap; 170 171 // Maps subprogram MDNode with its corresponding DwarfCompileUnit. 172 DenseMap<const MDNode *, DwarfCompileUnit *> SPMap; 173 174 // Maps a CU DIE with its corresponding DwarfCompileUnit. 175 DenseMap<const DIE *, DwarfCompileUnit *> CUDieMap; 176 177 /// Maps MDNodes for type system with the corresponding DIEs. These DIEs can 178 /// be shared across CUs, that is why we keep the map here instead 179 /// of in DwarfCompileUnit. 180 DenseMap<const MDNode *, DIE *> MDTypeNodeToDieMap; 181 182 // List of all labels used in aranges generation. 183 std::vector<SymbolCU> ArangeLabels; 184 185 // Size of each symbol emitted (for those symbols that have a specific size). 186 DenseMap<const MCSymbol *, uint64_t> SymSize; 187 188 // Provides a unique id per text section. 189 typedef DenseMap<const MCSection *, SmallVector<SymbolCU, 8> > SectionMapType; 190 SectionMapType SectionMap; 191 192 // List of arguments for current function. 193 SmallVector<DbgVariable *, 8> CurrentFnArguments; 194 195 LexicalScopes LScopes; 196 197 // Collection of abstract subprogram DIEs. 198 DenseMap<const MDNode *, DIE *> AbstractSPDies; 199 200 // Collection of dbg variables of a scope. 201 typedef DenseMap<LexicalScope *, SmallVector<DbgVariable *, 8> > 202 ScopeVariablesMap; 203 ScopeVariablesMap ScopeVariables; 204 205 // Collection of abstract variables. 206 DenseMap<const MDNode *, std::unique_ptr<DbgVariable>> AbstractVariables; 207 SmallVector<std::unique_ptr<DbgVariable>, 64> ConcreteVariables; 208 209 // Collection of DebugLocEntry. Stored in a linked list so that DIELocLists 210 // can refer to them in spite of insertions into this list. 211 SmallVector<DebugLocList, 4> DotDebugLocEntries; 212 213 // Collection of subprogram DIEs that are marked (at the end of the module) 214 // as DW_AT_inline. 215 SmallPtrSet<DIE *, 4> InlinedSubprogramDIEs; 216 217 // This is a collection of subprogram MDNodes that are processed to 218 // create DIEs. 219 SmallPtrSet<const MDNode *, 16> ProcessedSPNodes; 220 221 // Maps instruction with label emitted before instruction. 222 DenseMap<const MachineInstr *, MCSymbol *> LabelsBeforeInsn; 223 224 // Maps instruction with label emitted after instruction. 225 DenseMap<const MachineInstr *, MCSymbol *> LabelsAfterInsn; 226 227 // History of DBG_VALUE and clobber instructions for each user variable. 228 // Variables are listed in order of appearance. 229 DbgValueHistoryMap DbgValues; 230 231 // Previous instruction's location information. This is used to determine 232 // label location to indicate scope boundries in dwarf debug info. 233 DebugLoc PrevInstLoc; 234 MCSymbol *PrevLabel; 235 236 // This location indicates end of function prologue and beginning of function 237 // body. 238 DebugLoc PrologEndLoc; 239 240 // If nonnull, stores the current machine function we're processing. 241 const MachineFunction *CurFn; 242 243 // If nonnull, stores the current machine instruction we're processing. 244 const MachineInstr *CurMI; 245 246 // If nonnull, stores the section that the previous function was allocated to 247 // emitting. 248 const MCSection *PrevSection; 249 250 // If nonnull, stores the CU in which the previous subprogram was contained. 251 const DwarfCompileUnit *PrevCU; 252 253 // Section Symbols: these are assembler temporary labels that are emitted at 254 // the beginning of each supported dwarf section. These are used to form 255 // section offsets and are created by EmitSectionLabels. 256 MCSymbol *DwarfInfoSectionSym, *DwarfAbbrevSectionSym; 257 MCSymbol *DwarfStrSectionSym, *TextSectionSym, *DwarfDebugRangeSectionSym; 258 MCSymbol *DwarfDebugLocSectionSym, *DwarfLineSectionSym, *DwarfAddrSectionSym; 259 MCSymbol *FunctionBeginSym, *FunctionEndSym; 260 MCSymbol *DwarfInfoDWOSectionSym, *DwarfAbbrevDWOSectionSym; 261 MCSymbol *DwarfStrDWOSectionSym; 262 MCSymbol *DwarfGnuPubNamesSectionSym, *DwarfGnuPubTypesSectionSym; 263 264 // As an optimization, there is no need to emit an entry in the directory 265 // table for the same directory as DW_AT_comp_dir. 266 StringRef CompilationDir; 267 268 // Counter for assigning globally unique IDs for ranges. 269 unsigned GlobalRangeCount; 270 271 // Holder for the file specific debug information. 272 DwarfFile InfoHolder; 273 274 // Holders for the various debug information flags that we might need to 275 // have exposed. See accessor functions below for description. 276 277 // Holder for imported entities. 278 typedef SmallVector<std::pair<const MDNode *, const MDNode *>, 32> 279 ImportedEntityMap; 280 ImportedEntityMap ScopesWithImportedEntities; 281 282 // Map from MDNodes for user-defined types to the type units that describe 283 // them. 284 DenseMap<const MDNode *, const DwarfTypeUnit *> DwarfTypeUnits; 285 286 SmallVector<std::pair<std::unique_ptr<DwarfTypeUnit>, DICompositeType>, 1> TypeUnitsUnderConstruction; 287 288 // Whether to emit the pubnames/pubtypes sections. 289 bool HasDwarfPubSections; 290 291 // Whether or not to use AT_ranges for compilation units. 292 bool HasCURanges; 293 294 // Whether we emitted a function into a section other than the default 295 // text. 296 bool UsedNonDefaultText; 297 298 // Version of dwarf we're emitting. 299 unsigned DwarfVersion; 300 301 // Maps from a type identifier to the actual MDNode. 302 DITypeIdentifierMap TypeIdentifierMap; 303 304 // DWARF5 Experimental Options 305 bool HasDwarfAccelTables; 306 bool HasSplitDwarf; 307 308 // Separated Dwarf Variables 309 // In general these will all be for bits that are left in the 310 // original object file, rather than things that are meant 311 // to be in the .dwo sections. 312 313 // Holder for the skeleton information. 314 DwarfFile SkeletonHolder; 315 316 /// Store file names for type units under fission in a line table header that 317 /// will be emitted into debug_line.dwo. 318 // FIXME: replace this with a map from comp_dir to table so that we can emit 319 // multiple tables during LTO each of which uses directory 0, referencing the 320 // comp_dir of all the type units that use it. 321 MCDwarfDwoLineTable SplitTypeUnitFileTable; 322 323 // True iff there are multiple CUs in this module. 324 bool SingleCU; 325 326 AddressPool AddrPool; 327 328 DwarfAccelTable AccelNames; 329 DwarfAccelTable AccelObjC; 330 DwarfAccelTable AccelNamespace; 331 DwarfAccelTable AccelTypes; 332 333 DenseMap<const Function *, DISubprogram> FunctionDIs; 334 335 MCDwarfDwoLineTable *getDwoLineTable(const DwarfCompileUnit &); 336 337 void addScopeVariable(LexicalScope *LS, DbgVariable *Var); 338 getUnits()339 const SmallVectorImpl<std::unique_ptr<DwarfUnit>> &getUnits() { 340 return InfoHolder.getUnits(); 341 } 342 343 /// \brief Find abstract variable associated with Var. 344 DbgVariable *getExistingAbstractVariable(const DIVariable &DV, 345 DIVariable &Cleansed); 346 DbgVariable *getExistingAbstractVariable(const DIVariable &DV); 347 void createAbstractVariable(const DIVariable &DV, LexicalScope *Scope); 348 void ensureAbstractVariableIsCreated(const DIVariable &Var, 349 const MDNode *Scope); 350 void ensureAbstractVariableIsCreatedIfScoped(const DIVariable &Var, 351 const MDNode *Scope); 352 353 /// \brief Find DIE for the given subprogram and attach appropriate 354 /// DW_AT_low_pc and DW_AT_high_pc attributes. If there are global 355 /// variables in this scope then create and insert DIEs for these 356 /// variables. 357 DIE &updateSubprogramScopeDIE(DwarfCompileUnit &SPCU, DISubprogram SP); 358 359 /// \brief A helper function to check whether the DIE for a given Scope is 360 /// going to be null. 361 bool isLexicalScopeDIENull(LexicalScope *Scope); 362 363 /// \brief A helper function to construct a RangeSpanList for a given 364 /// lexical scope. 365 void addScopeRangeList(DwarfCompileUnit &TheCU, DIE &ScopeDIE, 366 const SmallVectorImpl<InsnRange> &Range); 367 368 /// \brief Construct new DW_TAG_lexical_block for this scope and 369 /// attach DW_AT_low_pc/DW_AT_high_pc labels. 370 std::unique_ptr<DIE> constructLexicalScopeDIE(DwarfCompileUnit &TheCU, 371 LexicalScope *Scope); 372 373 /// \brief This scope represents inlined body of a function. Construct 374 /// DIE to represent this concrete inlined copy of the function. 375 std::unique_ptr<DIE> constructInlinedScopeDIE(DwarfCompileUnit &TheCU, 376 LexicalScope *Scope); 377 378 /// \brief Construct a DIE for this scope. 379 std::unique_ptr<DIE> constructScopeDIE(DwarfCompileUnit &TheCU, 380 LexicalScope *Scope); 381 void createAndAddScopeChildren(DwarfCompileUnit &TheCU, LexicalScope *Scope, 382 DIE &ScopeDIE); 383 /// \brief Construct a DIE for this abstract scope. 384 void constructAbstractSubprogramScopeDIE(DwarfCompileUnit &TheCU, 385 LexicalScope *Scope); 386 /// \brief Construct a DIE for this subprogram scope. 387 DIE &constructSubprogramScopeDIE(DwarfCompileUnit &TheCU, 388 LexicalScope *Scope); 389 /// A helper function to create children of a Scope DIE. 390 DIE *createScopeChildrenDIE(DwarfCompileUnit &TheCU, LexicalScope *Scope, 391 SmallVectorImpl<std::unique_ptr<DIE>> &Children); 392 393 /// \brief Emit initial Dwarf sections with a label at the start of each one. 394 void emitSectionLabels(); 395 396 /// \brief Compute the size and offset of a DIE given an incoming Offset. 397 unsigned computeSizeAndOffset(DIE *Die, unsigned Offset); 398 399 /// \brief Compute the size and offset of all the DIEs. 400 void computeSizeAndOffsets(); 401 402 /// \brief Collect info for variables that were optimized out. 403 void collectDeadVariables(); 404 405 void finishVariableDefinitions(); 406 407 void finishSubprogramDefinitions(); 408 409 /// \brief Finish off debug information after all functions have been 410 /// processed. 411 void finalizeModuleInfo(); 412 413 /// \brief Emit labels to close any remaining sections that have been left 414 /// open. 415 void endSections(); 416 417 /// \brief Emit the debug info section. 418 void emitDebugInfo(); 419 420 /// \brief Emit the abbreviation section. 421 void emitAbbreviations(); 422 423 /// \brief Emit the last address of the section and the end of 424 /// the line matrix. 425 void emitEndOfLineMatrix(unsigned SectionEnd); 426 427 /// \brief Emit visible names into a hashed accelerator table section. 428 void emitAccelNames(); 429 430 /// \brief Emit objective C classes and categories into a hashed 431 /// accelerator table section. 432 void emitAccelObjC(); 433 434 /// \brief Emit namespace dies into a hashed accelerator table. 435 void emitAccelNamespaces(); 436 437 /// \brief Emit type dies into a hashed accelerator table. 438 void emitAccelTypes(); 439 440 /// \brief Emit visible names into a debug pubnames section. 441 /// \param GnuStyle determines whether or not we want to emit 442 /// additional information into the table ala newer gcc for gdb 443 /// index. 444 void emitDebugPubNames(bool GnuStyle = false); 445 446 /// \brief Emit visible types into a debug pubtypes section. 447 /// \param GnuStyle determines whether or not we want to emit 448 /// additional information into the table ala newer gcc for gdb 449 /// index. 450 void emitDebugPubTypes(bool GnuStyle = false); 451 452 void 453 emitDebugPubSection(bool GnuStyle, const MCSection *PSec, StringRef Name, 454 const StringMap<const DIE *> &(DwarfUnit::*Accessor)() 455 const); 456 457 /// \brief Emit visible names into a debug str section. 458 void emitDebugStr(); 459 460 /// \brief Emit visible names into a debug loc section. 461 void emitDebugLoc(); 462 463 /// \brief Emit visible names into a debug loc dwo section. 464 void emitDebugLocDWO(); 465 466 /// \brief Emit visible names into a debug aranges section. 467 void emitDebugARanges(); 468 469 /// \brief Emit visible names into a debug ranges section. 470 void emitDebugRanges(); 471 472 /// \brief Emit inline info using custom format. 473 void emitDebugInlineInfo(); 474 475 /// DWARF 5 Experimental Split Dwarf Emitters 476 477 /// \brief Initialize common features of skeleton units. 478 void initSkeletonUnit(const DwarfUnit &U, DIE &Die, 479 std::unique_ptr<DwarfUnit> NewU); 480 481 /// \brief Construct the split debug info compile unit for the debug info 482 /// section. 483 DwarfCompileUnit &constructSkeletonCU(const DwarfCompileUnit &CU); 484 485 /// \brief Construct the split debug info compile unit for the debug info 486 /// section. 487 DwarfTypeUnit &constructSkeletonTU(DwarfTypeUnit &TU); 488 489 /// \brief Emit the debug info dwo section. 490 void emitDebugInfoDWO(); 491 492 /// \brief Emit the debug abbrev dwo section. 493 void emitDebugAbbrevDWO(); 494 495 /// \brief Emit the debug line dwo section. 496 void emitDebugLineDWO(); 497 498 /// \brief Emit the debug str dwo section. 499 void emitDebugStrDWO(); 500 501 /// Flags to let the linker know we have emitted new style pubnames. Only 502 /// emit it here if we don't have a skeleton CU for split dwarf. 503 void addGnuPubAttributes(DwarfUnit &U, DIE &D) const; 504 505 /// \brief Create new DwarfCompileUnit for the given metadata node with tag 506 /// DW_TAG_compile_unit. 507 DwarfCompileUnit &constructDwarfCompileUnit(DICompileUnit DIUnit); 508 509 /// \brief Construct imported_module or imported_declaration DIE. 510 void constructImportedEntityDIE(DwarfCompileUnit &TheCU, const MDNode *N); 511 512 /// \brief Construct import_module DIE. 513 void constructImportedEntityDIE(DwarfCompileUnit &TheCU, const MDNode *N, 514 DIE &Context); 515 516 /// \brief Construct import_module DIE. 517 void constructImportedEntityDIE(DwarfCompileUnit &TheCU, 518 const DIImportedEntity &Module, DIE &Context); 519 520 /// \brief Register a source line with debug info. Returns the unique 521 /// label that was emitted and which provides correspondence to the 522 /// source line list. 523 void recordSourceLine(unsigned Line, unsigned Col, const MDNode *Scope, 524 unsigned Flags); 525 526 /// \brief Indentify instructions that are marking the beginning of or 527 /// ending of a scope. 528 void identifyScopeMarkers(); 529 530 /// \brief If Var is an current function argument that add it in 531 /// CurrentFnArguments list. 532 bool addCurrentFnArgument(DbgVariable *Var, LexicalScope *Scope); 533 534 /// \brief Populate LexicalScope entries with variables' info. 535 void collectVariableInfo(SmallPtrSet<const MDNode *, 16> &ProcessedVars); 536 537 /// \brief Collect variable information from the side table maintained 538 /// by MMI. 539 void collectVariableInfoFromMMITable(SmallPtrSet<const MDNode *, 16> &P); 540 541 /// \brief Ensure that a label will be emitted before MI. requestLabelBeforeInsn(const MachineInstr * MI)542 void requestLabelBeforeInsn(const MachineInstr *MI) { 543 LabelsBeforeInsn.insert(std::make_pair(MI, nullptr)); 544 } 545 546 /// \brief Return Label preceding the instruction. 547 MCSymbol *getLabelBeforeInsn(const MachineInstr *MI); 548 549 /// \brief Ensure that a label will be emitted after MI. requestLabelAfterInsn(const MachineInstr * MI)550 void requestLabelAfterInsn(const MachineInstr *MI) { 551 LabelsAfterInsn.insert(std::make_pair(MI, nullptr)); 552 } 553 554 /// \brief Return Label immediately following the instruction. 555 MCSymbol *getLabelAfterInsn(const MachineInstr *MI); 556 557 void attachRangesOrLowHighPC(DwarfCompileUnit &Unit, DIE &D, 558 const SmallVectorImpl<InsnRange> &Ranges); 559 void attachLowHighPC(DwarfCompileUnit &Unit, DIE &D, MCSymbol *Begin, 560 MCSymbol *End); 561 562 public: 563 //===--------------------------------------------------------------------===// 564 // Main entry points. 565 // 566 DwarfDebug(AsmPrinter *A, Module *M); 567 568 ~DwarfDebug() override; 569 insertDIE(const MDNode * TypeMD,DIE * Die)570 void insertDIE(const MDNode *TypeMD, DIE *Die) { 571 MDTypeNodeToDieMap.insert(std::make_pair(TypeMD, Die)); 572 } getDIE(const MDNode * TypeMD)573 DIE *getDIE(const MDNode *TypeMD) { 574 return MDTypeNodeToDieMap.lookup(TypeMD); 575 } 576 577 /// \brief Emit all Dwarf sections that should come prior to the 578 /// content. 579 void beginModule(); 580 581 /// \brief Emit all Dwarf sections that should come after the content. 582 void endModule() override; 583 584 /// \brief Gather pre-function debug information. 585 void beginFunction(const MachineFunction *MF) override; 586 587 /// \brief Gather and emit post-function debug information. 588 void endFunction(const MachineFunction *MF) override; 589 590 /// \brief Process beginning of an instruction. 591 void beginInstruction(const MachineInstr *MI) override; 592 593 /// \brief Process end of an instruction. 594 void endInstruction() override; 595 596 /// \brief Add a DIE to the set of types that we're going to pull into 597 /// type units. 598 void addDwarfTypeUnitType(DwarfCompileUnit &CU, StringRef Identifier, 599 DIE &Die, DICompositeType CTy); 600 601 /// \brief Add a label so that arange data can be generated for it. addArangeLabel(SymbolCU SCU)602 void addArangeLabel(SymbolCU SCU) { ArangeLabels.push_back(SCU); } 603 604 /// \brief For symbols that have a size designated (e.g. common symbols), 605 /// this tracks that size. setSymbolSize(const MCSymbol * Sym,uint64_t Size)606 void setSymbolSize(const MCSymbol *Sym, uint64_t Size) override { 607 SymSize[Sym] = Size; 608 } 609 610 /// \brief Recursively Emits a debug information entry. 611 void emitDIE(DIE &Die); 612 613 // Experimental DWARF5 features. 614 615 /// \brief Returns whether or not to emit tables that dwarf consumers can 616 /// use to accelerate lookup. useDwarfAccelTables()617 bool useDwarfAccelTables() const { return HasDwarfAccelTables; } 618 619 /// \brief Returns whether or not to change the current debug info for the 620 /// split dwarf proposal support. useSplitDwarf()621 bool useSplitDwarf() const { return HasSplitDwarf; } 622 623 /// Returns the Dwarf Version. getDwarfVersion()624 unsigned getDwarfVersion() const { return DwarfVersion; } 625 626 /// Returns the section symbol for the .debug_loc section. getDebugLocSym()627 MCSymbol *getDebugLocSym() const { return DwarfDebugLocSectionSym; } 628 629 /// Returns the previous section that was emitted into. getPrevSection()630 const MCSection *getPrevSection() const { return PrevSection; } 631 632 /// Returns the previous CU that was being updated getPrevCU()633 const DwarfCompileUnit *getPrevCU() const { return PrevCU; } 634 635 /// Returns the entries for the .debug_loc section. 636 const SmallVectorImpl<DebugLocList> & getDebugLocEntries()637 getDebugLocEntries() const { 638 return DotDebugLocEntries; 639 } 640 641 /// \brief Emit an entry for the debug loc section. This can be used to 642 /// handle an entry that's going to be emitted into the debug loc section. 643 void emitDebugLocEntry(ByteStreamer &Streamer, const DebugLocEntry &Entry); 644 645 /// Emit the location for a debug loc entry, including the size header. 646 void emitDebugLocEntryLocation(const DebugLocEntry &Entry); 647 648 /// Find the MDNode for the given reference. resolve(DIRef<T> Ref)649 template <typename T> T resolve(DIRef<T> Ref) const { 650 return Ref.resolve(TypeIdentifierMap); 651 } 652 653 /// \brief Return the TypeIdentifierMap. getTypeIdentifierMap()654 const DITypeIdentifierMap &getTypeIdentifierMap() const { 655 return TypeIdentifierMap; 656 } 657 658 /// Find the DwarfCompileUnit for the given CU Die. lookupUnit(const DIE * CU)659 DwarfCompileUnit *lookupUnit(const DIE *CU) const { 660 return CUDieMap.lookup(CU); 661 } 662 /// isSubprogramContext - Return true if Context is either a subprogram 663 /// or another context nested inside a subprogram. 664 bool isSubprogramContext(const MDNode *Context); 665 666 void addSubprogramNames(DISubprogram SP, DIE &Die); 667 getAddressPool()668 AddressPool &getAddressPool() { return AddrPool; } 669 670 void addAccelName(StringRef Name, const DIE &Die); 671 672 void addAccelObjC(StringRef Name, const DIE &Die); 673 674 void addAccelNamespace(StringRef Name, const DIE &Die); 675 676 void addAccelType(StringRef Name, const DIE &Die, char Flags); 677 }; 678 } // End of namespace llvm 679 680 #endif 681