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/ArrayRef.h"
20 #include "llvm/ADT/StringRef.h"
36 class DIGlobalVariable;
40 class DILexicalBlockFile;
43 class DITemplateTypeParameter;
44 class DITemplateValueParameter;
50 LLVMContext & VMContext;
53 MDNode *TempEnumTypes;
54 MDNode *TempRetainTypes;
55 MDNode *TempSubprograms;
58 Function *DeclareFn; // llvm.dbg.declare
59 Function *ValueFn; // llvm.dbg.value
61 SmallVector<Value *, 4> AllEnumTypes;
62 SmallVector<Value *, 4> AllRetainTypes;
63 SmallVector<Value *, 4> AllSubprograms;
64 SmallVector<Value *, 4> AllGVs;
66 DIBuilder(const DIBuilder &); // DO NOT IMPLEMENT
67 void operator=(const DIBuilder &); // DO NOT IMPLEMENT
70 explicit DIBuilder(Module &M);
71 const MDNode *getCU() { return TheCU; }
72 enum ComplexAddrKind { OpPlus=1, OpDeref };
74 /// finalize - Construct any deferred debug info descriptors.
77 /// createCompileUnit - A CompileUnit provides an anchor for all debugging
78 /// information generated during this instance of compilation.
79 /// @param Lang Source programming language, eg. dwarf::DW_LANG_C99
80 /// @param File File name
81 /// @param Dir Directory
82 /// @param Producer String identify producer of debugging information.
83 /// Usuall this is a compiler version string.
84 /// @param isOptimized A boolean flag which indicates whether optimization
86 /// @param Flags This string lists command line options. This string is
87 /// directly embedded in debug info output which may be used
88 /// by a tool analyzing generated debugging information.
89 /// @param RV This indicates runtime version for languages like
91 void createCompileUnit(unsigned Lang, StringRef File, StringRef Dir,
93 bool isOptimized, StringRef Flags, unsigned RV);
95 /// createFile - Create a file descriptor to hold debugging information
97 DIFile createFile(StringRef Filename, StringRef Directory);
99 /// createEnumerator - Create a single enumerator value.
100 DIEnumerator createEnumerator(StringRef Name, uint64_t Val);
102 /// createNullPtrType - Create C++0x nullptr type.
103 DIType createNullPtrType(StringRef Name);
105 /// createBasicType - Create debugging information entry for a basic
107 /// @param Name Type name.
108 /// @param SizeInBits Size of the type.
109 /// @param AlignInBits Type alignment.
110 /// @param Encoding DWARF encoding code, e.g. dwarf::DW_ATE_float.
111 DIType createBasicType(StringRef Name, uint64_t SizeInBits,
112 uint64_t AlignInBits, unsigned Encoding);
114 /// createQualifiedType - Create debugging information entry for a qualified
115 /// type, e.g. 'const int'.
116 /// @param Tag Tag identifing type, e.g. dwarf::TAG_volatile_type
117 /// @param FromTy Base Type.
118 DIType createQualifiedType(unsigned Tag, DIType FromTy);
120 /// createPointerType - Create debugging information entry for a pointer.
121 /// @param PointeeTy Type pointed by this pointer.
122 /// @param SizeInBits Size.
123 /// @param AlignInBits Alignment. (optional)
124 /// @param Name Pointer type name. (optional)
125 DIType createPointerType(DIType PointeeTy, uint64_t SizeInBits,
126 uint64_t AlignInBits = 0,
127 StringRef Name = StringRef());
129 /// createReferenceType - Create debugging information entry for a c++
131 DIType createReferenceType(DIType RTy);
133 /// createTypedef - Create debugging information entry for a typedef.
134 /// @param Ty Original type.
135 /// @param Name Typedef name.
136 /// @param File File where this type is defined.
137 /// @param LineNo Line number.
138 /// @param Context The surrounding context for the typedef.
139 DIType createTypedef(DIType Ty, StringRef Name, DIFile File,
140 unsigned LineNo, DIDescriptor Context);
142 /// createFriend - Create debugging information entry for a 'friend'.
143 DIType createFriend(DIType Ty, DIType FriendTy);
145 /// createInheritance - Create debugging information entry to establish
146 /// inheritance relationship between two types.
147 /// @param Ty Original type.
148 /// @param BaseTy Base type. Ty is inherits from base.
149 /// @param BaseOffset Base offset.
150 /// @param Flags Flags to describe inheritance attribute,
152 DIType createInheritance(DIType Ty, DIType BaseTy, uint64_t BaseOffset,
155 /// createMemberType - Create debugging information entry for a member.
156 /// @param Scope Member scope.
157 /// @param Name Member name.
158 /// @param File File where this member is defined.
159 /// @param LineNo Line number.
160 /// @param SizeInBits Member size.
161 /// @param AlignInBits Member alignment.
162 /// @param OffsetInBits Member offset.
163 /// @param Flags Flags to encode member attribute, e.g. private
164 /// @param Ty Parent type.
165 DIType createMemberType(DIDescriptor Scope, StringRef Name, DIFile File,
166 unsigned LineNo, uint64_t SizeInBits,
167 uint64_t AlignInBits, uint64_t OffsetInBits,
168 unsigned Flags, DIType Ty);
170 /// createObjCIVar - Create debugging information entry for Objective-C
171 /// instance variable.
172 /// @param Name Member name.
173 /// @param File File where this member is defined.
174 /// @param LineNo Line number.
175 /// @param SizeInBits Member size.
176 /// @param AlignInBits Member alignment.
177 /// @param OffsetInBits Member offset.
178 /// @param Flags Flags to encode member attribute, e.g. private
179 /// @param Ty Parent type.
180 /// @param PropertyName Name of the Objective C property assoicated with
182 /// @param GetterName Name of the Objective C property getter selector.
183 /// @param SetterName Name of the Objective C property setter selector.
184 /// @param PropertyAttributes Objective C property attributes.
185 DIType createObjCIVar(StringRef Name, DIFile File,
186 unsigned LineNo, uint64_t SizeInBits,
187 uint64_t AlignInBits, uint64_t OffsetInBits,
188 unsigned Flags, DIType Ty,
189 StringRef PropertyName = StringRef(),
190 StringRef PropertyGetterName = StringRef(),
191 StringRef PropertySetterName = StringRef(),
192 unsigned PropertyAttributes = 0);
194 /// createObjCIVar - Create debugging information entry for Objective-C
195 /// instance variable.
196 /// @param Name Member name.
197 /// @param File File where this member is defined.
198 /// @param LineNo Line number.
199 /// @param SizeInBits Member size.
200 /// @param AlignInBits Member alignment.
201 /// @param OffsetInBits Member offset.
202 /// @param Flags Flags to encode member attribute, e.g. private
203 /// @param Ty Parent type.
204 /// @param Property Property associated with this ivar.
205 DIType createObjCIVar(StringRef Name, DIFile File,
206 unsigned LineNo, uint64_t SizeInBits,
207 uint64_t AlignInBits, uint64_t OffsetInBits,
208 unsigned Flags, DIType Ty,
209 MDNode *PropertyNode);
211 /// createObjCProperty - Create debugging information entry for Objective-C
213 /// @param Name Property name.
214 /// @param GetterName Name of the Objective C property getter selector.
215 /// @param SetterName Name of the Objective C property setter selector.
216 /// @param PropertyAttributes Objective C property attributes.
217 DIObjCProperty createObjCProperty(StringRef Name, StringRef GetterName,
218 StringRef SetterName,
219 unsigned PropertyAttributes);
221 /// createClassType - Create debugging information entry for a class.
222 /// @param Scope Scope in which this class is defined.
223 /// @param Name class name.
224 /// @param File File where this member is defined.
225 /// @param LineNo Line number.
226 /// @param SizeInBits Member size.
227 /// @param AlignInBits Member alignment.
228 /// @param OffsetInBits Member offset.
229 /// @param Flags Flags to encode member attribute, e.g. private
230 /// @param Elements class members.
231 /// @param VTableHolder Debug info of the base class that contains vtable
232 /// for this type. This is used in
233 /// DW_AT_containing_type. See DWARF documentation
235 /// @param TemplateParms Template type parameters.
236 DIType createClassType(DIDescriptor Scope, StringRef Name, DIFile File,
237 unsigned LineNumber, uint64_t SizeInBits,
238 uint64_t AlignInBits, uint64_t OffsetInBits,
239 unsigned Flags, DIType DerivedFrom,
240 DIArray Elements, MDNode *VTableHolder = 0,
241 MDNode *TemplateParms = 0);
243 /// createStructType - Create debugging information entry for a struct.
244 /// @param Scope Scope in which this struct is defined.
245 /// @param Name Struct name.
246 /// @param File File where this member is defined.
247 /// @param LineNo Line number.
248 /// @param SizeInBits Member size.
249 /// @param AlignInBits Member alignment.
250 /// @param Flags Flags to encode member attribute, e.g. private
251 /// @param Elements Struct elements.
252 /// @param RunTimeLang Optional parameter, Objective-C runtime version.
253 DIType createStructType(DIDescriptor Scope, StringRef Name, DIFile File,
254 unsigned LineNumber, uint64_t SizeInBits,
255 uint64_t AlignInBits, unsigned Flags,
256 DIArray Elements, unsigned RunTimeLang = 0);
258 /// createUnionType - Create debugging information entry for an union.
259 /// @param Scope Scope in which this union is defined.
260 /// @param Name Union name.
261 /// @param File File where this member is defined.
262 /// @param LineNo Line number.
263 /// @param SizeInBits Member size.
264 /// @param AlignInBits Member alignment.
265 /// @param Flags Flags to encode member attribute, e.g. private
266 /// @param Elements Union elements.
267 /// @param RunTimeLang Optional parameter, Objective-C runtime version.
268 DIType createUnionType(DIDescriptor Scope, StringRef Name, DIFile File,
269 unsigned LineNumber, uint64_t SizeInBits,
270 uint64_t AlignInBits, unsigned Flags,
271 DIArray Elements, unsigned RunTimeLang = 0);
273 /// createTemplateTypeParameter - Create debugging information for template
275 /// @param Scope Scope in which this type is defined.
276 /// @param Name Type parameter name.
277 /// @param Ty Parameter type.
278 /// @param File File where this type parameter is defined.
279 /// @param LineNo Line number.
280 /// @param ColumnNo Column Number.
281 DITemplateTypeParameter
282 createTemplateTypeParameter(DIDescriptor Scope, StringRef Name, DIType Ty,
283 MDNode *File = 0, unsigned LineNo = 0,
284 unsigned ColumnNo = 0);
286 /// createTemplateValueParameter - Create debugging information for template
288 /// @param Scope Scope in which this type is defined.
289 /// @param Name Value parameter name.
290 /// @param Ty Parameter type.
291 /// @param Value Constant parameter value.
292 /// @param File File where this type parameter is defined.
293 /// @param LineNo Line number.
294 /// @param ColumnNo Column Number.
295 DITemplateValueParameter
296 createTemplateValueParameter(DIDescriptor Scope, StringRef Name, DIType Ty,
298 MDNode *File = 0, unsigned LineNo = 0,
299 unsigned ColumnNo = 0);
301 /// createArrayType - Create debugging information entry for an array.
302 /// @param Size Array size.
303 /// @param AlignInBits Alignment.
304 /// @param Ty Element type.
305 /// @param Subscripts Subscripts.
306 DIType createArrayType(uint64_t Size, uint64_t AlignInBits,
307 DIType Ty, DIArray Subscripts);
309 /// createVectorType - Create debugging information entry for a vector type.
310 /// @param Size Array size.
311 /// @param AlignInBits Alignment.
312 /// @param Ty Element type.
313 /// @param Subscripts Subscripts.
314 DIType createVectorType(uint64_t Size, uint64_t AlignInBits,
315 DIType Ty, DIArray Subscripts);
317 /// createEnumerationType - Create debugging information entry for an
319 /// @param Scope Scope in which this enumeration is defined.
320 /// @param Name Union name.
321 /// @param File File where this member is defined.
322 /// @param LineNo Line number.
323 /// @param SizeInBits Member size.
324 /// @param AlignInBits Member alignment.
325 /// @param Elements Enumeration elements.
326 DIType createEnumerationType(DIDescriptor Scope, StringRef Name,
327 DIFile File, unsigned LineNumber,
329 uint64_t AlignInBits, DIArray Elements);
331 /// createSubroutineType - Create subroutine type.
332 /// @param File File in which this subroutine is defined.
333 /// @param ParamterTypes An array of subroutine parameter types. This
334 /// includes return type at 0th index.
335 DIType createSubroutineType(DIFile File, DIArray ParameterTypes);
337 /// createArtificialType - Create a new DIType with "artificial" flag set.
338 DIType createArtificialType(DIType Ty);
340 /// createTemporaryType - Create a temporary forward-declared type.
341 DIType createTemporaryType();
342 DIType createTemporaryType(DIFile F);
344 /// createForwardDecl - Create a temporary forward-declared type.
345 DIType createForwardDecl(unsigned Tag, StringRef Name, DIFile F,
346 unsigned Line, unsigned RuntimeLang = 0);
348 /// retainType - Retain DIType in a module even if it is not referenced
349 /// through debug info anchors.
350 void retainType(DIType T);
352 /// createUnspecifiedParameter - Create unspeicified type descriptor
353 /// for a subroutine type.
354 DIDescriptor createUnspecifiedParameter();
356 /// getOrCreateArray - Get a DIArray, create one if required.
357 DIArray getOrCreateArray(ArrayRef<Value *> Elements);
359 /// getOrCreateSubrange - Create a descriptor for a value range. This
360 /// implicitly uniques the values returned.
361 DISubrange getOrCreateSubrange(int64_t Lo, int64_t Hi);
363 /// createGlobalVariable - Create a new descriptor for the specified global.
364 /// @param Name Name of the variable.
365 /// @param File File where this variable is defined.
366 /// @param LineNo Line number.
367 /// @param Ty Variable Type.
368 /// @param isLocalToUnit Boolean flag indicate whether this variable is
369 /// externally visible or not.
370 /// @param Val llvm::Value of the variable.
372 createGlobalVariable(StringRef Name, DIFile File, unsigned LineNo,
373 DIType Ty, bool isLocalToUnit, llvm::Value *Val);
376 /// createStaticVariable - Create a new descriptor for the specified
378 /// @param Conext Variable scope.
379 /// @param Name Name of the variable.
380 /// @param LinakgeName Mangled name of the variable.
381 /// @param File File where this variable is defined.
382 /// @param LineNo Line number.
383 /// @param Ty Variable Type.
384 /// @param isLocalToUnit Boolean flag indicate whether this variable is
385 /// externally visible or not.
386 /// @param Val llvm::Value of the variable.
388 createStaticVariable(DIDescriptor Context, StringRef Name,
389 StringRef LinkageName, DIFile File, unsigned LineNo,
390 DIType Ty, bool isLocalToUnit, llvm::Value *Val);
393 /// createLocalVariable - Create a new descriptor for the specified
395 /// @param Tag Dwarf TAG. Usually DW_TAG_auto_variable or
396 /// DW_TAG_arg_variable.
397 /// @param Scope Variable scope.
398 /// @param Name Variable name.
399 /// @param File File where this variable is defined.
400 /// @param LineNo Line number.
401 /// @param Ty Variable Type
402 /// @param AlwaysPreserve Boolean. Set to true if debug info for this
403 /// variable should be preserved in optimized build.
404 /// @param Flags Flags, e.g. artificial variable.
405 /// @param ArgNo If this variable is an arugment then this argument's
406 /// number. 1 indicates 1st argument.
407 DIVariable createLocalVariable(unsigned Tag, DIDescriptor Scope,
409 DIFile File, unsigned LineNo,
410 DIType Ty, bool AlwaysPreserve = false,
415 /// createComplexVariable - Create a new descriptor for the specified
416 /// variable which has a complex address expression for its address.
417 /// @param Tag Dwarf TAG. Usually DW_TAG_auto_variable or
418 /// DW_TAG_arg_variable.
419 /// @param Scope Variable scope.
420 /// @param Name Variable name.
421 /// @param File File where this variable is defined.
422 /// @param LineNo Line number.
423 /// @param Ty Variable Type
424 /// @param Addr An array of complex address operations.
425 /// @param ArgNo If this variable is an arugment then this argument's
426 /// number. 1 indicates 1st argument.
427 DIVariable createComplexVariable(unsigned Tag, DIDescriptor Scope,
428 StringRef Name, DIFile F, unsigned LineNo,
429 DIType Ty, ArrayRef<Value *> Addr,
432 /// createFunction - Create a new descriptor for the specified subprogram.
433 /// See comments in DISubprogram for descriptions of these fields.
434 /// @param Scope Function scope.
435 /// @param Name Function name.
436 /// @param LinkageName Mangled function name.
437 /// @param File File where this variable is defined.
438 /// @param LineNo Line number.
439 /// @param Ty Function type.
440 /// @param isLocalToUnit True if this function is not externally visible..
441 /// @param isDefinition True if this is a function definition.
442 /// @param Flags e.g. is this function prototyped or not.
443 /// This flags are used to emit dwarf attributes.
444 /// @param isOptimized True if optimization is ON.
445 /// @param Fn llvm::Function pointer.
446 /// @param TParam Function template parameters.
447 DISubprogram createFunction(DIDescriptor Scope, StringRef Name,
448 StringRef LinkageName,
449 DIFile File, unsigned LineNo,
450 DIType Ty, bool isLocalToUnit,
453 bool isOptimized = false,
458 /// createMethod - Create a new descriptor for the specified C++ method.
459 /// See comments in DISubprogram for descriptions of these fields.
460 /// @param Scope Function scope.
461 /// @param Name Function name.
462 /// @param LinkageName Mangled function name.
463 /// @param File File where this variable is defined.
464 /// @param LineNo Line number.
465 /// @param Ty Function type.
466 /// @param isLocalToUnit True if this function is not externally visible..
467 /// @param isDefinition True if this is a function definition.
468 /// @param Virtuality Attributes describing virtualness. e.g. pure
469 /// virtual function.
470 /// @param VTableIndex Index no of this method in virtual table.
471 /// @param VTableHolder Type that holds vtable.
472 /// @param Flags e.g. is this function prototyped or not.
473 /// This flags are used to emit dwarf attributes.
474 /// @param isOptimized True if optimization is ON.
475 /// @param Fn llvm::Function pointer.
476 /// @param TParam Function template parameters.
477 DISubprogram createMethod(DIDescriptor Scope, StringRef Name,
478 StringRef LinkageName,
479 DIFile File, unsigned LineNo,
480 DIType Ty, bool isLocalToUnit,
482 unsigned Virtuality = 0, unsigned VTableIndex = 0,
483 MDNode *VTableHolder = 0,
485 bool isOptimized = false,
489 /// createNameSpace - This creates new descriptor for a namespace
490 /// with the specified parent scope.
491 /// @param Scope Namespace scope
492 /// @param Name Name of this namespace
493 /// @param File Source file
494 /// @param LineNo Line number
495 DINameSpace createNameSpace(DIDescriptor Scope, StringRef Name,
496 DIFile File, unsigned LineNo);
499 /// createLexicalBlockFile - This creates a descriptor for a lexical
500 /// block with a new file attached. This merely extends the existing
501 /// lexical block as it crosses a file.
502 /// @param Scope Lexical block.
503 /// @param File Source file.
504 DILexicalBlockFile createLexicalBlockFile(DIDescriptor Scope,
507 /// createLexicalBlock - This creates a descriptor for a lexical block
508 /// with the specified parent context.
509 /// @param Scope Parent lexical scope.
510 /// @param File Source file
511 /// @param Line Line number
512 /// @param Col Column number
513 DILexicalBlock createLexicalBlock(DIDescriptor Scope, DIFile File,
514 unsigned Line, unsigned Col);
516 /// insertDeclare - Insert a new llvm.dbg.declare intrinsic call.
517 /// @param Storage llvm::Value of the variable
518 /// @param VarInfo Variable's debug info descriptor.
519 /// @param InsertAtEnd Location for the new intrinsic.
520 Instruction *insertDeclare(llvm::Value *Storage, DIVariable VarInfo,
521 BasicBlock *InsertAtEnd);
523 /// insertDeclare - Insert a new llvm.dbg.declare intrinsic call.
524 /// @param Storage llvm::Value of the variable
525 /// @param VarInfo Variable's debug info descriptor.
526 /// @param InsertBefore Location for the new intrinsic.
527 Instruction *insertDeclare(llvm::Value *Storage, DIVariable VarInfo,
528 Instruction *InsertBefore);
531 /// insertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
532 /// @param Val llvm::Value of the variable
533 /// @param Offset Offset
534 /// @param VarInfo Variable's debug info descriptor.
535 /// @param InsertAtEnd Location for the new intrinsic.
536 Instruction *insertDbgValueIntrinsic(llvm::Value *Val, uint64_t Offset,
538 BasicBlock *InsertAtEnd);
540 /// insertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
541 /// @param Val llvm::Value of the variable
542 /// @param Offset Offset
543 /// @param VarInfo Variable's debug info descriptor.
544 /// @param InsertBefore Location for the new intrinsic.
545 Instruction *insertDbgValueIntrinsic(llvm::Value *Val, uint64_t Offset,
547 Instruction *InsertBefore);
550 } // end namespace llvm