1 //===--- llvm/Analysis/DIBuilder.h - Debug Information Builder --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines a DIBuilder that is useful for creating debugging
11 // information entries in LLVM IR form.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_ANALYSIS_DIBUILDER_H
16 #define LLVM_ANALYSIS_DIBUILDER_H
18 #include "llvm/Support/DataTypes.h"
19 #include "llvm/ADT/StringRef.h"
35 class DIGlobalVariable;
41 class DITemplateTypeParameter;
42 class DITemplateValueParameter;
47 LLVMContext & VMContext;
50 Function *DeclareFn; // llvm.dbg.declare
51 Function *ValueFn; // llvm.dbg.value
53 DIBuilder(const DIBuilder &); // DO NOT IMPLEMENT
54 void operator=(const DIBuilder &); // DO NOT IMPLEMENT
57 explicit DIBuilder(Module &M);
58 const MDNode *getCU() { return TheCU; }
59 enum ComplexAddrKind { OpPlus=1, OpDeref };
61 /// createCompileUnit - A CompileUnit provides an anchor for all debugging
62 /// information generated during this instance of compilation.
63 /// @param Lang Source programming language, eg. dwarf::DW_LANG_C99
64 /// @param File File name
65 /// @param Dir Directory
66 /// @param Producer String identify producer of debugging information.
67 /// Usuall this is a compiler version string.
68 /// @param isOptimized A boolean flag which indicates whether optimization
70 /// @param Flags This string lists command line options. This string is
71 /// directly embedded in debug info output which may be used
72 /// by a tool analyzing generated debugging information.
73 /// @param RV This indicates runtime version for languages like
75 void createCompileUnit(unsigned Lang, StringRef File, StringRef Dir,
77 bool isOptimized, StringRef Flags, unsigned RV);
79 /// createFile - Create a file descriptor to hold debugging information
81 DIFile createFile(StringRef Filename, StringRef Directory);
83 /// createEnumerator - Create a single enumerator value.
84 DIEnumerator createEnumerator(StringRef Name, uint64_t Val);
86 /// createBasicType - Create debugging information entry for a basic
88 /// @param Name Type name.
89 /// @param SizeInBits Size of the type.
90 /// @param AlignInBits Type alignment.
91 /// @param Encoding DWARF encoding code, e.g. dwarf::DW_ATE_float.
92 DIType createBasicType(StringRef Name, uint64_t SizeInBits,
93 uint64_t AlignInBits, unsigned Encoding);
95 /// createQualifiedType - Create debugging information entry for a qualified
96 /// type, e.g. 'const int'.
97 /// @param Tag Tag identifing type, e.g. dwarf::TAG_volatile_type
98 /// @param FromTy Base Type.
99 DIType createQualifiedType(unsigned Tag, DIType FromTy);
101 /// createPointerType - Create debugging information entry for a pointer.
102 /// @param PointeeTy Type pointed by this pointer.
103 /// @param SizeInBits Size.
104 /// @param AlignInBits Alignment. (optional)
105 /// @param Name Pointer type name. (optional)
106 DIType createPointerType(DIType PointeeTy, uint64_t SizeInBits,
107 uint64_t AlignInBits = 0,
108 StringRef Name = StringRef());
110 /// createReferenceType - Create debugging information entry for a c++
112 DIType createReferenceType(DIType RTy);
114 /// createTypedef - Create debugging information entry for a typedef.
115 /// @param Ty Original type.
116 /// @param Name Typedef name.
117 /// @param File File where this type is defined.
118 /// @param LineNo Line number.
119 DIType createTypedef(DIType Ty, StringRef Name, DIFile File,
122 /// createFriend - Create debugging information entry for a 'friend'.
123 DIType createFriend(DIType Ty, DIType FriendTy);
125 /// createInheritance - Create debugging information entry to establish
126 /// inheritance relationship between two types.
127 /// @param Ty Original type.
128 /// @param BaseTy Base type. Ty is inherits from base.
129 /// @param BaseOffset Base offset.
130 /// @param Flags Flags to describe inheritance attribute,
132 DIType createInheritance(DIType Ty, DIType BaseTy, uint64_t BaseOffset,
135 /// createMemberType - Create debugging information entry for a member.
136 /// @param Name Member name.
137 /// @param File File where this member is defined.
138 /// @param LineNo Line number.
139 /// @param SizeInBits Member size.
140 /// @param AlignInBits Member alignment.
141 /// @param OffsetInBits Member offset.
142 /// @param Flags Flags to encode member attribute, e.g. private
143 /// @param Ty Parent type.
144 DIType createMemberType(StringRef Name, DIFile File,
145 unsigned LineNo, uint64_t SizeInBits,
146 uint64_t AlignInBits, uint64_t OffsetInBits,
147 unsigned Flags, DIType Ty);
149 /// createClassType - Create debugging information entry for a class.
150 /// @param Scope Scope in which this class is defined.
151 /// @param Name class name.
152 /// @param File File where this member is defined.
153 /// @param LineNo Line number.
154 /// @param SizeInBits Member size.
155 /// @param AlignInBits Member alignment.
156 /// @param OffsetInBits Member offset.
157 /// @param Flags Flags to encode member attribute, e.g. private
158 /// @param Elements class members.
159 /// @param VTableHolder Debug info of the base class that contains vtable
160 /// for this type. This is used in
161 /// DW_AT_containing_type. See DWARF documentation
163 /// @param TemplateParms Template type parameters.
164 DIType createClassType(DIDescriptor Scope, StringRef Name, DIFile File,
165 unsigned LineNumber, uint64_t SizeInBits,
166 uint64_t AlignInBits, uint64_t OffsetInBits,
167 unsigned Flags, DIType DerivedFrom,
168 DIArray Elements, MDNode *VTableHolder = 0,
169 MDNode *TemplateParms = 0);
171 /// createStructType - Create debugging information entry for a struct.
172 /// @param Scope Scope in which this struct is defined.
173 /// @param Name Struct name.
174 /// @param File File where this member is defined.
175 /// @param LineNo Line number.
176 /// @param SizeInBits Member size.
177 /// @param AlignInBits Member alignment.
178 /// @param Flags Flags to encode member attribute, e.g. private
179 /// @param Elements Struct elements.
180 /// @param RunTimeLang Optional parameter, Objective-C runtime version.
181 DIType createStructType(DIDescriptor Scope, StringRef Name, DIFile File,
182 unsigned LineNumber, uint64_t SizeInBits,
183 uint64_t AlignInBits, unsigned Flags,
184 DIArray Elements, unsigned RunTimeLang = 0);
186 /// createUnionType - Create debugging information entry for an union.
187 /// @param Scope Scope in which this union is defined.
188 /// @param Name Union name.
189 /// @param File File where this member is defined.
190 /// @param LineNo Line number.
191 /// @param SizeInBits Member size.
192 /// @param AlignInBits Member alignment.
193 /// @param Flags Flags to encode member attribute, e.g. private
194 /// @param Elements Union elements.
195 /// @param RunTimeLang Optional parameter, Objective-C runtime version.
196 DIType createUnionType(DIDescriptor Scope, StringRef Name, DIFile File,
197 unsigned LineNumber, uint64_t SizeInBits,
198 uint64_t AlignInBits, unsigned Flags,
199 DIArray Elements, unsigned RunTimeLang = 0);
201 /// createTemplateTypeParameter - Create debugging information for template
203 /// @param Scope Scope in which this type is defined.
204 /// @param Name Type parameter name.
205 /// @param Ty Parameter type.
206 /// @param File File where this type parameter is defined.
207 /// @param LineNo Line number.
208 /// @param ColumnNo Column Number.
209 DITemplateTypeParameter
210 createTemplateTypeParameter(DIDescriptor Scope, StringRef Name, DIType Ty,
211 MDNode *File = 0, unsigned LineNo = 0,
212 unsigned ColumnNo = 0);
214 /// createTemplateValueParameter - Create debugging information for template
216 /// @param Scope Scope in which this type is defined.
217 /// @param Name Value parameter name.
218 /// @param Ty Parameter type.
219 /// @param Value Constant parameter value.
220 /// @param File File where this type parameter is defined.
221 /// @param LineNo Line number.
222 /// @param ColumnNo Column Number.
223 DITemplateValueParameter
224 createTemplateValueParameter(DIDescriptor Scope, StringRef Name, DIType Ty,
226 MDNode *File = 0, unsigned LineNo = 0,
227 unsigned ColumnNo = 0);
229 /// createArrayType - Create debugging information entry for an array.
230 /// @param Size Array size.
231 /// @param AlignInBits Alignment.
232 /// @param Ty Element type.
233 /// @param Subscripts Subscripts.
234 DIType createArrayType(uint64_t Size, uint64_t AlignInBits,
235 DIType Ty, DIArray Subscripts);
237 /// createVectorType - Create debugging information entry for a vector type.
238 /// @param Size Array size.
239 /// @param AlignInBits Alignment.
240 /// @param Ty Element type.
241 /// @param Subscripts Subscripts.
242 DIType createVectorType(uint64_t Size, uint64_t AlignInBits,
243 DIType Ty, DIArray Subscripts);
245 /// createEnumerationType - Create debugging information entry for an
247 /// @param Scope Scope in which this enumeration is defined.
248 /// @param Name Union name.
249 /// @param File File where this member is defined.
250 /// @param LineNo Line number.
251 /// @param SizeInBits Member size.
252 /// @param AlignInBits Member alignment.
253 /// @param Elements Enumeration elements.
254 DIType createEnumerationType(DIDescriptor Scope, StringRef Name,
255 DIFile File, unsigned LineNumber,
257 uint64_t AlignInBits, DIArray Elements);
259 /// createSubroutineType - Create subroutine type.
260 /// @param File File in which this subroutine is defined.
261 /// @param ParamterTypes An array of subroutine parameter types. This
262 /// includes return type at 0th index.
263 DIType createSubroutineType(DIFile File, DIArray ParameterTypes);
265 /// createArtificialType - Create a new DIType with "artificial" flag set.
266 DIType createArtificialType(DIType Ty);
268 /// createTemporaryType - Create a temporary forward-declared type.
269 DIType createTemporaryType();
270 DIType createTemporaryType(DIFile F);
272 /// retainType - Retain DIType in a module even if it is not referenced
273 /// through debug info anchors.
274 void retainType(DIType T);
276 /// createUnspecifiedParameter - Create unspeicified type descriptor
277 /// for a subroutine type.
278 DIDescriptor createUnspecifiedParameter();
280 /// getOrCreateArray - Get a DIArray, create one if required.
281 DIArray getOrCreateArray(Value *const *Elements, unsigned NumElements);
283 /// getOrCreateSubrange - Create a descriptor for a value range. This
284 /// implicitly uniques the values returned.
285 DISubrange getOrCreateSubrange(int64_t Lo, int64_t Hi);
287 /// createGlobalVariable - Create a new descriptor for the specified global.
288 /// @param Name Name of the variable.
289 /// @param File File where this variable is defined.
290 /// @param LineNo Line number.
291 /// @param Ty Variable Type.
292 /// @param isLocalToUnit Boolean flag indicate whether this variable is
293 /// externally visible or not.
294 /// @param Val llvm::Value of the variable.
296 createGlobalVariable(StringRef Name, DIFile File, unsigned LineNo,
297 DIType Ty, bool isLocalToUnit, llvm::Value *Val);
300 /// createStaticVariable - Create a new descriptor for the specified
302 /// @param Conext Variable scope.
303 /// @param Name Name of the variable.
304 /// @param LinakgeName Mangled name of the variable.
305 /// @param File File where this variable is defined.
306 /// @param LineNo Line number.
307 /// @param Ty Variable Type.
308 /// @param isLocalToUnit Boolean flag indicate whether this variable is
309 /// externally visible or not.
310 /// @param Val llvm::Value of the variable.
312 createStaticVariable(DIDescriptor Context, StringRef Name,
313 StringRef LinkageName, DIFile File, unsigned LineNo,
314 DIType Ty, bool isLocalToUnit, llvm::Value *Val);
317 /// createLocalVariable - Create a new descriptor for the specified
319 /// @param Tag Dwarf TAG. Usually DW_TAG_auto_variable or
320 /// DW_TAG_arg_variable.
321 /// @param Scope Variable scope.
322 /// @param Name Variable name.
323 /// @param File File where this variable is defined.
324 /// @param LineNo Line number.
325 /// @param Ty Variable Type
326 /// @param AlwaysPreserve Boolean. Set to true if debug info for this
327 /// variable should be preserved in optimized build.
328 /// @param Flags Flags, e.g. artificial variable.
329 /// @param ArgNo If this variable is an arugment then this argument's
330 /// number. 1 indicates 1st argument.
331 DIVariable createLocalVariable(unsigned Tag, DIDescriptor Scope,
333 DIFile File, unsigned LineNo,
334 DIType Ty, bool AlwaysPreserve = false,
339 /// createComplexVariable - Create a new descriptor for the specified
340 /// variable which has a complex address expression for its address.
341 /// @param Tag Dwarf TAG. Usually DW_TAG_auto_variable or
342 /// DW_TAG_arg_variable.
343 /// @param Scope Variable scope.
344 /// @param Name Variable name.
345 /// @param File File where this variable is defined.
346 /// @param LineNo Line number.
347 /// @param Ty Variable Type
348 /// @param Addr A pointer to a vector of complex address operations.
349 /// @param NumAddr Num of address operations in the vector.
350 /// @param ArgNo If this variable is an arugment then this argument's
351 /// number. 1 indicates 1st argument.
352 DIVariable createComplexVariable(unsigned Tag, DIDescriptor Scope,
353 StringRef Name, DIFile F, unsigned LineNo,
354 DIType Ty, Value *const *Addr,
355 unsigned NumAddr, unsigned ArgNo = 0);
357 /// createFunction - Create a new descriptor for the specified subprogram.
358 /// See comments in DISubprogram for descriptions of these fields.
359 /// @param Scope Function scope.
360 /// @param Name Function name.
361 /// @param LinkageName Mangled function name.
362 /// @param File File where this variable is defined.
363 /// @param LineNo Line number.
364 /// @param Ty Function type.
365 /// @param isLocalToUnit True if this function is not externally visible..
366 /// @param isDefinition True if this is a function definition.
367 /// @param Flags e.g. is this function prototyped or not.
368 /// This flags are used to emit dwarf attributes.
369 /// @param isOptimized True if optimization is ON.
370 /// @param Fn llvm::Function pointer.
371 /// @param TParam Function template parameters.
372 DISubprogram createFunction(DIDescriptor Scope, StringRef Name,
373 StringRef LinkageName,
374 DIFile File, unsigned LineNo,
375 DIType Ty, bool isLocalToUnit,
378 bool isOptimized = false,
382 /// createMethod - Create a new descriptor for the specified C++ method.
383 /// See comments in DISubprogram for descriptions of these fields.
384 /// @param Scope Function scope.
385 /// @param Name Function name.
386 /// @param LinkageName Mangled function name.
387 /// @param File File where this variable is defined.
388 /// @param LineNo Line number.
389 /// @param Ty Function type.
390 /// @param isLocalToUnit True if this function is not externally visible..
391 /// @param isDefinition True if this is a function definition.
392 /// @param Virtuality Attributes describing virtualness. e.g. pure
393 /// virtual function.
394 /// @param VTableIndex Index no of this method in virtual table.
395 /// @param VTableHolder Type that holds vtable.
396 /// @param Flags e.g. is this function prototyped or not.
397 /// This flags are used to emit dwarf attributes.
398 /// @param isOptimized True if optimization is ON.
399 /// @param Fn llvm::Function pointer.
400 /// @param TParam Function template parameters.
401 DISubprogram createMethod(DIDescriptor Scope, StringRef Name,
402 StringRef LinkageName,
403 DIFile File, unsigned LineNo,
404 DIType Ty, bool isLocalToUnit,
406 unsigned Virtuality = 0, unsigned VTableIndex = 0,
407 MDNode *VTableHolder = 0,
409 bool isOptimized = false,
413 /// createNameSpace - This creates new descriptor for a namespace
414 /// with the specified parent scope.
415 /// @param Scope Namespace scope
416 /// @param Name Name of this namespace
417 /// @param File Source file
418 /// @param LineNo Line number
419 DINameSpace createNameSpace(DIDescriptor Scope, StringRef Name,
420 DIFile File, unsigned LineNo);
423 /// createLexicalBlock - This creates a descriptor for a lexical block
424 /// with the specified parent context.
425 /// @param Scope Parent lexical scope.
426 /// @param File Source file
427 /// @param Line Line number
428 /// @param Col Column number
429 DILexicalBlock createLexicalBlock(DIDescriptor Scope, DIFile File,
430 unsigned Line, unsigned Col);
432 /// insertDeclare - Insert a new llvm.dbg.declare intrinsic call.
433 /// @param Storage llvm::Value of the variable
434 /// @param VarInfo Variable's debug info descriptor.
435 /// @param InsertAtEnd Location for the new intrinsic.
436 Instruction *insertDeclare(llvm::Value *Storage, DIVariable VarInfo,
437 BasicBlock *InsertAtEnd);
439 /// insertDeclare - Insert a new llvm.dbg.declare intrinsic call.
440 /// @param Storage llvm::Value of the variable
441 /// @param VarInfo Variable's debug info descriptor.
442 /// @param InsertBefore Location for the new intrinsic.
443 Instruction *insertDeclare(llvm::Value *Storage, DIVariable VarInfo,
444 Instruction *InsertBefore);
447 /// insertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
448 /// @param Val llvm::Value of the variable
449 /// @param Offset Offset
450 /// @param VarInfo Variable's debug info descriptor.
451 /// @param InsertAtEnd Location for the new intrinsic.
452 Instruction *insertDbgValueIntrinsic(llvm::Value *Val, uint64_t Offset,
454 BasicBlock *InsertAtEnd);
456 /// insertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
457 /// @param Val llvm::Value of the variable
458 /// @param Offset Offset
459 /// @param VarInfo Variable's debug info descriptor.
460 /// @param InsertBefore Location for the new intrinsic.
461 Instruction *insertDbgValueIntrinsic(llvm::Value *Val, uint64_t Offset,
463 Instruction *InsertBefore);
466 } // end namespace llvm