Skip to content

Commit

Permalink
Print a warning and exit when the target process can't be hijacked du…
Browse files Browse the repository at this point in the history
…e to the main thread being blocked waiting for another thread to join. Still trying to find a workaround for this.
  • Loading branch information
Ian Leitch committed Sep 17, 2009
1 parent 6e65bf6 commit 257b542
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/hijack/gdb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,16 @@ def initialize(pid)
wait
end

def backtrace
@backtrace ||= exec('bt').reverse
end

def attached_to_ruby_process?
exec('bt').any? {|line| line =~ /ruby_run/}
backtrace.any? {|line| line =~ /ruby_run/}
end

def main_thread_blocked_by_join?
backtrace.any? {|line| line =~ /rb_thread_join/}
end

def eval(cmd)
Expand Down
5 changes: 5 additions & 0 deletions lib/hijack/payload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ def self.inject(pid)
puts "\n=> #{pid} doesn't appear to be a Ruby process!"
exit 1
end
if gdb.main_thread_blocked_by_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."
exit 1
end
gdb.eval(payload(pid))
gdb.detach
end
Expand Down

0 comments on commit 257b542

Please sign in to comment.