1 //===-- llvm/CodeGen/DwarfFile.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 #ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DWARFFILE_H 11 #define LLVM_LIB_CODEGEN_ASMPRINTER_DWARFFILE_H 12 13 #include "AddressPool.h" 14 #include "DwarfStringPool.h" 15 #include "llvm/ADT/DenseMap.h" 16 #include "llvm/ADT/FoldingSet.h" 17 #include "llvm/ADT/SmallVector.h" 18 #include "llvm/ADT/StringMap.h" 19 #include "llvm/Support/Allocator.h" 20 #include <memory> 21 #include <string> 22 #include <vector> 23 24 namespace llvm { 25 class AsmPrinter; 26 class DbgVariable; 27 class DwarfUnit; 28 class DIEAbbrev; 29 class MCSymbol; 30 class DIE; 31 class DISubprogram; 32 class LexicalScope; 33 class StringRef; 34 class DwarfDebug; 35 class MCSection; 36 class DwarfFile { 37 // Target of Dwarf emission, used for sizing of abbreviations. 38 AsmPrinter *Asm; 39 40 // Used to uniquely define abbreviations. 41 FoldingSet<DIEAbbrev> AbbreviationsSet; 42 43 // A list of all the unique abbreviations in use. 44 std::vector<DIEAbbrev *> Abbreviations; 45 46 // A pointer to all units in the section. 47 SmallVector<std::unique_ptr<DwarfUnit>, 1> CUs; 48 49 DwarfStringPool StrPool; 50 51 // Collection of dbg variables of a scope. 52 DenseMap<LexicalScope *, SmallVector<DbgVariable *, 8>> ScopeVariables; 53 54 // Collection of abstract subprogram DIEs. 55 DenseMap<const MDNode *, DIE *> AbstractSPDies; 56 57 /// Maps MDNodes for type system with the corresponding DIEs. These DIEs can 58 /// be shared across CUs, that is why we keep the map here instead 59 /// of in DwarfCompileUnit. 60 DenseMap<const MDNode *, DIE *> MDTypeNodeToDieMap; 61 62 public: 63 DwarfFile(AsmPrinter *AP, StringRef Pref, BumpPtrAllocator &DA); 64 65 ~DwarfFile(); 66 getUnits()67 const SmallVectorImpl<std::unique_ptr<DwarfUnit>> &getUnits() { return CUs; } 68 69 /// \brief Compute the size and offset of a DIE given an incoming Offset. 70 unsigned computeSizeAndOffset(DIE &Die, unsigned Offset); 71 72 /// \brief Compute the size and offset of all the DIEs. 73 void computeSizeAndOffsets(); 74 75 /// \brief Define a unique number for the abbreviation. 76 void assignAbbrevNumber(DIEAbbrev &Abbrev); 77 78 /// \brief Add a unit to the list of CUs. 79 void addUnit(std::unique_ptr<DwarfUnit> U); 80 81 /// \brief Emit all of the units to the section listed with the given 82 /// abbreviation section. 83 void emitUnits(bool UseOffsets); 84 85 /// \brief Emit a set of abbreviations to the specific section. 86 void emitAbbrevs(const MCSection *); 87 88 /// \brief Emit all of the strings to the section given. 89 void emitStrings(const MCSection *StrSection, 90 const MCSection *OffsetSection = nullptr); 91 92 /// \brief Returns the string pool. getStringPool()93 DwarfStringPool &getStringPool() { return StrPool; } 94 95 /// \returns false if the variable was merged with a previous one. 96 bool addScopeVariable(LexicalScope *LS, DbgVariable *Var); 97 getScopeVariables()98 DenseMap<LexicalScope *, SmallVector<DbgVariable *, 8>> &getScopeVariables() { 99 return ScopeVariables; 100 } 101 getAbstractSPDies()102 DenseMap<const MDNode *, DIE *> &getAbstractSPDies() { 103 return AbstractSPDies; 104 } 105 insertDIE(const MDNode * TypeMD,DIE * Die)106 void insertDIE(const MDNode *TypeMD, DIE *Die) { 107 MDTypeNodeToDieMap.insert(std::make_pair(TypeMD, Die)); 108 } getDIE(const MDNode * TypeMD)109 DIE *getDIE(const MDNode *TypeMD) { 110 return MDTypeNodeToDieMap.lookup(TypeMD); 111 } 112 }; 113 } 114 #endif 115