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_ANALYSIS_DIBUILDER_H
16 #define LLVM_ANALYSIS_DIBUILDER_H
18 #include "llvm/Support/DataTypes.h"
19 #include "llvm/ADT/ArrayRef.h"
20 #include "llvm/ADT/StringRef.h"
36 class DIGlobalVariable;
40 class DILexicalBlockFile;
43 class DITemplateTypeParameter;
44 class DITemplateValueParameter;
50 LLVMContext & VMContext;
53 MDNode *TempEnumTypes;
54 MDNode *TempRetainTypes;
55 MDNode *TempSubprograms;
58 Function *DeclareFn; // llvm.dbg.declare
59 Function *ValueFn; // llvm.dbg.value
61 SmallVector<Value *, 4> AllEnumTypes;
62 SmallVector<Value *, 4> AllRetainTypes;
63 SmallVector<Value *, 4> AllSubprograms;
64 SmallVector<Value *, 4> AllGVs;
66 DIBuilder(const DIBuilder &); // DO NOT IMPLEMENT
67 void operator=(const DIBuilder &); // DO NOT IMPLEMENT
70 explicit DIBuilder(Module &M);
71 const MDNode *getCU() { return TheCU; }
72 enum ComplexAddrKind { OpPlus=1, OpDeref };
74 /// finalize - Construct any deferred debug info descriptors.
77 /// createCompileUnit - A CompileUnit provides an anchor for all debugging
78 /// information generated during this instance of compilation.
79 /// @param Lang Source programming language, eg. dwarf::DW_LANG_C99
80 /// @param File File name
81 /// @param Dir Directory
82 /// @param Producer String identify producer of debugging information.
83 /// Usuall this is a compiler version string.
84 /// @param isOptimized A boolean flag which indicates whether optimization
86 /// @param Flags This string lists command line options. This string is
87 /// directly embedded in debug info output which may be used
88 /// by a tool analyzing generated debugging information.
89 /// @param RV This indicates runtime version for languages like
91 void createCompileUnit(unsigned Lang, StringRef File, StringRef Dir,
93 bool isOptimized, StringRef Flags, unsigned RV);
95 /// createFile - Create a file descriptor to hold debugging information
97 DIFile createFile(StringRef Filename, StringRef Directory);
99 /// createEnumerator - Create a single enumerator value.
100 DIEnumerator createEnumerator(StringRef Name, uint64_t Val);
102 /// createNullPtrType - Create C++0x nullptr type.
103 DIType createNullPtrType(StringRef Name);
105 /// createBasicType - Create debugging information entry for a basic
107 /// @param Name Type name.
108 /// @param SizeInBits Size of the type.
109 /// @param AlignInBits Type alignment.
110 /// @param Encoding DWARF encoding code, e.g. dwarf::DW_ATE_float.
111 DIType createBasicType(StringRef Name, uint64_t SizeInBits,
112 uint64_t AlignInBits, unsigned Encoding);
114 /// createQualifiedType - Create debugging information entry for a qualified
115 /// type, e.g. 'const int'.
116 /// @param Tag Tag identifing type, e.g. dwarf::TAG_volatile_type
117 /// @param FromTy Base Type.
118 DIType createQualifiedType(unsigned Tag, DIType FromTy);
120 /// createPointerType - Create debugging information entry for a pointer.
121 /// @param PointeeTy Type pointed by this pointer.
122 /// @param SizeInBits Size.
123 /// @param AlignInBits Alignment. (optional)
124 /// @param Name Pointer type name. (optional)
125 DIType createPointerType(DIType PointeeTy, uint64_t SizeInBits,
126 uint64_t AlignInBits = 0,
127 StringRef Name = StringRef());
129 /// createReferenceType - Create debugging information entry for a c++
130 /// style reference or rvalue reference type.
131 DIType createReferenceType(unsigned Tag, DIType RTy);
133 /// createTypedef - Create debugging information entry for a typedef.
134 /// @param Ty Original type.
135 /// @param Name Typedef name.
136 /// @param File File where this type is defined.
137 /// @param LineNo Line number.
138 /// @param Context The surrounding context for the typedef.
139 DIType createTypedef(DIType Ty, StringRef Name, DIFile File,
140 unsigned LineNo, DIDescriptor Context);
142 /// createFriend - Create debugging information entry for a 'friend'.
143 DIType createFriend(DIType Ty, DIType FriendTy);
145 /// createInheritance - Create debugging information entry to establish
146 /// inheritance relationship between two types.
147 /// @param Ty Original type.
148 /// @param BaseTy Base type. Ty is inherits from base.
149 /// @param BaseOffset Base offset.
150 /// @param Flags Flags to describe inheritance attribute,
152 DIType createInheritance(DIType Ty, DIType BaseTy, uint64_t BaseOffset,
155 /// createMemberType - Create debugging information entry for a member.
156 /// @param Scope Member scope.
157 /// @param Name Member name.
158 /// @param File File where this member is defined.
159 /// @param LineNo Line number.
160 /// @param SizeInBits Member size.
161 /// @param AlignInBits Member alignment.
162 /// @param OffsetInBits Member offset.
163 /// @param Flags Flags to encode member attribute, e.g. private
164 /// @param Ty Parent type.
165 DIType createMemberType(DIDescriptor Scope, StringRef Name, DIFile File,
166 unsigned LineNo, uint64_t SizeInBits,
167 uint64_t AlignInBits, uint64_t OffsetInBits,
168 unsigned Flags, DIType Ty);
170 /// createObjCIVar - Create debugging information entry for Objective-C
171 /// instance variable.
172 /// @param Name Member name.
173 /// @param File File where this member is defined.
174 /// @param LineNo Line number.
175 /// @param SizeInBits Member size.
176 /// @param AlignInBits Member alignment.
177 /// @param OffsetInBits Member offset.
178 /// @param Flags Flags to encode member attribute, e.g. private
179 /// @param Ty Parent type.
180 /// @param PropertyName Name of the Objective C property associated with
182 /// @param PropertyGetterName Name of the Objective C property getter
184 /// @param PropertySetterName Name of the Objective C property setter
186 /// @param PropertyAttributes Objective C property attributes.
187 DIType createObjCIVar(StringRef Name, DIFile File,
188 unsigned LineNo, uint64_t SizeInBits,
189 uint64_t AlignInBits, uint64_t OffsetInBits,
190 unsigned Flags, DIType Ty,
191 StringRef PropertyName = StringRef(),
192 StringRef PropertyGetterName = StringRef(),
193 StringRef PropertySetterName = StringRef(),
194 unsigned PropertyAttributes = 0);
196 /// createObjCIVar - Create debugging information entry for Objective-C
197 /// instance variable.
198 /// @param Name Member name.
199 /// @param File File where this member is defined.
200 /// @param LineNo Line number.
201 /// @param SizeInBits Member size.
202 /// @param AlignInBits Member alignment.
203 /// @param OffsetInBits Member offset.
204 /// @param Flags Flags to encode member attribute, e.g. private
205 /// @param Ty Parent type.
206 /// @param PropertyNode Property associated with this ivar.
207 DIType createObjCIVar(StringRef Name, DIFile File,
208 unsigned LineNo, uint64_t SizeInBits,
209 uint64_t AlignInBits, uint64_t OffsetInBits,
210 unsigned Flags, DIType Ty,
211 MDNode *PropertyNode);
213 /// createObjCProperty - Create debugging information entry for Objective-C
215 /// @param Name Property name.
216 /// @param File File where this property is defined.
217 /// @param LineNumber Line number.
218 /// @param GetterName Name of the Objective C property getter selector.
219 /// @param SetterName Name of the Objective C property setter selector.
220 /// @param PropertyAttributes Objective C property attributes.
222 DIObjCProperty createObjCProperty(StringRef Name,
223 DIFile File, unsigned LineNumber,
224 StringRef GetterName,
225 StringRef SetterName,
226 unsigned PropertyAttributes,
229 /// createClassType - Create debugging information entry for a class.
230 /// @param Scope Scope in which this class is defined.
231 /// @param Name class name.
232 /// @param File File where this member is defined.
233 /// @param LineNumber Line number.
234 /// @param SizeInBits Member size.
235 /// @param AlignInBits Member alignment.
236 /// @param OffsetInBits Member offset.
237 /// @param Flags Flags to encode member attribute, e.g. private
238 /// @param Elements class members.
239 /// @param VTableHolder Debug info of the base class that contains vtable
240 /// for this type. This is used in
241 /// DW_AT_containing_type. See DWARF documentation
243 /// @param TemplateParms Template type parameters.
244 DIType createClassType(DIDescriptor Scope, StringRef Name, DIFile File,
245 unsigned LineNumber, uint64_t SizeInBits,
246 uint64_t AlignInBits, uint64_t OffsetInBits,
247 unsigned Flags, DIType DerivedFrom,
248 DIArray Elements, MDNode *VTableHolder = 0,
249 MDNode *TemplateParms = 0);
251 /// createStructType - Create debugging information entry for a struct.
252 /// @param Scope Scope in which this struct is defined.
253 /// @param Name Struct name.
254 /// @param File File where this member is defined.
255 /// @param LineNumber Line number.
256 /// @param SizeInBits Member size.
257 /// @param AlignInBits Member alignment.
258 /// @param Flags Flags to encode member attribute, e.g. private
259 /// @param Elements Struct elements.
260 /// @param RunTimeLang Optional parameter, Objective-C runtime version.
261 DIType createStructType(DIDescriptor Scope, StringRef Name, DIFile File,
262 unsigned LineNumber, uint64_t SizeInBits,
263 uint64_t AlignInBits, unsigned Flags,
264 DIArray Elements, unsigned RunTimeLang = 0);
266 /// createUnionType - Create debugging information entry for an union.
267 /// @param Scope Scope in which this union is defined.
268 /// @param Name Union name.
269 /// @param File File where this member is defined.
270 /// @param LineNumber Line number.
271 /// @param SizeInBits Member size.
272 /// @param AlignInBits Member alignment.
273 /// @param Flags Flags to encode member attribute, e.g. private
274 /// @param Elements Union elements.
275 /// @param RunTimeLang Optional parameter, Objective-C runtime version.
276 DIType createUnionType(DIDescriptor Scope, StringRef Name, DIFile File,
277 unsigned LineNumber, uint64_t SizeInBits,
278 uint64_t AlignInBits, unsigned Flags,
279 DIArray Elements, unsigned RunTimeLang = 0);
281 /// createTemplateTypeParameter - Create debugging information for template
283 /// @param Scope Scope in which this type is defined.
284 /// @param Name Type parameter name.
285 /// @param Ty Parameter type.
286 /// @param File File where this type parameter is defined.
287 /// @param LineNo Line number.
288 /// @param ColumnNo Column Number.
289 DITemplateTypeParameter
290 createTemplateTypeParameter(DIDescriptor Scope, StringRef Name, DIType Ty,
291 MDNode *File = 0, unsigned LineNo = 0,
292 unsigned ColumnNo = 0);
294 /// createTemplateValueParameter - Create debugging information for template
296 /// @param Scope Scope in which this type is defined.
297 /// @param Name Value parameter name.
298 /// @param Ty Parameter type.
299 /// @param Value Constant parameter value.
300 /// @param File File where this type parameter is defined.
301 /// @param LineNo Line number.
302 /// @param ColumnNo Column Number.
303 DITemplateValueParameter
304 createTemplateValueParameter(DIDescriptor Scope, StringRef Name, DIType Ty,
306 MDNode *File = 0, unsigned LineNo = 0,
307 unsigned ColumnNo = 0);
309 /// createArrayType - Create debugging information entry for an array.
310 /// @param Size Array size.
311 /// @param AlignInBits Alignment.
312 /// @param Ty Element type.
313 /// @param Subscripts Subscripts.
314 DIType createArrayType(uint64_t Size, uint64_t AlignInBits,
315 DIType Ty, DIArray Subscripts);
317 /// createVectorType - Create debugging information entry for a vector type.
318 /// @param Size Array size.
319 /// @param AlignInBits Alignment.
320 /// @param Ty Element type.
321 /// @param Subscripts Subscripts.
322 DIType createVectorType(uint64_t Size, uint64_t AlignInBits,
323 DIType Ty, DIArray Subscripts);
325 /// createEnumerationType - Create debugging information entry for an
327 /// @param Scope Scope in which this enumeration is defined.
328 /// @param Name Union name.
329 /// @param File File where this member is defined.
330 /// @param LineNumber Line number.
331 /// @param SizeInBits Member size.
332 /// @param AlignInBits Member alignment.
333 /// @param Elements Enumeration elements.
334 /// @param Flags Flags (e.g. forward decl)
335 DIType createEnumerationType(DIDescriptor Scope, StringRef Name,
336 DIFile File, unsigned LineNumber,
337 uint64_t SizeInBits, uint64_t AlignInBits,
338 DIArray Elements, DIType ClassType,
341 /// createSubroutineType - Create subroutine type.
342 /// @param File File in which this subroutine is defined.
343 /// @param ParameterTypes An array of subroutine parameter types. This
344 /// includes return type at 0th index.
345 DIType createSubroutineType(DIFile File, DIArray ParameterTypes);
347 /// createArtificialType - Create a new DIType with "artificial" flag set.
348 DIType createArtificialType(DIType Ty);
350 /// createTemporaryType - Create a temporary forward-declared type.
351 DIType createTemporaryType();
352 DIType createTemporaryType(DIFile F);
354 /// createForwardDecl - Create a temporary forward-declared type.
355 DIType createForwardDecl(unsigned Tag, StringRef Name, DIDescriptor Scope,
356 DIFile F, unsigned Line, unsigned RuntimeLang = 0);
358 /// retainType - Retain DIType in a module even if it is not referenced
359 /// through debug info anchors.
360 void retainType(DIType T);
362 /// createUnspecifiedParameter - Create unspeicified type descriptor
363 /// for a subroutine type.
364 DIDescriptor createUnspecifiedParameter();
366 /// getOrCreateArray - Get a DIArray, create one if required.
367 DIArray getOrCreateArray(ArrayRef<Value *> Elements);
369 /// getOrCreateSubrange - Create a descriptor for a value range. This
370 /// implicitly uniques the values returned.
371 DISubrange getOrCreateSubrange(int64_t Lo, int64_t Hi);
373 /// createGlobalVariable - Create a new descriptor for the specified global.
374 /// @param Name Name of the variable.
375 /// @param File File where this variable is defined.
376 /// @param LineNo Line number.
377 /// @param Ty Variable Type.
378 /// @param isLocalToUnit Boolean flag indicate whether this variable is
379 /// externally visible or not.
380 /// @param Val llvm::Value of the variable.
382 createGlobalVariable(StringRef Name, DIFile File, unsigned LineNo,
383 DIType Ty, bool isLocalToUnit, llvm::Value *Val);
386 /// createStaticVariable - Create a new descriptor for the specified
388 /// @param Context Variable scope.
389 /// @param Name Name of the variable.
390 /// @param LinkageName Mangled name of the variable.
391 /// @param File File where this variable is defined.
392 /// @param LineNo Line number.
393 /// @param Ty Variable Type.
394 /// @param isLocalToUnit Boolean flag indicate whether this variable is
395 /// externally visible or not.
396 /// @param Val llvm::Value of the variable.
398 createStaticVariable(DIDescriptor Context, StringRef Name,
399 StringRef LinkageName, DIFile File, unsigned LineNo,
400 DIType Ty, bool isLocalToUnit, llvm::Value *Val);
403 /// createLocalVariable - Create a new descriptor for the specified
405 /// @param Tag Dwarf TAG. Usually DW_TAG_auto_variable or
406 /// DW_TAG_arg_variable.
407 /// @param Scope Variable scope.
408 /// @param Name Variable name.
409 /// @param File File where this variable is defined.
410 /// @param LineNo Line number.
411 /// @param Ty Variable Type
412 /// @param AlwaysPreserve Boolean. Set to true if debug info for this
413 /// variable should be preserved in optimized build.
414 /// @param Flags Flags, e.g. artificial variable.
415 /// @param ArgNo If this variable is an arugment then this argument's
416 /// number. 1 indicates 1st argument.
417 DIVariable createLocalVariable(unsigned Tag, DIDescriptor Scope,
419 DIFile File, unsigned LineNo,
420 DIType Ty, bool AlwaysPreserve = false,
425 /// createComplexVariable - Create a new descriptor for the specified
426 /// variable which has a complex address expression for its address.
427 /// @param Tag Dwarf TAG. Usually DW_TAG_auto_variable or
428 /// DW_TAG_arg_variable.
429 /// @param Scope Variable scope.
430 /// @param Name Variable name.
431 /// @param F File where this variable is defined.
432 /// @param LineNo Line number.
433 /// @param Ty Variable Type
434 /// @param Addr An array of complex address operations.
435 /// @param ArgNo If this variable is an arugment then this argument's
436 /// number. 1 indicates 1st argument.
437 DIVariable createComplexVariable(unsigned Tag, DIDescriptor Scope,
438 StringRef Name, DIFile F, unsigned LineNo,
439 DIType Ty, ArrayRef<Value *> Addr,
442 /// createFunction - Create a new descriptor for the specified subprogram.
443 /// See comments in DISubprogram for descriptions of these fields.
444 /// @param Scope Function scope.
445 /// @param Name Function name.
446 /// @param LinkageName Mangled function name.
447 /// @param File File where this variable is defined.
448 /// @param LineNo Line number.
449 /// @param Ty Function type.
450 /// @param isLocalToUnit True if this function is not externally visible..
451 /// @param isDefinition True if this is a function definition.
452 /// @param ScopeLine Set to the beginning of the scope this starts
453 /// @param Flags e.g. is this function prototyped or not.
454 /// This flags are used to emit dwarf attributes.
455 /// @param isOptimized True if optimization is ON.
456 /// @param Fn llvm::Function pointer.
457 /// @param TParam Function template parameters.
458 DISubprogram createFunction(DIDescriptor Scope, StringRef Name,
459 StringRef LinkageName,
460 DIFile File, unsigned LineNo,
461 DIType Ty, bool isLocalToUnit,
465 bool isOptimized = false,
470 /// createMethod - Create a new descriptor for the specified C++ method.
471 /// See comments in DISubprogram for descriptions of these fields.
472 /// @param Scope Function scope.
473 /// @param Name Function name.
474 /// @param LinkageName Mangled function name.
475 /// @param File File where this variable is defined.
476 /// @param LineNo Line number.
477 /// @param Ty Function type.
478 /// @param isLocalToUnit True if this function is not externally visible..
479 /// @param isDefinition True if this is a function definition.
480 /// @param Virtuality Attributes describing virtualness. e.g. pure
481 /// virtual function.
482 /// @param VTableIndex Index no of this method in virtual table.
483 /// @param VTableHolder Type that holds vtable.
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 createMethod(DIDescriptor Scope, StringRef Name,
490 StringRef LinkageName,
491 DIFile File, unsigned LineNo,
492 DIType Ty, bool isLocalToUnit,
494 unsigned Virtuality = 0, unsigned VTableIndex = 0,
495 MDNode *VTableHolder = 0,
497 bool isOptimized = false,
501 /// createNameSpace - This creates new descriptor for a namespace
502 /// with the specified parent scope.
503 /// @param Scope Namespace scope
504 /// @param Name Name of this namespace
505 /// @param File Source file
506 /// @param LineNo Line number
507 DINameSpace createNameSpace(DIDescriptor Scope, StringRef Name,
508 DIFile File, unsigned LineNo);
511 /// createLexicalBlockFile - This creates a descriptor for a lexical
512 /// block with a new file attached. This merely extends the existing
513 /// lexical block as it crosses a file.
514 /// @param Scope Lexical block.
515 /// @param File Source file.
516 DILexicalBlockFile createLexicalBlockFile(DIDescriptor Scope,
519 /// createLexicalBlock - This creates a descriptor for a lexical block
520 /// with the specified parent context.
521 /// @param Scope Parent lexical scope.
522 /// @param File Source file
523 /// @param Line Line number
524 /// @param Col Column number
525 DILexicalBlock createLexicalBlock(DIDescriptor Scope, DIFile File,
526 unsigned Line, unsigned Col);
528 /// insertDeclare - Insert a new llvm.dbg.declare intrinsic call.
529 /// @param Storage llvm::Value of the variable
530 /// @param VarInfo Variable's debug info descriptor.
531 /// @param InsertAtEnd Location for the new intrinsic.
532 Instruction *insertDeclare(llvm::Value *Storage, DIVariable VarInfo,
533 BasicBlock *InsertAtEnd);
535 /// insertDeclare - Insert a new llvm.dbg.declare intrinsic call.
536 /// @param Storage llvm::Value of the variable
537 /// @param VarInfo Variable's debug info descriptor.
538 /// @param InsertBefore Location for the new intrinsic.
539 Instruction *insertDeclare(llvm::Value *Storage, DIVariable VarInfo,
540 Instruction *InsertBefore);
543 /// insertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
544 /// @param Val llvm::Value of the variable
545 /// @param Offset Offset
546 /// @param VarInfo Variable's debug info descriptor.
547 /// @param InsertAtEnd Location for the new intrinsic.
548 Instruction *insertDbgValueIntrinsic(llvm::Value *Val, uint64_t Offset,
550 BasicBlock *InsertAtEnd);
552 /// insertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
553 /// @param Val llvm::Value of the variable
554 /// @param Offset Offset
555 /// @param VarInfo Variable's debug info descriptor.
556 /// @param InsertBefore Location for the new intrinsic.
557 Instruction *insertDbgValueIntrinsic(llvm::Value *Val, uint64_t Offset,
559 Instruction *InsertBefore);
562 } // end namespace llvm