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