Permalink
Browse files

Print a warning and exit when the target process can't be hijacked du…

…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
Ian Leitch committed Sep 17, 2009
1 parent 6e65bf6 commit 257b54265c627005f00e96457a230cddc9cc2972
Showing with 14 additions and 1 deletion.
  1. +9 −1 lib/hijack/gdb.rb
  2. +5 −0 lib/hijack/payload.rb
View
@@ -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)
View
@@ -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

0 comments on commit 257b542

Please sign in to comment.