Class: LLDB::Instruction

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

Instance Method Summary collapse

Methods included from NativeLifecycle

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

Constructor Details

#initialize(ptr, target: nil, context: nil) ⇒ Instruction

Returns a new instance of Instruction.

RBS:

  • target: Target?

  • context: Context?

  • return: void



12
13
14
15
16
17
18
19
# File 'lib/lldb/instruction.rb', line 12

def initialize(ptr, target: nil, context: nil)
  @target = target
  initialize_native_object(
    ptr,
    release: ->(released) { FFIBindings.lldb_instruction_destroy(released) },
    context: context || target&.context
  )
end

Instance Method Details

#addressObject

RBS:

  • return: Address?



27
28
29
30
31
32
33
34
# File 'lib/lldb/instruction.rb', line 27

def address
  return nil unless valid?

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

  Address.from_ptr(ptr, target: @target, context: context)
end

#byte_sizeObject

RBS:

  • return: Integer



58
59
60
61
62
# File 'lib/lldb/instruction.rb', line 58

def byte_size
  return 0 unless valid?

  FFIBindings.lldb_instruction_get_byte_size(@ptr)
end

#bytesObject

RBS:

  • return: String



65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/lldb/instruction.rb', line 65

def bytes
  return ''.b unless valid? && @target

  length = byte_size
  return ''.b if length.zero?

  buffer = FFI::MemoryPointer.new(:uint8, length)
  written = FFIBindings.lldb_instruction_get_bytes(
    @ptr, @target.to_ptr, buffer, length
  )
  buffer.get_bytes(0, [written, length].min).b
end

#commentObject

RBS:

  • return: String?



51
52
53
54
55
# File 'lib/lldb/instruction.rb', line 51

def comment
  return nil unless valid? && @target

  FFIBindings.lldb_instruction_get_comment(@ptr, @target.to_ptr)
end

#mnemonicObject

RBS:

  • return: String?



37
38
39
40
41
# File 'lib/lldb/instruction.rb', line 37

def mnemonic
  return nil unless valid? && @target

  FFIBindings.lldb_instruction_get_mnemonic(@ptr, @target.to_ptr)
end

#operandsObject

RBS:

  • return: String?



44
45
46
47
48
# File 'lib/lldb/instruction.rb', line 44

def operands
  return nil unless valid? && @target

  FFIBindings.lldb_instruction_get_operands(@ptr, @target.to_ptr)
end

#to_ptrObject

RBS:

  • return: FFI::Pointer



79
80
81
# File 'lib/lldb/instruction.rb', line 79

def to_ptr
  @ptr
end

#valid?Boolean

RBS:

  • return: bool

Returns:

  • (Boolean)


22
23
24
# File 'lib/lldb/instruction.rb', line 22

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