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 DIType createStructType(DIDescriptor Scope, StringRef Name, DIFile File,
286 unsigned LineNumber, uint64_t SizeInBits,
287 uint64_t AlignInBits, unsigned Flags,
288 DIArray Elements, unsigned RunTimeLang = 0);
290 /// createUnionType - Create debugging information entry for an union.
291 /// @param Scope Scope in which this union is defined.
292 /// @param Name Union name.
293 /// @param File File where this member is defined.
294 /// @param LineNumber Line number.
295 /// @param SizeInBits Member size.
296 /// @param AlignInBits Member alignment.
297 /// @param Flags Flags to encode member attribute, e.g. private
298 /// @param Elements Union elements.
299 /// @param RunTimeLang Optional parameter, Objective-C runtime version.
300 DICompositeType createUnionType(
301 DIDescriptor Scope, StringRef Name, DIFile File, unsigned LineNumber,
302 uint64_t SizeInBits, uint64_t AlignInBits, unsigned Flags,
303 DIArray Elements, unsigned RunTimeLang = 0);
305 /// createTemplateTypeParameter - Create debugging information for template
307 /// @param Scope Scope in which this type is defined.
308 /// @param Name Type parameter name.
309 /// @param Ty Parameter type.
310 /// @param File File where this type parameter is defined.
311 /// @param LineNo Line number.
312 /// @param ColumnNo Column Number.
313 DITemplateTypeParameter
314 createTemplateTypeParameter(DIDescriptor Scope, StringRef Name, DIType Ty,
315 MDNode *File = 0, unsigned LineNo = 0,
316 unsigned ColumnNo = 0);
318 /// createTemplateValueParameter - Create debugging information for template
320 /// @param Scope Scope in which this type is defined.
321 /// @param Name Value parameter name.
322 /// @param Ty Parameter type.
323 /// @param Value Constant parameter value.
324 /// @param File File where this type parameter is defined.
325 /// @param LineNo Line number.
326 /// @param ColumnNo Column Number.
327 DITemplateValueParameter
328 createTemplateValueParameter(DIDescriptor Scope, StringRef Name, DIType Ty,
330 MDNode *File = 0, unsigned LineNo = 0,
331 unsigned ColumnNo = 0);
333 /// createArrayType - Create debugging information entry for an array.
334 /// @param Size Array size.
335 /// @param AlignInBits Alignment.
336 /// @param Ty Element type.
337 /// @param Subscripts Subscripts.
338 DICompositeType createArrayType(uint64_t Size, uint64_t AlignInBits,
339 DIType Ty, DIArray Subscripts);
341 /// createVectorType - Create debugging information entry for a vector type.
342 /// @param Size Array size.
343 /// @param AlignInBits Alignment.
344 /// @param Ty Element type.
345 /// @param Subscripts Subscripts.
346 DIType createVectorType(uint64_t Size, uint64_t AlignInBits,
347 DIType Ty, DIArray Subscripts);
349 /// createEnumerationType - Create debugging information entry for an
351 /// @param Scope Scope in which this enumeration is defined.
352 /// @param Name Union name.
353 /// @param File File where this member is defined.
354 /// @param LineNumber Line number.
355 /// @param SizeInBits Member size.
356 /// @param AlignInBits Member alignment.
357 /// @param Elements Enumeration elements.
358 DICompositeType createEnumerationType(
359 DIDescriptor Scope, StringRef Name, DIFile File, unsigned LineNumber,
360 uint64_t SizeInBits, uint64_t AlignInBits, DIArray Elements,
363 /// createSubroutineType - Create subroutine type.
364 /// @param File File in which this subroutine is defined.
365 /// @param ParameterTypes An array of subroutine parameter types. This
366 /// includes return type at 0th index.
367 DICompositeType createSubroutineType(DIFile File, DIArray ParameterTypes);
369 /// createArtificialType - Create a new DIType with "artificial" flag set.
370 DIType createArtificialType(DIType Ty);
372 /// createObjectPointerType - Create a new DIType with the "object pointer"
374 DIType createObjectPointerType(DIType Ty);
376 /// createTemporaryType - Create a temporary forward-declared type.
377 DIType createTemporaryType();
378 DIType createTemporaryType(DIFile F);
380 /// createForwardDecl - Create a temporary forward-declared type.
381 DIType createForwardDecl(unsigned Tag, StringRef Name, DIDescriptor Scope,
382 DIFile F, unsigned Line, unsigned RuntimeLang = 0,
383 uint64_t SizeInBits = 0, uint64_t AlignInBits = 0);
385 /// retainType - Retain DIType in a module even if it is not referenced
386 /// through debug info anchors.
387 void retainType(DIType T);
389 /// createUnspecifiedParameter - Create unspeicified type descriptor
390 /// for a subroutine type.
391 DIDescriptor createUnspecifiedParameter();
393 /// getOrCreateArray - Get a DIArray, create one if required.
394 DIArray getOrCreateArray(ArrayRef<Value *> Elements);
396 /// getOrCreateSubrange - Create a descriptor for a value range. This
397 /// implicitly uniques the values returned.
398 DISubrange getOrCreateSubrange(int64_t Lo, int64_t Count);
400 /// createGlobalVariable - Create a new descriptor for the specified global.
401 /// @param Name Name of the variable.
402 /// @param File File where this variable is defined.
403 /// @param LineNo Line number.
404 /// @param Ty Variable Type.
405 /// @param isLocalToUnit Boolean flag indicate whether this variable is
406 /// externally visible or not.
407 /// @param Val llvm::Value of the variable.
409 createGlobalVariable(StringRef Name, DIFile File, unsigned LineNo,
410 DIType Ty, bool isLocalToUnit, llvm::Value *Val);
413 /// createStaticVariable - Create a new descriptor for the specified
415 /// @param Context Variable scope.
416 /// @param Name Name of the variable.
417 /// @param LinkageName Mangled name of the variable.
418 /// @param File File where this variable is defined.
419 /// @param LineNo Line number.
420 /// @param Ty Variable Type.
421 /// @param isLocalToUnit Boolean flag indicate whether this variable is
422 /// externally visible or not.
423 /// @param Val llvm::Value of the variable.
424 /// @param Decl Reference to the corresponding declaration.
426 createStaticVariable(DIDescriptor Context, StringRef Name,
427 StringRef LinkageName, DIFile File, unsigned LineNo,
428 DIType Ty, bool isLocalToUnit, llvm::Value *Val,
429 MDNode *Decl = NULL);
432 /// createLocalVariable - Create a new descriptor for the specified
434 /// @param Tag Dwarf TAG. Usually DW_TAG_auto_variable or
435 /// DW_TAG_arg_variable.
436 /// @param Scope Variable scope.
437 /// @param Name Variable name.
438 /// @param File File where this variable is defined.
439 /// @param LineNo Line number.
440 /// @param Ty Variable Type
441 /// @param AlwaysPreserve Boolean. Set to true if debug info for this
442 /// variable should be preserved in optimized build.
443 /// @param Flags Flags, e.g. artificial variable.
444 /// @param ArgNo If this variable is an arugment then this argument's
445 /// number. 1 indicates 1st argument.
446 DIVariable createLocalVariable(unsigned Tag, DIDescriptor Scope,
448 DIFile File, unsigned LineNo,
449 DIType Ty, bool AlwaysPreserve = false,
454 /// createComplexVariable - Create a new descriptor for the specified
455 /// variable which has a complex address expression for its address.
456 /// @param Tag Dwarf TAG. Usually DW_TAG_auto_variable or
457 /// DW_TAG_arg_variable.
458 /// @param Scope Variable scope.
459 /// @param Name Variable name.
460 /// @param F File where this variable is defined.
461 /// @param LineNo Line number.
462 /// @param Ty Variable Type
463 /// @param Addr An array of complex address operations.
464 /// @param ArgNo If this variable is an arugment then this argument's
465 /// number. 1 indicates 1st argument.
466 DIVariable createComplexVariable(unsigned Tag, DIDescriptor Scope,
467 StringRef Name, DIFile F, unsigned LineNo,
468 DIType Ty, ArrayRef<Value *> Addr,
471 /// createFunction - Create a new descriptor for the specified subprogram.
472 /// See comments in DISubprogram for descriptions of these fields.
473 /// @param Scope Function scope.
474 /// @param Name Function name.
475 /// @param LinkageName Mangled function name.
476 /// @param File File where this variable is defined.
477 /// @param LineNo Line number.
478 /// @param Ty Function type.
479 /// @param isLocalToUnit True if this function is not externally visible..
480 /// @param isDefinition True if this is a function definition.
481 /// @param ScopeLine Set to the beginning of the scope this starts
482 /// @param Flags e.g. is this function prototyped or not.
483 /// This flags are used to emit dwarf attributes.
484 /// @param isOptimized True if optimization is ON.
485 /// @param Fn llvm::Function pointer.
486 /// @param TParam Function template parameters.
487 DISubprogram createFunction(DIDescriptor Scope, StringRef Name,
488 StringRef LinkageName,
489 DIFile File, unsigned LineNo,
490 DIType Ty, bool isLocalToUnit,
494 bool isOptimized = false,
499 /// createMethod - Create a new descriptor for the specified C++ method.
500 /// See comments in DISubprogram for descriptions of these fields.
501 /// @param Scope Function scope.
502 /// @param Name Function name.
503 /// @param LinkageName Mangled function name.
504 /// @param File File where this variable is defined.
505 /// @param LineNo Line number.
506 /// @param Ty Function type.
507 /// @param isLocalToUnit True if this function is not externally visible..
508 /// @param isDefinition True if this is a function definition.
509 /// @param Virtuality Attributes describing virtualness. e.g. pure
510 /// virtual function.
511 /// @param VTableIndex Index no of this method in virtual table.
512 /// @param VTableHolder Type that holds vtable.
513 /// @param Flags e.g. is this function prototyped or not.
514 /// This flags are used to emit dwarf attributes.
515 /// @param isOptimized True if optimization is ON.
516 /// @param Fn llvm::Function pointer.
517 /// @param TParam Function template parameters.
518 DISubprogram createMethod(DIDescriptor Scope, StringRef Name,
519 StringRef LinkageName,
520 DIFile File, unsigned LineNo,
521 DIType Ty, bool isLocalToUnit,
523 unsigned Virtuality = 0, unsigned VTableIndex = 0,
524 MDNode *VTableHolder = 0,
526 bool isOptimized = false,
530 /// createNameSpace - This creates new descriptor for a namespace
531 /// with the specified parent scope.
532 /// @param Scope Namespace scope
533 /// @param Name Name of this namespace
534 /// @param File Source file
535 /// @param LineNo Line number
536 DINameSpace createNameSpace(DIDescriptor Scope, StringRef Name,
537 DIFile File, unsigned LineNo);
540 /// createLexicalBlockFile - This creates a descriptor for a lexical
541 /// block with a new file attached. This merely extends the existing
542 /// lexical block as it crosses a file.
543 /// @param Scope Lexical block.
544 /// @param File Source file.
545 DILexicalBlockFile createLexicalBlockFile(DIDescriptor Scope,
548 /// createLexicalBlock - This creates a descriptor for a lexical block
549 /// with the specified parent context.
550 /// @param Scope Parent lexical scope.
551 /// @param File Source file
552 /// @param Line Line number
553 /// @param Col Column number
554 DILexicalBlock createLexicalBlock(DIDescriptor Scope, DIFile File,
555 unsigned Line, unsigned Col);
557 /// insertDeclare - Insert a new llvm.dbg.declare intrinsic call.
558 /// @param Storage llvm::Value of the variable
559 /// @param VarInfo Variable's debug info descriptor.
560 /// @param InsertAtEnd Location for the new intrinsic.
561 Instruction *insertDeclare(llvm::Value *Storage, DIVariable VarInfo,
562 BasicBlock *InsertAtEnd);
564 /// insertDeclare - Insert a new llvm.dbg.declare intrinsic call.
565 /// @param Storage llvm::Value of the variable
566 /// @param VarInfo Variable's debug info descriptor.
567 /// @param InsertBefore Location for the new intrinsic.
568 Instruction *insertDeclare(llvm::Value *Storage, DIVariable VarInfo,
569 Instruction *InsertBefore);
572 /// insertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
573 /// @param Val llvm::Value of the variable
574 /// @param Offset Offset
575 /// @param VarInfo Variable's debug info descriptor.
576 /// @param InsertAtEnd Location for the new intrinsic.
577 Instruction *insertDbgValueIntrinsic(llvm::Value *Val, uint64_t Offset,
579 BasicBlock *InsertAtEnd);
581 /// insertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
582 /// @param Val llvm::Value of the variable
583 /// @param Offset Offset
584 /// @param VarInfo Variable's debug info descriptor.
585 /// @param InsertBefore Location for the new intrinsic.
586 Instruction *insertDbgValueIntrinsic(llvm::Value *Val, uint64_t Offset,
588 Instruction *InsertBefore);
591 } // end namespace llvm