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