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"
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 &) LLVM_DELETED_FUNCTION;
67 void operator=(const DIBuilder &) LLVM_DELETED_FUNCTION;
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 /// \brief Create debugging information entry for a pointer to member.
130 /// @param PointeeTy Type pointed to by this pointer.
131 /// @param Class Type for which this pointer points to members of.
132 DIType createMemberPointerType(DIType PointeeTy, DIType Class);
134 /// createReferenceType - Create debugging information entry for a c++
135 /// style reference or rvalue reference type.
136 DIType createReferenceType(unsigned Tag, DIType RTy);
138 /// createTypedef - Create debugging information entry for a typedef.
139 /// @param Ty Original type.
140 /// @param Name Typedef name.
141 /// @param File File where this type is defined.
142 /// @param LineNo Line number.
143 /// @param Context The surrounding context for the typedef.
144 DIType createTypedef(DIType Ty, StringRef Name, DIFile File,
145 unsigned LineNo, DIDescriptor Context);
147 /// createFriend - Create debugging information entry for a 'friend'.
148 DIType createFriend(DIType Ty, DIType FriendTy);
150 /// createInheritance - Create debugging information entry to establish
151 /// inheritance relationship between two types.
152 /// @param Ty Original type.
153 /// @param BaseTy Base type. Ty is inherits from base.
154 /// @param BaseOffset Base offset.
155 /// @param Flags Flags to describe inheritance attribute,
157 DIType createInheritance(DIType Ty, DIType BaseTy, uint64_t BaseOffset,
160 /// createMemberType - Create debugging information entry for a member.
161 /// @param Scope Member scope.
162 /// @param Name Member name.
163 /// @param File File where this member is defined.
164 /// @param LineNo Line number.
165 /// @param SizeInBits Member size.
166 /// @param AlignInBits Member alignment.
167 /// @param OffsetInBits Member offset.
168 /// @param Flags Flags to encode member attribute, e.g. private
169 /// @param Ty Parent type.
170 DIType createMemberType(DIDescriptor Scope, StringRef Name, DIFile File,
171 unsigned LineNo, uint64_t SizeInBits,
172 uint64_t AlignInBits, uint64_t OffsetInBits,
173 unsigned Flags, DIType Ty);
175 /// createObjCIVar - Create debugging information entry for Objective-C
176 /// instance variable.
177 /// @param Name Member name.
178 /// @param File File where this member is defined.
179 /// @param LineNo Line number.
180 /// @param SizeInBits Member size.
181 /// @param AlignInBits Member alignment.
182 /// @param OffsetInBits Member offset.
183 /// @param Flags Flags to encode member attribute, e.g. private
184 /// @param Ty Parent type.
185 /// @param PropertyName Name of the Objective C property associated with
187 /// @param PropertyGetterName Name of the Objective C property getter
189 /// @param PropertySetterName Name of the Objective C property setter
191 /// @param PropertyAttributes Objective C property attributes.
192 DIType createObjCIVar(StringRef Name, DIFile File,
193 unsigned LineNo, uint64_t SizeInBits,
194 uint64_t AlignInBits, uint64_t OffsetInBits,
195 unsigned Flags, DIType Ty,
196 StringRef PropertyName = StringRef(),
197 StringRef PropertyGetterName = StringRef(),
198 StringRef PropertySetterName = StringRef(),
199 unsigned PropertyAttributes = 0);
201 /// createObjCIVar - Create debugging information entry for Objective-C
202 /// instance variable.
203 /// @param Name Member name.
204 /// @param File File where this member is defined.
205 /// @param LineNo Line number.
206 /// @param SizeInBits Member size.
207 /// @param AlignInBits Member alignment.
208 /// @param OffsetInBits Member offset.
209 /// @param Flags Flags to encode member attribute, e.g. private
210 /// @param Ty Parent type.
211 /// @param PropertyNode Property associated with this ivar.
212 DIType createObjCIVar(StringRef Name, DIFile File,
213 unsigned LineNo, uint64_t SizeInBits,
214 uint64_t AlignInBits, uint64_t OffsetInBits,
215 unsigned Flags, DIType Ty,
216 MDNode *PropertyNode);
218 /// createObjCProperty - Create debugging information entry for Objective-C
220 /// @param Name Property name.
221 /// @param File File where this property is defined.
222 /// @param LineNumber Line number.
223 /// @param GetterName Name of the Objective C property getter selector.
224 /// @param SetterName Name of the Objective C property setter selector.
225 /// @param PropertyAttributes Objective C property attributes.
227 DIObjCProperty createObjCProperty(StringRef Name,
228 DIFile File, unsigned LineNumber,
229 StringRef GetterName,
230 StringRef SetterName,
231 unsigned PropertyAttributes,
234 /// createClassType - Create debugging information entry for a class.
235 /// @param Scope Scope in which this class is defined.
236 /// @param Name class name.
237 /// @param File File where this member is defined.
238 /// @param LineNumber Line number.
239 /// @param SizeInBits Member size.
240 /// @param AlignInBits Member alignment.
241 /// @param OffsetInBits Member offset.
242 /// @param Flags Flags to encode member attribute, e.g. private
243 /// @param Elements class members.
244 /// @param VTableHolder Debug info of the base class that contains vtable
245 /// for this type. This is used in
246 /// DW_AT_containing_type. See DWARF documentation
248 /// @param TemplateParms Template type parameters.
249 DIType createClassType(DIDescriptor Scope, StringRef Name, DIFile File,
250 unsigned LineNumber, uint64_t SizeInBits,
251 uint64_t AlignInBits, uint64_t OffsetInBits,
252 unsigned Flags, DIType DerivedFrom,
253 DIArray Elements, MDNode *VTableHolder = 0,
254 MDNode *TemplateParms = 0);
256 /// createStructType - Create debugging information entry for a struct.
257 /// @param Scope Scope in which this struct is defined.
258 /// @param Name Struct name.
259 /// @param File File where this member is defined.
260 /// @param LineNumber Line number.
261 /// @param SizeInBits Member size.
262 /// @param AlignInBits Member alignment.
263 /// @param Flags Flags to encode member attribute, e.g. private
264 /// @param Elements Struct elements.
265 /// @param RunTimeLang Optional parameter, Objective-C runtime version.
266 DIType createStructType(DIDescriptor Scope, StringRef Name, DIFile File,
267 unsigned LineNumber, uint64_t SizeInBits,
268 uint64_t AlignInBits, unsigned Flags,
269 DIArray Elements, unsigned RunTimeLang = 0);
271 /// createUnionType - Create debugging information entry for an union.
272 /// @param Scope Scope in which this union is defined.
273 /// @param Name Union name.
274 /// @param File File where this member is defined.
275 /// @param LineNumber Line number.
276 /// @param SizeInBits Member size.
277 /// @param AlignInBits Member alignment.
278 /// @param Flags Flags to encode member attribute, e.g. private
279 /// @param Elements Union elements.
280 /// @param RunTimeLang Optional parameter, Objective-C runtime version.
281 DIType createUnionType(DIDescriptor Scope, StringRef Name, DIFile File,
282 unsigned LineNumber, uint64_t SizeInBits,
283 uint64_t AlignInBits, unsigned Flags,
284 DIArray Elements, unsigned RunTimeLang = 0);
286 /// createTemplateTypeParameter - Create debugging information for template
288 /// @param Scope Scope in which this type is defined.
289 /// @param Name Type parameter name.
290 /// @param Ty Parameter type.
291 /// @param File File where this type parameter is defined.
292 /// @param LineNo Line number.
293 /// @param ColumnNo Column Number.
294 DITemplateTypeParameter
295 createTemplateTypeParameter(DIDescriptor Scope, StringRef Name, DIType Ty,
296 MDNode *File = 0, unsigned LineNo = 0,
297 unsigned ColumnNo = 0);
299 /// createTemplateValueParameter - Create debugging information for template
301 /// @param Scope Scope in which this type is defined.
302 /// @param Name Value parameter name.
303 /// @param Ty Parameter type.
304 /// @param Value Constant parameter value.
305 /// @param File File where this type parameter is defined.
306 /// @param LineNo Line number.
307 /// @param ColumnNo Column Number.
308 DITemplateValueParameter
309 createTemplateValueParameter(DIDescriptor Scope, StringRef Name, DIType Ty,
311 MDNode *File = 0, unsigned LineNo = 0,
312 unsigned ColumnNo = 0);
314 /// createArrayType - Create debugging information entry for an array.
315 /// @param Size Array size.
316 /// @param AlignInBits Alignment.
317 /// @param Ty Element type.
318 /// @param Subscripts Subscripts.
319 DIType createArrayType(uint64_t Size, uint64_t AlignInBits,
320 DIType Ty, DIArray Subscripts);
322 /// createVectorType - Create debugging information entry for a vector type.
323 /// @param Size Array size.
324 /// @param AlignInBits Alignment.
325 /// @param Ty Element type.
326 /// @param Subscripts Subscripts.
327 DIType createVectorType(uint64_t Size, uint64_t AlignInBits,
328 DIType Ty, DIArray Subscripts);
330 /// createEnumerationType - Create debugging information entry for an
332 /// @param Scope Scope in which this enumeration is defined.
333 /// @param Name Union name.
334 /// @param File File where this member is defined.
335 /// @param LineNumber Line number.
336 /// @param SizeInBits Member size.
337 /// @param AlignInBits Member alignment.
338 /// @param Elements Enumeration elements.
339 DIType createEnumerationType(DIDescriptor Scope, StringRef Name,
340 DIFile File, unsigned LineNumber,
341 uint64_t SizeInBits, uint64_t AlignInBits,
342 DIArray Elements, DIType ClassType);
344 /// createSubroutineType - Create subroutine type.
345 /// @param File File in which this subroutine is defined.
346 /// @param ParameterTypes An array of subroutine parameter types. This
347 /// includes return type at 0th index.
348 DIType createSubroutineType(DIFile File, DIArray ParameterTypes);
350 /// createArtificialType - Create a new DIType with "artificial" flag set.
351 DIType createArtificialType(DIType Ty);
353 /// createObjectPointerType - Create a new DIType with the "object pointer"
355 DIType createObjectPointerType(DIType Ty);
357 /// createTemporaryType - Create a temporary forward-declared type.
358 DIType createTemporaryType();
359 DIType createTemporaryType(DIFile F);
361 /// createForwardDecl - Create a temporary forward-declared type.
362 DIType createForwardDecl(unsigned Tag, StringRef Name, DIDescriptor Scope,
363 DIFile F, unsigned Line, unsigned RuntimeLang = 0,
364 uint64_t SizeInBits = 0, uint64_t AlignInBits = 0);
366 /// retainType - Retain DIType in a module even if it is not referenced
367 /// through debug info anchors.
368 void retainType(DIType T);
370 /// createUnspecifiedParameter - Create unspeicified type descriptor
371 /// for a subroutine type.
372 DIDescriptor createUnspecifiedParameter();
374 /// getOrCreateArray - Get a DIArray, create one if required.
375 DIArray getOrCreateArray(ArrayRef<Value *> Elements);
377 /// getOrCreateSubrange - Create a descriptor for a value range. This
378 /// implicitly uniques the values returned.
379 DISubrange getOrCreateSubrange(int64_t Lo, int64_t Count);
381 /// createGlobalVariable - Create a new descriptor for the specified global.
382 /// @param Name Name of the variable.
383 /// @param File File where this variable is defined.
384 /// @param LineNo Line number.
385 /// @param Ty Variable Type.
386 /// @param isLocalToUnit Boolean flag indicate whether this variable is
387 /// externally visible or not.
388 /// @param Val llvm::Value of the variable.
390 createGlobalVariable(StringRef Name, DIFile File, unsigned LineNo,
391 DIType Ty, bool isLocalToUnit, llvm::Value *Val);
394 /// createStaticVariable - Create a new descriptor for the specified
396 /// @param Context Variable scope.
397 /// @param Name Name of the variable.
398 /// @param LinkageName Mangled name of the variable.
399 /// @param File File where this variable is defined.
400 /// @param LineNo Line number.
401 /// @param Ty Variable Type.
402 /// @param isLocalToUnit Boolean flag indicate whether this variable is
403 /// externally visible or not.
404 /// @param Val llvm::Value of the variable.
406 createStaticVariable(DIDescriptor Context, StringRef Name,
407 StringRef LinkageName, DIFile File, unsigned LineNo,
408 DIType Ty, bool isLocalToUnit, llvm::Value *Val);
411 /// createLocalVariable - Create a new descriptor for the specified
413 /// @param Tag Dwarf TAG. Usually DW_TAG_auto_variable or
414 /// DW_TAG_arg_variable.
415 /// @param Scope Variable scope.
416 /// @param Name Variable name.
417 /// @param File File where this variable is defined.
418 /// @param LineNo Line number.
419 /// @param Ty Variable Type
420 /// @param AlwaysPreserve Boolean. Set to true if debug info for this
421 /// variable should be preserved in optimized build.
422 /// @param Flags Flags, e.g. artificial variable.
423 /// @param ArgNo If this variable is an arugment then this argument's
424 /// number. 1 indicates 1st argument.
425 DIVariable createLocalVariable(unsigned Tag, DIDescriptor Scope,
427 DIFile File, unsigned LineNo,
428 DIType Ty, bool AlwaysPreserve = false,
433 /// createComplexVariable - Create a new descriptor for the specified
434 /// variable which has a complex address expression for its address.
435 /// @param Tag Dwarf TAG. Usually DW_TAG_auto_variable or
436 /// DW_TAG_arg_variable.
437 /// @param Scope Variable scope.
438 /// @param Name Variable name.
439 /// @param F File where this variable is defined.
440 /// @param LineNo Line number.
441 /// @param Ty Variable Type
442 /// @param Addr An array of complex address operations.
443 /// @param ArgNo If this variable is an arugment then this argument's
444 /// number. 1 indicates 1st argument.
445 DIVariable createComplexVariable(unsigned Tag, DIDescriptor Scope,
446 StringRef Name, DIFile F, unsigned LineNo,
447 DIType Ty, ArrayRef<Value *> Addr,
450 /// createFunction - Create a new descriptor for the specified subprogram.
451 /// See comments in DISubprogram for descriptions of these fields.
452 /// @param Scope Function scope.
453 /// @param Name Function name.
454 /// @param LinkageName Mangled function name.
455 /// @param File File where this variable is defined.
456 /// @param LineNo Line number.
457 /// @param Ty Function type.
458 /// @param isLocalToUnit True if this function is not externally visible..
459 /// @param isDefinition True if this is a function definition.
460 /// @param ScopeLine Set to the beginning of the scope this starts
461 /// @param Flags e.g. is this function prototyped or not.
462 /// This flags are used to emit dwarf attributes.
463 /// @param isOptimized True if optimization is ON.
464 /// @param Fn llvm::Function pointer.
465 /// @param TParam Function template parameters.
466 DISubprogram createFunction(DIDescriptor Scope, StringRef Name,
467 StringRef LinkageName,
468 DIFile File, unsigned LineNo,
469 DIType Ty, bool isLocalToUnit,
473 bool isOptimized = false,
478 /// createMethod - Create a new descriptor for the specified C++ method.
479 /// See comments in DISubprogram for descriptions of these fields.
480 /// @param Scope Function scope.
481 /// @param Name Function name.
482 /// @param LinkageName Mangled function name.
483 /// @param File File where this variable is defined.
484 /// @param LineNo Line number.
485 /// @param Ty Function type.
486 /// @param isLocalToUnit True if this function is not externally visible..
487 /// @param isDefinition True if this is a function definition.
488 /// @param Virtuality Attributes describing virtualness. e.g. pure
489 /// virtual function.
490 /// @param VTableIndex Index no of this method in virtual table.
491 /// @param VTableHolder Type that holds vtable.
492 /// @param Flags e.g. is this function prototyped or not.
493 /// This flags are used to emit dwarf attributes.
494 /// @param isOptimized True if optimization is ON.
495 /// @param Fn llvm::Function pointer.
496 /// @param TParam Function template parameters.
497 DISubprogram createMethod(DIDescriptor Scope, StringRef Name,
498 StringRef LinkageName,
499 DIFile File, unsigned LineNo,
500 DIType Ty, bool isLocalToUnit,
502 unsigned Virtuality = 0, unsigned VTableIndex = 0,
503 MDNode *VTableHolder = 0,
505 bool isOptimized = false,
509 /// createNameSpace - This creates new descriptor for a namespace
510 /// with the specified parent scope.
511 /// @param Scope Namespace scope
512 /// @param Name Name of this namespace
513 /// @param File Source file
514 /// @param LineNo Line number
515 DINameSpace createNameSpace(DIDescriptor Scope, StringRef Name,
516 DIFile File, unsigned LineNo);
519 /// createLexicalBlockFile - This creates a descriptor for a lexical
520 /// block with a new file attached. This merely extends the existing
521 /// lexical block as it crosses a file.
522 /// @param Scope Lexical block.
523 /// @param File Source file.
524 DILexicalBlockFile createLexicalBlockFile(DIDescriptor Scope,
527 /// createLexicalBlock - This creates a descriptor for a lexical block
528 /// with the specified parent context.
529 /// @param Scope Parent lexical scope.
530 /// @param File Source file
531 /// @param Line Line number
532 /// @param Col Column number
533 DILexicalBlock createLexicalBlock(DIDescriptor Scope, DIFile File,
534 unsigned Line, unsigned Col);
536 /// insertDeclare - Insert a new llvm.dbg.declare intrinsic call.
537 /// @param Storage llvm::Value of the variable
538 /// @param VarInfo Variable's debug info descriptor.
539 /// @param InsertAtEnd Location for the new intrinsic.
540 Instruction *insertDeclare(llvm::Value *Storage, DIVariable VarInfo,
541 BasicBlock *InsertAtEnd);
543 /// insertDeclare - Insert a new llvm.dbg.declare intrinsic call.
544 /// @param Storage llvm::Value of the variable
545 /// @param VarInfo Variable's debug info descriptor.
546 /// @param InsertBefore Location for the new intrinsic.
547 Instruction *insertDeclare(llvm::Value *Storage, DIVariable VarInfo,
548 Instruction *InsertBefore);
551 /// insertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
552 /// @param Val llvm::Value of the variable
553 /// @param Offset Offset
554 /// @param VarInfo Variable's debug info descriptor.
555 /// @param InsertAtEnd Location for the new intrinsic.
556 Instruction *insertDbgValueIntrinsic(llvm::Value *Val, uint64_t Offset,
558 BasicBlock *InsertAtEnd);
560 /// insertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
561 /// @param Val llvm::Value of the variable
562 /// @param Offset Offset
563 /// @param VarInfo Variable's debug info descriptor.
564 /// @param InsertBefore Location for the new intrinsic.
565 Instruction *insertDbgValueIntrinsic(llvm::Value *Val, uint64_t Offset,
567 Instruction *InsertBefore);
570 } // end namespace llvm