Class: LLDB::Value

Inherits:
Object
  • Object
show all
Includes:
Enumerable, NativeLifecycle
Defined in:
lib/lldb/value.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from NativeLifecycle

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

Constructor Details

#initialize(ptr, parent:, context: parent.context) ⇒ Value

Returns a new instance of Value.

RBS:

  • ptr: FFI::Pointer

  • parent: Frame | Value | Target

  • return: void



16
17
18
19
20
21
22
23
# File 'lib/lldb/value.rb', line 16

def initialize(ptr, parent:, context: parent.context)
  @parent = parent
  initialize_native_object(
    ptr,
    release: ->(released) { FFIBindings.lldb_value_destroy(released) },
    context: context
  )
end

Instance Attribute Details

#parentObject (readonly)

RBS:

  • return: Frame | Value | Target



11
12
13
# File 'lib/lldb/value.rb', line 11

def parent
  @parent
end

Class Method Details

.release(ptr) ⇒ Object

RBS:

  • ptr: FFI::Pointer

  • return: ^(Integer) -> void



27
28
29
# File 'lib/lldb/value.rb', line 27

def self.release(ptr)
  ->(_id) { FFIBindings.lldb_value_destroy(ptr) unless ptr.null? }
end

Instance Method Details

#address_ofObject

RBS:

  • return: Value?

Raises:



170
171
172
173
174
175
176
177
# File 'lib/lldb/value.rb', line 170

def address_of
  raise InvalidObjectError, 'Value is not valid' unless valid?

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

  Value.new(addr_ptr, parent: self, context: context)
end

#byte_sizeObject

RBS:

  • return: Integer



131
132
133
134
135
# File 'lib/lldb/value.rb', line 131

def byte_size
  return 0 unless valid?

  FFIBindings.lldb_value_get_byte_size(@ptr)
end

#cast(target_type) ⇒ Object

RBS:

  • target_type: Type

  • return: Value?

Raises:



207
208
209
210
211
212
213
214
# File 'lib/lldb/value.rb', line 207

def cast(target_type)
  raise InvalidObjectError, 'Value is not valid' unless valid?

  cast_ptr = FFIBindings.lldb_value_cast(@ptr, target_type.to_ptr)
  return nil if cast_ptr.nil? || cast_ptr.null?

  Value.new(cast_ptr, parent: self, context: context)
end

#child_at_index(index) ⇒ Object

RBS:

  • index: Integer

  • return: Value?

Raises:



73
74
75
76
77
78
79
80
# File 'lib/lldb/value.rb', line 73

def child_at_index(index)
  raise InvalidObjectError, 'Value is not valid' unless valid?

  child_ptr = FFIBindings.lldb_value_get_child_at_index(@ptr, index)
  return nil if child_ptr.nil? || child_ptr.null?

  Value.new(child_ptr, parent: self, context: context)
end

#child_member(name) ⇒ Object Also known as: []

RBS:

  • name: String

  • return: Value?

Raises:



84
85
86
87
88
89
90
91
# File 'lib/lldb/value.rb', line 84

def child_member(name)
  raise InvalidObjectError, 'Value is not valid' unless valid?

  child_ptr = FFIBindings.lldb_value_get_child_member_with_name(@ptr, name)
  return nil if child_ptr.nil? || child_ptr.null?

  Value.new(child_ptr, parent: self, context: context)
end

#childrenObject

RBS:

  • return: Array[Value]



96
97
98
# File 'lib/lldb/value.rb', line 96

def children
  (0...num_children).map { |i| child_at_index(i) }.compact
end

#create_child_at_offset(name, value_type, offset) ⇒ Object

RBS:

  • name: String

  • value_type: Type

  • offset: Integer

  • return: Value?

Raises:



250
251
252
253
254
255
256
257
# File 'lib/lldb/value.rb', line 250

def create_child_at_offset(name, value_type, offset)
  raise InvalidObjectError, 'Value is not valid' unless valid?

  child_ptr = FFIBindings.lldb_value_create_child_at_offset(@ptr, name, value_type.to_ptr, offset)
  return nil if child_ptr.nil? || child_ptr.null?

  Value.new(child_ptr, parent: self, context: context)
end

#create_value_from_address(name, address, value_type) ⇒ Object

RBS:

  • name: String

  • address: Integer

  • value_type: Type

  • return: Value?

Raises:



263
264
265
266
267
268
269
270
# File 'lib/lldb/value.rb', line 263

def create_value_from_address(name, address, value_type)
  raise InvalidObjectError, 'Value is not valid' unless valid?

  value_ptr = FFIBindings.lldb_value_create_value_from_address(@ptr, name, address, value_type.to_ptr)
  return nil if value_ptr.nil? || value_ptr.null?

  Value.new(value_ptr, parent: self, context: context)
end

#create_value_from_expression(name, expression) ⇒ Object

RBS:

  • name: String

  • expression: String

  • return: Value?

Raises:



275
276
277
278
279
280
281
282
# File 'lib/lldb/value.rb', line 275

def create_value_from_expression(name, expression)
  raise InvalidObjectError, 'Value is not valid' unless valid?

  value_ptr = FFIBindings.lldb_value_create_value_from_expression(@ptr, name, expression)
  return nil if value_ptr.nil? || value_ptr.null?

  Value.new(value_ptr, parent: self, context: context)
end

#dereferenceObject

RBS:

  • return: Value?

Raises:



160
161
162
163
164
165
166
167
# File 'lib/lldb/value.rb', line 160

def dereference
  raise InvalidObjectError, 'Value is not valid' unless valid?

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

  Value.new(deref_ptr, parent: self, context: context)
end

#each(&block) ⇒ Object

RBS:

  • &block: (Value) -> void

  • return: Enumerator[Value, void] | void



102
103
104
105
106
# File 'lib/lldb/value.rb', line 102

def each(&block)
  return enum_for(:each) unless block_given?

  children.each(&block)
end

#errorObject

RBS:

  • return: Error

Raises:



145
146
147
148
149
150
151
# File 'lib/lldb/value.rb', line 145

def error
  raise InvalidObjectError, 'Value is not valid' unless valid?

  error = Error.new
  FFIBindings.lldb_value_get_error(@ptr, error.to_ptr)
  error
end

#expression_pathObject

RBS:

  • return: String?



302
303
304
305
306
# File 'lib/lldb/value.rb', line 302

def expression_path
  return nil unless valid?

  FFIBindings.lldb_value_get_expression_path(@ptr)
end

#has_error?Boolean

RBS:

  • return: bool

Returns:

  • (Boolean)


154
155
156
157
# File 'lib/lldb/value.rb', line 154

def has_error?
  err = error
  err.fail?
end

#inspectObject

RBS:

  • return: String



191
192
193
# File 'lib/lldb/value.rb', line 191

def inspect
  "#<LLDB::Value name=#{name.inspect} type=#{type_name.inspect} value=#{value.inspect}>"
end

#load_addressObject

RBS:

  • return: Integer



217
218
219
220
221
# File 'lib/lldb/value.rb', line 217

def load_address
  return INVALID_ADDRESS unless valid?

  FFIBindings.lldb_value_get_load_address(@ptr)
end

#might_have_children?Boolean

RBS:

  • return: bool

Returns:

  • (Boolean)


138
139
140
141
142
# File 'lib/lldb/value.rb', line 138

def might_have_children?
  return false unless valid?

  FFIBindings.lldb_value_might_have_children(@ptr) != 0
end

#nameObject

RBS:

  • return: String?



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

def name
  return nil unless valid?

  FFIBindings.lldb_value_get_name(@ptr)
end

#non_synthetic_valueObject

RBS:

  • return: Value?

Raises:



316
317
318
319
320
321
322
323
# File 'lib/lldb/value.rb', line 316

def non_synthetic_value
  raise InvalidObjectError, 'Value is not valid' unless valid?

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

  Value.new(value_ptr, parent: self, context: context)
end

#num_childrenObject

RBS:

  • return: Integer



65
66
67
68
69
# File 'lib/lldb/value.rb', line 65

def num_children
  return 0 unless valid?

  FFIBindings.lldb_value_get_num_children(@ptr)
end

#pointer_type?Boolean

RBS:

  • return: bool

Returns:

  • (Boolean)


309
310
311
312
313
# File 'lib/lldb/value.rb', line 309

def pointer_type?
  return false unless valid?

  FFIBindings.lldb_value_is_pointer_type(@ptr) != 0
end

#set_value_from_cstring(str) ⇒ Object

RBS:

  • str: String

  • return: bool

Raises:



237
238
239
240
241
242
243
244
# File 'lib/lldb/value.rb', line 237

def set_value_from_cstring(str)
  raise InvalidObjectError, 'Value is not valid' unless valid?

  error = Error.new
  result = FFIBindings.lldb_value_set_value_from_cstring(@ptr, str, error.to_ptr)
  error.raise_if_error!
  result != 0
end

#summaryObject

RBS:

  • return: String?



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

def summary
  return nil unless valid?

  FFIBindings.lldb_value_get_summary(@ptr)
end

#to_ptrObject

RBS:

  • return: FFI::Pointer



326
327
328
# File 'lib/lldb/value.rb', line 326

def to_ptr
  @ptr
end

#to_sObject

RBS:

  • return: String



180
181
182
183
184
185
186
187
188
# File 'lib/lldb/value.rb', line 180

def to_s
  if summary
    "#{name} = #{summary}"
  elsif value
    "#{name} = #{value}"
  else
    "#{name} (#{type_name})"
  end
end

#typeObject

RBS:

  • return: Type?

Raises:



196
197
198
199
200
201
202
203
# File 'lib/lldb/value.rb', line 196

def type
  raise InvalidObjectError, 'Value is not valid' unless valid?

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

  Type.new(type_ptr, context: context)
end

#type_nameObject

RBS:

  • return: String?



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

def type_name
  return nil unless valid?

  FFIBindings.lldb_value_get_type_name(@ptr)
end

#valid?Boolean

RBS:

  • return: bool

Returns:

  • (Boolean)


32
33
34
# File 'lib/lldb/value.rb', line 32

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

#valueObject

RBS:

  • return: String?



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

def value
  return nil unless valid?

  FFIBindings.lldb_value_get_value(@ptr)
end

#value_as_signedObject Also known as: to_i

RBS:

  • return: Integer



109
110
111
112
113
114
115
116
# File 'lib/lldb/value.rb', line 109

def value_as_signed
  return 0 unless valid?

  error = Error.new
  result = FFIBindings.lldb_value_get_value_as_signed(@ptr, error.to_ptr, 0)
  error.raise_if_error!('value.value_as_signed')
  result
end

#value_as_unsignedObject

RBS:

  • return: Integer



121
122
123
124
125
126
127
128
# File 'lib/lldb/value.rb', line 121

def value_as_unsigned
  return 0 unless valid?

  error = Error.new
  result = FFIBindings.lldb_value_get_value_as_unsigned(@ptr, error.to_ptr, 0)
  error.raise_if_error!('value.value_as_unsigned')
  result
end

#value_typeObject

RBS:

  • return: Integer



224
225
226
227
228
# File 'lib/lldb/value.rb', line 224

def value_type
  return ValueType::INVALID unless valid?

  FFIBindings.lldb_value_get_value_type(@ptr)
end

#value_type_nameObject

RBS:

  • return: String



231
232
233
# File 'lib/lldb/value.rb', line 231

def value_type_name
  ValueType.name(value_type)
end

#watch(resolve: true, read: false, write: true) ⇒ Object

RBS:

  • resolve: bool

  • read: bool

  • write: bool

  • return: Watchpoint?

Raises:



288
289
290
291
292
293
294
295
296
297
298
299
# File 'lib/lldb/value.rb', line 288

def watch(resolve: true, read: false, write: true)
  raise InvalidObjectError, 'Value is not valid' unless valid?

  error = Error.new
  wp_ptr = FFIBindings.lldb_value_watch(@ptr, resolve ? 1 : 0, read ? 1 : 0, write ? 1 : 0, error.to_ptr)

  error.raise_if_error!
  return nil if wp_ptr.nil? || wp_ptr.null?

  target = get_target_from_parent
  Watchpoint.new(wp_ptr, target: target, context: context)
end