Class: LLDB::Thread

Inherits:
Object
  • Object
show all
Includes:
NativeLifecycle
Defined in:
lib/lldb/thread.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, process:, context: process.context) ⇒ Thread

Returns a new instance of Thread.

RBS:

  • ptr: FFI::Pointer

  • process: Process

  • return: void



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

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

Instance Attribute Details

#processObject (readonly)

RBS:

  • return: Process



10
11
12
# File 'lib/lldb/thread.rb', line 10

def process
  @process
end

Class Method Details

.release(ptr) ⇒ Object

RBS:

  • ptr: FFI::Pointer

  • return: ^(Integer) -> void



26
27
28
# File 'lib/lldb/thread.rb', line 26

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

Instance Method Details

#frame_at_index(index) ⇒ Object

RBS:

  • index: Integer

  • return: Frame?

Raises:



99
100
101
102
103
104
105
106
# File 'lib/lldb/thread.rb', line 99

def frame_at_index(index)
  raise InvalidObjectError, 'Thread is not valid' unless valid?

  frame_ptr = FFIBindings.lldb_thread_get_frame_at_index(@ptr, index)
  return nil if frame_ptr.nil? || frame_ptr.null?

  Frame.new(frame_ptr, thread: self, context: context)
end

#framesObject

RBS:

  • return: Array[Frame]



127
128
129
# File 'lib/lldb/thread.rb', line 127

def frames
  (0...num_frames).map { |i| frame_at_index(i) }.compact
end

#get_processObject

RBS:

  • return: Process?

Raises:



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

def get_process
  raise InvalidObjectError, 'Thread is not valid' unless valid?

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

  Process.new(process_ptr, target: @process.target, context: context)
end

#index_idObject

RBS:

  • return: Integer



196
197
198
199
200
# File 'lib/lldb/thread.rb', line 196

def index_id
  return 0 unless valid?

  FFIBindings.lldb_thread_get_index_id(@ptr)
end

#nameObject

RBS:

  • return: String?



141
142
143
144
145
# File 'lib/lldb/thread.rb', line 141

def name
  return nil unless valid?

  FFIBindings.lldb_thread_get_name(@ptr)
end

#num_framesObject

RBS:

  • return: Integer



91
92
93
94
95
# File 'lib/lldb/thread.rb', line 91

def num_frames
  return 0 unless valid?

  FFIBindings.lldb_thread_get_num_frames(@ptr)
end

#queue_nameObject

RBS:

  • return: String?



203
204
205
206
207
# File 'lib/lldb/thread.rb', line 203

def queue_name
  return nil unless valid?

  FFIBindings.lldb_thread_get_queue_name(@ptr)
end

#resumeObject

RBS:

  • return: bool

Raises:



242
243
244
245
246
# File 'lib/lldb/thread.rb', line 242

def resume
  raise InvalidObjectError, 'Thread is not valid' unless valid?

  FFIBindings.lldb_thread_resume(@ptr) != 0
end

#run_to_address(address) ⇒ Object

RBS:

  • address: Integer

  • return: bool

Raises:



186
187
188
189
190
191
192
193
# File 'lib/lldb/thread.rb', line 186

def run_to_address(address)
  raise InvalidObjectError, 'Thread is not valid' unless valid?

  error = Error.new
  status = FFIBindings.lldb_thread_run_to_address(@ptr, address, error.to_ptr)
  Native.check_status!(status, 'thread.run_to_address', error)
  true
end

#select_frame(index) ⇒ Object

RBS:

  • index: Integer

  • return: bool

Raises:



120
121
122
123
124
# File 'lib/lldb/thread.rb', line 120

def select_frame(index)
  raise InvalidObjectError, 'Thread is not valid' unless valid?

  FFIBindings.lldb_thread_set_selected_frame(@ptr, index) != 0
end

#selected_frameObject

RBS:

  • return: Frame?

Raises:



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

def selected_frame
  raise InvalidObjectError, 'Thread is not valid' unless valid?

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

  Frame.new(frame_ptr, thread: self, context: context)
end

#step_instruction(step_over: false) ⇒ Object

RBS:

  • step_over: bool

  • return: true

Raises:



80
81
82
83
84
85
86
87
88
# File 'lib/lldb/thread.rb', line 80

def step_instruction(step_over: false)
  raise InvalidObjectError, 'Thread is not valid' unless valid?
  APISupport.require_method!(:lldb_thread_step_instruction, 'step_instruction')

  error = Error.new
  status = FFIBindings.lldb_thread_step_instruction(@ptr, step_over ? 1 : 0, error.to_ptr)
  Native.check_status!(status, 'thread.step_instruction', error)
  true
end

#step_into(target_name: nil, end_line: INVALID_LINE_NUMBER, run_mode: RunMode::ONLY_DURING_STEPPING) ⇒ Object

RBS:

  • target_name: String?

  • end_line: Integer

  • run_mode: Integer

  • return: true

Raises:



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/lldb/thread.rb', line 51

def step_into(target_name: nil, end_line: INVALID_LINE_NUMBER, run_mode: RunMode::ONLY_DURING_STEPPING)
  raise InvalidObjectError, 'Thread is not valid' unless valid?
  APISupport.require_method!(:lldb_thread_step_into, 'step_into')

  error = Error.new
  status = FFIBindings.lldb_thread_step_into(
    @ptr,
    target_name,
    end_line,
    run_mode,
    error.to_ptr
  )
  Native.check_status!(status, 'thread.step_into', error)
  true
end

#step_outObject

RBS:

  • return: true

Raises:



68
69
70
71
72
73
74
75
76
# File 'lib/lldb/thread.rb', line 68

def step_out
  raise InvalidObjectError, 'Thread is not valid' unless valid?
  APISupport.require_method!(:lldb_thread_step_out, 'step_out')

  error = Error.new
  status = FFIBindings.lldb_thread_step_out(@ptr, error.to_ptr)
  Native.check_status!(status, 'thread.step_out', error)
  true
end

#step_over(run_mode: RunMode::ONLY_DURING_STEPPING) ⇒ Object

RBS:

  • run_mode: Integer

  • return: true

Raises:



37
38
39
40
41
42
43
44
45
# File 'lib/lldb/thread.rb', line 37

def step_over(run_mode: RunMode::ONLY_DURING_STEPPING)
  raise InvalidObjectError, 'Thread is not valid' unless valid?
  APISupport.require_method!(:lldb_thread_step_over, 'step_over')

  error = Error.new
  status = FFIBindings.lldb_thread_step_over(@ptr, run_mode, error.to_ptr)
  Native.check_status!(status, 'thread.step_over', error)
  true
end

#stop_description(max_size = 256) ⇒ Object

RBS:

  • max_size: Integer

  • return: String?



211
212
213
214
215
216
217
218
# File 'lib/lldb/thread.rb', line 211

def stop_description(max_size = 256)
  return nil unless valid?
  return '' if max_size.zero?

  NativeBuffer.read_c_string(max_size: max_size) do |buffer, length|
    FFIBindings.lldb_thread_get_stop_description(@ptr, buffer, length)
  end
end

#stop_reasonObject

RBS:

  • return: Integer



148
149
150
151
152
# File 'lib/lldb/thread.rb', line 148

def stop_reason
  return StopReason::INVALID unless valid?

  FFIBindings.lldb_thread_get_stop_reason(@ptr)
end

#stop_reason_dataObject

RBS:

  • return: Array[Integer]



180
181
182
# File 'lib/lldb/thread.rb', line 180

def stop_reason_data
  (0...stop_reason_data_count).map { |i| stop_reason_data_at_index(i) }
end

#stop_reason_data_at_index(index) ⇒ Object

RBS:

  • index: Integer

  • return: Integer

Raises:



173
174
175
176
177
# File 'lib/lldb/thread.rb', line 173

def stop_reason_data_at_index(index)
  raise InvalidObjectError, 'Thread is not valid' unless valid?

  FFIBindings.lldb_thread_get_stop_reason_data_at_index(@ptr, index)
end

#stop_reason_data_countObject

RBS:

  • return: Integer



165
166
167
168
169
# File 'lib/lldb/thread.rb', line 165

def stop_reason_data_count
  return 0 unless valid?

  FFIBindings.lldb_thread_get_stop_reason_data_count(@ptr)
end

#stop_reason_nameObject

RBS:

  • return: String



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

def stop_reason_name
  StopReason.name(stop_reason)
end

#stopped?Boolean

RBS:

  • return: bool

Returns:

  • (Boolean)


221
222
223
224
225
# File 'lib/lldb/thread.rb', line 221

def stopped?
  return false unless valid?

  FFIBindings.lldb_thread_is_stopped(@ptr) != 0
end

#stopped_at_breakpoint?Boolean

RBS:

  • return: bool

Returns:

  • (Boolean)


160
161
162
# File 'lib/lldb/thread.rb', line 160

def stopped_at_breakpoint?
  stop_reason == StopReason::BREAKPOINT
end

#suspendObject

RBS:

  • return: bool

Raises:



235
236
237
238
239
# File 'lib/lldb/thread.rb', line 235

def suspend
  raise InvalidObjectError, 'Thread is not valid' unless valid?

  FFIBindings.lldb_thread_suspend(@ptr) != 0
end

#suspended?Boolean

RBS:

  • return: bool

Returns:

  • (Boolean)


228
229
230
231
232
# File 'lib/lldb/thread.rb', line 228

def suspended?
  return false unless valid?

  FFIBindings.lldb_thread_is_suspended(@ptr) != 0
end

#thread_idObject Also known as: id

RBS:

  • return: Integer



132
133
134
135
136
# File 'lib/lldb/thread.rb', line 132

def thread_id
  return 0 unless valid?

  FFIBindings.lldb_thread_get_thread_id(@ptr)
end

#to_ptrObject

RBS:

  • return: FFI::Pointer



259
260
261
# File 'lib/lldb/thread.rb', line 259

def to_ptr
  @ptr
end

#valid?Boolean

RBS:

  • return: bool

Returns:

  • (Boolean)


31
32
33
# File 'lib/lldb/thread.rb', line 31

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