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