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 "AsmPrinterHandler.h" 18 #include "DIE.h" 19 #include "llvm/ADT/DenseMap.h" 20 #include "llvm/ADT/FoldingSet.h" 21 #include "llvm/ADT/SetVector.h" 22 #include "llvm/ADT/SmallPtrSet.h" 23 #include "llvm/ADT/StringMap.h" 24 #include "llvm/ADT/MapVector.h" 25 #include "llvm/CodeGen/AsmPrinter.h" 26 #include "llvm/CodeGen/LexicalScopes.h" 27 #include "llvm/DebugInfo.h" 28 #include "llvm/MC/MachineLocation.h" 29 #include "llvm/Support/Allocator.h" 30 #include "llvm/Support/DebugLoc.h" 31 32 namespace llvm { 33 34 class DwarfUnit; 35 class DwarfCompileUnit; 36 class ConstantInt; 37 class ConstantFP; 38 class DbgVariable; 39 class MachineFrameInfo; 40 class MachineModuleInfo; 41 class MachineOperand; 42 class MCAsmInfo; 43 class MCObjectFileInfo; 44 class DIEAbbrev; 45 class DIE; 46 class DIELoc; 47 class DIEEntry; 48 49 //===----------------------------------------------------------------------===// 50 /// \brief This class is used to record source line correspondence. 51 class SrcLineInfo { 52 unsigned Line; // Source line number. 53 unsigned Column; // Source column. 54 unsigned SourceID; // Source ID number. 55 MCSymbol *Label; // Label in code ID number. 56 public: 57 SrcLineInfo(unsigned L, unsigned C, unsigned S, MCSymbol *label) 58 : Line(L), Column(C), SourceID(S), Label(label) {} 59 60 // Accessors 61 unsigned getLine() const { return Line; } 62 unsigned getColumn() const { return Column; } 63 unsigned getSourceID() const { return SourceID; } 64 MCSymbol *getLabel() const { return Label; } 65 }; 66 67 /// \brief This struct describes location entries emitted in the .debug_loc 68 /// section. 69 class DotDebugLocEntry { 70 // Begin and end symbols for the address range that this location is valid. 71 const MCSymbol *Begin; 72 const MCSymbol *End; 73 74 // Type of entry that this represents. 75 enum EntryType { 76 E_Location, 77 E_Integer, 78 E_ConstantFP, 79 E_ConstantInt 80 }; 81 enum EntryType EntryKind; 82 83 union { 84 int64_t Int; 85 const ConstantFP *CFP; 86 const ConstantInt *CIP; 87 } Constants; 88 89 // The location in the machine frame. 90 MachineLocation Loc; 91 92 // The variable to which this location entry corresponds. 93 const MDNode *Variable; 94 95 // Whether this location has been merged. 96 bool Merged; 97 98 public: 99 DotDebugLocEntry() : Begin(0), End(0), Variable(0), Merged(false) { 100 Constants.Int = 0; 101 } 102 DotDebugLocEntry(const MCSymbol *B, const MCSymbol *E, MachineLocation &L, 103 const MDNode *V) 104 : Begin(B), End(E), Loc(L), Variable(V), Merged(false) { 105 Constants.Int = 0; 106 EntryKind = E_Location; 107 } 108 DotDebugLocEntry(const MCSymbol *B, const MCSymbol *E, int64_t i) 109 : Begin(B), End(E), Variable(0), Merged(false) { 110 Constants.Int = i; 111 EntryKind = E_Integer; 112 } 113 DotDebugLocEntry(const MCSymbol *B, const MCSymbol *E, const ConstantFP *FPtr) 114 : Begin(B), End(E), Variable(0), Merged(false) { 115 Constants.CFP = FPtr; 116 EntryKind = E_ConstantFP; 117 } 118 DotDebugLocEntry(const MCSymbol *B, const MCSymbol *E, 119 const ConstantInt *IPtr) 120 : Begin(B), End(E), Variable(0), Merged(false) { 121 Constants.CIP = IPtr; 122 EntryKind = E_ConstantInt; 123 } 124 125 /// \brief Empty entries are also used as a trigger to emit temp label. Such 126 /// labels are referenced is used to find debug_loc offset for a given DIE. 127 bool isEmpty() { return Begin == 0 && End == 0; } 128 bool isMerged() { return Merged; } 129 void Merge(DotDebugLocEntry *Next) { 130 if (!(Begin && Loc == Next->Loc && End == Next->Begin)) 131 return; 132 Next->Begin = Begin; 133 Merged = true; 134 } 135 bool isLocation() const { return EntryKind == E_Location; } 136 bool isInt() const { return EntryKind == E_Integer; } 137 bool isConstantFP() const { return EntryKind == E_ConstantFP; } 138 bool isConstantInt() const { return EntryKind == E_ConstantInt; } 139 int64_t getInt() const { return Constants.Int; } 140 const ConstantFP *getConstantFP() const { return Constants.CFP; } 141 const ConstantInt *getConstantInt() const { return Constants.CIP; } 142 const MDNode *getVariable() const { return Variable; } 143 const MCSymbol *getBeginSym() const { return Begin; } 144 const MCSymbol *getEndSym() const { return End; } 145 MachineLocation getLoc() const { return Loc; } 146 }; 147 148 //===----------------------------------------------------------------------===// 149 /// \brief This class is used to track local variable information. 150 class DbgVariable { 151 DIVariable Var; // Variable Descriptor. 152 DIE *TheDIE; // Variable DIE. 153 unsigned DotDebugLocOffset; // Offset in DotDebugLocEntries. 154 DbgVariable *AbsVar; // Corresponding Abstract variable, if any. 155 const MachineInstr *MInsn; // DBG_VALUE instruction of the variable. 156 int FrameIndex; 157 DwarfDebug *DD; 158 159 public: 160 // AbsVar may be NULL. 161 DbgVariable(DIVariable V, DbgVariable *AV, DwarfDebug *DD) 162 : Var(V), TheDIE(0), DotDebugLocOffset(~0U), AbsVar(AV), MInsn(0), 163 FrameIndex(~0), DD(DD) {} 164 165 // Accessors. 166 DIVariable getVariable() const { return Var; } 167 void setDIE(DIE *D) { TheDIE = D; } 168 DIE *getDIE() const { return TheDIE; } 169 void setDotDebugLocOffset(unsigned O) { DotDebugLocOffset = O; } 170 unsigned getDotDebugLocOffset() const { return DotDebugLocOffset; } 171 StringRef getName() const { return Var.getName(); } 172 DbgVariable *getAbstractVariable() const { return AbsVar; } 173 const MachineInstr *getMInsn() const { return MInsn; } 174 void setMInsn(const MachineInstr *M) { MInsn = M; } 175 int getFrameIndex() const { return FrameIndex; } 176 void setFrameIndex(int FI) { FrameIndex = FI; } 177 // Translate tag to proper Dwarf tag. 178 uint16_t getTag() const { 179 if (Var.getTag() == dwarf::DW_TAG_arg_variable) 180 return dwarf::DW_TAG_formal_parameter; 181 182 return dwarf::DW_TAG_variable; 183 } 184 /// \brief Return true if DbgVariable is artificial. 185 bool isArtificial() const { 186 if (Var.isArtificial()) 187 return true; 188 if (getType().isArtificial()) 189 return true; 190 return false; 191 } 192 193 bool isObjectPointer() const { 194 if (Var.isObjectPointer()) 195 return true; 196 if (getType().isObjectPointer()) 197 return true; 198 return false; 199 } 200 201 bool variableHasComplexAddress() const { 202 assert(Var.isVariable() && "Invalid complex DbgVariable!"); 203 return Var.hasComplexAddress(); 204 } 205 bool isBlockByrefVariable() const { 206 assert(Var.isVariable() && "Invalid complex DbgVariable!"); 207 return Var.isBlockByrefVariable(); 208 } 209 unsigned getNumAddrElements() const { 210 assert(Var.isVariable() && "Invalid complex DbgVariable!"); 211 return Var.getNumAddrElements(); 212 } 213 uint64_t getAddrElement(unsigned i) const { return Var.getAddrElement(i); } 214 DIType getType() const; 215 216 private: 217 /// resolve - Look in the DwarfDebug map for the MDNode that 218 /// corresponds to the reference. 219 template <typename T> T resolve(DIRef<T> Ref) const; 220 }; 221 222 /// \brief Collects and handles information specific to a particular 223 /// collection of units. This collection represents all of the units 224 /// that will be ultimately output into a single object file. 225 class DwarfFile { 226 // Target of Dwarf emission, used for sizing of abbreviations. 227 AsmPrinter *Asm; 228 229 // Used to uniquely define abbreviations. 230 FoldingSet<DIEAbbrev> AbbreviationsSet; 231 232 // A list of all the unique abbreviations in use. 233 std::vector<DIEAbbrev *> Abbreviations; 234 235 // A pointer to all units in the section. 236 SmallVector<DwarfUnit *, 1> CUs; 237 238 // Collection of strings for this unit and assorted symbols. 239 // A String->Symbol mapping of strings used by indirect 240 // references. 241 typedef StringMap<std::pair<MCSymbol *, unsigned>, BumpPtrAllocator &> 242 StrPool; 243 StrPool StringPool; 244 unsigned NextStringPoolNumber; 245 std::string StringPref; 246 247 struct AddressPoolEntry { 248 unsigned Number; 249 bool TLS; 250 AddressPoolEntry(unsigned Number, bool TLS) : Number(Number), TLS(TLS) {} 251 }; 252 // Collection of addresses for this unit and assorted labels. 253 // A Symbol->unsigned mapping of addresses used by indirect 254 // references. 255 typedef DenseMap<const MCSymbol *, AddressPoolEntry> AddrPool; 256 AddrPool AddressPool; 257 unsigned NextAddrPoolNumber; 258 259 public: 260 DwarfFile(AsmPrinter *AP, const char *Pref, BumpPtrAllocator &DA) 261 : Asm(AP), StringPool(DA), NextStringPoolNumber(0), StringPref(Pref), 262 AddressPool(), NextAddrPoolNumber(0) {} 263 264 ~DwarfFile(); 265 266 const SmallVectorImpl<DwarfUnit *> &getUnits() { return CUs; } 267 268 /// \brief Compute the size and offset of a DIE given an incoming Offset. 269 unsigned computeSizeAndOffset(DIE *Die, unsigned Offset); 270 271 /// \brief Compute the size and offset of all the DIEs. 272 void computeSizeAndOffsets(); 273 274 /// \brief Define a unique number for the abbreviation. 275 void assignAbbrevNumber(DIEAbbrev &Abbrev); 276 277 /// \brief Add a unit to the list of CUs. 278 void addUnit(DwarfUnit *CU) { CUs.push_back(CU); } 279 280 /// \brief Emit all of the units to the section listed with the given 281 /// abbreviation section. 282 void emitUnits(DwarfDebug *DD, const MCSection *ASection, 283 const MCSymbol *ASectionSym); 284 285 /// \brief Emit a set of abbreviations to the specific section. 286 void emitAbbrevs(const MCSection *); 287 288 /// \brief Emit all of the strings to the section given. 289 void emitStrings(const MCSection *StrSection, const MCSection *OffsetSection, 290 const MCSymbol *StrSecSym); 291 292 /// \brief Emit all of the addresses to the section given. 293 void emitAddresses(const MCSection *AddrSection); 294 295 /// \brief Returns the entry into the start of the pool. 296 MCSymbol *getStringPoolSym(); 297 298 /// \brief Returns an entry into the string pool with the given 299 /// string text. 300 MCSymbol *getStringPoolEntry(StringRef Str); 301 302 /// \brief Returns the index into the string pool with the given 303 /// string text. 304 unsigned getStringPoolIndex(StringRef Str); 305 306 /// \brief Returns the string pool. 307 StrPool *getStringPool() { return &StringPool; } 308 309 /// \brief Returns the index into the address pool with the given 310 /// label/symbol. 311 unsigned getAddrPoolIndex(const MCSymbol *Sym, bool TLS = false); 312 313 /// \brief Returns the address pool. 314 AddrPool *getAddrPool() { return &AddressPool; } 315 }; 316 317 /// \brief Helper used to pair up a symbol and its DWARF compile unit. 318 struct SymbolCU { 319 SymbolCU(DwarfCompileUnit *CU, const MCSymbol *Sym) : Sym(Sym), CU(CU) {} 320 const MCSymbol *Sym; 321 DwarfCompileUnit *CU; 322 }; 323 324 /// \brief Collects and handles dwarf debug information. 325 class DwarfDebug : public AsmPrinterHandler { 326 // Target of Dwarf emission. 327 AsmPrinter *Asm; 328 329 // Collected machine module information. 330 MachineModuleInfo *MMI; 331 332 // All DIEValues are allocated through this allocator. 333 BumpPtrAllocator DIEValueAllocator; 334 335 // Handle to the compile unit used for the inline extension handling, 336 // this is just so that the DIEValue allocator has a place to store 337 // the particular elements. 338 // FIXME: Store these off of DwarfDebug instead? 339 DwarfCompileUnit *FirstCU; 340 341 // Maps MDNode with its corresponding DwarfCompileUnit. 342 MapVector<const MDNode *, DwarfCompileUnit *> CUMap; 343 344 // Maps subprogram MDNode with its corresponding DwarfCompileUnit. 345 DenseMap<const MDNode *, DwarfCompileUnit *> SPMap; 346 347 // Maps a CU DIE with its corresponding DwarfCompileUnit. 348 DenseMap<const DIE *, DwarfCompileUnit *> CUDieMap; 349 350 /// Maps MDNodes for type sysstem with the corresponding DIEs. These DIEs can 351 /// be shared across CUs, that is why we keep the map here instead 352 /// of in DwarfCompileUnit. 353 DenseMap<const MDNode *, DIE *> MDTypeNodeToDieMap; 354 355 // Stores the current file ID for a given compile unit. 356 DenseMap<unsigned, unsigned> FileIDCUMap; 357 // Source id map, i.e. CUID, source filename and directory, 358 // separated by a zero byte, mapped to a unique id. 359 StringMap<unsigned, BumpPtrAllocator &> SourceIdMap; 360 361 // List of all labels used in aranges generation. 362 std::vector<SymbolCU> ArangeLabels; 363 364 // Size of each symbol emitted (for those symbols that have a specific size). 365 DenseMap<const MCSymbol *, uint64_t> SymSize; 366 367 // Provides a unique id per text section. 368 typedef DenseMap<const MCSection *, SmallVector<SymbolCU, 8> > SectionMapType; 369 SectionMapType SectionMap; 370 371 // List of arguments for current function. 372 SmallVector<DbgVariable *, 8> CurrentFnArguments; 373 374 LexicalScopes LScopes; 375 376 // Collection of abstract subprogram DIEs. 377 DenseMap<const MDNode *, DIE *> AbstractSPDies; 378 379 // Collection of dbg variables of a scope. 380 typedef DenseMap<LexicalScope *, SmallVector<DbgVariable *, 8> > 381 ScopeVariablesMap; 382 ScopeVariablesMap ScopeVariables; 383 384 // Collection of abstract variables. 385 DenseMap<const MDNode *, DbgVariable *> AbstractVariables; 386 387 // Collection of DotDebugLocEntry. 388 SmallVector<DotDebugLocEntry, 4> DotDebugLocEntries; 389 390 // Collection of subprogram DIEs that are marked (at the end of the module) 391 // as DW_AT_inline. 392 SmallPtrSet<DIE *, 4> InlinedSubprogramDIEs; 393 394 // This is a collection of subprogram MDNodes that are processed to 395 // create DIEs. 396 SmallPtrSet<const MDNode *, 16> ProcessedSPNodes; 397 398 // Maps instruction with label emitted before instruction. 399 DenseMap<const MachineInstr *, MCSymbol *> LabelsBeforeInsn; 400 401 // Maps instruction with label emitted after instruction. 402 DenseMap<const MachineInstr *, MCSymbol *> LabelsAfterInsn; 403 404 // Every user variable mentioned by a DBG_VALUE instruction in order of 405 // appearance. 406 SmallVector<const MDNode *, 8> UserVariables; 407 408 // For each user variable, keep a list of DBG_VALUE instructions in order. 409 // The list can also contain normal instructions that clobber the previous 410 // DBG_VALUE. 411 typedef DenseMap<const MDNode *, SmallVector<const MachineInstr *, 4> > 412 DbgValueHistoryMap; 413 DbgValueHistoryMap DbgValues; 414 415 // Previous instruction's location information. This is used to determine 416 // label location to indicate scope boundries in dwarf debug info. 417 DebugLoc PrevInstLoc; 418 MCSymbol *PrevLabel; 419 420 // This location indicates end of function prologue and beginning of function 421 // body. 422 DebugLoc PrologEndLoc; 423 424 // If nonnull, stores the current machine function we're processing. 425 const MachineFunction *CurFn; 426 427 // If nonnull, stores the current machine instruction we're processing. 428 const MachineInstr *CurMI; 429 430 // Section Symbols: these are assembler temporary labels that are emitted at 431 // the beginning of each supported dwarf section. These are used to form 432 // section offsets and are created by EmitSectionLabels. 433 MCSymbol *DwarfInfoSectionSym, *DwarfAbbrevSectionSym; 434 MCSymbol *DwarfStrSectionSym, *TextSectionSym, *DwarfDebugRangeSectionSym; 435 MCSymbol *DwarfDebugLocSectionSym, *DwarfLineSectionSym, *DwarfAddrSectionSym; 436 MCSymbol *FunctionBeginSym, *FunctionEndSym; 437 MCSymbol *DwarfInfoDWOSectionSym, *DwarfAbbrevDWOSectionSym; 438 MCSymbol *DwarfStrDWOSectionSym; 439 MCSymbol *DwarfGnuPubNamesSectionSym, *DwarfGnuPubTypesSectionSym; 440 441 // As an optimization, there is no need to emit an entry in the directory 442 // table for the same directory as DW_AT_comp_dir. 443 StringRef CompilationDir; 444 445 // Counter for assigning globally unique IDs for ranges. 446 unsigned GlobalRangeCount; 447 448 // Holder for the file specific debug information. 449 DwarfFile InfoHolder; 450 451 // Holders for the various debug information flags that we might need to 452 // have exposed. See accessor functions below for description. 453 454 // Holder for imported entities. 455 typedef SmallVector<std::pair<const MDNode *, const MDNode *>, 32> 456 ImportedEntityMap; 457 ImportedEntityMap ScopesWithImportedEntities; 458 459 // Map from MDNodes for user-defined types to the type units that describe 460 // them. 461 DenseMap<const MDNode *, const DwarfTypeUnit *> DwarfTypeUnits; 462 463 // Whether to emit the pubnames/pubtypes sections. 464 bool HasDwarfPubSections; 465 466 // Whether or not to use AT_ranges for compilation units. 467 bool HasCURanges; 468 469 // Whether we emitted a function into a section other than the default 470 // text. 471 bool UsedNonDefaultText; 472 473 // Version of dwarf we're emitting. 474 unsigned DwarfVersion; 475 476 // Maps from a type identifier to the actual MDNode. 477 DITypeIdentifierMap TypeIdentifierMap; 478 479 // DWARF5 Experimental Options 480 bool HasDwarfAccelTables; 481 bool HasSplitDwarf; 482 483 // Separated Dwarf Variables 484 // In general these will all be for bits that are left in the 485 // original object file, rather than things that are meant 486 // to be in the .dwo sections. 487 488 // Holder for the skeleton information. 489 DwarfFile SkeletonHolder; 490 491 void addScopeVariable(LexicalScope *LS, DbgVariable *Var); 492 493 const SmallVectorImpl<DwarfUnit *> &getUnits() { 494 return InfoHolder.getUnits(); 495 } 496 497 /// \brief Find abstract variable associated with Var. 498 DbgVariable *findAbstractVariable(DIVariable &Var, DebugLoc Loc); 499 500 /// \brief Find DIE for the given subprogram and attach appropriate 501 /// DW_AT_low_pc and DW_AT_high_pc attributes. If there are global 502 /// variables in this scope then create and insert DIEs for these 503 /// variables. 504 DIE *updateSubprogramScopeDIE(DwarfCompileUnit *SPCU, DISubprogram SP); 505 506 /// \brief A helper function to check whether the DIE for a given Scope is 507 /// going to be null. 508 bool isLexicalScopeDIENull(LexicalScope *Scope); 509 510 /// \brief A helper function to construct a RangeSpanList for a given 511 /// lexical scope. 512 void addScopeRangeList(DwarfCompileUnit *TheCU, DIE *ScopeDIE, 513 const SmallVectorImpl<InsnRange> &Range); 514 515 /// \brief Construct new DW_TAG_lexical_block for this scope and 516 /// attach DW_AT_low_pc/DW_AT_high_pc labels. 517 DIE *constructLexicalScopeDIE(DwarfCompileUnit *TheCU, LexicalScope *Scope); 518 519 /// \brief This scope represents inlined body of a function. Construct 520 /// DIE to represent this concrete inlined copy of the function. 521 DIE *constructInlinedScopeDIE(DwarfCompileUnit *TheCU, LexicalScope *Scope); 522 523 /// \brief Construct a DIE for this scope. 524 DIE *constructScopeDIE(DwarfCompileUnit *TheCU, LexicalScope *Scope); 525 /// A helper function to create children of a Scope DIE. 526 DIE *createScopeChildrenDIE(DwarfCompileUnit *TheCU, LexicalScope *Scope, 527 SmallVectorImpl<DIE *> &Children); 528 529 /// \brief Emit initial Dwarf sections with a label at the start of each one. 530 void emitSectionLabels(); 531 532 /// \brief Compute the size and offset of a DIE given an incoming Offset. 533 unsigned computeSizeAndOffset(DIE *Die, unsigned Offset); 534 535 /// \brief Compute the size and offset of all the DIEs. 536 void computeSizeAndOffsets(); 537 538 /// \brief Attach DW_AT_inline attribute with inlined subprogram DIEs. 539 void computeInlinedDIEs(); 540 541 /// \brief Collect info for variables that were optimized out. 542 void collectDeadVariables(); 543 544 /// \brief Finish off debug information after all functions have been 545 /// processed. 546 void finalizeModuleInfo(); 547 548 /// \brief Emit labels to close any remaining sections that have been left 549 /// open. 550 void endSections(); 551 552 /// \brief Emit the debug info section. 553 void emitDebugInfo(); 554 555 /// \brief Emit the abbreviation section. 556 void emitAbbreviations(); 557 558 /// \brief Emit the last address of the section and the end of 559 /// the line matrix. 560 void emitEndOfLineMatrix(unsigned SectionEnd); 561 562 /// \brief Emit visible names into a hashed accelerator table section. 563 void emitAccelNames(); 564 565 /// \brief Emit objective C classes and categories into a hashed 566 /// accelerator table section. 567 void emitAccelObjC(); 568 569 /// \brief Emit namespace dies into a hashed accelerator table. 570 void emitAccelNamespaces(); 571 572 /// \brief Emit type dies into a hashed accelerator table. 573 void emitAccelTypes(); 574 575 /// \brief Emit visible names into a debug pubnames section. 576 /// \param GnuStyle determines whether or not we want to emit 577 /// additional information into the table ala newer gcc for gdb 578 /// index. 579 void emitDebugPubNames(bool GnuStyle = false); 580 581 /// \brief Emit visible types into a debug pubtypes section. 582 /// \param GnuStyle determines whether or not we want to emit 583 /// additional information into the table ala newer gcc for gdb 584 /// index. 585 void emitDebugPubTypes(bool GnuStyle = false); 586 587 /// \brief Emit visible names into a debug str section. 588 void emitDebugStr(); 589 590 /// \brief Emit visible names into a debug loc section. 591 void emitDebugLoc(); 592 593 /// \brief Emit visible names into a debug aranges section. 594 void emitDebugARanges(); 595 596 /// \brief Emit visible names into a debug ranges section. 597 void emitDebugRanges(); 598 599 /// \brief Emit inline info using custom format. 600 void emitDebugInlineInfo(); 601 602 /// DWARF 5 Experimental Split Dwarf Emitters 603 604 /// \brief Initialize common features of skeleton units. 605 void initSkeletonUnit(const DwarfUnit *U, DIE *Die, DwarfUnit *NewU); 606 607 /// \brief Construct the split debug info compile unit for the debug info 608 /// section. 609 DwarfCompileUnit *constructSkeletonCU(const DwarfCompileUnit *CU); 610 611 /// \brief Construct the split debug info compile unit for the debug info 612 /// section. 613 DwarfTypeUnit *constructSkeletonTU(DwarfTypeUnit *TU); 614 615 /// \brief Emit the debug info dwo section. 616 void emitDebugInfoDWO(); 617 618 /// \brief Emit the debug abbrev dwo section. 619 void emitDebugAbbrevDWO(); 620 621 /// \brief Emit the debug str dwo section. 622 void emitDebugStrDWO(); 623 624 /// Flags to let the linker know we have emitted new style pubnames. Only 625 /// emit it here if we don't have a skeleton CU for split dwarf. 626 void addGnuPubAttributes(DwarfUnit *U, DIE *D) const; 627 628 /// \brief Create new DwarfCompileUnit for the given metadata node with tag 629 /// DW_TAG_compile_unit. 630 DwarfCompileUnit *constructDwarfCompileUnit(DICompileUnit DIUnit); 631 632 /// \brief Construct subprogram DIE. 633 void constructSubprogramDIE(DwarfCompileUnit *TheCU, const MDNode *N); 634 635 /// \brief Construct imported_module or imported_declaration DIE. 636 void constructImportedEntityDIE(DwarfCompileUnit *TheCU, const MDNode *N); 637 638 /// \brief Construct import_module DIE. 639 void constructImportedEntityDIE(DwarfCompileUnit *TheCU, const MDNode *N, 640 DIE *Context); 641 642 /// \brief Construct import_module DIE. 643 void constructImportedEntityDIE(DwarfCompileUnit *TheCU, 644 const DIImportedEntity &Module, DIE *Context); 645 646 /// \brief Register a source line with debug info. Returns the unique 647 /// label that was emitted and which provides correspondence to the 648 /// source line list. 649 void recordSourceLine(unsigned Line, unsigned Col, const MDNode *Scope, 650 unsigned Flags); 651 652 /// \brief Indentify instructions that are marking the beginning of or 653 /// ending of a scope. 654 void identifyScopeMarkers(); 655 656 /// \brief If Var is an current function argument that add it in 657 /// CurrentFnArguments list. 658 bool addCurrentFnArgument(DbgVariable *Var, LexicalScope *Scope); 659 660 /// \brief Populate LexicalScope entries with variables' info. 661 void collectVariableInfo(SmallPtrSet<const MDNode *, 16> &ProcessedVars); 662 663 /// \brief Collect variable information from the side table maintained 664 /// by MMI. 665 void collectVariableInfoFromMMITable(SmallPtrSet<const MDNode *, 16> &P); 666 667 /// \brief Ensure that a label will be emitted before MI. 668 void requestLabelBeforeInsn(const MachineInstr *MI) { 669 LabelsBeforeInsn.insert(std::make_pair(MI, (MCSymbol *)0)); 670 } 671 672 /// \brief Return Label preceding the instruction. 673 MCSymbol *getLabelBeforeInsn(const MachineInstr *MI); 674 675 /// \brief Ensure that a label will be emitted after MI. 676 void requestLabelAfterInsn(const MachineInstr *MI) { 677 LabelsAfterInsn.insert(std::make_pair(MI, (MCSymbol *)0)); 678 } 679 680 /// \brief Return Label immediately following the instruction. 681 MCSymbol *getLabelAfterInsn(const MachineInstr *MI); 682 683 public: 684 //===--------------------------------------------------------------------===// 685 // Main entry points. 686 // 687 DwarfDebug(AsmPrinter *A, Module *M); 688 689 void insertDIE(const MDNode *TypeMD, DIE *Die) { 690 MDTypeNodeToDieMap.insert(std::make_pair(TypeMD, Die)); 691 } 692 DIE *getDIE(const MDNode *TypeMD) { 693 return MDTypeNodeToDieMap.lookup(TypeMD); 694 } 695 696 /// \brief Emit all Dwarf sections that should come prior to the 697 /// content. 698 void beginModule(); 699 700 /// \brief Emit all Dwarf sections that should come after the content. 701 void endModule(); 702 703 /// \brief Gather pre-function debug information. 704 void beginFunction(const MachineFunction *MF); 705 706 /// \brief Gather and emit post-function debug information. 707 void endFunction(const MachineFunction *MF); 708 709 /// \brief Process beginning of an instruction. 710 void beginInstruction(const MachineInstr *MI); 711 712 /// \brief Process end of an instruction. 713 void endInstruction(); 714 715 /// \brief Add a DIE to the set of types that we're going to pull into 716 /// type units. 717 void addDwarfTypeUnitType(DwarfCompileUnit &CU, StringRef Identifier, 718 DIE *Die, DICompositeType CTy); 719 720 /// \brief Add a label so that arange data can be generated for it. 721 void addArangeLabel(SymbolCU SCU) { ArangeLabels.push_back(SCU); } 722 723 /// \brief For symbols that have a size designated (e.g. common symbols), 724 /// this tracks that size. 725 void setSymbolSize(const MCSymbol *Sym, uint64_t Size) { 726 SymSize[Sym] = Size; 727 } 728 729 /// \brief Look up the source id with the given directory and source file 730 /// names. If none currently exists, create a new id and insert it in the 731 /// SourceIds map. 732 unsigned getOrCreateSourceID(StringRef DirName, StringRef FullName, 733 unsigned CUID); 734 735 /// \brief Recursively Emits a debug information entry. 736 void emitDIE(DIE *Die); 737 738 // Experimental DWARF5 features. 739 740 /// \brief Returns whether or not to emit tables that dwarf consumers can 741 /// use to accelerate lookup. 742 bool useDwarfAccelTables() { return HasDwarfAccelTables; } 743 744 /// \brief Returns whether or not to change the current debug info for the 745 /// split dwarf proposal support. 746 bool useSplitDwarf() { return HasSplitDwarf; } 747 748 /// \brief Returns whether or not to use AT_ranges for compilation units. 749 bool useCURanges() { return HasCURanges; } 750 751 /// Returns the Dwarf Version. 752 unsigned getDwarfVersion() const { return DwarfVersion; } 753 754 /// Find the MDNode for the given reference. 755 template <typename T> T resolve(DIRef<T> Ref) const { 756 return Ref.resolve(TypeIdentifierMap); 757 } 758 759 /// isSubprogramContext - Return true if Context is either a subprogram 760 /// or another context nested inside a subprogram. 761 bool isSubprogramContext(const MDNode *Context); 762 }; 763 } // End of namespace llvm 764 765 #endif 766