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/CodeGen/DIE.h" 20 #include "llvm/IR/Metadata.h" 21 #include "llvm/Support/Allocator.h" 22 #include <memory> 23 24 namespace llvm { 25 class AsmPrinter; 26 class DbgVariable; 27 class DwarfCompileUnit; 28 class DwarfUnit; 29 class DIEAbbrev; 30 class MCSymbol; 31 class DIE; 32 class LexicalScope; 33 class StringRef; 34 class DwarfDebug; 35 class MCSection; 36 class MDNode; 37 class DwarfFile { 38 // Target of Dwarf emission, used for sizing of abbreviations. 39 AsmPrinter *Asm; 40 41 BumpPtrAllocator AbbrevAllocator; 42 43 // Used to uniquely define abbreviations. 44 DIEAbbrevSet Abbrevs; 45 46 // A pointer to all units in the section. 47 SmallVector<std::unique_ptr<DwarfCompileUnit>, 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 *> DITypeNodeToDieMap; 61 62 public: 63 DwarfFile(AsmPrinter *AP, StringRef Pref, BumpPtrAllocator &DA); 64 65 const SmallVectorImpl<std::unique_ptr<DwarfCompileUnit>> &getUnits() { 66 return CUs; 67 } 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 Compute the size and offset of all the DIEs in the given unit. 76 /// \returns The size of the root DIE. 77 unsigned computeSizeAndOffsetsForUnit(DwarfUnit *TheU); 78 79 /// \brief Add a unit to the list of CUs. 80 void addUnit(std::unique_ptr<DwarfCompileUnit> U); 81 82 /// \brief Emit all of the units to the section listed with the given 83 /// abbreviation section. 84 void emitUnits(bool UseOffsets); 85 86 /// \brief Emit the given unit to its section. 87 void emitUnit(DwarfUnit *U, bool UseOffsets); 88 89 /// \brief Emit a set of abbreviations to the specific section. 90 void emitAbbrevs(MCSection *); 91 92 /// \brief Emit all of the strings to the section given. 93 void emitStrings(MCSection *StrSection, MCSection *OffsetSection = nullptr); 94 95 /// \brief Returns the string pool. 96 DwarfStringPool &getStringPool() { return StrPool; } 97 98 /// \returns false if the variable was merged with a previous one. 99 bool addScopeVariable(LexicalScope *LS, DbgVariable *Var); 100 101 DenseMap<LexicalScope *, SmallVector<DbgVariable *, 8>> &getScopeVariables() { 102 return ScopeVariables; 103 } 104 105 DenseMap<const MDNode *, DIE *> &getAbstractSPDies() { 106 return AbstractSPDies; 107 } 108 109 void insertDIE(const MDNode *TypeMD, DIE *Die) { 110 DITypeNodeToDieMap.insert(std::make_pair(TypeMD, Die)); 111 } 112 DIE *getDIE(const MDNode *TypeMD) { 113 return DITypeNodeToDieMap.lookup(TypeMD); 114 } 115 }; 116 } 117 #endif 118