DwarfCompileUnit.h revision 94c7ddb6f52a5200983fed0ce74dc602a7737879
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 associate 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, unsigned Form, 154 const StringRef Str); 155 156 /// addLabel - Add a Dwarf label attribute data and value. 157 /// 158 void addLabel(DIE *Die, unsigned Attribute, unsigned Form, 159 const MCSymbol *Label); 160 161 /// addDelta - Add a label delta attribute data and value. 162 /// 163 void addDelta(DIE *Die, unsigned Attribute, unsigned Form, 164 const MCSymbol *Hi, const MCSymbol *Lo); 165 166 /// addDIEEntry - Add a DIE attribute data and value. 167 /// 168 void addDIEEntry(DIE *Die, unsigned Attribute, unsigned Form, DIE *Entry); 169 170 /// addBlock - Add block data. 171 /// 172 void addBlock(DIE *Die, unsigned Attribute, unsigned Form, DIEBlock *Block); 173 174 /// addSourceLine - Add location information to specified debug information 175 /// entry. 176 void addSourceLine(DIE *Die, DIVariable V); 177 void addSourceLine(DIE *Die, DIGlobalVariable G); 178 void addSourceLine(DIE *Die, DISubprogram SP); 179 void addSourceLine(DIE *Die, DIType Ty); 180 void addSourceLine(DIE *Die, DINameSpace NS); 181 182 /// addAddress - Add an address attribute to a die based on the location 183 /// provided. 184 void addAddress(DIE *Die, unsigned Attribute, 185 const MachineLocation &Location); 186 187 /// addConstantValue - Add constant value entry in variable DIE. 188 bool addConstantValue(DIE *Die, const MachineOperand &MO, DIType Ty); 189 bool addConstantValue(DIE *Die, const ConstantInt *CI, bool Unsigned); 190 191 /// addConstantFPValue - Add constant value entry in variable DIE. 192 bool addConstantFPValue(DIE *Die, const MachineOperand &MO); 193 194 /// addTemplateParams - Add template parameters in buffer. 195 void addTemplateParams(DIE &Buffer, DIArray TParams); 196 197 /// addRegisterOp - Add register operand. 198 void addRegisterOp(DIE *TheDie, unsigned Reg); 199 200 /// addRegisterOffset - Add register offset. 201 void addRegisterOffset(DIE *TheDie, unsigned Reg, int64_t Offset); 202 203 /// addComplexAddress - Start with the address based on the location provided, 204 /// and generate the DWARF information necessary to find the actual variable 205 /// (navigating the extra location information encoded in the type) based on 206 /// the starting location. Add the DWARF information to the die. 207 /// 208 void addComplexAddress(DbgVariable *&DV, DIE *Die, unsigned Attribute, 209 const MachineLocation &Location); 210 211 // FIXME: Should be reformulated in terms of addComplexAddress. 212 /// addBlockByrefAddress - Start with the address based on the location 213 /// provided, and generate the DWARF information necessary to find the 214 /// actual Block variable (navigating the Block struct) based on the 215 /// starting location. Add the DWARF information to the die. Obsolete, 216 /// please use addComplexAddress instead. 217 /// 218 void addBlockByrefAddress(DbgVariable *&DV, DIE *Die, unsigned Attribute, 219 const MachineLocation &Location); 220 221 /// addVariableAddress - Add DW_AT_location attribute for a 222 /// DbgVariable based on provided MachineLocation. 223 void addVariableAddress(DbgVariable *&DV, DIE *Die, MachineLocation Location); 224 225 /// addToContextOwner - Add Die into the list of its context owner's children. 226 void addToContextOwner(DIE *Die, DIDescriptor Context); 227 228 /// addType - Add a new type attribute to the specified entity. 229 void addType(DIE *Entity, DIType Ty); 230 231 /// getOrCreateNameSpace - Create a DIE for DINameSpace. 232 DIE *getOrCreateNameSpace(DINameSpace NS); 233 234 /// getOrCreateSubprogramDIE - Create new DIE using SP. 235 DIE *getOrCreateSubprogramDIE(DISubprogram SP); 236 237 /// getOrCreateTypeDIE - Find existing DIE or create new DIE for the 238 /// given DIType. 239 DIE *getOrCreateTypeDIE(const MDNode *N); 240 241 /// getOrCreateTemplateTypeParameterDIE - Find existing DIE or create new DIE 242 /// for the given DITemplateTypeParameter. 243 DIE *getOrCreateTemplateTypeParameterDIE(DITemplateTypeParameter TP); 244 245 /// getOrCreateTemplateValueParameterDIE - Find existing DIE or create new DIE 246 /// for the given DITemplateValueParameter. 247 DIE *getOrCreateTemplateValueParameterDIE(DITemplateValueParameter TVP); 248 249 /// createDIEEntry - Creates a new DIEEntry to be a proxy for a debug 250 /// information entry. 251 DIEEntry *createDIEEntry(DIE *Entry); 252 253 /// createGlobalVariableDIE - create global variable DIE. 254 void createGlobalVariableDIE(const MDNode *N); 255 256 void addPubTypes(DISubprogram SP); 257 258 /// constructTypeDIE - Construct basic type die from DIBasicType. 259 void constructTypeDIE(DIE &Buffer, 260 DIBasicType BTy); 261 262 /// constructTypeDIE - Construct derived type die from DIDerivedType. 263 void constructTypeDIE(DIE &Buffer, 264 DIDerivedType DTy); 265 266 /// constructTypeDIE - Construct type DIE from DICompositeType. 267 void constructTypeDIE(DIE &Buffer, 268 DICompositeType CTy); 269 270 /// constructSubrangeDIE - Construct subrange DIE from DISubrange. 271 void constructSubrangeDIE(DIE &Buffer, DISubrange SR, DIE *IndexTy); 272 273 /// constructArrayTypeDIE - Construct array type DIE from DICompositeType. 274 void constructArrayTypeDIE(DIE &Buffer, 275 DICompositeType *CTy); 276 277 /// constructEnumTypeDIE - Construct enum type DIE from DIEnumerator. 278 DIE *constructEnumTypeDIE(DIEnumerator ETy); 279 280 /// constructContainingTypeDIEs - Construct DIEs for types that contain 281 /// vtables. 282 void constructContainingTypeDIEs(); 283 284 /// constructVariableDIE - Construct a DIE for the given DbgVariable. 285 DIE *constructVariableDIE(DbgVariable *DV, bool isScopeAbstract); 286 287 /// createMemberDIE - Create new member DIE. 288 DIE *createMemberDIE(DIDerivedType DT); 289 290private: 291 292 // DIEValueAllocator - All DIEValues are allocated through this allocator. 293 BumpPtrAllocator DIEValueAllocator; 294 DIEInteger *DIEIntegerOne; 295}; 296 297} // end llvm namespace 298#endif 299