Skip to content

Commit

Permalink
Merge pull request #16 from farleyknight/patch-1
Browse files Browse the repository at this point in the history
Test for ggdb, which is provided on Mac ports.
  • Loading branch information
ileitch committed Dec 5, 2013
2 parents 06ff782 + 8c29f80 commit d2bc6ff
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
18 changes: 15 additions & 3 deletions lib/hijack/gdb.rb
Expand Up @@ -10,7 +10,8 @@ def initialize(pid)
end end


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


def quit def quit
Expand All @@ -22,14 +23,25 @@ def quit
@gdb = nil @gdb = nil
end end


protected protected


def previous_frame_inner_to_this_frame? def previous_frame_inner_to_this_frame?
backtrace.last =~ /previous frame inner to this frame/i backtrace.last =~ /previous frame inner to this frame/i
end end


def gdb_path
# Check for gdb
if File.exists?(`which gdb`.strip)
`which gdb`.strip
elsif File.exists?(`which ggdb`.strip)
`which ggdb`.strip
else
raise "Cannot find suitable gdb!"
end
end

def attach_outside_gc def attach_outside_gc
@gdb = IO.popen("gdb -q #{@exec_path} #{@pid} 2>&1", 'r+') @gdb = IO.popen("#{gdb_path} -q #{@exec_path} #{@pid} 2>&1", 'r+')
wait wait
ensure_attached_to_ruby_process ensure_attached_to_ruby_process
attached = false attached = false
Expand Down
17 changes: 10 additions & 7 deletions tasks/gem.rake
@@ -1,14 +1,16 @@
require 'rake/gempackagetask' # require 'rake/packagetask'
require 'rubygems'
require 'rubygems/package_task'
require 'yaml' require 'yaml'
require './lib/hijack' require './lib/hijack'


task :clean => :clobber_package task :clean => :clobber_package


spec = Gem::Specification.new do |s| spec = Gem::Specification.new do |s|
s.name = 'hijack' s.name = 'hijack'
s.version = Hijack.version s.version = Hijack.version
s.platform = Gem::Platform::RUBY s.platform = Gem::Platform::RUBY
s.summary = s.summary =
s.description = 'Provides an irb session to a running ruby process.' s.description = 'Provides an irb session to a running ruby process.'
s.author = "Ian Leitch" s.author = "Ian Leitch"
s.email = 'port001@gmail.com' s.email = 'port001@gmail.com'
Expand All @@ -20,15 +22,16 @@ spec = Gem::Specification.new do |s|
s.require_path = "lib" s.require_path = "lib"
end end


Rake::GemPackageTask.new(spec) do |p| Gem::PackageTask.new(spec) do |pkg|
p.gem_spec = spec pkg.need_zip = true
pkg.need_tar = true
end end


namespace :gem do namespace :gem do
desc "Update the gemspec" desc "Update the gemspec"
task :spec do task :spec do
File.open("hijack.gemspec", 'w') { |f| f << YAML.dump(spec) } File.open("hijack.gemspec", 'w') { |f| f << YAML.dump(spec) }
end end
end end


task :install => [:clean, :clobber, :package] do task :install => [:clean, :clobber, :package] do
Expand All @@ -37,4 +40,4 @@ end


task :uninstall => :clean do task :uninstall => :clean do
sh "sudo gem uninstall -v #{HIJACK_VERSION} -x hijack" sh "sudo gem uninstall -v #{HIJACK_VERSION} -x hijack"
end end

0 comments on commit d2bc6ff

Please sign in to comment.