Class: ProcessThread

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-debug-ide/attach/process_thread.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(thread_num, is_main, thread_info, native_debugger) ⇒ ProcessThread

Returns a new instance of ProcessThread.



7
8
9
10
11
12
13
# File 'lib/ruby-debug-ide/attach/process_thread.rb', line 7

def initialize(thread_num, is_main, thread_info, native_debugger)
  @thread_num = thread_num
  @is_main = is_main
  @native_debugger = native_debugger
  @thread_info = thread_info
  @last_bt = nil
end

Instance Attribute Details

#is_mainObject (readonly)

Returns the value of attribute is_main.



5
6
7
# File 'lib/ruby-debug-ide/attach/process_thread.rb', line 5

def is_main
  @is_main
end

#last_btObject (readonly)

Returns the value of attribute last_bt.



5
6
7
# File 'lib/ruby-debug-ide/attach/process_thread.rb', line 5

def last_bt
  @last_bt
end

#thread_infoObject (readonly)

Returns the value of attribute thread_info.



5
6
7
# File 'lib/ruby-debug-ide/attach/process_thread.rb', line 5

def thread_info
  @thread_info
end

#thread_numObject (readonly)

Returns the value of attribute thread_num.



5
6
7
# File 'lib/ruby-debug-ide/attach/process_thread.rb', line 5

def thread_num
  @thread_num
end

Instance Method Details

#any_caller_match(bt, pattern) ⇒ Object



27
28
29
# File 'lib/ruby-debug-ide/attach/process_thread.rb', line 27

def any_caller_match(bt, pattern)
  bt =~ /#{pattern}/
end

#finishObject



19
20
21
# File 'lib/ruby-debug-ide/attach/process_thread.rb', line 19

def finish
  @native_debugger.execute 'finish'
end

#get_btObject



23
24
25
# File 'lib/ruby-debug-ide/attach/process_thread.rb', line 23

def get_bt
  @last_bt = @native_debugger.execute 'bt'
end

#is_inside_gc(bt = get_bt) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/ruby-debug-ide/attach/process_thread.rb', line 40

def is_inside_gc(bt = get_bt)
  if any_caller_match(bt, '(gc\.c)')
    $stderr.puts "process #{@native_debugger.pid} is currently in garbage collection phase."
    true
  else
    false
  end
end

#is_inside_malloc(bt = get_bt) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/ruby-debug-ide/attach/process_thread.rb', line 31

def is_inside_malloc(bt = get_bt)
  if any_caller_match(bt, '(malloc)')
    $stderr.puts "process #{@native_debugger.pid} is currently inside malloc."
    true
  else
    false
  end
end

#need_finish_frameObject



49
50
51
52
# File 'lib/ruby-debug-ide/attach/process_thread.rb', line 49

def need_finish_frame
  bt = get_bt
  is_inside_malloc(bt) || is_inside_gc(bt)
end

#switchObject



15
16
17
# File 'lib/ruby-debug-ide/attach/process_thread.rb', line 15

def switch
  @native_debugger.switch_to_thread(thread_num)
end