DIBuilder
public final class DIBuilder
A DIBuilder
is a helper object used to generate debugging information in
the form of LLVM metadata. A DIBuilder
is usually paired with an
IRBuilder
to allow for the generation of code and metadata in lock step.
-
The module this
DIBuilder
is associated with.Declaration
Swift
public let module: Module
-
Initializes a new
DIBuilder
object.Declaration
Swift
public init(module: Module, allowUnresolved: Bool = true)
Parameters
module
The parent module.
allowUnresolved
If true, when this DIBuilder is finalized it will collect unresolved nodes attached to the module in order to resolve cycles
-
Construct any deferred debug info descriptors.
Declaration
Swift
public func finalize()
-
Builds a call to a debug intrinsic for declaring a local variable and inserts it before a given instruction.
This intrinsic provides information about a local element (e.g. a variable) defined in some lexical scope. The variable does not have to be physically represented in the source.
Each variable may have at most one corresponding
llvm.dbg.declare
. A variable declaration is not control-dependent: A variable is declared at most once, and that declaration remains in effect until the lifetime of that variable ends.lldb.dbg.declare
can make optimizing code that needs accurate debug info difficult because of these scoping constraints.Declaration
Swift
public func buildDeclare( of variable: IRValue, before: IRInstruction, metadata: LocalVariableMetadata, expr: ExpressionMetadata, location: DebugLocation )
Parameters
variable
The IRValue of a variable to declare.
before
The instruction before which the intrinsic will be inserted.
metadata
Local variable metadata.
expr
A “complex expression” that modifies the current variable declaration.
location
The location of the variable in source.
-
Builds a call to a debug intrinsic for declaring a local variable and inserts it at the end of a given basic block.
This intrinsic provides information about a local element (e.g. a variable) defined in some lexical scope. The variable does not have to be physically represented in the source.
Each variable may have at most one corresponding
llvm.dbg.declare
. A variable declaration is not control-dependent: A variable is declared at most once, and that declaration remains in effect until the lifetime of that variable ends.lldb.dbg.declare
can make optimizing code that needs accurate debug info difficult because of these scoping constraints.Declaration
Swift
public func buildDeclare( of variable: IRValue, atEndOf block: BasicBlock, metadata: LocalVariableMetadata, expr: ExpressionMetadata, location: DebugLocation )
Parameters
variable
The IRValue of a variable to declare.
block
The block in which the intrinsic will be placed.
metadata
Local variable metadata.
expr
A “complex expression” that modifies the current variable declaration.
location
The location of the variable in source.
-
Builds a call to a debug intrinsic for providing information about the value of a local variable and inserts it before a given instruction.
This intrinsic provides information to model the result of a source variable being set to a new value.
This intrinsic is built to describe the value of a source variable directly. That is, the source variable may be a value or an address, but the value for that variable provided to this intrinsic is considered without interpretation to be the value of the given variable.
Declaration
Swift
public func buildDbgValue( of value: IRValue, to metadata: LocalVariableMetadata, before: IRInstruction, expr: ExpressionMetadata, location: DebugLocation )
Parameters
value
The value to set the given variable to.
metadata
Metadata for the given local variable.
before
The instruction before which the intrinsic will be inserted.
expr
A “complex expression” that modifies the given value.
location
The location of the variable assignment in source.
-
Builds a call to a debug intrinsic for providing information about the value of a local variable and inserts it before a given instruction.
This intrinsic provides information to model the result of a source variable being set to a new value.
This intrinsic is built to describe the value of a source variable directly. That is, the source variable may be a value or an address, but the value for that variable provided to this intrinsic is considered without interpretation to be the value of the given variable.
Declaration
Swift
public func buildDbgValue( of value: IRValue, to metadata: LocalVariableMetadata, atEndOf block: BasicBlock, expr: ExpressionMetadata, location: DebugLocation )
Parameters
value
The value to set the given variable to.
metadata
Metadata for the given local variable.
block
The block in which the intrinsic will be placed.
expr
A “complex expression” that modifies the given value.
location
The location of the variable assignment in source.
-
buildCompileUnit(for:
in: kind: optimized: splitDebugInlining: debugInfoForProfiling: flags: runtimeVersion: splitDWARFPath: identity: sysRoot: sdkRoot: ) A CompileUnit provides an anchor for all debugging information generated during this instance of compilation.
Declaration
Swift
public func buildCompileUnit( for language: DWARFSourceLanguage, in file: FileMetadata, kind: DWARFEmissionKind, optimized: Bool = false, splitDebugInlining: Bool = false, debugInfoForProfiling: Bool = false, flags: [String] = [], runtimeVersion: Int = 0, splitDWARFPath: String = "", identity: String = "", sysRoot: String = "", sdkRoot: String = "" ) -> CompileUnitMetadata
Parameters
language
The source programming language.
file
The file descriptor for the source file.
kind
The kind of debug info to generate.
optimized
A flag that indicates whether optimization is enabled or not when compiling the source file. Defaults to
false
.splitDebugInlining
If true, minimal debug info in the module is emitted to facilitate online symbolication and stack traces in the absence of .dwo/.dwp files when using Split DWARF.
debugInfoForProfiling
A flag that indicates whether to emit extra debug information for profile collection.
flags
Command line options that are embedded in debug info for use by third-party tools.
splitDWARFPath
The path to the split DWARF file.
identity
The identity of the tool that is compiling this source file.
sysRoot
The Clang system root (the value of the
-isysroot
that’s passed to clang).sdkRoot
The SDK root – on Darwin platforms, this is the last component of the sysroot.
Return Value
A value representing a compilation-unit level scope.
-
Create a file descriptor to hold debugging information for a file.
Global variables and top level functions would be defined using this context. File descriptors also provide context for source line correspondence.
Declaration
Swift
public func buildFile( named name: String, in directory: String ) -> FileMetadata
Parameters
name
The name of the file.
directory
The directory the file resides in.
Return Value
A value represending metadata about a given file.
-
Creates a new descriptor for a module with the specified parent scope.
Declaration
Swift
public func buildModule( named name: String, scope: DIScope, macros: [String] = [], includePath: String = "", includeSystemRoot: String = "" ) -> ModuleMetadata
Parameters
name
Module name.
scope
The parent scope containing this module declaration.
macros
A list of -D macro definitions as they would appear on a command line.
includePath
The path to the module map file.
includeSystemRoot
The Clang system root (value of -isysroot).
-
Creates a new descriptor for a namespace with the specified parent scope.
Declaration
Swift
public func buildNameSpace( named name: String, scope: DIScope, exportsSymbols: Bool ) -> NameSpaceMetadata
Parameters
name
NameSpace name.
scope
The parent scope containing this module declaration.
exportsSymbols
Whether or not the namespace exports symbols, e.g. this is true of C++ inline namespaces.
-
buildFunction(named:
linkageName: scope: file: line: scopeLine: type: flags: isLocal: isDefinition: isOptimized: ) Create a new descriptor for the specified subprogram.
Declaration
Swift
public func buildFunction( named name: String, linkageName: String, scope: DIScope, file: FileMetadata, line: Int, scopeLine: Int, type: DISubroutineType, flags: DIFlags, isLocal: Bool = true, isDefinition: Bool = true, isOptimized: Bool = false ) -> FunctionMetadata
Parameters
name
Function name.
linkageName
Mangled function name.
scope
Function scope.
file
File where this variable is defined.
line
Line number.
scopeLine
Set to the beginning of the scope this starts
type
Function type.
flags
Flags to emit DWARF attributes.
isLocal
True if this function is not externally visible.
isDefinition
True if this is a function definition.
isOptimized
True if optimization is enabled.
-
Create a descriptor for a lexical block with the specified parent context.
Declaration
Swift
public func buildLexicalBlock( scope: DIScope, file: FileMetadata, line: Int, column: Int ) -> LexicalBlockMetadata
Parameters
scope
Parent lexical block.
File
Source file.
line
The line in the source file.
column
The column in the source file.
-
Create a descriptor for a lexical block with a new file attached.
Declaration
Swift
public func buildLexicalBlockFile( scope: DIScope, file: FileMetadata, discriminator: Int ) -> LexicalBlockFileMetadata
Parameters
scope
Lexical block.
file
Source file.
discriminator
DWARF path discriminator value.
-
Create a new descriptor for a local auto variable.
Declaration
Swift
public func buildLocalVariable( named name: String, scope: DIScope, file: FileMetadata, line: Int, type: DIType, alwaysPreserve: Bool = false, flags: DIFlags = [], alignment: Alignment ) -> LocalVariableMetadata
Parameters
name
Variable name.
scope
The local scope the variable is declared in.
file
File where this variable is defined.
line
Line number.
type
Metadata describing the type of the variable.
alwaysPreserve
If true, this descriptor will survive optimizations.
flags
Flags.
alignment
Variable alignment.
-
Create a new descriptor for a function parameter variable.
Declaration
Swift
public func buildParameterVariable( named name: String, index: Int, scope: DIScope, file: FileMetadata, line: Int, type: DIType, alwaysPreserve: Bool = false, flags: DIFlags = [] ) -> LocalVariableMetadata
Parameters
name
Variable name.
index
Unique argument number for this variable; starts at 1.
scope
The local scope the variable is declared in.
file
File where this variable is defined.
line
Line number.
type
Metadata describing the type of the variable.
alwaysPreserve
If true, this descriptor will survive optimizations.
flags
Flags.
-
Creates a new debug location that describes a source location.
Declaration
Swift
public func buildDebugLocation( at location : (line: Int, column: Int), in scope: DIScope, inlinedAt: DIScope? = nil ) -> DebugLocation
Parameters
location
The location of the line and column for this information. If the location of the value is unknown, pass
(line: 0, column: 0)
.scope
The scope this debug location resides in.
inlinedAt
If this location has been inlined somewhere, the scope in which it was inlined. Defaults to
nil
.Return Value
A value representing a debug location.
-
Create subroutine type.
Declaration
Swift
public func buildSubroutineType( in file: FileMetadata, parameterTypes: [DIType], returnType: DIType? = nil, flags: DIFlags = [] ) -> DISubroutineType
Parameters
file
The file in which the subroutine resides.
parameterTypes
An array of subroutine parameter types.
returnType
The return type of the function, if any.
flags
Flags to emit DWARF attributes.
-
Create a debugging information entry for an enumeration.
Declaration
Parameters
name
Enumeration name.
scope
Scope in which this enumeration is defined.
file
File where this member is defined.
line
Line number.
size
Member size.
alignment
Member alignment.
elements
Enumeration elements.
numElements
Number of enumeration elements.
underlyingType
Underlying type of a C++11/ObjC fixed enum.
-
Create a debugging information entry for a union.
Declaration
Parameters
name
Union name.
scope
Scope in which this union is defined.
file
File where this member is defined.
line
Line number.
size
Member size.
alignment
Member alignment.
flags
Flags to encode member attribute, e.g. private
elements
Union elements.
runtimeVersion
Optional parameter, Objective-C runtime version.
uniqueID
A unique identifier for the union.
-
Create a debugging information entry for an array.
Declaration
Parameters
elementType
Metadata describing the type of the elements.
size
The total size of the array.
alignment
The alignment of the array.
subscripts
A list of ranges of valid subscripts into the array. For unbounded arrays, pass the unchecked range
-1...0
. -
Create a debugging information entry for a vector.
Declaration
Parameters
elementType
Metadata describing the type of the elements.
size
The total size of the array.
alignment
The alignment of the array.
subscripts
A list of ranges of valid subscripts into the array. For unbounded arrays, pass the unchecked range
-1...0
. -
Create a debugging information entry for a DWARF unspecified type.
Some languages have constructs in which a type may be left unspecified or the absence of a type may be explicitly indicated. For example, C++ permits using the
auto
return type specifier for the return type of a member function declaration. The actual return type is deduced based on the definition of the function, so it may not be known when the function is declared. The language implementation can provide an unspecified type entry with the nameauto
which can be referenced by the return type attribute of a function declaration entry. When the function is later defined, thesubprogram
entry for the definition includes a reference to the actual return type.Declaration
Swift
public func buildUnspecifiedType(named name: String) -> DIType
Parameters
name
The name of the type
-
Create a debugging information entry for a basic type.
Declaration
Swift
public func buildBasicType( named name: String, encoding: DIAttributeTypeEncoding, flags: DIFlags, size: Size ) -> DIType
Parameters
name
Type name.
encoding
The basic type encoding
size
Size of the type.
-
Create a debugging information entry for a pointer.
Declaration
Swift
public func buildPointerType( pointee: DIType, size: Size, alignment: Alignment, addressSpace: AddressSpace = .zero, name: String = "" ) -> DIType
Parameters
pointee
Type pointed by this pointer.
size
The size of the pointer value.
alignment
The alignment of the pointer.
addressSpace
The address space the pointer type reside in.
name
The name of the pointer type.
-
buildStructType(named:
scope: file: line: size: alignment: flags: baseType: elements: vtableHolder: runtimeVersion: uniqueID: ) Create a debugging information entry for a struct.
Declaration
Parameters
name
Struct name.
scope
Scope in which this struct is defined.
file
File where this member is defined.
line
Line number.
size
The total size of the struct and its members.
alignment
The alignment of the struct.
flags
Flags to encode member attributes.
elements
Struct elements.
vtableHolder
The object containing the vtable for the struct.
runtimeVersion
Optional parameter, Objective-C runtime version.
uniqueId
A unique identifier for the struct.
-
Create a debugging information entry for a member.
Declaration
Parameters
parentType
Parent type.
scope
Member scope.
name
Member name.
file
File where this member is defined.
line
Line number.
size
Member size.
alignment
Member alignment.
offset
Member offset.
flags
Flags to encode member attributes.
-
Create a debugging information entry for a C++ static data member.
Declaration
Swift
public func buildStaticMemberType( of parentType: DIType, scope: DIScope, name: String, file: FileMetadata, line: Int, alignment: Alignment, flags: DIFlags = [], initialValue: IRConstant? = nil ) -> DIType
Parameters
parentType
Type of the static member.
scope
Member scope.
name
Member name.
file
File where this member is declared.
line
Line number.
alignment
Member alignment.
flags
Flags to encode member attributes.
initialValue
Constant initializer of the member.
-
Create a debugging information entry for a pointer to member.
Declaration
Parameters
pointee
Type pointed to by this pointer.
baseType
Type for which this pointer points to members of.
size
Size.
alignment
Alignment.
flags
Flags.
-
Create C++11 nullptr type.
Declaration
Swift
public func buildNullPtrType() -> DIType
-
Create a debugging information entry for a typedef.
Declaration
Swift
public func buildTypedef( of type: DIType, name: String, alignment: Alignment, scope: DIScope, file: FileMetadata, line: Int ) -> DIType
Parameters
type
Original type.
name
Typedef name.
alignment
Alignment of the type.
scope
The surrounding context for the typedef.
file
File where this type is defined.
line
Line number.
-
Create a debugging information entry to establish inheritance relationship between two types.
Declaration
Parameters
derived
Original type.
base
Base type. Ty is inherits from base.
baseOffset
Base offset.
virtualBasePointerOffset
Virtual base pointer offset.
flags
Flags to describe inheritance attribute, e.g. private
-
Create a permanent forward-declared type.
Declaration
Parameters
name
Type name.
tag
A unique tag for this type.
scope
Type scope.
file
File where this type is defined.
line
Line number where this type is defined.
size
Member size.
alignment
Member alignment.
runtimeLanguage
Indicates runtime version for languages like Objective-C.
uniqueID
A unique identifier for the type.
-
buildReplaceableCompositeType(named:
tag: scope: file: line: size: alignment: flags: runtimeVersion: uniqueID: ) Create a temporary forward-declared type.
Declaration
Parameters
name
Type name.
tag
A unique tag for this type.
scope
Type scope.
file
File where this type is defined.
line
Line number where this type is defined. Objective-C.
size
Member size.
alignment
Member alignment.
flags
Flags.
runtimeVersion
Indicates runtime version for languages like
uniqueID
A unique identifier for the type.
-
Create a debugging information entry for a bit field member.
Declaration
Parameters
name
Member name.
type
Parent type.
scope
Member scope.
file
File where this member is defined.
line
Line number.
size
Member size.
offset
Member offset.
storageOffset
Member storage offset.
flags
Flags to encode member attribute.
-
buildClassType(named:
derivedFrom: scope: file: line: size: alignment: offset: flags: elements: vtableHolder: uniqueID: ) Create a debugging information entry for a class.
- name: Class name.
- baseType: Debug info of the base class of this type.
- scope: Scope in which this class is defined.
- file: File where this member is defined.
- line: Line number.
- size: Member size.
- alignment: Member alignment.
- offset: Member offset.
- flags: Flags to encode member attribute, e.g. private.
- elements: Class members.
- vtableHolder: Debug info of the base class that contains vtable
for this type. This is used in
DW_AT_containing_type
. - uniqueID: A unique identifier for the type.
-
Create a descriptor for an imported module.
Declaration
Swift
public func buildImportedModule( in context: DIScope, namespace: NameSpaceMetadata, file: FileMetadata, line: Int ) -> ImportedEntityMetadata
Parameters
context
The scope this module is imported into
namespace
The namespace being imported here.
file
File where the declaration is located.
line
Line number of the declaration.
-
Create a descriptor for an imported module.
Declaration
Swift
public func buildImportedModule( in context: DIScope, aliasee: ImportedEntityMetadata, file: FileMetadata, line: Int ) -> ImportedEntityMetadata
Parameters
context
The scope this module is imported into.
aliasee
An aliased namespace.
file
File where the declaration is located.
line
Line number of the declaration.
-
Create a descriptor for an imported module.
Declaration
Swift
public func buildImportedModule( in context: DIScope, module: ModuleMetadata, file: FileMetadata, line: Int ) -> ImportedEntityMetadata
Parameters
context
The scope this module is imported into.
module
The module being imported here
file
File where the declaration is located.
line
Line number of the declaration.
-
Create a descriptor for an imported function.
Declaration
Swift
public func buildImportedDeclaration( in context: DIScope, declaration: IRMetadata, file: FileMetadata, line: Int, name: String = "" ) -> ImportedEntityMetadata
Parameters
context
The scope this module is imported into.
declaration
The declaration (or definition) of a function, type, or variable.
file
File where the declaration is located.
line
Line number of the declaration.
name
The name of the imported declaration.
-
Create a debugging information entry for Objective-C instance variable.
Declaration
Swift
public func buildObjCIVar( for property: ObjectiveCPropertyMetadata, name: String, type: DIType, file: FileMetadata, line: Int, size: Size, alignment: Alignment, offset: Size, flags: DIFlags = [] ) -> DIType
Parameters
property
The property associated with this ivar.
name
Member name.
type
Type.
file
File where this member is defined.
line
Line number.
size
Member size.
alignment
Member alignment.
offset
Member offset.
flags
Flags to encode member attributes.
-
Create a debugging information entry for Objective-C property.
Declaration
Swift
public func buildObjCProperty( named name: String, type: DIType, file: FileMetadata, line: Int, getter: String, setter: String, propertyAttributes: ObjectiveCPropertyAttribute ) -> ObjectiveCPropertyMetadata
Parameters
name
Property name.
type
Type.
file
File where this property is defined.
line
Line number.
getter
Name of the Objective C property getter selector.
setter
Name of the Objective C property setter selector.
propertyAttributes
Objective C property attributes.
-
Create a new descriptor for the specified variable which has a complex address expression for its address.
Declaration
Swift
public func buildExpression(_ expression: [DWARFExpression]) -> ExpressionMetadata
Parameters
expression
An array of complex address operations.
-
Create a new descriptor for the specified variable that does not have an address, but does have a constant value.
Declaration
Swift
public func buildConstantExpresion(_ value: Int) -> ExpressionMetadata
Parameters
value
The constant value.
-
buildGlobalExpression(named:
linkageName: type: scope: file: line: isLocal: expression: declaration: alignment: ) Create a new descriptor for the specified variable.
Declaration
Swift
public func buildGlobalExpression( named name: String, linkageName: String, type: DIType, scope: DIScope, file: FileMetadata, line: Int, isLocal: Bool = true, expression: ExpressionMetadata? = nil, declaration: IRMetadata? = nil, alignment: Alignment ) -> ExpressionMetadata
Parameters
name
Name of the variable.
linkageName
Mangled name of the variable.
type
Variable Type.
scope
Variable scope.
file
File where this variable is defined.
line
Line number.
isLocal
Boolean flag indicate whether this variable is externally visible or not.
expression
The location of the global relative to the attached GlobalVariable.
declaration
Reference to the corresponding declaration.
alignment
Variable alignment