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