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 void createCompileUnit(unsigned Lang, StringRef File, StringRef Dir,
96 bool isOptimized, StringRef Flags, unsigned RV);
98 /// createFile - Create a file descriptor to hold debugging information
100 DIFile createFile(StringRef Filename, StringRef Directory);
102 /// createEnumerator - Create a single enumerator value.
103 DIEnumerator createEnumerator(StringRef Name, uint64_t Val);
105 /// createNullPtrType - Create C++0x nullptr type.
106 DIType createNullPtrType(StringRef Name);
108 /// createBasicType - Create debugging information entry for a basic
110 /// @param Name Type name.
111 /// @param SizeInBits Size of the type.
112 /// @param AlignInBits Type alignment.
113 /// @param Encoding DWARF encoding code, e.g. dwarf::DW_ATE_float.
114 DIBasicType createBasicType(StringRef Name, uint64_t SizeInBits,
115 uint64_t AlignInBits, unsigned Encoding);
117 /// createQualifiedType - Create debugging information entry for a qualified
118 /// type, e.g. 'const int'.
119 /// @param Tag Tag identifing type, e.g. dwarf::TAG_volatile_type
120 /// @param FromTy Base Type.
121 DIDerivedType createQualifiedType(unsigned Tag, DIType FromTy);
123 /// createPointerType - Create debugging information entry for a pointer.
124 /// @param PointeeTy Type pointed by this pointer.
125 /// @param SizeInBits Size.
126 /// @param AlignInBits Alignment. (optional)
127 /// @param Name Pointer type name. (optional)
129 createPointerType(DIType PointeeTy, uint64_t SizeInBits,
130 uint64_t AlignInBits = 0, StringRef Name = StringRef());
132 /// \brief Create debugging information entry for a pointer to member.
133 /// @param PointeeTy Type pointed to by this pointer.
134 /// @param Class Type for which this pointer points to members of.
135 DIDerivedType createMemberPointerType(DIType PointeeTy, DIType Class);
137 /// createReferenceType - Create debugging information entry for a c++
138 /// style reference or rvalue reference type.
139 DIDerivedType createReferenceType(unsigned Tag, DIType RTy);
141 /// createTypedef - Create debugging information entry for a typedef.
142 /// @param Ty Original type.
143 /// @param Name Typedef name.
144 /// @param File File where this type is defined.
145 /// @param LineNo Line number.
146 /// @param Context The surrounding context for the typedef.
147 DIDerivedType createTypedef(DIType Ty, StringRef Name, DIFile File,
148 unsigned LineNo, DIDescriptor Context);
150 /// createFriend - Create debugging information entry for a 'friend'.
151 DIType createFriend(DIType Ty, DIType FriendTy);
153 /// createInheritance - Create debugging information entry to establish
154 /// inheritance relationship between two types.
155 /// @param Ty Original type.
156 /// @param BaseTy Base type. Ty is inherits from base.
157 /// @param BaseOffset Base offset.
158 /// @param Flags Flags to describe inheritance attribute,
160 DIDerivedType createInheritance(DIType Ty, DIType BaseTy,
161 uint64_t BaseOffset, unsigned Flags);
163 /// createMemberType - Create debugging information entry for a member.
164 /// @param Scope Member scope.
165 /// @param Name Member name.
166 /// @param File File where this member is defined.
167 /// @param LineNo Line number.
168 /// @param SizeInBits Member size.
169 /// @param AlignInBits Member alignment.
170 /// @param OffsetInBits Member offset.
171 /// @param Flags Flags to encode member attribute, e.g. private
172 /// @param Ty Parent type.
174 createMemberType(DIDescriptor Scope, StringRef Name, DIFile File,
175 unsigned LineNo, uint64_t SizeInBits, uint64_t AlignInBits,
176 uint64_t OffsetInBits, unsigned Flags, DIType Ty);
178 /// createStaticMemberType - Create debugging information entry for a
179 /// C++ static data member.
180 /// @param Scope Member scope.
181 /// @param Name Member name.
182 /// @param File File where this member is declared.
183 /// @param LineNo Line number.
184 /// @param Ty Type of the static member.
185 /// @param Flags Flags to encode member attribute, e.g. private.
186 /// @param Val Const initializer of the member.
187 DIType createStaticMemberType(DIDescriptor Scope, StringRef Name,
188 DIFile File, unsigned LineNo, DIType Ty,
189 unsigned Flags, llvm::Value *Val);
191 /// createObjCIVar - Create debugging information entry for Objective-C
192 /// instance variable.
193 /// @param Name Member name.
194 /// @param File File where this member is defined.
195 /// @param LineNo Line number.
196 /// @param SizeInBits Member size.
197 /// @param AlignInBits Member alignment.
198 /// @param OffsetInBits Member offset.
199 /// @param Flags Flags to encode member attribute, e.g. private
200 /// @param Ty Parent type.
201 /// @param PropertyName Name of the Objective C property associated with
203 /// @param PropertyGetterName Name of the Objective C property getter
205 /// @param PropertySetterName Name of the Objective C property setter
207 /// @param PropertyAttributes Objective C property attributes.
208 DIType createObjCIVar(StringRef Name, DIFile File,
209 unsigned LineNo, uint64_t SizeInBits,
210 uint64_t AlignInBits, uint64_t OffsetInBits,
211 unsigned Flags, DIType Ty,
212 StringRef PropertyName = StringRef(),
213 StringRef PropertyGetterName = StringRef(),
214 StringRef PropertySetterName = StringRef(),
215 unsigned PropertyAttributes = 0);
217 /// createObjCIVar - Create debugging information entry for Objective-C
218 /// instance variable.
219 /// @param Name Member name.
220 /// @param File File where this member is defined.
221 /// @param LineNo Line number.
222 /// @param SizeInBits Member size.
223 /// @param AlignInBits Member alignment.
224 /// @param OffsetInBits Member offset.
225 /// @param Flags Flags to encode member attribute, e.g. private
226 /// @param Ty Parent type.
227 /// @param PropertyNode Property associated with this ivar.
228 DIType createObjCIVar(StringRef Name, DIFile File,
229 unsigned LineNo, uint64_t SizeInBits,
230 uint64_t AlignInBits, uint64_t OffsetInBits,
231 unsigned Flags, DIType Ty,
232 MDNode *PropertyNode);
234 /// createObjCProperty - Create debugging information entry for Objective-C
236 /// @param Name Property name.
237 /// @param File File where this property is defined.
238 /// @param LineNumber Line number.
239 /// @param GetterName Name of the Objective C property getter selector.
240 /// @param SetterName Name of the Objective C property setter selector.
241 /// @param PropertyAttributes Objective C property attributes.
243 DIObjCProperty createObjCProperty(StringRef Name,
244 DIFile File, unsigned LineNumber,
245 StringRef GetterName,
246 StringRef SetterName,
247 unsigned PropertyAttributes,
250 /// createClassType - Create debugging information entry for a class.
251 /// @param Scope Scope in which this class is defined.
252 /// @param Name class name.
253 /// @param File File where this member is defined.
254 /// @param LineNumber Line number.
255 /// @param SizeInBits Member size.
256 /// @param AlignInBits Member alignment.
257 /// @param OffsetInBits Member offset.
258 /// @param Flags Flags to encode member attribute, e.g. private
259 /// @param Elements class members.
260 /// @param VTableHolder Debug info of the base class that contains vtable
261 /// for this type. This is used in
262 /// DW_AT_containing_type. See DWARF documentation
264 /// @param TemplateParms Template type parameters.
265 DIType createClassType(DIDescriptor Scope, StringRef Name, DIFile File,
266 unsigned LineNumber, uint64_t SizeInBits,
267 uint64_t AlignInBits, uint64_t OffsetInBits,
268 unsigned Flags, DIType DerivedFrom,
269 DIArray Elements, MDNode *VTableHolder = 0,
270 MDNode *TemplateParms = 0);
272 /// createStructType - Create debugging information entry for a struct.
273 /// @param Scope Scope in which this struct is defined.
274 /// @param Name Struct name.
275 /// @param File File where this member is defined.
276 /// @param LineNumber Line number.
277 /// @param SizeInBits Member size.
278 /// @param AlignInBits Member alignment.
279 /// @param Flags Flags to encode member attribute, e.g. private
280 /// @param Elements Struct elements.
281 /// @param RunTimeLang Optional parameter, Objective-C runtime version.
282 DIType createStructType(DIDescriptor Scope, StringRef Name, DIFile File,
283 unsigned LineNumber, uint64_t SizeInBits,
284 uint64_t AlignInBits, unsigned Flags,
285 DIArray Elements, unsigned RunTimeLang = 0);
287 /// createUnionType - Create debugging information entry for an union.
288 /// @param Scope Scope in which this union is defined.
289 /// @param Name Union name.
290 /// @param File File where this member is defined.
291 /// @param LineNumber Line number.
292 /// @param SizeInBits Member size.
293 /// @param AlignInBits Member alignment.
294 /// @param Flags Flags to encode member attribute, e.g. private
295 /// @param Elements Union elements.
296 /// @param RunTimeLang Optional parameter, Objective-C runtime version.
297 DICompositeType createUnionType(
298 DIDescriptor Scope, StringRef Name, DIFile File, unsigned LineNumber,
299 uint64_t SizeInBits, uint64_t AlignInBits, unsigned Flags,
300 DIArray Elements, unsigned RunTimeLang = 0);
302 /// createTemplateTypeParameter - Create debugging information for template
304 /// @param Scope Scope in which this type is defined.
305 /// @param Name Type parameter name.
306 /// @param Ty Parameter type.
307 /// @param File File where this type parameter is defined.
308 /// @param LineNo Line number.
309 /// @param ColumnNo Column Number.
310 DITemplateTypeParameter
311 createTemplateTypeParameter(DIDescriptor Scope, StringRef Name, DIType Ty,
312 MDNode *File = 0, unsigned LineNo = 0,
313 unsigned ColumnNo = 0);
315 /// createTemplateValueParameter - Create debugging information for template
317 /// @param Scope Scope in which this type is defined.
318 /// @param Name Value parameter name.
319 /// @param Ty Parameter type.
320 /// @param Value Constant parameter value.
321 /// @param File File where this type parameter is defined.
322 /// @param LineNo Line number.
323 /// @param ColumnNo Column Number.
324 DITemplateValueParameter
325 createTemplateValueParameter(DIDescriptor Scope, StringRef Name, DIType Ty,
327 MDNode *File = 0, unsigned LineNo = 0,
328 unsigned ColumnNo = 0);
330 /// createArrayType - Create debugging information entry for an array.
331 /// @param Size Array size.
332 /// @param AlignInBits Alignment.
333 /// @param Ty Element type.
334 /// @param Subscripts Subscripts.
335 DICompositeType createArrayType(uint64_t Size, uint64_t AlignInBits,
336 DIType Ty, DIArray Subscripts);
338 /// createVectorType - Create debugging information entry for a vector type.
339 /// @param Size Array size.
340 /// @param AlignInBits Alignment.
341 /// @param Ty Element type.
342 /// @param Subscripts Subscripts.
343 DIType createVectorType(uint64_t Size, uint64_t AlignInBits,
344 DIType Ty, DIArray Subscripts);
346 /// createEnumerationType - Create debugging information entry for an
348 /// @param Scope Scope in which this enumeration is defined.
349 /// @param Name Union name.
350 /// @param File File where this member is defined.
351 /// @param LineNumber Line number.
352 /// @param SizeInBits Member size.
353 /// @param AlignInBits Member alignment.
354 /// @param Elements Enumeration elements.
355 DICompositeType createEnumerationType(
356 DIDescriptor Scope, StringRef Name, DIFile File, unsigned LineNumber,
357 uint64_t SizeInBits, uint64_t AlignInBits, DIArray Elements,
360 /// createSubroutineType - Create subroutine type.
361 /// @param File File in which this subroutine is defined.
362 /// @param ParameterTypes An array of subroutine parameter types. This
363 /// includes return type at 0th index.
364 DICompositeType createSubroutineType(DIFile File, DIArray ParameterTypes);
366 /// createArtificialType - Create a new DIType with "artificial" flag set.
367 DIType createArtificialType(DIType Ty);
369 /// createObjectPointerType - Create a new DIType with the "object pointer"
371 DIType createObjectPointerType(DIType Ty);
373 /// createTemporaryType - Create a temporary forward-declared type.
374 DIType createTemporaryType();
375 DIType createTemporaryType(DIFile F);
377 /// createForwardDecl - Create a temporary forward-declared type.
378 DIType createForwardDecl(unsigned Tag, StringRef Name, DIDescriptor Scope,
379 DIFile F, unsigned Line, unsigned RuntimeLang = 0,
380 uint64_t SizeInBits = 0, uint64_t AlignInBits = 0);
382 /// retainType - Retain DIType in a module even if it is not referenced
383 /// through debug info anchors.
384 void retainType(DIType T);
386 /// createUnspecifiedParameter - Create unspeicified type descriptor
387 /// for a subroutine type.
388 DIDescriptor createUnspecifiedParameter();
390 /// getOrCreateArray - Get a DIArray, create one if required.
391 DIArray getOrCreateArray(ArrayRef<Value *> Elements);
393 /// getOrCreateSubrange - Create a descriptor for a value range. This
394 /// implicitly uniques the values returned.
395 DISubrange getOrCreateSubrange(int64_t Lo, int64_t Count);
397 /// createGlobalVariable - Create a new descriptor for the specified global.
398 /// @param Name Name of the variable.
399 /// @param File File where this variable is defined.
400 /// @param LineNo Line number.
401 /// @param Ty Variable Type.
402 /// @param isLocalToUnit Boolean flag indicate whether this variable is
403 /// externally visible or not.
404 /// @param Val llvm::Value of the variable.
406 createGlobalVariable(StringRef Name, DIFile File, unsigned LineNo,
407 DIType Ty, bool isLocalToUnit, llvm::Value *Val);
410 /// createStaticVariable - Create a new descriptor for the specified
412 /// @param Context Variable scope.
413 /// @param Name Name of the variable.
414 /// @param LinkageName Mangled name of the variable.
415 /// @param File File where this variable is defined.
416 /// @param LineNo Line number.
417 /// @param Ty Variable Type.
418 /// @param isLocalToUnit Boolean flag indicate whether this variable is
419 /// externally visible or not.
420 /// @param Val llvm::Value of the variable.
421 /// @param Decl Reference to the corresponding declaration.
423 createStaticVariable(DIDescriptor Context, StringRef Name,
424 StringRef LinkageName, DIFile File, unsigned LineNo,
425 DIType Ty, bool isLocalToUnit, llvm::Value *Val,
426 MDNode *Decl = NULL);
429 /// createLocalVariable - Create a new descriptor for the specified
431 /// @param Tag Dwarf TAG. Usually DW_TAG_auto_variable or
432 /// DW_TAG_arg_variable.
433 /// @param Scope Variable scope.
434 /// @param Name Variable name.
435 /// @param File File where this variable is defined.
436 /// @param LineNo Line number.
437 /// @param Ty Variable Type
438 /// @param AlwaysPreserve Boolean. Set to true if debug info for this
439 /// variable should be preserved in optimized build.
440 /// @param Flags Flags, e.g. artificial variable.
441 /// @param ArgNo If this variable is an arugment then this argument's
442 /// number. 1 indicates 1st argument.
443 DIVariable createLocalVariable(unsigned Tag, DIDescriptor Scope,
445 DIFile File, unsigned LineNo,
446 DIType Ty, bool AlwaysPreserve = false,
451 /// createComplexVariable - Create a new descriptor for the specified
452 /// variable which has a complex address expression for its address.
453 /// @param Tag Dwarf TAG. Usually DW_TAG_auto_variable or
454 /// DW_TAG_arg_variable.
455 /// @param Scope Variable scope.
456 /// @param Name Variable name.
457 /// @param F File where this variable is defined.
458 /// @param LineNo Line number.
459 /// @param Ty Variable Type
460 /// @param Addr An array of complex address operations.
461 /// @param ArgNo If this variable is an arugment then this argument's
462 /// number. 1 indicates 1st argument.
463 DIVariable createComplexVariable(unsigned Tag, DIDescriptor Scope,
464 StringRef Name, DIFile F, unsigned LineNo,
465 DIType Ty, ArrayRef<Value *> Addr,
468 /// createFunction - Create a new descriptor for the specified subprogram.
469 /// See comments in DISubprogram for descriptions of these fields.
470 /// @param Scope Function scope.
471 /// @param Name Function name.
472 /// @param LinkageName Mangled function name.
473 /// @param File File where this variable is defined.
474 /// @param LineNo Line number.
475 /// @param Ty Function type.
476 /// @param isLocalToUnit True if this function is not externally visible..
477 /// @param isDefinition True if this is a function definition.
478 /// @param ScopeLine Set to the beginning of the scope this starts
479 /// @param Flags e.g. is this function prototyped or not.
480 /// This flags are used to emit dwarf attributes.
481 /// @param isOptimized True if optimization is ON.
482 /// @param Fn llvm::Function pointer.
483 /// @param TParam Function template parameters.
484 DISubprogram createFunction(DIDescriptor Scope, StringRef Name,
485 StringRef LinkageName,
486 DIFile File, unsigned LineNo,
487 DIType Ty, bool isLocalToUnit,
491 bool isOptimized = false,
496 /// createMethod - Create a new descriptor for the specified C++ method.
497 /// See comments in DISubprogram for descriptions of these fields.
498 /// @param Scope Function scope.
499 /// @param Name Function name.
500 /// @param LinkageName Mangled function name.
501 /// @param File File where this variable is defined.
502 /// @param LineNo Line number.
503 /// @param Ty Function type.
504 /// @param isLocalToUnit True if this function is not externally visible..
505 /// @param isDefinition True if this is a function definition.
506 /// @param Virtuality Attributes describing virtualness. e.g. pure
507 /// virtual function.
508 /// @param VTableIndex Index no of this method in virtual table.
509 /// @param VTableHolder Type that holds vtable.
510 /// @param Flags e.g. is this function prototyped or not.
511 /// This flags are used to emit dwarf attributes.
512 /// @param isOptimized True if optimization is ON.
513 /// @param Fn llvm::Function pointer.
514 /// @param TParam Function template parameters.
515 DISubprogram createMethod(DIDescriptor Scope, StringRef Name,
516 StringRef LinkageName,
517 DIFile File, unsigned LineNo,
518 DIType Ty, bool isLocalToUnit,
520 unsigned Virtuality = 0, unsigned VTableIndex = 0,
521 MDNode *VTableHolder = 0,
523 bool isOptimized = false,
527 /// createNameSpace - This creates new descriptor for a namespace
528 /// with the specified parent scope.
529 /// @param Scope Namespace scope
530 /// @param Name Name of this namespace
531 /// @param File Source file
532 /// @param LineNo Line number
533 DINameSpace createNameSpace(DIDescriptor Scope, StringRef Name,
534 DIFile File, unsigned LineNo);
537 /// createLexicalBlockFile - This creates a descriptor for a lexical
538 /// block with a new file attached. This merely extends the existing
539 /// lexical block as it crosses a file.
540 /// @param Scope Lexical block.
541 /// @param File Source file.
542 DILexicalBlockFile createLexicalBlockFile(DIDescriptor Scope,
545 /// createLexicalBlock - This creates a descriptor for a lexical block
546 /// with the specified parent context.
547 /// @param Scope Parent lexical scope.
548 /// @param File Source file
549 /// @param Line Line number
550 /// @param Col Column number
551 DILexicalBlock createLexicalBlock(DIDescriptor Scope, DIFile File,
552 unsigned Line, unsigned Col);
554 /// insertDeclare - Insert a new llvm.dbg.declare intrinsic call.
555 /// @param Storage llvm::Value of the variable
556 /// @param VarInfo Variable's debug info descriptor.
557 /// @param InsertAtEnd Location for the new intrinsic.
558 Instruction *insertDeclare(llvm::Value *Storage, DIVariable VarInfo,
559 BasicBlock *InsertAtEnd);
561 /// insertDeclare - Insert a new llvm.dbg.declare intrinsic call.
562 /// @param Storage llvm::Value of the variable
563 /// @param VarInfo Variable's debug info descriptor.
564 /// @param InsertBefore Location for the new intrinsic.
565 Instruction *insertDeclare(llvm::Value *Storage, DIVariable VarInfo,
566 Instruction *InsertBefore);
569 /// insertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
570 /// @param Val llvm::Value of the variable
571 /// @param Offset Offset
572 /// @param VarInfo Variable's debug info descriptor.
573 /// @param InsertAtEnd Location for the new intrinsic.
574 Instruction *insertDbgValueIntrinsic(llvm::Value *Val, uint64_t Offset,
576 BasicBlock *InsertAtEnd);
578 /// insertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
579 /// @param Val llvm::Value of the variable
580 /// @param Offset Offset
581 /// @param VarInfo Variable's debug info descriptor.
582 /// @param InsertBefore Location for the new intrinsic.
583 Instruction *insertDbgValueIntrinsic(llvm::Value *Val, uint64_t Offset,
585 Instruction *InsertBefore);
588 } // end namespace llvm