Class: LLDB::Address

Inherits:
Object
  • Object
show all
Includes:
NativeLifecycle
Defined in:
lib/lldb/address.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from NativeLifecycle

#close, #closed?, #context, #context!, #ensure_open!, #initialize_native_object

Constructor Details

#initialize(target: nil, context: nil, pointer: nil, load_address: nil) ⇒ Address

Returns a new instance of Address.

RBS:

  • target: Target?

  • context: Context?

  • pointer: FFI::Pointer?

  • return: void



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/lldb/address.rb', line 13

def initialize(target: nil, context: nil, pointer: nil, load_address: nil)
  if load_address
    raise ArgumentError, 'target is required for a load address' unless target.is_a?(Target)

    ptr = FFIBindings.lldb_address_create_from_load_address(load_address, target.to_ptr)
  else
    ptr = pointer || FFIBindings.lldb_address_create
  end
  @target = target
  initialize_native_object(
    ptr,
    release: ->(released) { FFIBindings.lldb_address_destroy(released) },
    context: context || target&.context
  )
end

Class Method Details

.from_ptr(ptr, target: nil, context: nil) ⇒ Object

RBS:

  • ptr: FFI::Pointer

  • target: Target?

  • context: Context?

  • return: Address



33
34
35
# File 'lib/lldb/address.rb', line 33

def self.from_ptr(ptr, target: nil, context: nil)
  new(pointer: ptr, target: target, context: context)
end

Instance Method Details

#file_addressObject

RBS:

  • return: Integer



43
44
45
46
47
# File 'lib/lldb/address.rb', line 43

def file_address
  return INVALID_ADDRESS unless valid?

  FFIBindings.lldb_address_get_file_address(@ptr)
end

#line_entryObject

RBS:

  • return: LineEntry?



67
68
69
70
71
72
73
74
# File 'lib/lldb/address.rb', line 67

def line_entry
  return nil unless valid?

  ptr = FFIBindings.lldb_address_get_line_entry(@ptr)
  return nil if ptr.nil? || ptr.null?

  LineEntry.new(ptr, target: @target, context: context)
end

#load_address(target: @target) ⇒ Object

RBS:

  • target: Target?

  • return: Integer

Raises:

  • (ArgumentError)


51
52
53
54
55
56
57
# File 'lib/lldb/address.rb', line 51

def load_address(target: @target)
  return INVALID_ADDRESS unless valid?
  raise ArgumentError, 'target must be a Target' if target && !target.is_a?(Target)

  target_ptr = target ? target.to_ptr : NativeHandle::NULL_POINTER
  FFIBindings.lldb_address_get_load_address(@ptr, target_ptr)
end

#offsetObject

RBS:

  • return: Integer



60
61
62
63
64
# File 'lib/lldb/address.rb', line 60

def offset
  return 0 unless valid?

  FFIBindings.lldb_address_get_offset(@ptr)
end

#to_ptrObject

RBS:

  • return: FFI::Pointer



77
78
79
# File 'lib/lldb/address.rb', line 77

def to_ptr
  @ptr
end

#valid?Boolean

RBS:

  • return: bool

Returns:

  • (Boolean)


38
39
40
# File 'lib/lldb/address.rb', line 38

def valid?
  !@ptr.null? && FFIBindings.lldb_address_is_valid(@ptr) != 0
end