Class: Hijack::GDB

Inherits:
Object
  • Object
show all
Defined in:
lib/hijack/gdb.rb

Instance Method Summary collapse

Constructor Details

#initialize(pid) ⇒ GDB

Returns a new instance of GDB.



5
6
7
8
9
10
# File 'lib/hijack/gdb.rb', line 5

def initialize(pid)
  @pid = pid
  @verbose = Hijack.options[:gdb_debug]
  @exec_path = File.join(Config::CONFIG['bindir'], Config::CONFIG['RUBY_INSTALL_NAME'] + Config::CONFIG['EXEEXT'])
  attach
end

Instance Method Details

#detachObject



33
34
35
36
37
38
39
40
# File 'lib/hijack/gdb.rb', line 33

def detach
  return unless @gdb
  exec('detach')
  exec('quit')
  @backtrace = nil
  @gdb.close
  @gdb = nil
end

#ensure_attached_to_ruby_processObject



12
13
14
15
16
17
18
# File 'lib/hijack/gdb.rb', line 12

def ensure_attached_to_ruby_process
  unless backtrace.any? {|line| line =~ /rb_/}
    puts "\n=> #{@pid} doesn't appear to be a Ruby process!"
    detach
    exit 1
  end
end

#ensure_main_thread_not_blocked_by_joinObject



20
21
22
23
24
25
26
27
# File 'lib/hijack/gdb.rb', line 20

def ensure_main_thread_not_blocked_by_join
  if backtrace.any? {|line| line =~ /rb_thread_join/}
    puts "\n=> Unable to hijack #{@pid} because the main thread is blocked waiting for another thread to join."
    puts "=> Check that you are using the most recent version of hijack, a newer version may have solved this shortcoming."
    detach
    exit 1
  end
end

#eval(cmd) ⇒ Object



29
30
31
# File 'lib/hijack/gdb.rb', line 29

def eval(cmd)
  call("(void)rb_eval_string(#{cmd.strip.gsub(/"/, '\"').inspect})")
end