DwarfCompileUnit.h revision 09ac3d841367d5d56328eade506c951e0dc3a72d
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 /// AccelNames - A map of names for the name accelerator table. 68 /// 69 StringMap<DIE*> AccelNames; 70 StringMap<std::vector<DIE*> > AccelObjC; 71 StringMap<DIE*> AccelNamespace; 72 StringMap<DIE*> AccelTypes; 73 74 /// DIEBlocks - A list of all the DIEBlocks in use. 75 std::vector<DIEBlock *> DIEBlocks; 76 77 /// ContainingTypeMap - This map is used to keep track of subprogram DIEs that 78 /// need DW_AT_containing_type attribute. This attribute points to a DIE that 79 /// corresponds to the MDNode mapped with the subprogram DIE. 80 DenseMap<DIE *, const MDNode *> ContainingTypeMap; 81 82public: 83 CompileUnit(unsigned I, DIE *D, AsmPrinter *A, DwarfDebug *DW); 84 ~CompileUnit(); 85 86 // Accessors. 87 unsigned getID() const { return ID; } 88 DIE* getCUDie() const { return CUDie.get(); } 89 const StringMap<DIE*> &getGlobals() const { return Globals; } 90 const StringMap<DIE*> &getGlobalTypes() const { return GlobalTypes; } 91 92 const StringMap<DIE*> &getAccelNames() const { return AccelNames; } 93 const StringMap<std::vector<DIE*> > &getAccelObjC() const { 94 return AccelObjC; 95 } 96 const StringMap<DIE*> &getAccelNamespace() const { return AccelNamespace; } 97 const StringMap<DIE*> &getAccelTypes() const { return AccelTypes; } 98 99 /// hasContent - Return true if this compile unit has something to write out. 100 /// 101 bool hasContent() const { return !CUDie->getChildren().empty(); } 102 103 /// addGlobal - Add a new global entity to the compile unit. 104 /// 105 void addGlobal(StringRef Name, DIE *Die) { Globals[Name] = Die; } 106 107 /// addGlobalType - Add a new global type to the compile unit. 108 /// 109 void addGlobalType(DIType Ty); 110 111 112 /// addAccelName - Add a new name to the name accelerator table. 113 void addAccelName(StringRef Name, DIE *Die) { AccelNames[Name] = Die; } 114 void addAccelObjC(StringRef Name, DIE *Die) { 115 std::vector<DIE*> &DIEs = AccelObjC[Name]; 116 DIEs.push_back(Die); 117 } 118 void addAccelNamespace(StringRef Name, DIE *Die) { 119 AccelNamespace[Name] = Die; 120 } 121 void addAccelType(StringRef Name, DIE *Die) { 122 AccelTypes[Name] = Die; 123 } 124 125 /// getDIE - Returns the debug information entry map slot for the 126 /// specified debug variable. 127 DIE *getDIE(const MDNode *N) { return MDNodeToDieMap.lookup(N); } 128 129 DIEBlock *getDIEBlock() { 130 return new (DIEValueAllocator) DIEBlock(); 131 } 132 133 /// insertDIE - Insert DIE into the map. 134 void insertDIE(const MDNode *N, DIE *D) { 135 MDNodeToDieMap.insert(std::make_pair(N, D)); 136 } 137 138 /// getDIEEntry - Returns the debug information entry for the specified 139 /// debug variable. 140 DIEEntry *getDIEEntry(const MDNode *N) { 141 DenseMap<const MDNode *, DIEEntry *>::iterator I = 142 MDNodeToDIEEntryMap.find(N); 143 if (I == MDNodeToDIEEntryMap.end()) 144 return NULL; 145 return I->second; 146 } 147 148 /// insertDIEEntry - Insert debug information entry into the map. 149 void insertDIEEntry(const MDNode *N, DIEEntry *E) { 150 MDNodeToDIEEntryMap.insert(std::make_pair(N, E)); 151 } 152 153 /// addDie - Adds or interns the DIE to the compile unit. 154 /// 155 void addDie(DIE *Buffer) { 156 this->CUDie->addChild(Buffer); 157 } 158 159 // getIndexTyDie - Get an anonymous type for index type. 160 DIE *getIndexTyDie() { 161 return IndexTyDie; 162 } 163 164 // setIndexTyDie - Set D as anonymous type for index which can be reused 165 // later. 166 void setIndexTyDie(DIE *D) { 167 IndexTyDie = D; 168 } 169public: 170 171 /// addUInt - Add an unsigned integer attribute data and value. 172 /// 173 void addUInt(DIE *Die, unsigned Attribute, unsigned Form, uint64_t Integer); 174 175 /// addSInt - Add an signed integer attribute data and value. 176 /// 177 void addSInt(DIE *Die, unsigned Attribute, unsigned Form, int64_t Integer); 178 179 /// addString - Add a string attribute data and value. 180 /// 181 void addString(DIE *Die, unsigned Attribute, const StringRef Str); 182 183 /// addLabel - Add a Dwarf label attribute data and value. 184 /// 185 void addLabel(DIE *Die, unsigned Attribute, unsigned Form, 186 const MCSymbol *Label); 187 188 /// addDelta - Add a label delta attribute data and value. 189 /// 190 void addDelta(DIE *Die, unsigned Attribute, unsigned Form, 191 const MCSymbol *Hi, const MCSymbol *Lo); 192 193 /// addDIEEntry - Add a DIE attribute data and value. 194 /// 195 void addDIEEntry(DIE *Die, unsigned Attribute, unsigned Form, DIE *Entry); 196 197 /// addBlock - Add block data. 198 /// 199 void addBlock(DIE *Die, unsigned Attribute, unsigned Form, DIEBlock *Block); 200 201 /// addSourceLine - Add location information to specified debug information 202 /// entry. 203 void addSourceLine(DIE *Die, DIVariable V); 204 void addSourceLine(DIE *Die, DIGlobalVariable G); 205 void addSourceLine(DIE *Die, DISubprogram SP); 206 void addSourceLine(DIE *Die, DIType Ty); 207 void addSourceLine(DIE *Die, DINameSpace NS); 208 209 /// addAddress - Add an address attribute to a die based on the location 210 /// provided. 211 void addAddress(DIE *Die, unsigned Attribute, 212 const MachineLocation &Location); 213 214 /// addConstantValue - Add constant value entry in variable DIE. 215 bool addConstantValue(DIE *Die, const MachineOperand &MO, DIType Ty); 216 bool addConstantValue(DIE *Die, const ConstantInt *CI, bool Unsigned); 217 218 /// addConstantFPValue - Add constant value entry in variable DIE. 219 bool addConstantFPValue(DIE *Die, const MachineOperand &MO); 220 221 /// addTemplateParams - Add template parameters in buffer. 222 void addTemplateParams(DIE &Buffer, DIArray TParams); 223 224 /// addRegisterOp - Add register operand. 225 void addRegisterOp(DIE *TheDie, unsigned Reg); 226 227 /// addRegisterOffset - Add register offset. 228 void addRegisterOffset(DIE *TheDie, unsigned Reg, int64_t Offset); 229 230 /// addComplexAddress - Start with the address based on the location provided, 231 /// and generate the DWARF information necessary to find the actual variable 232 /// (navigating the extra location information encoded in the type) based on 233 /// the starting location. Add the DWARF information to the die. 234 /// 235 void addComplexAddress(DbgVariable *&DV, DIE *Die, unsigned Attribute, 236 const MachineLocation &Location); 237 238 // FIXME: Should be reformulated in terms of addComplexAddress. 239 /// addBlockByrefAddress - Start with the address based on the location 240 /// provided, and generate the DWARF information necessary to find the 241 /// actual Block variable (navigating the Block struct) based on the 242 /// starting location. Add the DWARF information to the die. Obsolete, 243 /// please use addComplexAddress instead. 244 /// 245 void addBlockByrefAddress(DbgVariable *&DV, DIE *Die, unsigned Attribute, 246 const MachineLocation &Location); 247 248 /// addVariableAddress - Add DW_AT_location attribute for a 249 /// DbgVariable based on provided MachineLocation. 250 void addVariableAddress(DbgVariable *&DV, DIE *Die, MachineLocation Location); 251 252 /// addToContextOwner - Add Die into the list of its context owner's children. 253 void addToContextOwner(DIE *Die, DIDescriptor Context); 254 255 /// addType - Add a new type attribute to the specified entity. 256 void addType(DIE *Entity, DIType Ty); 257 258 /// getOrCreateNameSpace - Create a DIE for DINameSpace. 259 DIE *getOrCreateNameSpace(DINameSpace NS); 260 261 /// getOrCreateSubprogramDIE - Create new DIE using SP. 262 DIE *getOrCreateSubprogramDIE(DISubprogram SP); 263 264 /// getOrCreateTypeDIE - Find existing DIE or create new DIE for the 265 /// given DIType. 266 DIE *getOrCreateTypeDIE(const MDNode *N); 267 268 /// getOrCreateTemplateTypeParameterDIE - Find existing DIE or create new DIE 269 /// for the given DITemplateTypeParameter. 270 DIE *getOrCreateTemplateTypeParameterDIE(DITemplateTypeParameter TP); 271 272 /// getOrCreateTemplateValueParameterDIE - Find existing DIE or create new DIE 273 /// for the given DITemplateValueParameter. 274 DIE *getOrCreateTemplateValueParameterDIE(DITemplateValueParameter TVP); 275 276 /// createDIEEntry - Creates a new DIEEntry to be a proxy for a debug 277 /// information entry. 278 DIEEntry *createDIEEntry(DIE *Entry); 279 280 /// createGlobalVariableDIE - create global variable DIE. 281 void createGlobalVariableDIE(const MDNode *N); 282 283 void addPubTypes(DISubprogram SP); 284 285 /// constructTypeDIE - Construct basic type die from DIBasicType. 286 void constructTypeDIE(DIE &Buffer, 287 DIBasicType BTy); 288 289 /// constructTypeDIE - Construct derived type die from DIDerivedType. 290 void constructTypeDIE(DIE &Buffer, 291 DIDerivedType DTy); 292 293 /// constructTypeDIE - Construct type DIE from DICompositeType. 294 void constructTypeDIE(DIE &Buffer, 295 DICompositeType CTy); 296 297 /// constructSubrangeDIE - Construct subrange DIE from DISubrange. 298 void constructSubrangeDIE(DIE &Buffer, DISubrange SR, DIE *IndexTy); 299 300 /// constructArrayTypeDIE - Construct array type DIE from DICompositeType. 301 void constructArrayTypeDIE(DIE &Buffer, 302 DICompositeType *CTy); 303 304 /// constructEnumTypeDIE - Construct enum type DIE from DIEnumerator. 305 DIE *constructEnumTypeDIE(DIEnumerator ETy); 306 307 /// constructContainingTypeDIEs - Construct DIEs for types that contain 308 /// vtables. 309 void constructContainingTypeDIEs(); 310 311 /// constructVariableDIE - Construct a DIE for the given DbgVariable. 312 DIE *constructVariableDIE(DbgVariable *DV, bool isScopeAbstract); 313 314 /// createMemberDIE - Create new member DIE. 315 DIE *createMemberDIE(DIDerivedType DT); 316 317private: 318 319 // DIEValueAllocator - All DIEValues are allocated through this allocator. 320 BumpPtrAllocator DIEValueAllocator; 321 DIEInteger *DIEIntegerOne; 322}; 323 324} // end llvm namespace 325#endif 326