LLVM API Documentation

DwarfDebug.h
Go to the documentation of this file.
00001 //===-- llvm/CodeGen/DwarfDebug.h - Dwarf Debug Framework ------*- C++ -*--===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file contains support for writing dwarf debug info into asm files.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DWARFDEBUG_H
00015 #define LLVM_LIB_CODEGEN_ASMPRINTER_DWARFDEBUG_H
00016 
00017 #include "DwarfFile.h"
00018 #include "AsmPrinterHandler.h"
00019 #include "DIE.h"
00020 #include "DbgValueHistoryCalculator.h"
00021 #include "DebugLocEntry.h"
00022 #include "DebugLocList.h"
00023 #include "DwarfAccelTable.h"
00024 #include "llvm/ADT/DenseMap.h"
00025 #include "llvm/ADT/MapVector.h"
00026 #include "llvm/ADT/SmallPtrSet.h"
00027 #include "llvm/ADT/StringMap.h"
00028 #include "llvm/ADT/FoldingSet.h"
00029 #include "llvm/CodeGen/LexicalScopes.h"
00030 #include "llvm/CodeGen/MachineInstr.h"
00031 #include "llvm/IR/DebugInfo.h"
00032 #include "llvm/IR/DebugLoc.h"
00033 #include "llvm/MC/MachineLocation.h"
00034 #include "llvm/MC/MCDwarf.h"
00035 #include "llvm/Support/Allocator.h"
00036 
00037 #include <memory>
00038 
00039 namespace llvm {
00040 
00041 class AsmPrinter;
00042 class ByteStreamer;
00043 class ConstantInt;
00044 class ConstantFP;
00045 class DwarfCompileUnit;
00046 class DwarfDebug;
00047 class DwarfTypeUnit;
00048 class DwarfUnit;
00049 class MachineModuleInfo;
00050 
00051 //===----------------------------------------------------------------------===//
00052 /// \brief This class is used to record source line correspondence.
00053 class SrcLineInfo {
00054   unsigned Line;     // Source line number.
00055   unsigned Column;   // Source column.
00056   unsigned SourceID; // Source ID number.
00057   MCSymbol *Label;   // Label in code ID number.
00058 public:
00059   SrcLineInfo(unsigned L, unsigned C, unsigned S, MCSymbol *label)
00060       : Line(L), Column(C), SourceID(S), Label(label) {}
00061 
00062   // Accessors
00063   unsigned getLine() const { return Line; }
00064   unsigned getColumn() const { return Column; }
00065   unsigned getSourceID() const { return SourceID; }
00066   MCSymbol *getLabel() const { return Label; }
00067 };
00068 
00069 //===----------------------------------------------------------------------===//
00070 /// \brief This class is used to track local variable information.
00071 class DbgVariable {
00072   DIVariable Var;             // Variable Descriptor.
00073   DIE *TheDIE;                // Variable DIE.
00074   unsigned DotDebugLocOffset; // Offset in DotDebugLocEntries.
00075   const MachineInstr *MInsn;  // DBG_VALUE instruction of the variable.
00076   int FrameIndex;
00077   DwarfDebug *DD;
00078 
00079 public:
00080   /// Construct a DbgVariable from a DIVariable.
00081   DbgVariable(DIVariable V, DwarfDebug *DD)
00082       : Var(V), TheDIE(nullptr), DotDebugLocOffset(~0U), MInsn(nullptr),
00083         FrameIndex(~0), DD(DD) {}
00084 
00085   /// Construct a DbgVariable from a DEBUG_VALUE.
00086   /// AbstractVar may be NULL.
00087   DbgVariable(const MachineInstr *DbgValue, DwarfDebug *DD)
00088       : Var(DbgValue->getDebugVariable()), TheDIE(nullptr),
00089         DotDebugLocOffset(~0U), MInsn(DbgValue), FrameIndex(~0), DD(DD) {}
00090 
00091   // Accessors.
00092   DIVariable getVariable() const { return Var; }
00093   void setDIE(DIE &D) { TheDIE = &D; }
00094   DIE *getDIE() const { return TheDIE; }
00095   void setDotDebugLocOffset(unsigned O) { DotDebugLocOffset = O; }
00096   unsigned getDotDebugLocOffset() const { return DotDebugLocOffset; }
00097   StringRef getName() const { return Var.getName(); }
00098   const MachineInstr *getMInsn() const { return MInsn; }
00099   int getFrameIndex() const { return FrameIndex; }
00100   void setFrameIndex(int FI) { FrameIndex = FI; }
00101   // Translate tag to proper Dwarf tag.
00102   dwarf::Tag getTag() const {
00103     if (Var.getTag() == dwarf::DW_TAG_arg_variable)
00104       return dwarf::DW_TAG_formal_parameter;
00105 
00106     return dwarf::DW_TAG_variable;
00107   }
00108   /// \brief Return true if DbgVariable is artificial.
00109   bool isArtificial() const {
00110     if (Var.isArtificial())
00111       return true;
00112     if (getType().isArtificial())
00113       return true;
00114     return false;
00115   }
00116 
00117   bool isObjectPointer() const {
00118     if (Var.isObjectPointer())
00119       return true;
00120     if (getType().isObjectPointer())
00121       return true;
00122     return false;
00123   }
00124 
00125   bool variableHasComplexAddress() const {
00126     assert(Var.isVariable() && "Invalid complex DbgVariable!");
00127     return Var.hasComplexAddress();
00128   }
00129   bool isBlockByrefVariable() const;
00130   unsigned getNumAddrElements() const {
00131     assert(Var.isVariable() && "Invalid complex DbgVariable!");
00132     return Var.getNumAddrElements();
00133   }
00134   uint64_t getAddrElement(unsigned i) const { return Var.getAddrElement(i); }
00135   DIType getType() const;
00136 
00137 private:
00138   /// resolve - Look in the DwarfDebug map for the MDNode that
00139   /// corresponds to the reference.
00140   template <typename T> T resolve(DIRef<T> Ref) const;
00141 };
00142 
00143 
00144 /// \brief Helper used to pair up a symbol and its DWARF compile unit.
00145 struct SymbolCU {
00146   SymbolCU(DwarfCompileUnit *CU, const MCSymbol *Sym) : Sym(Sym), CU(CU) {}
00147   const MCSymbol *Sym;
00148   DwarfCompileUnit *CU;
00149 };
00150 
00151 /// \brief Collects and handles dwarf debug information.
00152 class DwarfDebug : public AsmPrinterHandler {
00153   // Target of Dwarf emission.
00154   AsmPrinter *Asm;
00155 
00156   // Collected machine module information.
00157   MachineModuleInfo *MMI;
00158 
00159   // All DIEValues are allocated through this allocator.
00160   BumpPtrAllocator DIEValueAllocator;
00161 
00162   // Handle to the compile unit used for the inline extension handling,
00163   // this is just so that the DIEValue allocator has a place to store
00164   // the particular elements.
00165   // FIXME: Store these off of DwarfDebug instead?
00166   DwarfCompileUnit *FirstCU;
00167 
00168   // Maps MDNode with its corresponding DwarfCompileUnit.
00169   MapVector<const MDNode *, DwarfCompileUnit *> CUMap;
00170 
00171   // Maps subprogram MDNode with its corresponding DwarfCompileUnit.
00172   DenseMap<const MDNode *, DwarfCompileUnit *> SPMap;
00173 
00174   // Maps a CU DIE with its corresponding DwarfCompileUnit.
00175   DenseMap<const DIE *, DwarfCompileUnit *> CUDieMap;
00176 
00177   /// Maps MDNodes for type system with the corresponding DIEs. These DIEs can
00178   /// be shared across CUs, that is why we keep the map here instead
00179   /// of in DwarfCompileUnit.
00180   DenseMap<const MDNode *, DIE *> MDTypeNodeToDieMap;
00181 
00182   // List of all labels used in aranges generation.
00183   std::vector<SymbolCU> ArangeLabels;
00184 
00185   // Size of each symbol emitted (for those symbols that have a specific size).
00186   DenseMap<const MCSymbol *, uint64_t> SymSize;
00187 
00188   // Provides a unique id per text section.
00189   typedef DenseMap<const MCSection *, SmallVector<SymbolCU, 8> > SectionMapType;
00190   SectionMapType SectionMap;
00191 
00192   // List of arguments for current function.
00193   SmallVector<DbgVariable *, 8> CurrentFnArguments;
00194 
00195   LexicalScopes LScopes;
00196 
00197   // Collection of abstract subprogram DIEs.
00198   DenseMap<const MDNode *, DIE *> AbstractSPDies;
00199 
00200   // Collection of dbg variables of a scope.
00201   typedef DenseMap<LexicalScope *, SmallVector<DbgVariable *, 8> >
00202   ScopeVariablesMap;
00203   ScopeVariablesMap ScopeVariables;
00204 
00205   // Collection of abstract variables.
00206   DenseMap<const MDNode *, std::unique_ptr<DbgVariable>> AbstractVariables;
00207   SmallVector<std::unique_ptr<DbgVariable>, 64> ConcreteVariables;
00208 
00209   // Collection of DebugLocEntry. Stored in a linked list so that DIELocLists
00210   // can refer to them in spite of insertions into this list.
00211   SmallVector<DebugLocList, 4> DotDebugLocEntries;
00212 
00213   // Collection of subprogram DIEs that are marked (at the end of the module)
00214   // as DW_AT_inline.
00215   SmallPtrSet<DIE *, 4> InlinedSubprogramDIEs;
00216 
00217   // This is a collection of subprogram MDNodes that are processed to
00218   // create DIEs.
00219   SmallPtrSet<const MDNode *, 16> ProcessedSPNodes;
00220 
00221   // Maps instruction with label emitted before instruction.
00222   DenseMap<const MachineInstr *, MCSymbol *> LabelsBeforeInsn;
00223 
00224   // Maps instruction with label emitted after instruction.
00225   DenseMap<const MachineInstr *, MCSymbol *> LabelsAfterInsn;
00226 
00227   // History of DBG_VALUE and clobber instructions for each user variable.
00228   // Variables are listed in order of appearance.
00229   DbgValueHistoryMap DbgValues;
00230 
00231   // Previous instruction's location information. This is used to determine
00232   // label location to indicate scope boundries in dwarf debug info.
00233   DebugLoc PrevInstLoc;
00234   MCSymbol *PrevLabel;
00235 
00236   // This location indicates end of function prologue and beginning of function
00237   // body.
00238   DebugLoc PrologEndLoc;
00239 
00240   // If nonnull, stores the current machine function we're processing.
00241   const MachineFunction *CurFn;
00242 
00243   // If nonnull, stores the current machine instruction we're processing.
00244   const MachineInstr *CurMI;
00245 
00246   // If nonnull, stores the CU in which the previous subprogram was contained.
00247   const DwarfCompileUnit *PrevCU;
00248 
00249   // Section Symbols: these are assembler temporary labels that are emitted at
00250   // the beginning of each supported dwarf section.  These are used to form
00251   // section offsets and are created by EmitSectionLabels.
00252   MCSymbol *DwarfInfoSectionSym, *DwarfAbbrevSectionSym;
00253   MCSymbol *DwarfStrSectionSym, *TextSectionSym, *DwarfDebugRangeSectionSym;
00254   MCSymbol *DwarfDebugLocSectionSym, *DwarfLineSectionSym, *DwarfAddrSectionSym;
00255   MCSymbol *FunctionBeginSym, *FunctionEndSym;
00256   MCSymbol *DwarfInfoDWOSectionSym, *DwarfAbbrevDWOSectionSym;
00257   MCSymbol *DwarfTypesDWOSectionSym;
00258   MCSymbol *DwarfStrDWOSectionSym;
00259   MCSymbol *DwarfGnuPubNamesSectionSym, *DwarfGnuPubTypesSectionSym;
00260 
00261   // As an optimization, there is no need to emit an entry in the directory
00262   // table for the same directory as DW_AT_comp_dir.
00263   StringRef CompilationDir;
00264 
00265   // Counter for assigning globally unique IDs for ranges.
00266   unsigned GlobalRangeCount;
00267 
00268   // Holder for the file specific debug information.
00269   DwarfFile InfoHolder;
00270 
00271   // Holders for the various debug information flags that we might need to
00272   // have exposed. See accessor functions below for description.
00273 
00274   // Holder for imported entities.
00275   typedef SmallVector<std::pair<const MDNode *, const MDNode *>, 32>
00276   ImportedEntityMap;
00277   ImportedEntityMap ScopesWithImportedEntities;
00278 
00279   // Map from MDNodes for user-defined types to the type units that describe
00280   // them.
00281   DenseMap<const MDNode *, const DwarfTypeUnit *> DwarfTypeUnits;
00282 
00283   SmallVector<std::pair<std::unique_ptr<DwarfTypeUnit>, DICompositeType>, 1> TypeUnitsUnderConstruction;
00284 
00285   // Whether to emit the pubnames/pubtypes sections.
00286   bool HasDwarfPubSections;
00287 
00288   // Whether or not to use AT_ranges for compilation units.
00289   bool HasCURanges;
00290 
00291   // Whether we emitted a function into a section other than the default
00292   // text.
00293   bool UsedNonDefaultText;
00294 
00295   // Version of dwarf we're emitting.
00296   unsigned DwarfVersion;
00297 
00298   // Maps from a type identifier to the actual MDNode.
00299   DITypeIdentifierMap TypeIdentifierMap;
00300 
00301   // DWARF5 Experimental Options
00302   bool HasDwarfAccelTables;
00303   bool HasSplitDwarf;
00304 
00305   // Separated Dwarf Variables
00306   // In general these will all be for bits that are left in the
00307   // original object file, rather than things that are meant
00308   // to be in the .dwo sections.
00309 
00310   // Holder for the skeleton information.
00311   DwarfFile SkeletonHolder;
00312 
00313   /// Store file names for type units under fission in a line table header that
00314   /// will be emitted into debug_line.dwo.
00315   // FIXME: replace this with a map from comp_dir to table so that we can emit
00316   // multiple tables during LTO each of which uses directory 0, referencing the
00317   // comp_dir of all the type units that use it.
00318   MCDwarfDwoLineTable SplitTypeUnitFileTable;
00319 
00320   // True iff there are multiple CUs in this module.
00321   bool SingleCU;
00322 
00323   AddressPool AddrPool;
00324 
00325   DwarfAccelTable AccelNames;
00326   DwarfAccelTable AccelObjC;
00327   DwarfAccelTable AccelNamespace;
00328   DwarfAccelTable AccelTypes;
00329 
00330   DenseMap<const Function *, DISubprogram> FunctionDIs;
00331 
00332   MCDwarfDwoLineTable *getDwoLineTable(const DwarfCompileUnit &);
00333 
00334   void addScopeVariable(LexicalScope *LS, DbgVariable *Var);
00335 
00336   const SmallVectorImpl<std::unique_ptr<DwarfUnit>> &getUnits() {
00337     return InfoHolder.getUnits();
00338   }
00339 
00340   /// \brief Find abstract variable associated with Var.
00341   DbgVariable *getExistingAbstractVariable(const DIVariable &DV,
00342                                            DIVariable &Cleansed);
00343   DbgVariable *getExistingAbstractVariable(const DIVariable &DV);
00344   void createAbstractVariable(const DIVariable &DV, LexicalScope *Scope);
00345   void ensureAbstractVariableIsCreated(const DIVariable &Var,
00346                                        const MDNode *Scope);
00347   void ensureAbstractVariableIsCreatedIfScoped(const DIVariable &Var,
00348                                                const MDNode *Scope);
00349 
00350   /// \brief Find DIE for the given subprogram and attach appropriate
00351   /// DW_AT_low_pc and DW_AT_high_pc attributes. If there are global
00352   /// variables in this scope then create and insert DIEs for these
00353   /// variables.
00354   DIE &updateSubprogramScopeDIE(DwarfCompileUnit &SPCU, DISubprogram SP);
00355 
00356   /// \brief A helper function to check whether the DIE for a given Scope is
00357   /// going to be null.
00358   bool isLexicalScopeDIENull(LexicalScope *Scope);
00359 
00360   /// \brief A helper function to construct a RangeSpanList for a given
00361   /// lexical scope.
00362   void addScopeRangeList(DwarfCompileUnit &TheCU, DIE &ScopeDIE,
00363                          const SmallVectorImpl<InsnRange> &Range);
00364 
00365   /// \brief Construct new DW_TAG_lexical_block for this scope and
00366   /// attach DW_AT_low_pc/DW_AT_high_pc labels.
00367   std::unique_ptr<DIE> constructLexicalScopeDIE(DwarfCompileUnit &TheCU,
00368                                                 LexicalScope *Scope);
00369 
00370   /// \brief This scope represents inlined body of a function. Construct
00371   /// DIE to represent this concrete inlined copy of the function.
00372   std::unique_ptr<DIE> constructInlinedScopeDIE(DwarfCompileUnit &TheCU,
00373                                                 LexicalScope *Scope);
00374 
00375   /// \brief Construct a DIE for this scope.
00376   void constructScopeDIE(DwarfCompileUnit &TheCU, LexicalScope *Scope,
00377                          SmallVectorImpl<std::unique_ptr<DIE>> &FinalChildren);
00378   DIE *createAndAddScopeChildren(DwarfCompileUnit &TheCU, LexicalScope *Scope,
00379                                  DIE &ScopeDIE);
00380   /// \brief Construct a DIE for this abstract scope.
00381   void constructAbstractSubprogramScopeDIE(DwarfCompileUnit &TheCU,
00382                                            LexicalScope *Scope);
00383   /// \brief Construct a DIE for this subprogram scope.
00384   DIE &constructSubprogramScopeDIE(DwarfCompileUnit &TheCU,
00385                                    LexicalScope *Scope);
00386   /// A helper function to create children of a Scope DIE.
00387   DIE *createScopeChildrenDIE(DwarfCompileUnit &TheCU, LexicalScope *Scope,
00388                               SmallVectorImpl<std::unique_ptr<DIE>> &Children,
00389                               unsigned *ChildScopeCount = nullptr);
00390 
00391   /// \brief Emit initial Dwarf sections with a label at the start of each one.
00392   void emitSectionLabels();
00393 
00394   /// \brief Compute the size and offset of a DIE given an incoming Offset.
00395   unsigned computeSizeAndOffset(DIE *Die, unsigned Offset);
00396 
00397   /// \brief Compute the size and offset of all the DIEs.
00398   void computeSizeAndOffsets();
00399 
00400   /// \brief Collect info for variables that were optimized out.
00401   void collectDeadVariables();
00402 
00403   void finishVariableDefinitions();
00404 
00405   void finishSubprogramDefinitions();
00406 
00407   /// \brief Finish off debug information after all functions have been
00408   /// processed.
00409   void finalizeModuleInfo();
00410 
00411   /// \brief Emit labels to close any remaining sections that have been left
00412   /// open.
00413   void endSections();
00414 
00415   /// \brief Emit the debug info section.
00416   void emitDebugInfo();
00417 
00418   /// \brief Emit the abbreviation section.
00419   void emitAbbreviations();
00420 
00421   /// \brief Emit the last address of the section and the end of
00422   /// the line matrix.
00423   void emitEndOfLineMatrix(unsigned SectionEnd);
00424 
00425   /// \brief Emit a specified accelerator table.
00426   void emitAccel(DwarfAccelTable &Accel, const MCSection *Section,
00427                  StringRef TableName, StringRef SymName);
00428 
00429   /// \brief Emit visible names into a hashed accelerator table section.
00430   void emitAccelNames();
00431 
00432   /// \brief Emit objective C classes and categories into a hashed
00433   /// accelerator table section.
00434   void emitAccelObjC();
00435 
00436   /// \brief Emit namespace dies into a hashed accelerator table.
00437   void emitAccelNamespaces();
00438 
00439   /// \brief Emit type dies into a hashed accelerator table.
00440   void emitAccelTypes();
00441 
00442   /// \brief Emit visible names into a debug pubnames section.
00443   /// \param GnuStyle determines whether or not we want to emit
00444   /// additional information into the table ala newer gcc for gdb
00445   /// index.
00446   void emitDebugPubNames(bool GnuStyle = false);
00447 
00448   /// \brief Emit visible types into a debug pubtypes section.
00449   /// \param GnuStyle determines whether or not we want to emit
00450   /// additional information into the table ala newer gcc for gdb
00451   /// index.
00452   void emitDebugPubTypes(bool GnuStyle = false);
00453 
00454   void
00455   emitDebugPubSection(bool GnuStyle, const MCSection *PSec, StringRef Name,
00456                       const StringMap<const DIE *> &(DwarfUnit::*Accessor)()
00457                       const);
00458 
00459   /// \brief Emit visible names into a debug str section.
00460   void emitDebugStr();
00461 
00462   /// \brief Emit visible names into a debug loc section.
00463   void emitDebugLoc();
00464 
00465   /// \brief Emit visible names into a debug loc dwo section.
00466   void emitDebugLocDWO();
00467 
00468   /// \brief Emit visible names into a debug aranges section.
00469   void emitDebugARanges();
00470 
00471   /// \brief Emit visible names into a debug ranges section.
00472   void emitDebugRanges();
00473 
00474   /// \brief Emit inline info using custom format.
00475   void emitDebugInlineInfo();
00476 
00477   /// DWARF 5 Experimental Split Dwarf Emitters
00478 
00479   /// \brief Initialize common features of skeleton units.
00480   void initSkeletonUnit(const DwarfUnit &U, DIE &Die,
00481                         std::unique_ptr<DwarfUnit> NewU);
00482 
00483   /// \brief Construct the split debug info compile unit for the debug info
00484   /// section.
00485   DwarfCompileUnit &constructSkeletonCU(const DwarfCompileUnit &CU);
00486 
00487   /// \brief Construct the split debug info compile unit for the debug info
00488   /// section.
00489   DwarfTypeUnit &constructSkeletonTU(DwarfTypeUnit &TU);
00490 
00491   /// \brief Emit the debug info dwo section.
00492   void emitDebugInfoDWO();
00493 
00494   /// \brief Emit the debug abbrev dwo section.
00495   void emitDebugAbbrevDWO();
00496 
00497   /// \brief Emit the debug line dwo section.
00498   void emitDebugLineDWO();
00499 
00500   /// \brief Emit the debug str dwo section.
00501   void emitDebugStrDWO();
00502 
00503   /// Flags to let the linker know we have emitted new style pubnames. Only
00504   /// emit it here if we don't have a skeleton CU for split dwarf.
00505   void addGnuPubAttributes(DwarfUnit &U, DIE &D) const;
00506 
00507   /// \brief Create new DwarfCompileUnit for the given metadata node with tag
00508   /// DW_TAG_compile_unit.
00509   DwarfCompileUnit &constructDwarfCompileUnit(DICompileUnit DIUnit);
00510 
00511   /// \brief Construct imported_module or imported_declaration DIE.
00512   void constructAndAddImportedEntityDIE(DwarfCompileUnit &TheCU,
00513                                         const MDNode *N);
00514 
00515   /// \brief Construct import_module DIE.
00516   std::unique_ptr<DIE>
00517   constructImportedEntityDIE(DwarfCompileUnit &TheCU,
00518                              const DIImportedEntity &Module);
00519 
00520   /// \brief Register a source line with debug info. Returns the unique
00521   /// label that was emitted and which provides correspondence to the
00522   /// source line list.
00523   void recordSourceLine(unsigned Line, unsigned Col, const MDNode *Scope,
00524                         unsigned Flags);
00525 
00526   /// \brief Indentify instructions that are marking the beginning of or
00527   /// ending of a scope.
00528   void identifyScopeMarkers();
00529 
00530   /// \brief If Var is an current function argument that add it in
00531   /// CurrentFnArguments list.
00532   bool addCurrentFnArgument(DbgVariable *Var, LexicalScope *Scope);
00533 
00534   /// \brief Populate LexicalScope entries with variables' info.
00535   void collectVariableInfo(SmallPtrSetImpl<const MDNode *> &ProcessedVars);
00536 
00537   /// \brief Build the location list for all DBG_VALUEs in the
00538   /// function that describe the same variable.
00539   void buildLocationList(SmallVectorImpl<DebugLocEntry> &DebugLoc,
00540                          const DbgValueHistoryMap::InstrRanges &Ranges);
00541 
00542   /// \brief Collect variable information from the side table maintained
00543   /// by MMI.
00544   void collectVariableInfoFromMMITable(SmallPtrSetImpl<const MDNode *> &P);
00545 
00546   /// \brief Ensure that a label will be emitted before MI.
00547   void requestLabelBeforeInsn(const MachineInstr *MI) {
00548     LabelsBeforeInsn.insert(std::make_pair(MI, nullptr));
00549   }
00550 
00551   /// \brief Return Label preceding the instruction.
00552   MCSymbol *getLabelBeforeInsn(const MachineInstr *MI);
00553 
00554   /// \brief Ensure that a label will be emitted after MI.
00555   void requestLabelAfterInsn(const MachineInstr *MI) {
00556     LabelsAfterInsn.insert(std::make_pair(MI, nullptr));
00557   }
00558 
00559   /// \brief Return Label immediately following the instruction.
00560   MCSymbol *getLabelAfterInsn(const MachineInstr *MI);
00561 
00562   void attachRangesOrLowHighPC(DwarfCompileUnit &Unit, DIE &D,
00563                                const SmallVectorImpl<InsnRange> &Ranges);
00564   void attachLowHighPC(DwarfCompileUnit &Unit, DIE &D, const MCSymbol *Begin,
00565                        const MCSymbol *End);
00566 
00567 public:
00568   //===--------------------------------------------------------------------===//
00569   // Main entry points.
00570   //
00571   DwarfDebug(AsmPrinter *A, Module *M);
00572 
00573   ~DwarfDebug() override;
00574 
00575   void insertDIE(const MDNode *TypeMD, DIE *Die) {
00576     MDTypeNodeToDieMap.insert(std::make_pair(TypeMD, Die));
00577   }
00578   DIE *getDIE(const MDNode *TypeMD) {
00579     return MDTypeNodeToDieMap.lookup(TypeMD);
00580   }
00581 
00582   /// \brief Emit all Dwarf sections that should come prior to the
00583   /// content.
00584   void beginModule();
00585 
00586   /// \brief Emit all Dwarf sections that should come after the content.
00587   void endModule() override;
00588 
00589   /// \brief Gather pre-function debug information.
00590   void beginFunction(const MachineFunction *MF) override;
00591 
00592   /// \brief Gather and emit post-function debug information.
00593   void endFunction(const MachineFunction *MF) override;
00594 
00595   /// \brief Process beginning of an instruction.
00596   void beginInstruction(const MachineInstr *MI) override;
00597 
00598   /// \brief Process end of an instruction.
00599   void endInstruction() override;
00600 
00601   /// \brief Add a DIE to the set of types that we're going to pull into
00602   /// type units.
00603   void addDwarfTypeUnitType(DwarfCompileUnit &CU, StringRef Identifier,
00604                             DIE &Die, DICompositeType CTy);
00605 
00606   /// \brief Add a label so that arange data can be generated for it.
00607   void addArangeLabel(SymbolCU SCU) { ArangeLabels.push_back(SCU); }
00608 
00609   /// \brief For symbols that have a size designated (e.g. common symbols),
00610   /// this tracks that size.
00611   void setSymbolSize(const MCSymbol *Sym, uint64_t Size) override {
00612     SymSize[Sym] = Size;
00613   }
00614 
00615   /// \brief Recursively Emits a debug information entry.
00616   void emitDIE(DIE &Die);
00617 
00618   // Experimental DWARF5 features.
00619 
00620   /// \brief Returns whether or not to emit tables that dwarf consumers can
00621   /// use to accelerate lookup.
00622   bool useDwarfAccelTables() const { return HasDwarfAccelTables; }
00623 
00624   /// \brief Returns whether or not to change the current debug info for the
00625   /// split dwarf proposal support.
00626   bool useSplitDwarf() const { return HasSplitDwarf; }
00627 
00628   /// Returns the Dwarf Version.
00629   unsigned getDwarfVersion() const { return DwarfVersion; }
00630 
00631   /// Returns the section symbol for the .debug_loc section.
00632   MCSymbol *getDebugLocSym() const { return DwarfDebugLocSectionSym; }
00633 
00634   /// Returns the section symbol for the .debug_str section.
00635   MCSymbol *getDebugStrSym() const { return DwarfStrSectionSym; }
00636 
00637   /// Returns the previous CU that was being updated
00638   const DwarfCompileUnit *getPrevCU() const { return PrevCU; }
00639   void setPrevCU(const DwarfCompileUnit *PrevCU) { this->PrevCU = PrevCU; }
00640 
00641   /// Returns the entries for the .debug_loc section.
00642   const SmallVectorImpl<DebugLocList> &
00643   getDebugLocEntries() const {
00644     return DotDebugLocEntries;
00645   }
00646 
00647   /// \brief Emit an entry for the debug loc section. This can be used to
00648   /// handle an entry that's going to be emitted into the debug loc section.
00649   void emitDebugLocEntry(ByteStreamer &Streamer, const DebugLocEntry &Entry);
00650   /// \brief emit a single value for the debug loc section.
00651   void emitDebugLocValue(ByteStreamer &Streamer,
00652                          const DebugLocEntry::Value &Value);
00653   /// Emits an optimal (=sorted) sequence of DW_OP_pieces.
00654   void emitLocPieces(ByteStreamer &Streamer,
00655                      const DITypeIdentifierMap &Map,
00656                      ArrayRef<DebugLocEntry::Value> Values);
00657 
00658   /// Emit the location for a debug loc entry, including the size header.
00659   void emitDebugLocEntryLocation(const DebugLocEntry &Entry);
00660 
00661   /// Find the MDNode for the given reference.
00662   template <typename T> T resolve(DIRef<T> Ref) const {
00663     return Ref.resolve(TypeIdentifierMap);
00664   }
00665 
00666   /// \brief Return the TypeIdentifierMap.
00667   const DITypeIdentifierMap &getTypeIdentifierMap() const {
00668     return TypeIdentifierMap;
00669   }
00670 
00671   /// Find the DwarfCompileUnit for the given CU Die.
00672   DwarfCompileUnit *lookupUnit(const DIE *CU) const {
00673     return CUDieMap.lookup(CU);
00674   }
00675   /// isSubprogramContext - Return true if Context is either a subprogram
00676   /// or another context nested inside a subprogram.
00677   bool isSubprogramContext(const MDNode *Context);
00678 
00679   void addSubprogramNames(DISubprogram SP, DIE &Die);
00680 
00681   AddressPool &getAddressPool() { return AddrPool; }
00682 
00683   void addAccelName(StringRef Name, const DIE &Die);
00684 
00685   void addAccelObjC(StringRef Name, const DIE &Die);
00686 
00687   void addAccelNamespace(StringRef Name, const DIE &Die);
00688 
00689   void addAccelType(StringRef Name, const DIE &Die, char Flags);
00690 };
00691 } // End of namespace llvm
00692 
00693 #endif