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 DIType createClassType(DIDescriptor Scope, StringRef Name, DIFile File,
269 unsigned LineNumber, uint64_t SizeInBits,
270 uint64_t AlignInBits, uint64_t OffsetInBits,
271 unsigned Flags, DIType DerivedFrom,
272 DIArray Elements, MDNode *VTableHolder = 0,
273 MDNode *TemplateParms = 0);
275 /// createStructType - Create debugging information entry for a struct.
276 /// @param Scope Scope in which this struct is defined.
277 /// @param Name Struct name.
278 /// @param File File where this member is defined.
279 /// @param LineNumber Line number.
280 /// @param SizeInBits Member size.
281 /// @param AlignInBits Member alignment.
282 /// @param Flags Flags to encode member attribute, e.g. private
283 /// @param Elements Struct elements.
284 /// @param RunTimeLang Optional parameter, Objective-C runtime version.
285 DICompositeType createStructType(DIDescriptor Scope, StringRef Name,
286 DIFile File, unsigned LineNumber,
287 uint64_t SizeInBits, uint64_t AlignInBits,
288 unsigned Flags, DIType DerivedFrom,
289 DIArray Elements, unsigned RunTimeLang = 0,
290 MDNode *VTableHolder = 0);
292 /// createUnionType - Create debugging information entry for an union.
293 /// @param Scope Scope in which this union is defined.
294 /// @param Name Union name.
295 /// @param File File where this member is defined.
296 /// @param LineNumber Line number.
297 /// @param SizeInBits Member size.
298 /// @param AlignInBits Member alignment.
299 /// @param Flags Flags to encode member attribute, e.g. private
300 /// @param Elements Union elements.
301 /// @param RunTimeLang Optional parameter, Objective-C runtime version.
302 DICompositeType createUnionType(
303 DIDescriptor Scope, StringRef Name, DIFile File, unsigned LineNumber,
304 uint64_t SizeInBits, uint64_t AlignInBits, unsigned Flags,
305 DIArray Elements, unsigned RunTimeLang = 0);
307 /// createTemplateTypeParameter - Create debugging information for template
309 /// @param Scope Scope in which this type is defined.
310 /// @param Name Type parameter name.
311 /// @param Ty Parameter type.
312 /// @param File File where this type parameter is defined.
313 /// @param LineNo Line number.
314 /// @param ColumnNo Column Number.
315 DITemplateTypeParameter
316 createTemplateTypeParameter(DIDescriptor Scope, StringRef Name, DIType Ty,
317 MDNode *File = 0, unsigned LineNo = 0,
318 unsigned ColumnNo = 0);
320 /// createTemplateValueParameter - Create debugging information for template
322 /// @param Scope Scope in which this type is defined.
323 /// @param Name Value parameter name.
324 /// @param Ty Parameter type.
325 /// @param Value Constant parameter value.
326 /// @param File File where this type parameter is defined.
327 /// @param LineNo Line number.
328 /// @param ColumnNo Column Number.
329 DITemplateValueParameter
330 createTemplateValueParameter(DIDescriptor Scope, StringRef Name, DIType Ty,
332 MDNode *File = 0, unsigned LineNo = 0,
333 unsigned ColumnNo = 0);
335 /// createArrayType - Create debugging information entry for an array.
336 /// @param Size Array size.
337 /// @param AlignInBits Alignment.
338 /// @param Ty Element type.
339 /// @param Subscripts Subscripts.
340 DICompositeType createArrayType(uint64_t Size, uint64_t AlignInBits,
341 DIType Ty, DIArray Subscripts);
343 /// createVectorType - Create debugging information entry for a vector type.
344 /// @param Size Array size.
345 /// @param AlignInBits Alignment.
346 /// @param Ty Element type.
347 /// @param Subscripts Subscripts.
348 DIType createVectorType(uint64_t Size, uint64_t AlignInBits,
349 DIType Ty, DIArray Subscripts);
351 /// createEnumerationType - Create debugging information entry for an
353 /// @param Scope Scope in which this enumeration is defined.
354 /// @param Name Union name.
355 /// @param File File where this member is defined.
356 /// @param LineNumber Line number.
357 /// @param SizeInBits Member size.
358 /// @param AlignInBits Member alignment.
359 /// @param Elements Enumeration elements.
360 DICompositeType createEnumerationType(
361 DIDescriptor Scope, StringRef Name, DIFile File, unsigned LineNumber,
362 uint64_t SizeInBits, uint64_t AlignInBits, DIArray Elements,
365 /// createSubroutineType - Create subroutine type.
366 /// @param File File in which this subroutine is defined.
367 /// @param ParameterTypes An array of subroutine parameter types. This
368 /// includes return type at 0th index.
369 DICompositeType createSubroutineType(DIFile File, DIArray ParameterTypes);
371 /// createArtificialType - Create a new DIType with "artificial" flag set.
372 DIType createArtificialType(DIType Ty);
374 /// createObjectPointerType - Create a new DIType with the "object pointer"
376 DIType createObjectPointerType(DIType Ty);
378 /// createTemporaryType - Create a temporary forward-declared type.
379 DIType createTemporaryType();
380 DIType createTemporaryType(DIFile F);
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);
415 /// createStaticVariable - Create a new descriptor for the specified
417 /// @param Context Variable scope.
418 /// @param Name Name of the variable.
419 /// @param LinkageName Mangled name of the variable.
420 /// @param File File where this variable is defined.
421 /// @param LineNo Line number.
422 /// @param Ty Variable Type.
423 /// @param isLocalToUnit Boolean flag indicate whether this variable is
424 /// externally visible or not.
425 /// @param Val llvm::Value of the variable.
426 /// @param Decl Reference to the corresponding declaration.
428 createStaticVariable(DIDescriptor Context, StringRef Name,
429 StringRef LinkageName, DIFile File, unsigned LineNo,
430 DIType Ty, bool isLocalToUnit, llvm::Value *Val,
431 MDNode *Decl = NULL);
434 /// createLocalVariable - Create a new descriptor for the specified
436 /// @param Tag Dwarf TAG. Usually DW_TAG_auto_variable or
437 /// DW_TAG_arg_variable.
438 /// @param Scope Variable scope.
439 /// @param Name Variable name.
440 /// @param File File where this variable is defined.
441 /// @param LineNo Line number.
442 /// @param Ty Variable Type
443 /// @param AlwaysPreserve Boolean. Set to true if debug info for this
444 /// variable should be preserved in optimized build.
445 /// @param Flags Flags, e.g. artificial variable.
446 /// @param ArgNo If this variable is an arugment then this argument's
447 /// number. 1 indicates 1st argument.
448 DIVariable createLocalVariable(unsigned Tag, DIDescriptor Scope,
450 DIFile File, unsigned LineNo,
451 DIType Ty, bool AlwaysPreserve = false,
456 /// createComplexVariable - Create a new descriptor for the specified
457 /// variable which has a complex address expression for its address.
458 /// @param Tag Dwarf TAG. Usually DW_TAG_auto_variable or
459 /// DW_TAG_arg_variable.
460 /// @param Scope Variable scope.
461 /// @param Name Variable name.
462 /// @param F File where this variable is defined.
463 /// @param LineNo Line number.
464 /// @param Ty Variable Type
465 /// @param Addr An array of complex address operations.
466 /// @param ArgNo If this variable is an arugment then this argument's
467 /// number. 1 indicates 1st argument.
468 DIVariable createComplexVariable(unsigned Tag, DIDescriptor Scope,
469 StringRef Name, DIFile F, unsigned LineNo,
470 DIType Ty, ArrayRef<Value *> Addr,
473 /// createFunction - Create a new descriptor for the specified subprogram.
474 /// See comments in DISubprogram for descriptions of these fields.
475 /// @param Scope Function scope.
476 /// @param Name Function name.
477 /// @param LinkageName Mangled function name.
478 /// @param File File where this variable is defined.
479 /// @param LineNo Line number.
480 /// @param Ty Function type.
481 /// @param isLocalToUnit True if this function is not externally visible..
482 /// @param isDefinition True if this is a function definition.
483 /// @param ScopeLine Set to the beginning of the scope this starts
484 /// @param Flags e.g. is this function prototyped or not.
485 /// This flags are used to emit dwarf attributes.
486 /// @param isOptimized True if optimization is ON.
487 /// @param Fn llvm::Function pointer.
488 /// @param TParam Function template parameters.
489 DISubprogram createFunction(DIDescriptor Scope, StringRef Name,
490 StringRef LinkageName,
491 DIFile File, unsigned LineNo,
492 DIType Ty, bool isLocalToUnit,
496 bool isOptimized = false,
501 /// createMethod - Create a new descriptor for the specified C++ method.
502 /// See comments in DISubprogram for descriptions of these fields.
503 /// @param Scope Function scope.
504 /// @param Name Function name.
505 /// @param LinkageName Mangled function name.
506 /// @param File File where this variable is defined.
507 /// @param LineNo Line number.
508 /// @param Ty Function type.
509 /// @param isLocalToUnit True if this function is not externally visible..
510 /// @param isDefinition True if this is a function definition.
511 /// @param Virtuality Attributes describing virtualness. e.g. pure
512 /// virtual function.
513 /// @param VTableIndex Index no of this method in virtual table.
514 /// @param VTableHolder Type that holds vtable.
515 /// @param Flags e.g. is this function prototyped or not.
516 /// This flags are used to emit dwarf attributes.
517 /// @param isOptimized True if optimization is ON.
518 /// @param Fn llvm::Function pointer.
519 /// @param TParam Function template parameters.
520 DISubprogram createMethod(DIDescriptor Scope, StringRef Name,
521 StringRef LinkageName,
522 DIFile File, unsigned LineNo,
523 DIType Ty, bool isLocalToUnit,
525 unsigned Virtuality = 0, unsigned VTableIndex = 0,
526 MDNode *VTableHolder = 0,
528 bool isOptimized = false,
532 /// createNameSpace - This creates new descriptor for a namespace
533 /// with the specified parent scope.
534 /// @param Scope Namespace scope
535 /// @param Name Name of this namespace
536 /// @param File Source file
537 /// @param LineNo Line number
538 DINameSpace createNameSpace(DIDescriptor Scope, StringRef Name,
539 DIFile File, unsigned LineNo);
542 /// createLexicalBlockFile - This creates a descriptor for a lexical
543 /// block with a new file attached. This merely extends the existing
544 /// lexical block as it crosses a file.
545 /// @param Scope Lexical block.
546 /// @param File Source file.
547 DILexicalBlockFile createLexicalBlockFile(DIDescriptor Scope,
550 /// createLexicalBlock - This creates a descriptor for a lexical block
551 /// with the specified parent context.
552 /// @param Scope Parent lexical scope.
553 /// @param File Source file
554 /// @param Line Line number
555 /// @param Col Column number
556 DILexicalBlock createLexicalBlock(DIDescriptor Scope, DIFile File,
557 unsigned Line, unsigned Col);
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 InsertAtEnd Location for the new intrinsic.
563 Instruction *insertDeclare(llvm::Value *Storage, DIVariable VarInfo,
564 BasicBlock *InsertAtEnd);
566 /// insertDeclare - Insert a new llvm.dbg.declare intrinsic call.
567 /// @param Storage llvm::Value of the variable
568 /// @param VarInfo Variable's debug info descriptor.
569 /// @param InsertBefore Location for the new intrinsic.
570 Instruction *insertDeclare(llvm::Value *Storage, DIVariable VarInfo,
571 Instruction *InsertBefore);
574 /// insertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
575 /// @param Val llvm::Value of the variable
576 /// @param Offset Offset
577 /// @param VarInfo Variable's debug info descriptor.
578 /// @param InsertAtEnd Location for the new intrinsic.
579 Instruction *insertDbgValueIntrinsic(llvm::Value *Val, uint64_t Offset,
581 BasicBlock *InsertAtEnd);
583 /// insertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
584 /// @param Val llvm::Value of the variable
585 /// @param Offset Offset
586 /// @param VarInfo Variable's debug info descriptor.
587 /// @param InsertBefore Location for the new intrinsic.
588 Instruction *insertDbgValueIntrinsic(llvm::Value *Val, uint64_t Offset,
590 Instruction *InsertBefore);
593 } // end namespace llvm