1 //===--- llvm/Analysis/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;
42 class DITemplateTypeParameter;
43 class DITemplateValueParameter;
48 LLVMContext & VMContext;
51 Function *DeclareFn; // llvm.dbg.declare
52 Function *ValueFn; // llvm.dbg.value
54 DIBuilder(const DIBuilder &); // DO NOT IMPLEMENT
55 void operator=(const DIBuilder &); // DO NOT IMPLEMENT
58 explicit DIBuilder(Module &M);
59 const MDNode *getCU() { return TheCU; }
60 enum ComplexAddrKind { OpPlus=1, OpDeref };
62 /// createCompileUnit - A CompileUnit provides an anchor for all debugging
63 /// information generated during this instance of compilation.
64 /// @param Lang Source programming language, eg. dwarf::DW_LANG_C99
65 /// @param File File name
66 /// @param Dir Directory
67 /// @param Producer String identify producer of debugging information.
68 /// Usuall this is a compiler version string.
69 /// @param isOptimized A boolean flag which indicates whether optimization
71 /// @param Flags This string lists command line options. This string is
72 /// directly embedded in debug info output which may be used
73 /// by a tool analyzing generated debugging information.
74 /// @param RV This indicates runtime version for languages like
76 void createCompileUnit(unsigned Lang, StringRef File, StringRef Dir,
78 bool isOptimized, StringRef Flags, unsigned RV);
80 /// createFile - Create a file descriptor to hold debugging information
82 DIFile createFile(StringRef Filename, StringRef Directory);
84 /// createEnumerator - Create a single enumerator value.
85 DIEnumerator createEnumerator(StringRef Name, uint64_t Val);
87 /// createBasicType - Create debugging information entry for a basic
89 /// @param Name Type name.
90 /// @param SizeInBits Size of the type.
91 /// @param AlignInBits Type alignment.
92 /// @param Encoding DWARF encoding code, e.g. dwarf::DW_ATE_float.
93 DIType createBasicType(StringRef Name, uint64_t SizeInBits,
94 uint64_t AlignInBits, unsigned Encoding);
96 /// createQualifiedType - Create debugging information entry for a qualified
97 /// type, e.g. 'const int'.
98 /// @param Tag Tag identifing type, e.g. dwarf::TAG_volatile_type
99 /// @param FromTy Base Type.
100 DIType createQualifiedType(unsigned Tag, DIType FromTy);
102 /// createPointerType - Create debugging information entry for a pointer.
103 /// @param PointeeTy Type pointed by this pointer.
104 /// @param SizeInBits Size.
105 /// @param AlignInBits Alignment. (optional)
106 /// @param Name Pointer type name. (optional)
107 DIType createPointerType(DIType PointeeTy, uint64_t SizeInBits,
108 uint64_t AlignInBits = 0,
109 StringRef Name = StringRef());
111 /// createReferenceType - Create debugging information entry for a c++
113 DIType createReferenceType(DIType RTy);
115 /// createTypedef - Create debugging information entry for a typedef.
116 /// @param Ty Original type.
117 /// @param Name Typedef name.
118 /// @param File File where this type is defined.
119 /// @param LineNo Line number.
120 DIType createTypedef(DIType Ty, StringRef Name, DIFile File,
123 /// createFriend - Create debugging information entry for a 'friend'.
124 DIType createFriend(DIType Ty, DIType FriendTy);
126 /// createInheritance - Create debugging information entry to establish
127 /// inheritance relationship between two types.
128 /// @param Ty Original type.
129 /// @param BaseTy Base type. Ty is inherits from base.
130 /// @param BaseOffset Base offset.
131 /// @param Flags Flags to describe inheritance attribute,
133 DIType createInheritance(DIType Ty, DIType BaseTy, uint64_t BaseOffset,
136 /// createMemberType - Create debugging information entry for a member.
137 /// @param Name Member name.
138 /// @param File File where this member is defined.
139 /// @param LineNo Line number.
140 /// @param SizeInBits Member size.
141 /// @param AlignInBits Member alignment.
142 /// @param OffsetInBits Member offset.
143 /// @param Flags Flags to encode member attribute, e.g. private
144 /// @param Ty Parent type.
145 DIType createMemberType(StringRef Name, DIFile File,
146 unsigned LineNo, uint64_t SizeInBits,
147 uint64_t AlignInBits, uint64_t OffsetInBits,
148 unsigned Flags, DIType Ty);
150 /// createObjCIVar - Create debugging information entry for Objective-C
151 /// instance variable.
152 /// @param Name Member name.
153 /// @param File File where this member is defined.
154 /// @param LineNo Line number.
155 /// @param SizeInBits Member size.
156 /// @param AlignInBits Member alignment.
157 /// @param OffsetInBits Member offset.
158 /// @param Flags Flags to encode member attribute, e.g. private
159 /// @param Ty Parent type.
160 /// @param PropertyName Name of the Objective C property assoicated with
162 /// @param GetterName Name of the Objective C property getter selector.
163 /// @param SetterName Name of the Objective C property setter selector.
164 /// @param PropertyAttributes Objective C property attributes.
165 DIType createObjCIVar(StringRef Name, DIFile File,
166 unsigned LineNo, uint64_t SizeInBits,
167 uint64_t AlignInBits, uint64_t OffsetInBits,
168 unsigned Flags, DIType Ty,
169 StringRef PropertyName = StringRef(),
170 StringRef PropertyGetterName = StringRef(),
171 StringRef PropertySetterName = StringRef(),
172 unsigned PropertyAttributes = 0);
174 /// createClassType - Create debugging information entry for a class.
175 /// @param Scope Scope in which this class is defined.
176 /// @param Name class name.
177 /// @param File File where this member is defined.
178 /// @param LineNo Line number.
179 /// @param SizeInBits Member size.
180 /// @param AlignInBits Member alignment.
181 /// @param OffsetInBits Member offset.
182 /// @param Flags Flags to encode member attribute, e.g. private
183 /// @param Elements class members.
184 /// @param VTableHolder Debug info of the base class that contains vtable
185 /// for this type. This is used in
186 /// DW_AT_containing_type. See DWARF documentation
188 /// @param TemplateParms Template type parameters.
189 DIType createClassType(DIDescriptor Scope, StringRef Name, DIFile File,
190 unsigned LineNumber, uint64_t SizeInBits,
191 uint64_t AlignInBits, uint64_t OffsetInBits,
192 unsigned Flags, DIType DerivedFrom,
193 DIArray Elements, MDNode *VTableHolder = 0,
194 MDNode *TemplateParms = 0);
196 /// createStructType - Create debugging information entry for a struct.
197 /// @param Scope Scope in which this struct is defined.
198 /// @param Name Struct 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 Flags Flags to encode member attribute, e.g. private
204 /// @param Elements Struct elements.
205 /// @param RunTimeLang Optional parameter, Objective-C runtime version.
206 DIType createStructType(DIDescriptor Scope, StringRef Name, DIFile File,
207 unsigned LineNumber, uint64_t SizeInBits,
208 uint64_t AlignInBits, unsigned Flags,
209 DIArray Elements, unsigned RunTimeLang = 0);
211 /// createUnionType - Create debugging information entry for an union.
212 /// @param Scope Scope in which this union is defined.
213 /// @param Name Union name.
214 /// @param File File where this member is defined.
215 /// @param LineNo Line number.
216 /// @param SizeInBits Member size.
217 /// @param AlignInBits Member alignment.
218 /// @param Flags Flags to encode member attribute, e.g. private
219 /// @param Elements Union elements.
220 /// @param RunTimeLang Optional parameter, Objective-C runtime version.
221 DIType createUnionType(DIDescriptor Scope, StringRef Name, DIFile File,
222 unsigned LineNumber, uint64_t SizeInBits,
223 uint64_t AlignInBits, unsigned Flags,
224 DIArray Elements, unsigned RunTimeLang = 0);
226 /// createTemplateTypeParameter - Create debugging information for template
228 /// @param Scope Scope in which this type is defined.
229 /// @param Name Type parameter name.
230 /// @param Ty Parameter type.
231 /// @param File File where this type parameter is defined.
232 /// @param LineNo Line number.
233 /// @param ColumnNo Column Number.
234 DITemplateTypeParameter
235 createTemplateTypeParameter(DIDescriptor Scope, StringRef Name, DIType Ty,
236 MDNode *File = 0, unsigned LineNo = 0,
237 unsigned ColumnNo = 0);
239 /// createTemplateValueParameter - Create debugging information for template
241 /// @param Scope Scope in which this type is defined.
242 /// @param Name Value parameter name.
243 /// @param Ty Parameter type.
244 /// @param Value Constant parameter value.
245 /// @param File File where this type parameter is defined.
246 /// @param LineNo Line number.
247 /// @param ColumnNo Column Number.
248 DITemplateValueParameter
249 createTemplateValueParameter(DIDescriptor Scope, StringRef Name, DIType Ty,
251 MDNode *File = 0, unsigned LineNo = 0,
252 unsigned ColumnNo = 0);
254 /// createArrayType - Create debugging information entry for an array.
255 /// @param Size Array size.
256 /// @param AlignInBits Alignment.
257 /// @param Ty Element type.
258 /// @param Subscripts Subscripts.
259 DIType createArrayType(uint64_t Size, uint64_t AlignInBits,
260 DIType Ty, DIArray Subscripts);
262 /// createVectorType - Create debugging information entry for a vector type.
263 /// @param Size Array size.
264 /// @param AlignInBits Alignment.
265 /// @param Ty Element type.
266 /// @param Subscripts Subscripts.
267 DIType createVectorType(uint64_t Size, uint64_t AlignInBits,
268 DIType Ty, DIArray Subscripts);
270 /// createEnumerationType - Create debugging information entry for an
272 /// @param Scope Scope in which this enumeration is defined.
273 /// @param Name Union name.
274 /// @param File File where this member is defined.
275 /// @param LineNo Line number.
276 /// @param SizeInBits Member size.
277 /// @param AlignInBits Member alignment.
278 /// @param Elements Enumeration elements.
279 DIType createEnumerationType(DIDescriptor Scope, StringRef Name,
280 DIFile File, unsigned LineNumber,
282 uint64_t AlignInBits, DIArray Elements);
284 /// createSubroutineType - Create subroutine type.
285 /// @param File File in which this subroutine is defined.
286 /// @param ParamterTypes An array of subroutine parameter types. This
287 /// includes return type at 0th index.
288 DIType createSubroutineType(DIFile File, DIArray ParameterTypes);
290 /// createArtificialType - Create a new DIType with "artificial" flag set.
291 DIType createArtificialType(DIType Ty);
293 /// createTemporaryType - Create a temporary forward-declared type.
294 DIType createTemporaryType();
295 DIType createTemporaryType(DIFile F);
297 /// retainType - Retain DIType in a module even if it is not referenced
298 /// through debug info anchors.
299 void retainType(DIType T);
301 /// createUnspecifiedParameter - Create unspeicified type descriptor
302 /// for a subroutine type.
303 DIDescriptor createUnspecifiedParameter();
305 /// getOrCreateArray - Get a DIArray, create one if required.
306 DIArray getOrCreateArray(ArrayRef<Value *> Elements);
308 /// getOrCreateSubrange - Create a descriptor for a value range. This
309 /// implicitly uniques the values returned.
310 DISubrange getOrCreateSubrange(int64_t Lo, int64_t Hi);
312 /// createGlobalVariable - Create a new descriptor for the specified global.
313 /// @param Name Name of the variable.
314 /// @param File File where this variable is defined.
315 /// @param LineNo Line number.
316 /// @param Ty Variable Type.
317 /// @param isLocalToUnit Boolean flag indicate whether this variable is
318 /// externally visible or not.
319 /// @param Val llvm::Value of the variable.
321 createGlobalVariable(StringRef Name, DIFile File, unsigned LineNo,
322 DIType Ty, bool isLocalToUnit, llvm::Value *Val);
325 /// createStaticVariable - Create a new descriptor for the specified
327 /// @param Conext Variable scope.
328 /// @param Name Name of the variable.
329 /// @param LinakgeName Mangled name of the variable.
330 /// @param File File where this variable is defined.
331 /// @param LineNo Line number.
332 /// @param Ty Variable Type.
333 /// @param isLocalToUnit Boolean flag indicate whether this variable is
334 /// externally visible or not.
335 /// @param Val llvm::Value of the variable.
337 createStaticVariable(DIDescriptor Context, StringRef Name,
338 StringRef LinkageName, DIFile File, unsigned LineNo,
339 DIType Ty, bool isLocalToUnit, llvm::Value *Val);
342 /// createLocalVariable - Create a new descriptor for the specified
344 /// @param Tag Dwarf TAG. Usually DW_TAG_auto_variable or
345 /// DW_TAG_arg_variable.
346 /// @param Scope Variable scope.
347 /// @param Name Variable name.
348 /// @param File File where this variable is defined.
349 /// @param LineNo Line number.
350 /// @param Ty Variable Type
351 /// @param AlwaysPreserve Boolean. Set to true if debug info for this
352 /// variable should be preserved in optimized build.
353 /// @param Flags Flags, e.g. artificial variable.
354 /// @param ArgNo If this variable is an arugment then this argument's
355 /// number. 1 indicates 1st argument.
356 DIVariable createLocalVariable(unsigned Tag, DIDescriptor Scope,
358 DIFile File, unsigned LineNo,
359 DIType Ty, bool AlwaysPreserve = false,
364 /// createComplexVariable - Create a new descriptor for the specified
365 /// variable which has a complex address expression for its address.
366 /// @param Tag Dwarf TAG. Usually DW_TAG_auto_variable or
367 /// DW_TAG_arg_variable.
368 /// @param Scope Variable scope.
369 /// @param Name Variable name.
370 /// @param File File where this variable is defined.
371 /// @param LineNo Line number.
372 /// @param Ty Variable Type
373 /// @param Addr An array of complex address operations.
374 /// @param ArgNo If this variable is an arugment then this argument's
375 /// number. 1 indicates 1st argument.
376 DIVariable createComplexVariable(unsigned Tag, DIDescriptor Scope,
377 StringRef Name, DIFile F, unsigned LineNo,
378 DIType Ty, ArrayRef<Value *> Addr,
381 /// createFunction - Create a new descriptor for the specified subprogram.
382 /// See comments in DISubprogram for descriptions of these fields.
383 /// @param Scope Function scope.
384 /// @param Name Function name.
385 /// @param LinkageName Mangled function name.
386 /// @param File File where this variable is defined.
387 /// @param LineNo Line number.
388 /// @param Ty Function type.
389 /// @param isLocalToUnit True if this function is not externally visible..
390 /// @param isDefinition True if this is a function definition.
391 /// @param Flags e.g. is this function prototyped or not.
392 /// This flags are used to emit dwarf attributes.
393 /// @param isOptimized True if optimization is ON.
394 /// @param Fn llvm::Function pointer.
395 /// @param TParam Function template parameters.
396 DISubprogram createFunction(DIDescriptor Scope, StringRef Name,
397 StringRef LinkageName,
398 DIFile File, unsigned LineNo,
399 DIType Ty, bool isLocalToUnit,
402 bool isOptimized = false,
407 /// createMethod - Create a new descriptor for the specified C++ method.
408 /// See comments in DISubprogram for descriptions of these fields.
409 /// @param Scope Function scope.
410 /// @param Name Function name.
411 /// @param LinkageName Mangled function name.
412 /// @param File File where this variable is defined.
413 /// @param LineNo Line number.
414 /// @param Ty Function type.
415 /// @param isLocalToUnit True if this function is not externally visible..
416 /// @param isDefinition True if this is a function definition.
417 /// @param Virtuality Attributes describing virtualness. e.g. pure
418 /// virtual function.
419 /// @param VTableIndex Index no of this method in virtual table.
420 /// @param VTableHolder Type that holds vtable.
421 /// @param Flags e.g. is this function prototyped or not.
422 /// This flags are used to emit dwarf attributes.
423 /// @param isOptimized True if optimization is ON.
424 /// @param Fn llvm::Function pointer.
425 /// @param TParam Function template parameters.
426 DISubprogram createMethod(DIDescriptor Scope, StringRef Name,
427 StringRef LinkageName,
428 DIFile File, unsigned LineNo,
429 DIType Ty, bool isLocalToUnit,
431 unsigned Virtuality = 0, unsigned VTableIndex = 0,
432 MDNode *VTableHolder = 0,
434 bool isOptimized = false,
438 /// createNameSpace - This creates new descriptor for a namespace
439 /// with the specified parent scope.
440 /// @param Scope Namespace scope
441 /// @param Name Name of this namespace
442 /// @param File Source file
443 /// @param LineNo Line number
444 DINameSpace createNameSpace(DIDescriptor Scope, StringRef Name,
445 DIFile File, unsigned LineNo);
448 /// createLexicalBlock - This creates a descriptor for a lexical block
449 /// with the specified parent context.
450 /// @param Scope Parent lexical scope.
451 /// @param File Source file
452 /// @param Line Line number
453 /// @param Col Column number
454 DILexicalBlock createLexicalBlock(DIDescriptor Scope, DIFile File,
455 unsigned Line, unsigned Col);
457 /// insertDeclare - Insert a new llvm.dbg.declare intrinsic call.
458 /// @param Storage llvm::Value of the variable
459 /// @param VarInfo Variable's debug info descriptor.
460 /// @param InsertAtEnd Location for the new intrinsic.
461 Instruction *insertDeclare(llvm::Value *Storage, DIVariable VarInfo,
462 BasicBlock *InsertAtEnd);
464 /// insertDeclare - Insert a new llvm.dbg.declare intrinsic call.
465 /// @param Storage llvm::Value of the variable
466 /// @param VarInfo Variable's debug info descriptor.
467 /// @param InsertBefore Location for the new intrinsic.
468 Instruction *insertDeclare(llvm::Value *Storage, DIVariable VarInfo,
469 Instruction *InsertBefore);
472 /// insertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
473 /// @param Val llvm::Value of the variable
474 /// @param Offset Offset
475 /// @param VarInfo Variable's debug info descriptor.
476 /// @param InsertAtEnd Location for the new intrinsic.
477 Instruction *insertDbgValueIntrinsic(llvm::Value *Val, uint64_t Offset,
479 BasicBlock *InsertAtEnd);
481 /// insertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
482 /// @param Val llvm::Value of the variable
483 /// @param Offset Offset
484 /// @param VarInfo Variable's debug info descriptor.
485 /// @param InsertBefore Location for the new intrinsic.
486 Instruction *insertDbgValueIntrinsic(llvm::Value *Val, uint64_t Offset,
488 Instruction *InsertBefore);
491 } // end namespace llvm