1 //===--- llvm/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_DIBUILDER_H
16 #define LLVM_DIBUILDER_H
18 #include "llvm/ADT/ArrayRef.h"
19 #include "llvm/ADT/StringRef.h"
20 #include "llvm/Support/DataTypes.h"
37 class DIGlobalVariable;
41 class DILexicalBlockFile;
44 class DITemplateTypeParameter;
45 class DITemplateValueParameter;
51 LLVMContext & VMContext;
54 MDNode *TempEnumTypes;
55 MDNode *TempRetainTypes;
56 MDNode *TempSubprograms;
59 Function *DeclareFn; // llvm.dbg.declare
60 Function *ValueFn; // llvm.dbg.value
62 SmallVector<Value *, 4> AllEnumTypes;
63 SmallVector<Value *, 4> AllRetainTypes;
64 SmallVector<Value *, 4> AllSubprograms;
65 SmallVector<Value *, 4> AllGVs;
67 DIBuilder(const DIBuilder &) LLVM_DELETED_FUNCTION;
68 void operator=(const DIBuilder &) LLVM_DELETED_FUNCTION;
71 explicit DIBuilder(Module &M);
72 const MDNode *getCU() { return TheCU; }
73 enum ComplexAddrKind { OpPlus=1, OpDeref };
75 /// finalize - Construct any deferred debug info descriptors.
78 /// createCompileUnit - A CompileUnit provides an anchor for all debugging
79 /// information generated during this instance of compilation.
80 /// @param Lang Source programming language, eg. dwarf::DW_LANG_C99
81 /// @param File File name
82 /// @param Dir Directory
83 /// @param Producer String identify producer of debugging information.
84 /// Usuall this is a compiler version string.
85 /// @param isOptimized A boolean flag which indicates whether optimization
87 /// @param Flags This string lists command line options. This string is
88 /// directly embedded in debug info output which may be used
89 /// by a tool analyzing generated debugging information.
90 /// @param RV This indicates runtime version for languages like
92 void createCompileUnit(unsigned Lang, StringRef File, StringRef Dir,
94 bool isOptimized, StringRef Flags, unsigned RV);
96 /// createFile - Create a file descriptor to hold debugging information
98 DIFile createFile(StringRef Filename, StringRef Directory);
100 /// createEnumerator - Create a single enumerator value.
101 DIEnumerator createEnumerator(StringRef Name, uint64_t Val);
103 /// createNullPtrType - Create C++0x nullptr type.
104 DIType createNullPtrType(StringRef Name);
106 /// createBasicType - Create debugging information entry for a basic
108 /// @param Name Type name.
109 /// @param SizeInBits Size of the type.
110 /// @param AlignInBits Type alignment.
111 /// @param Encoding DWARF encoding code, e.g. dwarf::DW_ATE_float.
112 DIBasicType createBasicType(StringRef Name, uint64_t SizeInBits,
113 uint64_t AlignInBits, unsigned Encoding);
115 /// createQualifiedType - Create debugging information entry for a qualified
116 /// type, e.g. 'const int'.
117 /// @param Tag Tag identifing type, e.g. dwarf::TAG_volatile_type
118 /// @param FromTy Base Type.
119 DIType createQualifiedType(unsigned Tag, DIType FromTy);
121 /// createPointerType - Create debugging information entry for a pointer.
122 /// @param PointeeTy Type pointed by this pointer.
123 /// @param SizeInBits Size.
124 /// @param AlignInBits Alignment. (optional)
125 /// @param Name Pointer type name. (optional)
126 DIType createPointerType(DIType PointeeTy, uint64_t SizeInBits,
127 uint64_t AlignInBits = 0,
128 StringRef Name = StringRef());
130 /// \brief Create debugging information entry for a pointer to member.
131 /// @param PointeeTy Type pointed to by this pointer.
132 /// @param Class Type for which this pointer points to members of.
133 DIType createMemberPointerType(DIType PointeeTy, DIType Class);
135 /// createReferenceType - Create debugging information entry for a c++
136 /// style reference or rvalue reference type.
137 DIType createReferenceType(unsigned Tag, DIType RTy);
139 /// createTypedef - Create debugging information entry for a typedef.
140 /// @param Ty Original type.
141 /// @param Name Typedef name.
142 /// @param File File where this type is defined.
143 /// @param LineNo Line number.
144 /// @param Context The surrounding context for the typedef.
145 DIType createTypedef(DIType Ty, StringRef Name, DIFile File,
146 unsigned LineNo, DIDescriptor Context);
148 /// createFriend - Create debugging information entry for a 'friend'.
149 DIType createFriend(DIType Ty, DIType FriendTy);
151 /// createInheritance - Create debugging information entry to establish
152 /// inheritance relationship between two types.
153 /// @param Ty Original type.
154 /// @param BaseTy Base type. Ty is inherits from base.
155 /// @param BaseOffset Base offset.
156 /// @param Flags Flags to describe inheritance attribute,
158 DIType createInheritance(DIType Ty, DIType BaseTy, uint64_t BaseOffset,
161 /// createMemberType - Create debugging information entry for a member.
162 /// @param Scope Member scope.
163 /// @param Name Member name.
164 /// @param File File where this member is defined.
165 /// @param LineNo Line number.
166 /// @param SizeInBits Member size.
167 /// @param AlignInBits Member alignment.
168 /// @param OffsetInBits Member offset.
169 /// @param Flags Flags to encode member attribute, e.g. private
170 /// @param Ty Parent type.
171 DIType createMemberType(DIDescriptor Scope, StringRef Name, DIFile File,
172 unsigned LineNo, uint64_t SizeInBits,
173 uint64_t AlignInBits, uint64_t OffsetInBits,
174 unsigned Flags, DIType Ty);
176 /// createStaticMemberType - Create debugging information entry for a
177 /// C++ static data member.
178 /// @param Scope Member scope.
179 /// @param Name Member name.
180 /// @param File File where this member is declared.
181 /// @param LineNo Line number.
182 /// @param Ty Type of the static member.
183 /// @param Flags Flags to encode member attribute, e.g. private.
184 /// @param Val Const initializer of the member.
185 DIType createStaticMemberType(DIDescriptor Scope, StringRef Name,
186 DIFile File, unsigned LineNo, DIType Ty,
187 unsigned Flags, llvm::Value *Val);
189 /// createObjCIVar - Create debugging information entry for Objective-C
190 /// instance variable.
191 /// @param Name Member name.
192 /// @param File File where this member is defined.
193 /// @param LineNo Line number.
194 /// @param SizeInBits Member size.
195 /// @param AlignInBits Member alignment.
196 /// @param OffsetInBits Member offset.
197 /// @param Flags Flags to encode member attribute, e.g. private
198 /// @param Ty Parent type.
199 /// @param PropertyName Name of the Objective C property associated with
201 /// @param PropertyGetterName Name of the Objective C property getter
203 /// @param PropertySetterName Name of the Objective C property setter
205 /// @param PropertyAttributes Objective C property attributes.
206 DIType createObjCIVar(StringRef Name, DIFile File,
207 unsigned LineNo, uint64_t SizeInBits,
208 uint64_t AlignInBits, uint64_t OffsetInBits,
209 unsigned Flags, DIType Ty,
210 StringRef PropertyName = StringRef(),
211 StringRef PropertyGetterName = StringRef(),
212 StringRef PropertySetterName = StringRef(),
213 unsigned PropertyAttributes = 0);
215 /// createObjCIVar - Create debugging information entry for Objective-C
216 /// instance variable.
217 /// @param Name Member name.
218 /// @param File File where this member is defined.
219 /// @param LineNo Line number.
220 /// @param SizeInBits Member size.
221 /// @param AlignInBits Member alignment.
222 /// @param OffsetInBits Member offset.
223 /// @param Flags Flags to encode member attribute, e.g. private
224 /// @param Ty Parent type.
225 /// @param PropertyNode Property associated with this ivar.
226 DIType createObjCIVar(StringRef Name, DIFile File,
227 unsigned LineNo, uint64_t SizeInBits,
228 uint64_t AlignInBits, uint64_t OffsetInBits,
229 unsigned Flags, DIType Ty,
230 MDNode *PropertyNode);
232 /// createObjCProperty - Create debugging information entry for Objective-C
234 /// @param Name Property name.
235 /// @param File File where this property is defined.
236 /// @param LineNumber Line number.
237 /// @param GetterName Name of the Objective C property getter selector.
238 /// @param SetterName Name of the Objective C property setter selector.
239 /// @param PropertyAttributes Objective C property attributes.
241 DIObjCProperty createObjCProperty(StringRef Name,
242 DIFile File, unsigned LineNumber,
243 StringRef GetterName,
244 StringRef SetterName,
245 unsigned PropertyAttributes,
248 /// createClassType - Create debugging information entry for a class.
249 /// @param Scope Scope in which this class is defined.
250 /// @param Name class name.
251 /// @param File File where this member is defined.
252 /// @param LineNumber Line number.
253 /// @param SizeInBits Member size.
254 /// @param AlignInBits Member alignment.
255 /// @param OffsetInBits Member offset.
256 /// @param Flags Flags to encode member attribute, e.g. private
257 /// @param Elements class members.
258 /// @param VTableHolder Debug info of the base class that contains vtable
259 /// for this type. This is used in
260 /// DW_AT_containing_type. See DWARF documentation
262 /// @param TemplateParms Template type parameters.
263 DIType createClassType(DIDescriptor Scope, StringRef Name, DIFile File,
264 unsigned LineNumber, uint64_t SizeInBits,
265 uint64_t AlignInBits, uint64_t OffsetInBits,
266 unsigned Flags, DIType DerivedFrom,
267 DIArray Elements, MDNode *VTableHolder = 0,
268 MDNode *TemplateParms = 0);
270 /// createStructType - Create debugging information entry for a struct.
271 /// @param Scope Scope in which this struct is defined.
272 /// @param Name Struct name.
273 /// @param File File where this member is defined.
274 /// @param LineNumber Line number.
275 /// @param SizeInBits Member size.
276 /// @param AlignInBits Member alignment.
277 /// @param Flags Flags to encode member attribute, e.g. private
278 /// @param Elements Struct elements.
279 /// @param RunTimeLang Optional parameter, Objective-C runtime version.
280 DIType createStructType(DIDescriptor Scope, StringRef Name, DIFile File,
281 unsigned LineNumber, uint64_t SizeInBits,
282 uint64_t AlignInBits, unsigned Flags,
283 DIArray Elements, unsigned RunTimeLang = 0);
285 /// createUnionType - Create debugging information entry for an union.
286 /// @param Scope Scope in which this union is defined.
287 /// @param Name Union name.
288 /// @param File File where this member is defined.
289 /// @param LineNumber Line number.
290 /// @param SizeInBits Member size.
291 /// @param AlignInBits Member alignment.
292 /// @param Flags Flags to encode member attribute, e.g. private
293 /// @param Elements Union elements.
294 /// @param RunTimeLang Optional parameter, Objective-C runtime version.
295 DIType createUnionType(DIDescriptor Scope, StringRef Name, DIFile File,
296 unsigned LineNumber, uint64_t SizeInBits,
297 uint64_t AlignInBits, unsigned Flags,
298 DIArray Elements, unsigned RunTimeLang = 0);
300 /// createTemplateTypeParameter - Create debugging information for template
302 /// @param Scope Scope in which this type is defined.
303 /// @param Name Type parameter name.
304 /// @param Ty Parameter type.
305 /// @param File File where this type parameter is defined.
306 /// @param LineNo Line number.
307 /// @param ColumnNo Column Number.
308 DITemplateTypeParameter
309 createTemplateTypeParameter(DIDescriptor Scope, StringRef Name, DIType Ty,
310 MDNode *File = 0, unsigned LineNo = 0,
311 unsigned ColumnNo = 0);
313 /// createTemplateValueParameter - Create debugging information for template
315 /// @param Scope Scope in which this type is defined.
316 /// @param Name Value parameter name.
317 /// @param Ty Parameter type.
318 /// @param Value Constant parameter value.
319 /// @param File File where this type parameter is defined.
320 /// @param LineNo Line number.
321 /// @param ColumnNo Column Number.
322 DITemplateValueParameter
323 createTemplateValueParameter(DIDescriptor Scope, StringRef Name, DIType Ty,
325 MDNode *File = 0, unsigned LineNo = 0,
326 unsigned ColumnNo = 0);
328 /// createArrayType - Create debugging information entry for an array.
329 /// @param Size Array size.
330 /// @param AlignInBits Alignment.
331 /// @param Ty Element type.
332 /// @param Subscripts Subscripts.
333 DIType createArrayType(uint64_t Size, uint64_t AlignInBits,
334 DIType Ty, DIArray Subscripts);
336 /// createVectorType - Create debugging information entry for a vector type.
337 /// @param Size Array size.
338 /// @param AlignInBits Alignment.
339 /// @param Ty Element type.
340 /// @param Subscripts Subscripts.
341 DIType createVectorType(uint64_t Size, uint64_t AlignInBits,
342 DIType Ty, DIArray Subscripts);
344 /// createEnumerationType - Create debugging information entry for an
346 /// @param Scope Scope in which this enumeration is defined.
347 /// @param Name Union name.
348 /// @param File File where this member is defined.
349 /// @param LineNumber Line number.
350 /// @param SizeInBits Member size.
351 /// @param AlignInBits Member alignment.
352 /// @param Elements Enumeration elements.
353 DIType createEnumerationType(DIDescriptor Scope, StringRef Name,
354 DIFile File, unsigned LineNumber,
355 uint64_t SizeInBits, uint64_t AlignInBits,
356 DIArray Elements, DIType ClassType);
358 /// createSubroutineType - Create subroutine type.
359 /// @param File File in which this subroutine is defined.
360 /// @param ParameterTypes An array of subroutine parameter types. This
361 /// includes return type at 0th index.
362 DIType createSubroutineType(DIFile File, DIArray ParameterTypes);
364 /// createArtificialType - Create a new DIType with "artificial" flag set.
365 DIType createArtificialType(DIType Ty);
367 /// createObjectPointerType - Create a new DIType with the "object pointer"
369 DIType createObjectPointerType(DIType Ty);
371 /// createTemporaryType - Create a temporary forward-declared type.
372 DIType createTemporaryType();
373 DIType createTemporaryType(DIFile F);
375 /// createForwardDecl - Create a temporary forward-declared type.
376 DIType createForwardDecl(unsigned Tag, StringRef Name, DIDescriptor Scope,
377 DIFile F, unsigned Line, unsigned RuntimeLang = 0,
378 uint64_t SizeInBits = 0, uint64_t AlignInBits = 0);
380 /// retainType - Retain DIType in a module even if it is not referenced
381 /// through debug info anchors.
382 void retainType(DIType T);
384 /// createUnspecifiedParameter - Create unspeicified type descriptor
385 /// for a subroutine type.
386 DIDescriptor createUnspecifiedParameter();
388 /// getOrCreateArray - Get a DIArray, create one if required.
389 DIArray getOrCreateArray(ArrayRef<Value *> Elements);
391 /// getOrCreateSubrange - Create a descriptor for a value range. This
392 /// implicitly uniques the values returned.
393 DISubrange getOrCreateSubrange(int64_t Lo, int64_t Count);
395 /// createGlobalVariable - Create a new descriptor for the specified global.
396 /// @param Name Name of the variable.
397 /// @param File File where this variable is defined.
398 /// @param LineNo Line number.
399 /// @param Ty Variable Type.
400 /// @param isLocalToUnit Boolean flag indicate whether this variable is
401 /// externally visible or not.
402 /// @param Val llvm::Value of the variable.
404 createGlobalVariable(StringRef Name, DIFile File, unsigned LineNo,
405 DIType Ty, bool isLocalToUnit, llvm::Value *Val);
408 /// createStaticVariable - Create a new descriptor for the specified
410 /// @param Context Variable scope.
411 /// @param Name Name of the variable.
412 /// @param LinkageName Mangled name of the variable.
413 /// @param File File where this variable is defined.
414 /// @param LineNo Line number.
415 /// @param Ty Variable Type.
416 /// @param isLocalToUnit Boolean flag indicate whether this variable is
417 /// externally visible or not.
418 /// @param Val llvm::Value of the variable.
419 /// @param Decl Reference to the corresponding declaration.
421 createStaticVariable(DIDescriptor Context, StringRef Name,
422 StringRef LinkageName, DIFile File, unsigned LineNo,
423 DIType Ty, bool isLocalToUnit, llvm::Value *Val,
424 MDNode *Decl = NULL);
427 /// createLocalVariable - Create a new descriptor for the specified
429 /// @param Tag Dwarf TAG. Usually DW_TAG_auto_variable or
430 /// DW_TAG_arg_variable.
431 /// @param Scope Variable scope.
432 /// @param Name Variable name.
433 /// @param File File where this variable is defined.
434 /// @param LineNo Line number.
435 /// @param Ty Variable Type
436 /// @param AlwaysPreserve Boolean. Set to true if debug info for this
437 /// variable should be preserved in optimized build.
438 /// @param Flags Flags, e.g. artificial variable.
439 /// @param ArgNo If this variable is an arugment then this argument's
440 /// number. 1 indicates 1st argument.
441 DIVariable createLocalVariable(unsigned Tag, DIDescriptor Scope,
443 DIFile File, unsigned LineNo,
444 DIType Ty, bool AlwaysPreserve = false,
449 /// createComplexVariable - Create a new descriptor for the specified
450 /// variable which has a complex address expression for its address.
451 /// @param Tag Dwarf TAG. Usually DW_TAG_auto_variable or
452 /// DW_TAG_arg_variable.
453 /// @param Scope Variable scope.
454 /// @param Name Variable name.
455 /// @param F File where this variable is defined.
456 /// @param LineNo Line number.
457 /// @param Ty Variable Type
458 /// @param Addr An array of complex address operations.
459 /// @param ArgNo If this variable is an arugment then this argument's
460 /// number. 1 indicates 1st argument.
461 DIVariable createComplexVariable(unsigned Tag, DIDescriptor Scope,
462 StringRef Name, DIFile F, unsigned LineNo,
463 DIType Ty, ArrayRef<Value *> Addr,
466 /// createFunction - Create a new descriptor for the specified subprogram.
467 /// See comments in DISubprogram for descriptions of these fields.
468 /// @param Scope Function scope.
469 /// @param Name Function name.
470 /// @param LinkageName Mangled function name.
471 /// @param File File where this variable is defined.
472 /// @param LineNo Line number.
473 /// @param Ty Function type.
474 /// @param isLocalToUnit True if this function is not externally visible..
475 /// @param isDefinition True if this is a function definition.
476 /// @param ScopeLine Set to the beginning of the scope this starts
477 /// @param Flags e.g. is this function prototyped or not.
478 /// This flags are used to emit dwarf attributes.
479 /// @param isOptimized True if optimization is ON.
480 /// @param Fn llvm::Function pointer.
481 /// @param TParam Function template parameters.
482 DISubprogram createFunction(DIDescriptor Scope, StringRef Name,
483 StringRef LinkageName,
484 DIFile File, unsigned LineNo,
485 DIType Ty, bool isLocalToUnit,
489 bool isOptimized = false,
494 /// createMethod - Create a new descriptor for the specified C++ method.
495 /// See comments in DISubprogram for descriptions of these fields.
496 /// @param Scope Function scope.
497 /// @param Name Function name.
498 /// @param LinkageName Mangled function name.
499 /// @param File File where this variable is defined.
500 /// @param LineNo Line number.
501 /// @param Ty Function type.
502 /// @param isLocalToUnit True if this function is not externally visible..
503 /// @param isDefinition True if this is a function definition.
504 /// @param Virtuality Attributes describing virtualness. e.g. pure
505 /// virtual function.
506 /// @param VTableIndex Index no of this method in virtual table.
507 /// @param VTableHolder Type that holds vtable.
508 /// @param Flags e.g. is this function prototyped or not.
509 /// This flags are used to emit dwarf attributes.
510 /// @param isOptimized True if optimization is ON.
511 /// @param Fn llvm::Function pointer.
512 /// @param TParam Function template parameters.
513 DISubprogram createMethod(DIDescriptor Scope, StringRef Name,
514 StringRef LinkageName,
515 DIFile File, unsigned LineNo,
516 DIType Ty, bool isLocalToUnit,
518 unsigned Virtuality = 0, unsigned VTableIndex = 0,
519 MDNode *VTableHolder = 0,
521 bool isOptimized = false,
525 /// createNameSpace - This creates new descriptor for a namespace
526 /// with the specified parent scope.
527 /// @param Scope Namespace scope
528 /// @param Name Name of this namespace
529 /// @param File Source file
530 /// @param LineNo Line number
531 DINameSpace createNameSpace(DIDescriptor Scope, StringRef Name,
532 DIFile File, unsigned LineNo);
535 /// createLexicalBlockFile - This creates a descriptor for a lexical
536 /// block with a new file attached. This merely extends the existing
537 /// lexical block as it crosses a file.
538 /// @param Scope Lexical block.
539 /// @param File Source file.
540 DILexicalBlockFile createLexicalBlockFile(DIDescriptor Scope,
543 /// createLexicalBlock - This creates a descriptor for a lexical block
544 /// with the specified parent context.
545 /// @param Scope Parent lexical scope.
546 /// @param File Source file
547 /// @param Line Line number
548 /// @param Col Column number
549 DILexicalBlock createLexicalBlock(DIDescriptor Scope, DIFile File,
550 unsigned Line, unsigned Col);
552 /// insertDeclare - Insert a new llvm.dbg.declare intrinsic call.
553 /// @param Storage llvm::Value of the variable
554 /// @param VarInfo Variable's debug info descriptor.
555 /// @param InsertAtEnd Location for the new intrinsic.
556 Instruction *insertDeclare(llvm::Value *Storage, DIVariable VarInfo,
557 BasicBlock *InsertAtEnd);
559 /// insertDeclare - Insert a new llvm.dbg.declare intrinsic call.
560 /// @param Storage llvm::Value of the variable
561 /// @param VarInfo Variable's debug info descriptor.
562 /// @param InsertBefore Location for the new intrinsic.
563 Instruction *insertDeclare(llvm::Value *Storage, DIVariable VarInfo,
564 Instruction *InsertBefore);
567 /// insertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
568 /// @param Val llvm::Value of the variable
569 /// @param Offset Offset
570 /// @param VarInfo Variable's debug info descriptor.
571 /// @param InsertAtEnd Location for the new intrinsic.
572 Instruction *insertDbgValueIntrinsic(llvm::Value *Val, uint64_t Offset,
574 BasicBlock *InsertAtEnd);
576 /// insertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
577 /// @param Val llvm::Value of the variable
578 /// @param Offset Offset
579 /// @param VarInfo Variable's debug info descriptor.
580 /// @param InsertBefore Location for the new intrinsic.
581 Instruction *insertDbgValueIntrinsic(llvm::Value *Val, uint64_t Offset,
583 Instruction *InsertBefore);
586 } // end namespace llvm