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 /// createStaticMemberType - Create debugging information entry for a
176 /// C++ static data member.
177 /// @param Scope Member scope.
178 /// @param Name Member name.
179 /// @param File File where this member is declared.
180 /// @param LineNo Line number.
181 /// @param Ty Type of the static member.
182 /// @param Flags Flags to encode member attribute, e.g. private.
183 /// @param Val Const initializer of the member.
184 DIType createStaticMemberType(DIDescriptor Scope, StringRef Name,
185 DIFile File, unsigned LineNo, DIType Ty,
186 unsigned Flags, llvm::Value *Val);
188 /// createObjCIVar - Create debugging information entry for Objective-C
189 /// instance variable.
190 /// @param Name Member name.
191 /// @param File File where this member is defined.
192 /// @param LineNo Line number.
193 /// @param SizeInBits Member size.
194 /// @param AlignInBits Member alignment.
195 /// @param OffsetInBits Member offset.
196 /// @param Flags Flags to encode member attribute, e.g. private
197 /// @param Ty Parent type.
198 /// @param PropertyName Name of the Objective C property associated with
200 /// @param PropertyGetterName Name of the Objective C property getter
202 /// @param PropertySetterName Name of the Objective C property setter
204 /// @param PropertyAttributes Objective C property attributes.
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 StringRef PropertyName = StringRef(),
210 StringRef PropertyGetterName = StringRef(),
211 StringRef PropertySetterName = StringRef(),
212 unsigned PropertyAttributes = 0);
214 /// createObjCIVar - Create debugging information entry for Objective-C
215 /// instance variable.
216 /// @param Name Member name.
217 /// @param File File where this member is defined.
218 /// @param LineNo Line number.
219 /// @param SizeInBits Member size.
220 /// @param AlignInBits Member alignment.
221 /// @param OffsetInBits Member offset.
222 /// @param Flags Flags to encode member attribute, e.g. private
223 /// @param Ty Parent type.
224 /// @param PropertyNode Property associated with this ivar.
225 DIType createObjCIVar(StringRef Name, DIFile File,
226 unsigned LineNo, uint64_t SizeInBits,
227 uint64_t AlignInBits, uint64_t OffsetInBits,
228 unsigned Flags, DIType Ty,
229 MDNode *PropertyNode);
231 /// createObjCProperty - Create debugging information entry for Objective-C
233 /// @param Name Property name.
234 /// @param File File where this property is defined.
235 /// @param LineNumber Line number.
236 /// @param GetterName Name of the Objective C property getter selector.
237 /// @param SetterName Name of the Objective C property setter selector.
238 /// @param PropertyAttributes Objective C property attributes.
240 DIObjCProperty createObjCProperty(StringRef Name,
241 DIFile File, unsigned LineNumber,
242 StringRef GetterName,
243 StringRef SetterName,
244 unsigned PropertyAttributes,
247 /// createClassType - Create debugging information entry for a class.
248 /// @param Scope Scope in which this class is defined.
249 /// @param Name class name.
250 /// @param File File where this member is defined.
251 /// @param LineNumber Line number.
252 /// @param SizeInBits Member size.
253 /// @param AlignInBits Member alignment.
254 /// @param OffsetInBits Member offset.
255 /// @param Flags Flags to encode member attribute, e.g. private
256 /// @param Elements class members.
257 /// @param VTableHolder Debug info of the base class that contains vtable
258 /// for this type. This is used in
259 /// DW_AT_containing_type. See DWARF documentation
261 /// @param TemplateParms Template type parameters.
262 DIType createClassType(DIDescriptor Scope, StringRef Name, DIFile File,
263 unsigned LineNumber, uint64_t SizeInBits,
264 uint64_t AlignInBits, uint64_t OffsetInBits,
265 unsigned Flags, DIType DerivedFrom,
266 DIArray Elements, MDNode *VTableHolder = 0,
267 MDNode *TemplateParms = 0);
269 /// createStructType - Create debugging information entry for a struct.
270 /// @param Scope Scope in which this struct is defined.
271 /// @param Name Struct name.
272 /// @param File File where this member is defined.
273 /// @param LineNumber Line number.
274 /// @param SizeInBits Member size.
275 /// @param AlignInBits Member alignment.
276 /// @param Flags Flags to encode member attribute, e.g. private
277 /// @param Elements Struct elements.
278 /// @param RunTimeLang Optional parameter, Objective-C runtime version.
279 DIType createStructType(DIDescriptor Scope, StringRef Name, DIFile File,
280 unsigned LineNumber, uint64_t SizeInBits,
281 uint64_t AlignInBits, unsigned Flags,
282 DIArray Elements, unsigned RunTimeLang = 0);
284 /// createUnionType - Create debugging information entry for an union.
285 /// @param Scope Scope in which this union is defined.
286 /// @param Name Union name.
287 /// @param File File where this member is defined.
288 /// @param LineNumber Line number.
289 /// @param SizeInBits Member size.
290 /// @param AlignInBits Member alignment.
291 /// @param Flags Flags to encode member attribute, e.g. private
292 /// @param Elements Union elements.
293 /// @param RunTimeLang Optional parameter, Objective-C runtime version.
294 DIType createUnionType(DIDescriptor Scope, StringRef Name, DIFile File,
295 unsigned LineNumber, uint64_t SizeInBits,
296 uint64_t AlignInBits, unsigned Flags,
297 DIArray Elements, unsigned RunTimeLang = 0);
299 /// createTemplateTypeParameter - Create debugging information for template
301 /// @param Scope Scope in which this type is defined.
302 /// @param Name Type parameter name.
303 /// @param Ty Parameter type.
304 /// @param File File where this type parameter is defined.
305 /// @param LineNo Line number.
306 /// @param ColumnNo Column Number.
307 DITemplateTypeParameter
308 createTemplateTypeParameter(DIDescriptor Scope, StringRef Name, DIType Ty,
309 MDNode *File = 0, unsigned LineNo = 0,
310 unsigned ColumnNo = 0);
312 /// createTemplateValueParameter - Create debugging information for template
314 /// @param Scope Scope in which this type is defined.
315 /// @param Name Value parameter name.
316 /// @param Ty Parameter type.
317 /// @param Value Constant parameter value.
318 /// @param File File where this type parameter is defined.
319 /// @param LineNo Line number.
320 /// @param ColumnNo Column Number.
321 DITemplateValueParameter
322 createTemplateValueParameter(DIDescriptor Scope, StringRef Name, DIType Ty,
324 MDNode *File = 0, unsigned LineNo = 0,
325 unsigned ColumnNo = 0);
327 /// createArrayType - Create debugging information entry for an array.
328 /// @param Size Array size.
329 /// @param AlignInBits Alignment.
330 /// @param Ty Element type.
331 /// @param Subscripts Subscripts.
332 DIType createArrayType(uint64_t Size, uint64_t AlignInBits,
333 DIType Ty, DIArray Subscripts);
335 /// createVectorType - Create debugging information entry for a vector type.
336 /// @param Size Array size.
337 /// @param AlignInBits Alignment.
338 /// @param Ty Element type.
339 /// @param Subscripts Subscripts.
340 DIType createVectorType(uint64_t Size, uint64_t AlignInBits,
341 DIType Ty, DIArray Subscripts);
343 /// createEnumerationType - Create debugging information entry for an
345 /// @param Scope Scope in which this enumeration is defined.
346 /// @param Name Union name.
347 /// @param File File where this member is defined.
348 /// @param LineNumber Line number.
349 /// @param SizeInBits Member size.
350 /// @param AlignInBits Member alignment.
351 /// @param Elements Enumeration elements.
352 DIType createEnumerationType(DIDescriptor Scope, StringRef Name,
353 DIFile File, unsigned LineNumber,
354 uint64_t SizeInBits, uint64_t AlignInBits,
355 DIArray Elements, DIType ClassType);
357 /// createSubroutineType - Create subroutine type.
358 /// @param File File in which this subroutine is defined.
359 /// @param ParameterTypes An array of subroutine parameter types. This
360 /// includes return type at 0th index.
361 DIType createSubroutineType(DIFile File, DIArray ParameterTypes);
363 /// createArtificialType - Create a new DIType with "artificial" flag set.
364 DIType createArtificialType(DIType Ty);
366 /// createObjectPointerType - Create a new DIType with the "object pointer"
368 DIType createObjectPointerType(DIType Ty);
370 /// createTemporaryType - Create a temporary forward-declared type.
371 DIType createTemporaryType();
372 DIType createTemporaryType(DIFile F);
374 /// createForwardDecl - Create a temporary forward-declared type.
375 DIType createForwardDecl(unsigned Tag, StringRef Name, DIDescriptor Scope,
376 DIFile F, unsigned Line, unsigned RuntimeLang = 0,
377 uint64_t SizeInBits = 0, uint64_t AlignInBits = 0);
379 /// retainType - Retain DIType in a module even if it is not referenced
380 /// through debug info anchors.
381 void retainType(DIType T);
383 /// createUnspecifiedParameter - Create unspeicified type descriptor
384 /// for a subroutine type.
385 DIDescriptor createUnspecifiedParameter();
387 /// getOrCreateArray - Get a DIArray, create one if required.
388 DIArray getOrCreateArray(ArrayRef<Value *> Elements);
390 /// getOrCreateSubrange - Create a descriptor for a value range. This
391 /// implicitly uniques the values returned.
392 DISubrange getOrCreateSubrange(int64_t Lo, int64_t Count);
394 /// createGlobalVariable - Create a new descriptor for the specified global.
395 /// @param Name Name of the variable.
396 /// @param File File where this variable is defined.
397 /// @param LineNo Line number.
398 /// @param Ty Variable Type.
399 /// @param isLocalToUnit Boolean flag indicate whether this variable is
400 /// externally visible or not.
401 /// @param Val llvm::Value of the variable.
403 createGlobalVariable(StringRef Name, DIFile File, unsigned LineNo,
404 DIType Ty, bool isLocalToUnit, llvm::Value *Val);
407 /// createStaticVariable - Create a new descriptor for the specified
409 /// @param Context Variable scope.
410 /// @param Name Name of the variable.
411 /// @param LinkageName Mangled name of the variable.
412 /// @param File File where this variable is defined.
413 /// @param LineNo Line number.
414 /// @param Ty Variable Type.
415 /// @param isLocalToUnit Boolean flag indicate whether this variable is
416 /// externally visible or not.
417 /// @param Val llvm::Value of the variable.
418 /// @param Decl Reference to the corresponding declaration.
420 createStaticVariable(DIDescriptor Context, StringRef Name,
421 StringRef LinkageName, DIFile File, unsigned LineNo,
422 DIType Ty, bool isLocalToUnit, llvm::Value *Val,
423 MDNode *Decl = NULL);
426 /// createLocalVariable - Create a new descriptor for the specified
428 /// @param Tag Dwarf TAG. Usually DW_TAG_auto_variable or
429 /// DW_TAG_arg_variable.
430 /// @param Scope Variable scope.
431 /// @param Name Variable name.
432 /// @param File File where this variable is defined.
433 /// @param LineNo Line number.
434 /// @param Ty Variable Type
435 /// @param AlwaysPreserve Boolean. Set to true if debug info for this
436 /// variable should be preserved in optimized build.
437 /// @param Flags Flags, e.g. artificial variable.
438 /// @param ArgNo If this variable is an arugment then this argument's
439 /// number. 1 indicates 1st argument.
440 DIVariable createLocalVariable(unsigned Tag, DIDescriptor Scope,
442 DIFile File, unsigned LineNo,
443 DIType Ty, bool AlwaysPreserve = false,
448 /// createComplexVariable - Create a new descriptor for the specified
449 /// variable which has a complex address expression for its address.
450 /// @param Tag Dwarf TAG. Usually DW_TAG_auto_variable or
451 /// DW_TAG_arg_variable.
452 /// @param Scope Variable scope.
453 /// @param Name Variable name.
454 /// @param F File where this variable is defined.
455 /// @param LineNo Line number.
456 /// @param Ty Variable Type
457 /// @param Addr An array of complex address operations.
458 /// @param ArgNo If this variable is an arugment then this argument's
459 /// number. 1 indicates 1st argument.
460 DIVariable createComplexVariable(unsigned Tag, DIDescriptor Scope,
461 StringRef Name, DIFile F, unsigned LineNo,
462 DIType Ty, ArrayRef<Value *> Addr,
465 /// createFunction - Create a new descriptor for the specified subprogram.
466 /// See comments in DISubprogram for descriptions of these fields.
467 /// @param Scope Function scope.
468 /// @param Name Function name.
469 /// @param LinkageName Mangled function name.
470 /// @param File File where this variable is defined.
471 /// @param LineNo Line number.
472 /// @param Ty Function type.
473 /// @param isLocalToUnit True if this function is not externally visible..
474 /// @param isDefinition True if this is a function definition.
475 /// @param ScopeLine Set to the beginning of the scope this starts
476 /// @param Flags e.g. is this function prototyped or not.
477 /// This flags are used to emit dwarf attributes.
478 /// @param isOptimized True if optimization is ON.
479 /// @param Fn llvm::Function pointer.
480 /// @param TParam Function template parameters.
481 DISubprogram createFunction(DIDescriptor Scope, StringRef Name,
482 StringRef LinkageName,
483 DIFile File, unsigned LineNo,
484 DIType Ty, bool isLocalToUnit,
488 bool isOptimized = false,
493 /// createMethod - Create a new descriptor for the specified C++ method.
494 /// See comments in DISubprogram for descriptions of these fields.
495 /// @param Scope Function scope.
496 /// @param Name Function name.
497 /// @param LinkageName Mangled function name.
498 /// @param File File where this variable is defined.
499 /// @param LineNo Line number.
500 /// @param Ty Function type.
501 /// @param isLocalToUnit True if this function is not externally visible..
502 /// @param isDefinition True if this is a function definition.
503 /// @param Virtuality Attributes describing virtualness. e.g. pure
504 /// virtual function.
505 /// @param VTableIndex Index no of this method in virtual table.
506 /// @param VTableHolder Type that holds vtable.
507 /// @param Flags e.g. is this function prototyped or not.
508 /// This flags are used to emit dwarf attributes.
509 /// @param isOptimized True if optimization is ON.
510 /// @param Fn llvm::Function pointer.
511 /// @param TParam Function template parameters.
512 DISubprogram createMethod(DIDescriptor Scope, StringRef Name,
513 StringRef LinkageName,
514 DIFile File, unsigned LineNo,
515 DIType Ty, bool isLocalToUnit,
517 unsigned Virtuality = 0, unsigned VTableIndex = 0,
518 MDNode *VTableHolder = 0,
520 bool isOptimized = false,
524 /// createNameSpace - This creates new descriptor for a namespace
525 /// with the specified parent scope.
526 /// @param Scope Namespace scope
527 /// @param Name Name of this namespace
528 /// @param File Source file
529 /// @param LineNo Line number
530 DINameSpace createNameSpace(DIDescriptor Scope, StringRef Name,
531 DIFile File, unsigned LineNo);
534 /// createLexicalBlockFile - This creates a descriptor for a lexical
535 /// block with a new file attached. This merely extends the existing
536 /// lexical block as it crosses a file.
537 /// @param Scope Lexical block.
538 /// @param File Source file.
539 DILexicalBlockFile createLexicalBlockFile(DIDescriptor Scope,
542 /// createLexicalBlock - This creates a descriptor for a lexical block
543 /// with the specified parent context.
544 /// @param Scope Parent lexical scope.
545 /// @param File Source file
546 /// @param Line Line number
547 /// @param Col Column number
548 DILexicalBlock createLexicalBlock(DIDescriptor Scope, DIFile File,
549 unsigned Line, unsigned Col);
551 /// insertDeclare - Insert a new llvm.dbg.declare intrinsic call.
552 /// @param Storage llvm::Value of the variable
553 /// @param VarInfo Variable's debug info descriptor.
554 /// @param InsertAtEnd Location for the new intrinsic.
555 Instruction *insertDeclare(llvm::Value *Storage, DIVariable VarInfo,
556 BasicBlock *InsertAtEnd);
558 /// insertDeclare - Insert a new llvm.dbg.declare intrinsic call.
559 /// @param Storage llvm::Value of the variable
560 /// @param VarInfo Variable's debug info descriptor.
561 /// @param InsertBefore Location for the new intrinsic.
562 Instruction *insertDeclare(llvm::Value *Storage, DIVariable VarInfo,
563 Instruction *InsertBefore);
566 /// insertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
567 /// @param Val llvm::Value of the variable
568 /// @param Offset Offset
569 /// @param VarInfo Variable's debug info descriptor.
570 /// @param InsertAtEnd Location for the new intrinsic.
571 Instruction *insertDbgValueIntrinsic(llvm::Value *Val, uint64_t Offset,
573 BasicBlock *InsertAtEnd);
575 /// insertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
576 /// @param Val llvm::Value of the variable
577 /// @param Offset Offset
578 /// @param VarInfo Variable's debug info descriptor.
579 /// @param InsertBefore Location for the new intrinsic.
580 Instruction *insertDbgValueIntrinsic(llvm::Value *Val, uint64_t Offset,
582 Instruction *InsertBefore);
585 } // end namespace llvm