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"
32 class DICompositeType;
39 class DIGlobalVariable;
43 class DILexicalBlockFile;
46 class DITemplateTypeParameter;
47 class DITemplateValueParameter;
53 LLVMContext & VMContext;
56 MDNode *TempEnumTypes;
57 MDNode *TempRetainTypes;
58 MDNode *TempSubprograms;
61 Function *DeclareFn; // llvm.dbg.declare
62 Function *ValueFn; // llvm.dbg.value
64 SmallVector<Value *, 4> AllEnumTypes;
65 SmallVector<Value *, 4> AllRetainTypes;
66 SmallVector<Value *, 4> AllSubprograms;
67 SmallVector<Value *, 4> AllGVs;
69 DIBuilder(const DIBuilder &) LLVM_DELETED_FUNCTION;
70 void operator=(const DIBuilder &) LLVM_DELETED_FUNCTION;
73 explicit DIBuilder(Module &M);
74 const MDNode *getCU() { return TheCU; }
75 enum ComplexAddrKind { OpPlus=1, OpDeref };
77 /// finalize - Construct any deferred debug info descriptors.
80 /// createCompileUnit - A CompileUnit provides an anchor for all debugging
81 /// information generated during this instance of compilation.
82 /// @param Lang Source programming language, eg. dwarf::DW_LANG_C99
83 /// @param File File name
84 /// @param Dir Directory
85 /// @param Producer String identify producer of debugging information.
86 /// Usuall this is a compiler version string.
87 /// @param isOptimized A boolean flag which indicates whether optimization
89 /// @param Flags This string lists command line options. This string is
90 /// directly embedded in debug info output which may be used
91 /// by a tool analyzing generated debugging information.
92 /// @param RV This indicates runtime version for languages like
94 /// @param SplitName The name of the file that we'll split debug info out
96 void createCompileUnit(unsigned Lang, StringRef File, StringRef Dir,
97 StringRef Producer, bool isOptimized,
98 StringRef Flags, unsigned RV,
99 StringRef SplitName = StringRef());
101 /// createFile - Create a file descriptor to hold debugging information
103 DIFile createFile(StringRef Filename, StringRef Directory);
105 /// createEnumerator - Create a single enumerator value.
106 DIEnumerator createEnumerator(StringRef Name, uint64_t Val);
108 /// createNullPtrType - Create C++0x nullptr type.
109 DIType createNullPtrType(StringRef Name);
111 /// createBasicType - Create debugging information entry for a basic
113 /// @param Name Type name.
114 /// @param SizeInBits Size of the type.
115 /// @param AlignInBits Type alignment.
116 /// @param Encoding DWARF encoding code, e.g. dwarf::DW_ATE_float.
117 DIBasicType createBasicType(StringRef Name, uint64_t SizeInBits,
118 uint64_t AlignInBits, unsigned Encoding);
120 /// createQualifiedType - Create debugging information entry for a qualified
121 /// type, e.g. 'const int'.
122 /// @param Tag Tag identifing type, e.g. dwarf::TAG_volatile_type
123 /// @param FromTy Base Type.
124 DIDerivedType createQualifiedType(unsigned Tag, DIType FromTy);
126 /// createPointerType - Create debugging information entry for a pointer.
127 /// @param PointeeTy Type pointed by this pointer.
128 /// @param SizeInBits Size.
129 /// @param AlignInBits Alignment. (optional)
130 /// @param Name Pointer type name. (optional)
132 createPointerType(DIType PointeeTy, uint64_t SizeInBits,
133 uint64_t AlignInBits = 0, StringRef Name = StringRef());
135 /// \brief Create debugging information entry for a pointer to member.
136 /// @param PointeeTy Type pointed to by this pointer.
137 /// @param Class Type for which this pointer points to members of.
138 DIDerivedType createMemberPointerType(DIType PointeeTy, DIType Class);
140 /// createReferenceType - Create debugging information entry for a c++
141 /// style reference or rvalue reference type.
142 DIDerivedType createReferenceType(unsigned Tag, DIType RTy);
144 /// createTypedef - Create debugging information entry for a typedef.
145 /// @param Ty Original type.
146 /// @param Name Typedef name.
147 /// @param File File where this type is defined.
148 /// @param LineNo Line number.
149 /// @param Context The surrounding context for the typedef.
150 DIDerivedType createTypedef(DIType Ty, StringRef Name, DIFile File,
151 unsigned LineNo, DIDescriptor Context);
153 /// createFriend - Create debugging information entry for a 'friend'.
154 DIType createFriend(DIType Ty, DIType FriendTy);
156 /// createInheritance - Create debugging information entry to establish
157 /// inheritance relationship between two types.
158 /// @param Ty Original type.
159 /// @param BaseTy Base type. Ty is inherits from base.
160 /// @param BaseOffset Base offset.
161 /// @param Flags Flags to describe inheritance attribute,
163 DIDerivedType createInheritance(DIType Ty, DIType BaseTy,
164 uint64_t BaseOffset, unsigned Flags);
166 /// createMemberType - Create debugging information entry for a member.
167 /// @param Scope Member scope.
168 /// @param Name Member name.
169 /// @param File File where this member is defined.
170 /// @param LineNo Line number.
171 /// @param SizeInBits Member size.
172 /// @param AlignInBits Member alignment.
173 /// @param OffsetInBits Member offset.
174 /// @param Flags Flags to encode member attribute, e.g. private
175 /// @param Ty Parent type.
177 createMemberType(DIDescriptor Scope, StringRef Name, DIFile File,
178 unsigned LineNo, uint64_t SizeInBits, uint64_t AlignInBits,
179 uint64_t OffsetInBits, unsigned Flags, DIType Ty);
181 /// createStaticMemberType - Create debugging information entry for a
182 /// C++ static data member.
183 /// @param Scope Member scope.
184 /// @param Name Member name.
185 /// @param File File where this member is declared.
186 /// @param LineNo Line number.
187 /// @param Ty Type of the static member.
188 /// @param Flags Flags to encode member attribute, e.g. private.
189 /// @param Val Const initializer of the member.
190 DIType createStaticMemberType(DIDescriptor Scope, StringRef Name,
191 DIFile File, unsigned LineNo, DIType Ty,
192 unsigned Flags, llvm::Value *Val);
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 PropertyName Name of the Objective C property associated with
206 /// @param PropertyGetterName Name of the Objective C property getter
208 /// @param PropertySetterName Name of the Objective C property setter
210 /// @param PropertyAttributes Objective C property attributes.
211 DIType createObjCIVar(StringRef Name, DIFile File,
212 unsigned LineNo, uint64_t SizeInBits,
213 uint64_t AlignInBits, uint64_t OffsetInBits,
214 unsigned Flags, DIType Ty,
215 StringRef PropertyName = StringRef(),
216 StringRef PropertyGetterName = StringRef(),
217 StringRef PropertySetterName = StringRef(),
218 unsigned PropertyAttributes = 0);
220 /// createObjCIVar - Create debugging information entry for Objective-C
221 /// instance variable.
222 /// @param Name Member name.
223 /// @param File File where this member is defined.
224 /// @param LineNo Line number.
225 /// @param SizeInBits Member size.
226 /// @param AlignInBits Member alignment.
227 /// @param OffsetInBits Member offset.
228 /// @param Flags Flags to encode member attribute, e.g. private
229 /// @param Ty Parent type.
230 /// @param PropertyNode Property associated with this ivar.
231 DIType createObjCIVar(StringRef Name, DIFile File,
232 unsigned LineNo, uint64_t SizeInBits,
233 uint64_t AlignInBits, uint64_t OffsetInBits,
234 unsigned Flags, DIType Ty,
235 MDNode *PropertyNode);
237 /// createObjCProperty - Create debugging information entry for Objective-C
239 /// @param Name Property name.
240 /// @param File File where this property is defined.
241 /// @param LineNumber Line number.
242 /// @param GetterName Name of the Objective C property getter selector.
243 /// @param SetterName Name of the Objective C property setter selector.
244 /// @param PropertyAttributes Objective C property attributes.
246 DIObjCProperty createObjCProperty(StringRef Name,
247 DIFile File, unsigned LineNumber,
248 StringRef GetterName,
249 StringRef SetterName,
250 unsigned PropertyAttributes,
253 /// createClassType - Create debugging information entry for a class.
254 /// @param Scope Scope in which this class is defined.
255 /// @param Name class name.
256 /// @param File File where this member is defined.
257 /// @param LineNumber Line number.
258 /// @param SizeInBits Member size.
259 /// @param AlignInBits Member alignment.
260 /// @param OffsetInBits Member offset.
261 /// @param Flags Flags to encode member attribute, e.g. private
262 /// @param Elements class members.
263 /// @param VTableHolder Debug info of the base class that contains vtable
264 /// for this type. This is used in
265 /// DW_AT_containing_type. See DWARF documentation
267 /// @param TemplateParms Template type parameters.
268 DICompositeType createClassType(DIDescriptor Scope, StringRef Name,
269 DIFile File, unsigned LineNumber,
270 uint64_t SizeInBits, uint64_t AlignInBits,
271 uint64_t OffsetInBits, unsigned Flags,
272 DIType DerivedFrom, DIArray Elements,
273 MDNode *VTableHolder = 0,
274 MDNode *TemplateParms = 0);
276 /// createStructType - Create debugging information entry for a struct.
277 /// @param Scope Scope in which this struct is defined.
278 /// @param Name Struct name.
279 /// @param File File where this member is defined.
280 /// @param LineNumber Line number.
281 /// @param SizeInBits Member size.
282 /// @param AlignInBits Member alignment.
283 /// @param Flags Flags to encode member attribute, e.g. private
284 /// @param Elements Struct elements.
285 /// @param RunTimeLang Optional parameter, Objective-C runtime version.
286 DICompositeType createStructType(DIDescriptor Scope, StringRef Name,
287 DIFile File, unsigned LineNumber,
288 uint64_t SizeInBits, uint64_t AlignInBits,
289 unsigned Flags, DIType DerivedFrom,
290 DIArray Elements, unsigned RunTimeLang = 0,
291 MDNode *VTableHolder = 0);
293 /// createUnionType - Create debugging information entry for an union.
294 /// @param Scope Scope in which this union is defined.
295 /// @param Name Union name.
296 /// @param File File where this member is defined.
297 /// @param LineNumber Line number.
298 /// @param SizeInBits Member size.
299 /// @param AlignInBits Member alignment.
300 /// @param Flags Flags to encode member attribute, e.g. private
301 /// @param Elements Union elements.
302 /// @param RunTimeLang Optional parameter, Objective-C runtime version.
303 DICompositeType createUnionType(
304 DIDescriptor Scope, StringRef Name, DIFile File, unsigned LineNumber,
305 uint64_t SizeInBits, uint64_t AlignInBits, unsigned Flags,
306 DIArray Elements, unsigned RunTimeLang = 0);
308 /// createTemplateTypeParameter - Create debugging information for template
310 /// @param Scope Scope in which this type is defined.
311 /// @param Name Type parameter name.
312 /// @param Ty Parameter type.
313 /// @param File File where this type parameter is defined.
314 /// @param LineNo Line number.
315 /// @param ColumnNo Column Number.
316 DITemplateTypeParameter
317 createTemplateTypeParameter(DIDescriptor Scope, StringRef Name, DIType Ty,
318 MDNode *File = 0, unsigned LineNo = 0,
319 unsigned ColumnNo = 0);
321 /// createTemplateValueParameter - Create debugging information for template
323 /// @param Scope Scope in which this type is defined.
324 /// @param Name Value parameter name.
325 /// @param Ty Parameter type.
326 /// @param Value Constant parameter value.
327 /// @param File File where this type parameter is defined.
328 /// @param LineNo Line number.
329 /// @param ColumnNo Column Number.
330 DITemplateValueParameter
331 createTemplateValueParameter(DIDescriptor Scope, StringRef Name, DIType Ty,
333 MDNode *File = 0, unsigned LineNo = 0,
334 unsigned ColumnNo = 0);
336 /// createArrayType - Create debugging information entry for an array.
337 /// @param Size Array size.
338 /// @param AlignInBits Alignment.
339 /// @param Ty Element type.
340 /// @param Subscripts Subscripts.
341 DICompositeType createArrayType(uint64_t Size, uint64_t AlignInBits,
342 DIType Ty, DIArray Subscripts);
344 /// createVectorType - Create debugging information entry for a vector type.
345 /// @param Size Array size.
346 /// @param AlignInBits Alignment.
347 /// @param Ty Element type.
348 /// @param Subscripts Subscripts.
349 DIType createVectorType(uint64_t Size, uint64_t AlignInBits,
350 DIType Ty, DIArray Subscripts);
352 /// createEnumerationType - Create debugging information entry for an
354 /// @param Scope Scope in which this enumeration is defined.
355 /// @param Name Union name.
356 /// @param File File where this member is defined.
357 /// @param LineNumber Line number.
358 /// @param SizeInBits Member size.
359 /// @param AlignInBits Member alignment.
360 /// @param Elements Enumeration elements.
361 /// @param UnderlyingType Underlying type of a C++11/ObjC fixed enum.
362 DICompositeType createEnumerationType(DIDescriptor Scope, StringRef Name,
363 DIFile File, unsigned LineNumber,
365 uint64_t AlignInBits,
367 DIType UnderlyingType);
369 /// createSubroutineType - Create subroutine type.
370 /// @param File File in which this subroutine is defined.
371 /// @param ParameterTypes An array of subroutine parameter types. This
372 /// includes return type at 0th index.
373 DICompositeType createSubroutineType(DIFile File, DIArray ParameterTypes);
375 /// createArtificialType - Create a new DIType with "artificial" flag set.
376 DIType createArtificialType(DIType Ty);
378 /// createObjectPointerType - Create a new DIType with the "object pointer"
380 DIType createObjectPointerType(DIType Ty);
382 /// createForwardDecl - Create a temporary forward-declared type.
383 DIType createForwardDecl(unsigned Tag, StringRef Name, DIDescriptor Scope,
384 DIFile F, unsigned Line, unsigned RuntimeLang = 0,
385 uint64_t SizeInBits = 0, uint64_t AlignInBits = 0);
387 /// retainType - Retain DIType in a module even if it is not referenced
388 /// through debug info anchors.
389 void retainType(DIType T);
391 /// createUnspecifiedParameter - Create unspeicified type descriptor
392 /// for a subroutine type.
393 DIDescriptor createUnspecifiedParameter();
395 /// getOrCreateArray - Get a DIArray, create one if required.
396 DIArray getOrCreateArray(ArrayRef<Value *> Elements);
398 /// getOrCreateSubrange - Create a descriptor for a value range. This
399 /// implicitly uniques the values returned.
400 DISubrange getOrCreateSubrange(int64_t Lo, int64_t Count);
402 /// createGlobalVariable - Create a new descriptor for the specified global.
403 /// @param Name Name of the variable.
404 /// @param File File where this variable is defined.
405 /// @param LineNo Line number.
406 /// @param Ty Variable Type.
407 /// @param isLocalToUnit Boolean flag indicate whether this variable is
408 /// externally visible or not.
409 /// @param Val llvm::Value of the variable.
411 createGlobalVariable(StringRef Name, DIFile File, unsigned LineNo,
412 DIType Ty, bool isLocalToUnit, llvm::Value *Val);
414 /// \brief Create a new descriptor for the specified global.
415 /// @param Name Name of the variable.
416 /// @param LinkageName Mangled variable name.
417 /// @param File File where this variable is defined.
418 /// @param LineNo Line number.
419 /// @param Ty Variable Type.
420 /// @param isLocalToUnit Boolean flag indicate whether this variable is
421 /// externally visible or not.
422 /// @param Val llvm::Value of the variable.
424 createGlobalVariable(StringRef Name, StringRef LinkageName, DIFile File,
425 unsigned LineNo, DIType Ty, bool isLocalToUnit,
428 /// createStaticVariable - Create a new descriptor for the specified
430 /// @param Context Variable scope.
431 /// @param Name Name of the variable.
432 /// @param LinkageName Mangled name of the variable.
433 /// @param File File where this variable is defined.
434 /// @param LineNo Line number.
435 /// @param Ty Variable Type.
436 /// @param isLocalToUnit Boolean flag indicate whether this variable is
437 /// externally visible or not.
438 /// @param Val llvm::Value of the variable.
439 /// @param Decl Reference to the corresponding declaration.
441 createStaticVariable(DIDescriptor Context, StringRef Name,
442 StringRef LinkageName, DIFile File, unsigned LineNo,
443 DIType Ty, bool isLocalToUnit, llvm::Value *Val,
444 MDNode *Decl = NULL);
447 /// createLocalVariable - Create a new descriptor for the specified
449 /// @param Tag Dwarf TAG. Usually DW_TAG_auto_variable or
450 /// DW_TAG_arg_variable.
451 /// @param Scope Variable scope.
452 /// @param Name Variable name.
453 /// @param File File where this variable is defined.
454 /// @param LineNo Line number.
455 /// @param Ty Variable Type
456 /// @param AlwaysPreserve Boolean. Set to true if debug info for this
457 /// variable should be preserved in optimized build.
458 /// @param Flags Flags, e.g. artificial variable.
459 /// @param ArgNo If this variable is an arugment then this argument's
460 /// number. 1 indicates 1st argument.
461 DIVariable createLocalVariable(unsigned Tag, DIDescriptor Scope,
463 DIFile File, unsigned LineNo,
464 DIType Ty, bool AlwaysPreserve = false,
469 /// createComplexVariable - Create a new descriptor for the specified
470 /// variable which has a complex address expression for its address.
471 /// @param Tag Dwarf TAG. Usually DW_TAG_auto_variable or
472 /// DW_TAG_arg_variable.
473 /// @param Scope Variable scope.
474 /// @param Name Variable name.
475 /// @param F File where this variable is defined.
476 /// @param LineNo Line number.
477 /// @param Ty Variable Type
478 /// @param Addr An array of complex address operations.
479 /// @param ArgNo If this variable is an arugment then this argument's
480 /// number. 1 indicates 1st argument.
481 DIVariable createComplexVariable(unsigned Tag, DIDescriptor Scope,
482 StringRef Name, DIFile F, unsigned LineNo,
483 DIType Ty, ArrayRef<Value *> Addr,
486 /// createFunction - Create a new descriptor for the specified subprogram.
487 /// See comments in DISubprogram for descriptions of these fields.
488 /// @param Scope Function scope.
489 /// @param Name Function name.
490 /// @param LinkageName Mangled function name.
491 /// @param File File where this variable is defined.
492 /// @param LineNo Line number.
493 /// @param Ty Function type.
494 /// @param isLocalToUnit True if this function is not externally visible..
495 /// @param isDefinition True if this is a function definition.
496 /// @param ScopeLine Set to the beginning of the scope this starts
497 /// @param Flags e.g. is this function prototyped or not.
498 /// This flags are used to emit dwarf attributes.
499 /// @param isOptimized True if optimization is ON.
500 /// @param Fn llvm::Function pointer.
501 /// @param TParam Function template parameters.
502 DISubprogram createFunction(DIDescriptor Scope, StringRef Name,
503 StringRef LinkageName,
504 DIFile File, unsigned LineNo,
505 DIType Ty, bool isLocalToUnit,
509 bool isOptimized = false,
514 /// createMethod - Create a new descriptor for the specified C++ method.
515 /// See comments in DISubprogram for descriptions of these fields.
516 /// @param Scope Function scope.
517 /// @param Name Function name.
518 /// @param LinkageName Mangled function name.
519 /// @param File File where this variable is defined.
520 /// @param LineNo Line number.
521 /// @param Ty Function type.
522 /// @param isLocalToUnit True if this function is not externally visible..
523 /// @param isDefinition True if this is a function definition.
524 /// @param Virtuality Attributes describing virtualness. e.g. pure
525 /// virtual function.
526 /// @param VTableIndex Index no of this method in virtual table.
527 /// @param VTableHolder Type that holds vtable.
528 /// @param Flags e.g. is this function prototyped or not.
529 /// This flags are used to emit dwarf attributes.
530 /// @param isOptimized True if optimization is ON.
531 /// @param Fn llvm::Function pointer.
532 /// @param TParam Function template parameters.
533 DISubprogram createMethod(DIDescriptor Scope, StringRef Name,
534 StringRef LinkageName,
535 DIFile File, unsigned LineNo,
536 DIType Ty, bool isLocalToUnit,
538 unsigned Virtuality = 0, unsigned VTableIndex = 0,
539 MDNode *VTableHolder = 0,
541 bool isOptimized = false,
545 /// createNameSpace - This creates new descriptor for a namespace
546 /// with the specified parent scope.
547 /// @param Scope Namespace scope
548 /// @param Name Name of this namespace
549 /// @param File Source file
550 /// @param LineNo Line number
551 DINameSpace createNameSpace(DIDescriptor Scope, StringRef Name,
552 DIFile File, unsigned LineNo);
555 /// createLexicalBlockFile - This creates a descriptor for a lexical
556 /// block with a new file attached. This merely extends the existing
557 /// lexical block as it crosses a file.
558 /// @param Scope Lexical block.
559 /// @param File Source file.
560 DILexicalBlockFile createLexicalBlockFile(DIDescriptor Scope,
563 /// createLexicalBlock - This creates a descriptor for a lexical block
564 /// with the specified parent context.
565 /// @param Scope Parent lexical scope.
566 /// @param File Source file
567 /// @param Line Line number
568 /// @param Col Column number
569 DILexicalBlock createLexicalBlock(DIDescriptor Scope, DIFile File,
570 unsigned Line, unsigned Col);
572 /// insertDeclare - Insert a new llvm.dbg.declare intrinsic call.
573 /// @param Storage llvm::Value of the variable
574 /// @param VarInfo Variable's debug info descriptor.
575 /// @param InsertAtEnd Location for the new intrinsic.
576 Instruction *insertDeclare(llvm::Value *Storage, DIVariable VarInfo,
577 BasicBlock *InsertAtEnd);
579 /// insertDeclare - Insert a new llvm.dbg.declare intrinsic call.
580 /// @param Storage llvm::Value of the variable
581 /// @param VarInfo Variable's debug info descriptor.
582 /// @param InsertBefore Location for the new intrinsic.
583 Instruction *insertDeclare(llvm::Value *Storage, DIVariable VarInfo,
584 Instruction *InsertBefore);
587 /// insertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
588 /// @param Val llvm::Value of the variable
589 /// @param Offset Offset
590 /// @param VarInfo Variable's debug info descriptor.
591 /// @param InsertAtEnd Location for the new intrinsic.
592 Instruction *insertDbgValueIntrinsic(llvm::Value *Val, uint64_t Offset,
594 BasicBlock *InsertAtEnd);
596 /// insertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
597 /// @param Val llvm::Value of the variable
598 /// @param Offset Offset
599 /// @param VarInfo Variable's debug info descriptor.
600 /// @param InsertBefore Location for the new intrinsic.
601 Instruction *insertDbgValueIntrinsic(llvm::Value *Val, uint64_t Offset,
603 Instruction *InsertBefore);
606 } // end namespace llvm