DIBuilder.h revision fe58f95f3604b394916bee7bd289e1f0e0488ec5
1f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)//===--- llvm/Analysis/DIBuilder.h - Debug Information Builder --*- C++ -*-===// 2f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// 3f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// The LLVM Compiler Infrastructure 4f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// 5f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// This file is distributed under the University of Illinois Open Source 6f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// License. See LICENSE.TXT for details. 7f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// 8f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)//===----------------------------------------------------------------------===// 9f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// 10f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// This file defines a DIBuilder that is useful for creating debugging 11a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// information entries in LLVM IR form. 12f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// 13f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)//===----------------------------------------------------------------------===// 14f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 15f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#ifndef LLVM_ANALYSIS_DIBUILDER_H 16f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#define LLVM_ANALYSIS_DIBUILDER_H 17f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 18f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "llvm/Support/DataTypes.h" 19f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "llvm/ADT/StringRef.h" 20f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 21f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)namespace llvm { 22f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) class BasicBlock; 23f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) class Instruction; 24f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) class Function; 25f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) class Module; 26f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) class Value; 27f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) class LLVMContext; 28f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) class MDNode; 29f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) class StringRef; 30f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) class DIDescriptor; 31f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) class DIFile; 32f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) class DIEnumerator; 33f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) class DIType; 34f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) class DIArray; 35f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) class DIGlobalVariable; 36f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) class DINameSpace; 37f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) class DIVariable; 38f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 39f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) class DIBuilder { 40f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) private: 41f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) Module &M; 42 LLVMContext & VMContext; 43 MDNode *TheCU; 44 45 Function *DeclareFn; // llvm.dbg.declare 46 Function *ValueFn; // llvm.dbg.value 47 48 DIBuilder(const DIBuilder &); // DO NOT IMPLEMENT 49 void operator=(const DIBuilder &); // DO NOT IMPLEMENT 50 51 public: 52 explicit DIBuilder(Module &M); 53 const MDNode *getCU() { return TheCU; } 54 55 /// CreateCompileUnit - A CompileUnit provides an anchor for all debugging 56 /// information generated during this instance of compilation. 57 /// @param Lang Source programming language, eg. dwarf::DW_LANG_C99 58 /// @param File File name 59 /// @param Dir Directory 60 /// @param Producer String identify producer of debugging information. 61 /// Usuall this is a compiler version string. 62 /// @param isOptimized A boolean flag which indicates whether optimization 63 /// is ON or not. 64 /// @param Flags This string lists command line options. This string is 65 /// directly embedded in debug info output which may be used 66 /// by a tool analyzing generated debugging information. 67 /// @param RV This indicates runtime version for languages like 68 /// Objective-C. 69 void CreateCompileUnit(unsigned Lang, StringRef File, StringRef Dir, 70 StringRef Producer, 71 bool isOptimized, StringRef Flags, unsigned RV); 72 73 /// CreateFile - Create a file descriptor to hold debugging information 74 /// for a file. 75 DIFile CreateFile(StringRef Filename, StringRef Directory); 76 77 /// CreateEnumerator - Create a single enumerator value. 78 DIEnumerator CreateEnumerator(StringRef Name, uint64_t Val); 79 80 /// CreateBasicType - Create debugging information entry for a basic 81 /// type. 82 /// @param Name Type name. 83 /// @param SizeInBits Size of the type. 84 /// @param AlignInBits Type alignment. 85 /// @param Encoding DWARF encoding code, e.g. dwarf::DW_ATE_float. 86 DIType CreateBasicType(StringRef Name, uint64_t SizeInBits, 87 uint64_t AlignInBits, unsigned Encoding); 88 89 /// CreateQualifiedType - Create debugging information entry for a qualified 90 /// type, e.g. 'const int'. 91 /// @param Tag Tag identifing type, e.g. dwarf::TAG_volatile_type 92 /// @param FromTy Base Type. 93 DIType CreateQualifiedType(unsigned Tag, DIType FromTy); 94 95 /// CreatePointerType - Create debugging information entry for a pointer. 96 /// @param PointeeTy Type pointed by this pointer. 97 /// @param SizeInBits Size. 98 /// @param AlignInBits Alignment. (optional) 99 /// @param Name Pointer type name. (optional) 100 DIType CreatePointerType(DIType PointeeTy, uint64_t SizeInBits, 101 uint64_t AlignInBits = 0, 102 StringRef Name = StringRef()); 103 104 /// CreateReferenceType - Create debugging information entry for a c++ 105 /// style reference. 106 DIType CreateReferenceType(DIType RTy); 107 108 /// CreateTypedef - Create debugging information entry for a typedef. 109 /// @param Ty Original type. 110 /// @param Name Typedef name. 111 /// @param File File where this type is defined. 112 /// @param LineNo Line number. 113 DIType CreateTypedef(DIType Ty, StringRef Name, DIFile File, 114 unsigned LineNo); 115 116 /// CreateFriend - Create debugging information entry for a 'friend'. 117 DIType CreateFriend(DIType Ty, DIType FriendTy); 118 119 /// CreateInheritance - Create debugging information entry to establish 120 /// inheritance relationship between two types. 121 /// @param Ty Original type. 122 /// @param BaseTy Base type. Ty is inherits from base. 123 /// @param BaseOffset Base offset. 124 /// @param Flags Flags to describe inheritance attribute, 125 /// e.g. private 126 DIType CreateInheritance(DIType Ty, DIType BaseTy, uint64_t BaseOffset, 127 unsigned Flags); 128 129 /// CreateMemberType - Create debugging information entry for a member. 130 /// @param Name Member name. 131 /// @param File File where this member is defined. 132 /// @param LineNo Line number. 133 /// @param SizeInBits Member size. 134 /// @param AlignInBits Member alignment. 135 /// @param OffsetInBits Member offset. 136 /// @param Flags Flags to encode member attribute, e.g. private 137 /// @param Ty Parent type. 138 DIType CreateMemberType(StringRef Name, DIFile File, 139 unsigned LineNo, uint64_t SizeInBits, 140 uint64_t AlignInBits, uint64_t OffsetInBits, 141 unsigned Flags, DIType Ty); 142 143 /// CreateStructType - Create debugging information entry for a struct. 144 DIType CreateStructType(DIDescriptor Context, StringRef Name, DIFile F, 145 unsigned LineNumber, uint64_t SizeInBits, 146 uint64_t AlignInBits, unsigned Flags, 147 DIArray Elements, unsigned RunTimeLang = 0); 148 149 /// CreateArtificialType - Create a new DIType with "artificial" flag set. 150 DIType CreateArtificialType(DIType Ty); 151 152 /// CreateTemporaryType - Create a temporary forward-declared type. 153 DIType CreateTemporaryType(); 154 DIType CreateTemporaryType(DIFile F); 155 156 /// GetOrCreateArray - Get a DIArray, create one if required. 157 DIArray GetOrCreateArray(Value *const *Elements, unsigned NumElements); 158 159 /// CreateGlobalVariable - Create a new descriptor for the specified global. 160 /// @param Name Name of the variable. 161 /// @param LinakgeName Mangled name of the variable. 162 /// @param File File where this variable is defined. 163 /// @param LineNo Line number. 164 /// @param Ty Variable Type. 165 /// @param isLocalToUnit Boolean flag indicate whether this variable is 166 /// externally visible or not. 167 /// @param Val llvm::Value of the variable. 168 DIGlobalVariable 169 CreateGlobalVariable(StringRef Name, 170 StringRef LinkageName, DIFile File, unsigned LineNo, 171 DIType Ty, bool isLocalToUnit, llvm::Value *Val); 172 173 174 /// CreateStaticVariable - Create a new descriptor for the specified 175 /// variable. 176 /// @param Conext Variable scope. 177 /// @param Name Name of the variable. 178 /// @param LinakgeName Mangled name of the variable. 179 /// @param File File where this variable is defined. 180 /// @param LineNo Line number. 181 /// @param Ty Variable Type. 182 /// @param isLocalToUnit Boolean flag indicate whether this variable is 183 /// externally visible or not. 184 /// @param Val llvm::Value of the variable. 185 DIGlobalVariable 186 CreateStaticVariable(DIDescriptor Context, StringRef Name, 187 StringRef LinkageName, DIFile File, unsigned LineNo, 188 DIType Ty, bool isLocalToUnit, llvm::Value *Val); 189 190 191 /// CreateComplexVariable - Create a new descriptor for the specified 192 /// variable which has a complex address expression for its address. 193 /// @param Tag Dwarf TAG. Usually DW_TAG_auto_variable or 194 /// DW_TAG_arg_variable. 195 /// @param Scope Variable scope. 196 /// @param Name Variable name. 197 /// @param File File where this variable is defined. 198 /// @param LineNo Line number. 199 /// @param Ty Variable Type 200 /// @param Addr A pointer to a vector of complex address operations. 201 /// @param NumAddr Num of address operations in the vector. 202 DIVariable CreateComplexVariable(unsigned Tag, DIDescriptor Scope, 203 StringRef Name, DIFile F, unsigned LineNo, 204 DIType Ty, Value *const *Addr, 205 unsigned NumAddr); 206 207 208 /// CreateNameSpace - This creates new descriptor for a namespace 209 /// with the specified parent scope. 210 /// @param Scope Namespace scope 211 /// @param Name Name of this namespace 212 /// @param File Source file 213 /// @param LineNo Line number 214 DINameSpace CreateNameSpace(DIDescriptor Scope, StringRef Name, 215 DIFile File, unsigned LineNo); 216 217 218 /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call. 219 /// @param Storage llvm::Value of the variable 220 /// @param VarInfo Variable's debug info descriptor. 221 /// @param InsertAtEnd Location for the new intrinsic. 222 Instruction *InsertDeclare(llvm::Value *Storage, DIVariable VarInfo, 223 BasicBlock *InsertAtEnd); 224 225 /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call. 226 /// @param Storage llvm::Value of the variable 227 /// @param VarInfo Variable's debug info descriptor. 228 /// @param InsertBefore Location for the new intrinsic. 229 Instruction *InsertDeclare(llvm::Value *Storage, DIVariable VarInfo, 230 Instruction *InsertBefore); 231 232 233 /// InsertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call. 234 /// @param Val llvm::Value of the variable 235 /// @param Offset Offset 236 /// @param VarInfo Variable's debug info descriptor. 237 /// @param InsertAtEnd Location for the new intrinsic. 238 Instruction *InsertDbgValueIntrinsic(llvm::Value *Val, uint64_t Offset, 239 DIVariable VarInfo, 240 BasicBlock *InsertAtEnd); 241 242 /// InsertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call. 243 /// @param Val llvm::Value of the variable 244 /// @param Offset Offset 245 /// @param VarInfo Variable's debug info descriptor. 246 /// @param InsertBefore Location for the new intrinsic. 247 Instruction *InsertDbgValueIntrinsic(llvm::Value *Val, uint64_t Offset, 248 DIVariable VarInfo, 249 Instruction *InsertBefore); 250 251 }; 252} // end namespace llvm 253 254#endif 255