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()

Declarations

  • 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.

Scope Entities

  • 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.

  • 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.

Local Variables

  • 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.

Debug Locations

  • 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

    Swift

    public func buildEnumerationType(
      named name: String,
      scope: DIScope, file: FileMetadata, line: Int,
      size: Size, alignment: Alignment,
      elements: [DIType], underlyingType: DIType
    ) -> DIType

    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

    Swift

    public func buildUnionType(
      named name: String,
      scope: DIScope, file: FileMetadata, line: Int,
      size: Size, alignment: Alignment, flags: DIFlags,
      elements: [DIType],
      runtimeVersion: Int = 0, uniqueID: String = ""
    ) -> DIType

    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

    Swift

    public func buildArrayType(
      of elementType: DIType,
      size: Size, alignment: Alignment,
      subscripts: [Range<Int>] = []
    ) -> DIType

    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

    Swift

    public func buildVectorType(
      of elementType: DIType,
      size: Size, alignment: Alignment,
      subscripts: [Range<Int>] = []
    ) -> DIType

    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 name auto which can be referenced by the return type attribute of a function declaration entry. When the function is later defined, the subprogram 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.

  • Create a debugging information entry for a struct.

    Declaration

    Swift

    public func buildStructType(
      named name: String,
      scope: DIScope, file: FileMetadata, line: Int,
      size: Size, alignment: Alignment, flags: DIFlags = [],
      baseType: DIType? = nil, elements: [DIType] = [],
      vtableHolder: DIType? = nil, runtimeVersion: Int = 0, uniqueID: String = ""
    ) -> DIType

    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

    Swift

    public func buildMemberType(
      of parentType: DIType, scope: DIScope, name: String,
      file: FileMetadata, line: Int,
      size: Size, alignment: Alignment, offset: Size, flags: DIFlags = []
    ) -> DIType

    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

    Swift

    public func buildMemberPointerType(
      pointee: DIType, baseType: DIType,
      size: Size, alignment: Alignment,
      flags: DIFlags = []
    ) -> DIType

    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 a uniqued DIType* clone with FlagObjectPointer and FlagArtificial set.

    Declaration

    Swift

    public func buildObjectPointerType(pointee: DIType) -> DIType

    Parameters

    pointee

    The underlying type to which this pointer points.

  • Create a debugging information entry for a qualified type, e.g. ‘const int’.

    Declaration

    Swift

    public func buildQualifiedType(_ tag: DWARFTag, _ type: DIType) -> DIType

    Parameters

    tag

    Tag identifying type.

    type

    Base Type.

  • Create a debugging information entry for a c++ style reference or rvalue reference type.

    Declaration

    Swift

    public func buildReferenceType(_ tag: DWARFTag, _ type: DIType) -> DIType

    Parameters

    tag

    Tag identifying type.

    type

    Base Type.

  • 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

    Swift

    public func buildInheritance(
      of derived: DIType, to base: DIType,
      baseOffset: Size, virtualBasePointerOffset: Size, flags: DIFlags = []
    ) -> DIType

    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

    Swift

    public func buildForwardDeclaration(
      named name: String, tag: DWARFTag,
      scope: DIScope, file: FileMetadata, line: Int,
      size: Size, alignment: Alignment,
      runtimeLanguage: Int = 0, uniqueID: String = ""
    ) -> DIType

    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.

  • Create a temporary forward-declared type.

    Declaration

    Swift

    public func buildReplaceableCompositeType(
      named name: String, tag: DWARFTag,
      scope: DIScope, file: FileMetadata, line: Int,
      size: Size, alignment: Alignment, flags: DIFlags = [],
      runtimeVersion: Int = 0, uniqueID: String = ""
    ) -> DIType

    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

    Swift

    public func buildBitFieldMemberType(
      named name: String, type: DIType,
      scope: DIScope, file: FileMetadata, line: Int,
      size: Size, offset: Size, storageOffset: Size,
      flags: DIFlags = []
    ) -> DIType

    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.

  • 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.

    Declaration

    Swift

    public func buildClassType(
      named name: String, derivedFrom baseType: DIType?,
      scope: DIScope, file: FileMetadata, line: Int,
      size: Size, alignment: Alignment, offset: Size, flags: DIFlags,
      elements: [DIType] = [],
      vtableHolder: DIType? = nil, uniqueID: String = ""
    ) -> DIType
  • Create a uniqued DIType* clone with FlagArtificial set.

    Declaration

    Swift

    public func buildArtificialType(_ type: DIType) -> DIType

    Parameters

    type

    The underlying type.

Imported Entities

Objective-C