DwarfCompileUnit.h revision 33aa20f737e9ebb3c29c93508da0c041a6a772c7
1//===-- llvm/CodeGen/DwarfCompileUnit.h - Dwarf Compile Unit ---*- 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 compile unit. 11// 12//===----------------------------------------------------------------------===// 13 14#ifndef CODEGEN_ASMPRINTER_DWARFCOMPILEUNIT_H 15#define CODEGEN_ASMPRINTER_DWARFCOMPILEUNIT_H 16 17#include "DIE.h" 18#include "llvm/Analysis/DebugInfo.h" 19#include "llvm/ADT/DenseMap.h" 20#include "llvm/ADT/StringMap.h" 21#include "llvm/ADT/OwningPtr.h" 22 23namespace llvm { 24 25class DwarfDebug; 26class MachineLocation; 27class MachineOperand; 28class ConstantInt; 29class DbgVariable; 30 31//===----------------------------------------------------------------------===// 32/// CompileUnit - This dwarf writer support class manages information associated 33/// with a source file. 34class CompileUnit { 35 /// ID - File identifier for source. 36 /// 37 unsigned ID; 38 39 /// Die - Compile unit debug information entry. 40 /// 41 const OwningPtr<DIE> CUDie; 42 43 /// Asm - Target of Dwarf emission. 44 AsmPrinter *Asm; 45 46 DwarfDebug *DD; 47 48 /// IndexTyDie - An anonymous type for index type. Owned by CUDie. 49 DIE *IndexTyDie; 50 51 /// MDNodeToDieMap - Tracks the mapping of unit level debug informaton 52 /// variables to debug information entries. 53 DenseMap<const MDNode *, DIE *> MDNodeToDieMap; 54 55 /// MDNodeToDIEEntryMap - Tracks the mapping of unit level debug informaton 56 /// descriptors to debug information entries using a DIEEntry proxy. 57 DenseMap<const MDNode *, DIEEntry *> MDNodeToDIEEntryMap; 58 59 /// Globals - A map of globally visible named entities for this unit. 60 /// 61 StringMap<DIE*> Globals; 62 63 /// GlobalTypes - A map of globally visible types for this unit. 64 /// 65 StringMap<DIE*> GlobalTypes; 66 67 /// DIEBlocks - A list of all the DIEBlocks in use. 68 std::vector<DIEBlock *> DIEBlocks; 69 70 /// ContainingTypeMap - This map is used to keep track of subprogram DIEs that 71 /// need DW_AT_containing_type attribute. This attribute points to a DIE that 72 /// corresponds to the MDNode mapped with the subprogram DIE. 73 DenseMap<DIE *, const MDNode *> ContainingTypeMap; 74 75public: 76 CompileUnit(unsigned I, DIE *D, AsmPrinter *A, DwarfDebug *DW); 77 ~CompileUnit(); 78 79 // Accessors. 80 unsigned getID() const { return ID; } 81 DIE* getCUDie() const { return CUDie.get(); } 82 const StringMap<DIE*> &getGlobals() const { return Globals; } 83 const StringMap<DIE*> &getGlobalTypes() const { return GlobalTypes; } 84 85 /// hasContent - Return true if this compile unit has something to write out. 86 /// 87 bool hasContent() const { return !CUDie->getChildren().empty(); } 88 89 /// addGlobal - Add a new global entity to the compile unit. 90 /// 91 void addGlobal(StringRef Name, DIE *Die) { Globals[Name] = Die; } 92 93 /// addGlobalType - Add a new global type to the compile unit. 94 /// 95 void addGlobalType(DIType Ty); 96 97 /// getDIE - Returns the debug information entry map slot for the 98 /// specified debug variable. 99 DIE *getDIE(const MDNode *N) { return MDNodeToDieMap.lookup(N); } 100 101 DIEBlock *getDIEBlock() { 102 return new (DIEValueAllocator) DIEBlock(); 103 } 104 105 /// insertDIE - Insert DIE into the map. 106 void insertDIE(const MDNode *N, DIE *D) { 107 MDNodeToDieMap.insert(std::make_pair(N, D)); 108 } 109 110 /// getDIEEntry - Returns the debug information entry for the specified 111 /// debug variable. 112 DIEEntry *getDIEEntry(const MDNode *N) { 113 DenseMap<const MDNode *, DIEEntry *>::iterator I = 114 MDNodeToDIEEntryMap.find(N); 115 if (I == MDNodeToDIEEntryMap.end()) 116 return NULL; 117 return I->second; 118 } 119 120 /// insertDIEEntry - Insert debug information entry into the map. 121 void insertDIEEntry(const MDNode *N, DIEEntry *E) { 122 MDNodeToDIEEntryMap.insert(std::make_pair(N, E)); 123 } 124 125 /// addDie - Adds or interns the DIE to the compile unit. 126 /// 127 void addDie(DIE *Buffer) { 128 this->CUDie->addChild(Buffer); 129 } 130 131 // getIndexTyDie - Get an anonymous type for index type. 132 DIE *getIndexTyDie() { 133 return IndexTyDie; 134 } 135 136 // setIndexTyDie - Set D as anonymous type for index which can be reused 137 // later. 138 void setIndexTyDie(DIE *D) { 139 IndexTyDie = D; 140 } 141public: 142 143 /// addUInt - Add an unsigned integer attribute data and value. 144 /// 145 void addUInt(DIE *Die, unsigned Attribute, unsigned Form, uint64_t Integer); 146 147 /// addSInt - Add an signed integer attribute data and value. 148 /// 149 void addSInt(DIE *Die, unsigned Attribute, unsigned Form, int64_t Integer); 150 151 /// addString - Add a string attribute data and value. 152 /// 153 void addString(DIE *Die, unsigned Attribute, const StringRef Str); 154 155 /// addLabel - Add a Dwarf label attribute data and value. 156 /// 157 void addLabel(DIE *Die, unsigned Attribute, unsigned Form, 158 const MCSymbol *Label); 159 160 /// addDelta - Add a label delta attribute data and value. 161 /// 162 void addDelta(DIE *Die, unsigned Attribute, unsigned Form, 163 const MCSymbol *Hi, const MCSymbol *Lo); 164 165 /// addDIEEntry - Add a DIE attribute data and value. 166 /// 167 void addDIEEntry(DIE *Die, unsigned Attribute, unsigned Form, DIE *Entry); 168 169 /// addBlock - Add block data. 170 /// 171 void addBlock(DIE *Die, unsigned Attribute, unsigned Form, DIEBlock *Block); 172 173 /// addSourceLine - Add location information to specified debug information 174 /// entry. 175 void addSourceLine(DIE *Die, DIVariable V); 176 void addSourceLine(DIE *Die, DIGlobalVariable G); 177 void addSourceLine(DIE *Die, DISubprogram SP); 178 void addSourceLine(DIE *Die, DIType Ty); 179 void addSourceLine(DIE *Die, DINameSpace NS); 180 181 /// addAddress - Add an address attribute to a die based on the location 182 /// provided. 183 void addAddress(DIE *Die, unsigned Attribute, 184 const MachineLocation &Location); 185 186 /// addConstantValue - Add constant value entry in variable DIE. 187 bool addConstantValue(DIE *Die, const MachineOperand &MO, DIType Ty); 188 bool addConstantValue(DIE *Die, const ConstantInt *CI, bool Unsigned); 189 190 /// addConstantFPValue - Add constant value entry in variable DIE. 191 bool addConstantFPValue(DIE *Die, const MachineOperand &MO); 192 193 /// addTemplateParams - Add template parameters in buffer. 194 void addTemplateParams(DIE &Buffer, DIArray TParams); 195 196 /// addRegisterOp - Add register operand. 197 void addRegisterOp(DIE *TheDie, unsigned Reg); 198 199 /// addRegisterOffset - Add register offset. 200 void addRegisterOffset(DIE *TheDie, unsigned Reg, int64_t Offset); 201 202 /// addComplexAddress - Start with the address based on the location provided, 203 /// and generate the DWARF information necessary to find the actual variable 204 /// (navigating the extra location information encoded in the type) based on 205 /// the starting location. Add the DWARF information to the die. 206 /// 207 void addComplexAddress(DbgVariable *&DV, DIE *Die, unsigned Attribute, 208 const MachineLocation &Location); 209 210 // FIXME: Should be reformulated in terms of addComplexAddress. 211 /// addBlockByrefAddress - Start with the address based on the location 212 /// provided, and generate the DWARF information necessary to find the 213 /// actual Block variable (navigating the Block struct) based on the 214 /// starting location. Add the DWARF information to the die. Obsolete, 215 /// please use addComplexAddress instead. 216 /// 217 void addBlockByrefAddress(DbgVariable *&DV, DIE *Die, unsigned Attribute, 218 const MachineLocation &Location); 219 220 /// addVariableAddress - Add DW_AT_location attribute for a 221 /// DbgVariable based on provided MachineLocation. 222 void addVariableAddress(DbgVariable *&DV, DIE *Die, MachineLocation Location); 223 224 /// addToContextOwner - Add Die into the list of its context owner's children. 225 void addToContextOwner(DIE *Die, DIDescriptor Context); 226 227 /// addType - Add a new type attribute to the specified entity. 228 void addType(DIE *Entity, DIType Ty); 229 230 /// getOrCreateNameSpace - Create a DIE for DINameSpace. 231 DIE *getOrCreateNameSpace(DINameSpace NS); 232 233 /// getOrCreateSubprogramDIE - Create new DIE using SP. 234 DIE *getOrCreateSubprogramDIE(DISubprogram SP); 235 236 /// getOrCreateTypeDIE - Find existing DIE or create new DIE for the 237 /// given DIType. 238 DIE *getOrCreateTypeDIE(const MDNode *N); 239 240 /// getOrCreateTemplateTypeParameterDIE - Find existing DIE or create new DIE 241 /// for the given DITemplateTypeParameter. 242 DIE *getOrCreateTemplateTypeParameterDIE(DITemplateTypeParameter TP); 243 244 /// getOrCreateTemplateValueParameterDIE - Find existing DIE or create new DIE 245 /// for the given DITemplateValueParameter. 246 DIE *getOrCreateTemplateValueParameterDIE(DITemplateValueParameter TVP); 247 248 /// createDIEEntry - Creates a new DIEEntry to be a proxy for a debug 249 /// information entry. 250 DIEEntry *createDIEEntry(DIE *Entry); 251 252 /// createGlobalVariableDIE - create global variable DIE. 253 void createGlobalVariableDIE(const MDNode *N); 254 255 void addPubTypes(DISubprogram SP); 256 257 /// constructTypeDIE - Construct basic type die from DIBasicType. 258 void constructTypeDIE(DIE &Buffer, 259 DIBasicType BTy); 260 261 /// constructTypeDIE - Construct derived type die from DIDerivedType. 262 void constructTypeDIE(DIE &Buffer, 263 DIDerivedType DTy); 264 265 /// constructTypeDIE - Construct type DIE from DICompositeType. 266 void constructTypeDIE(DIE &Buffer, 267 DICompositeType CTy); 268 269 /// constructSubrangeDIE - Construct subrange DIE from DISubrange. 270 void constructSubrangeDIE(DIE &Buffer, DISubrange SR, DIE *IndexTy); 271 272 /// constructArrayTypeDIE - Construct array type DIE from DICompositeType. 273 void constructArrayTypeDIE(DIE &Buffer, 274 DICompositeType *CTy); 275 276 /// constructEnumTypeDIE - Construct enum type DIE from DIEnumerator. 277 DIE *constructEnumTypeDIE(DIEnumerator ETy); 278 279 /// constructContainingTypeDIEs - Construct DIEs for types that contain 280 /// vtables. 281 void constructContainingTypeDIEs(); 282 283 /// constructVariableDIE - Construct a DIE for the given DbgVariable. 284 DIE *constructVariableDIE(DbgVariable *DV, bool isScopeAbstract); 285 286 /// createMemberDIE - Create new member DIE. 287 DIE *createMemberDIE(DIDerivedType DT); 288 289private: 290 291 // DIEValueAllocator - All DIEValues are allocated through this allocator. 292 BumpPtrAllocator DIEValueAllocator; 293 DIEInteger *DIEIntegerOne; 294}; 295 296} // end llvm namespace 297#endif 298