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