lib/breakpoint.rb in ruby-breakpoint-0.5.0 vs lib/breakpoint.rb in ruby-breakpoint-0.5.1
- old
+ new
@@ -20,17 +20,17 @@
require 'drb'
require 'drb/acl'
require 'thread'
module Breakpoint
- id = %q$Id: breakpoint.rb 52 2005-02-26 19:43:19Z flgr $
+ id = %q$Id: breakpoint.rb 118 2006-05-28 11:44:14Z flgr $
current_version = id.split(" ")[2]
unless defined?(Version)
# The Version of ruby-breakpoint you are using as String of the
# 1.2.3 form where the digits stand for release, major and minor
# version respectively.
- Version = "0.5.0"
+ Version = "0.5.1"
end
extend self
# This will pop up an interactive ruby session at a
@@ -52,11 +52,11 @@
# it isn't able to read in the source code.
#
# breakpoints can also return a value. They will execute
# a supplied block for getting a default return value.
# A custom value can be returned from the session by doing
- # +throw(:debug_return, value)+.
+ # <code>throw(:debug_return, value)</code>.
#
# You can also give names to break points which will be
# used in the message that is displayed upon execution
# of them.
#
@@ -105,10 +105,20 @@
# You have to call Breakpoint.activate_drb to enable
# support for remote breakpoints and then run
# breakpoint_client.rb which is distributed with this
# library. See the documentation of Breakpoint.activate_drb
# for details.
+ #
+ # Please use breakpoint() instead of Breakpoint.breakpoint().
+ # If you use Breakpoint.breakpoint() you might get a shell with
+ # a wrong self context meaning that you will not be able to
+ # access instance variables, call methods on the object where
+ # you are breakpointing and so on. You will however still be
+ # able to access local variables.
+ #
+ # The former is believed to be caused by a bug in Ruby and it has
+ # been reported to ruby-core: http://www.ruby-forum.com/topic/67255
def breakpoint(id = nil, context = nil, &block)
callstack = caller
callstack.slice!(0, 3) if callstack.first["breakpoint"]
file, line, method = *callstack.first.match(/^(.+?):(\d+)(?::in `(.*?)')?/).captures
@@ -142,10 +152,20 @@
# Executes the specified code at the client.
def eval(code)
@eval_handler.call(code)
end
+ # Need to work around an odd RubyGems issue that causes it
+ # to not load libraries...
+ def require(*args, &block)
+ begin
+ method_missing(:require__, *args, &block)
+ rescue LoadError
+ method_missing(:require, *args, &block)
+ end
+ end
+
# Will execute the specified statement at the client.
def method_missing(method, *args, &block)
if args.empty? and not block
result = eval "#{method}"
else
@@ -153,11 +173,11 @@
# eval context instead of an eval handler for executing
# the code at the client. The problem with that approach
# is that we would have to handle special expressions
# like "self", "nil" or constants ourself which is hard.
remote = eval %{
- result = lambda { |block, *args| #{method}(*args, &block) }
+ result = lambda { |block, *args| self.send(#{method.inspect}, *args, &block) }
def result.call_with_block(*args, &block)
call(block, *args)
end
result
}
@@ -288,12 +308,16 @@
include DRbUndumped
def initialize
@handler = @eval_handler = @collision_handler = nil
- IRB.instance_eval { @CONF[:RC] = true }
- IRB.run_config
+ begin
+ IRB.instance_eval { @CONF[:RC] = true }
+ IRB.init_config(nil)
+ IRB.run_config
+ rescue Exception
+ end
end
def collision
sleep(0.5) until @collision_handler
@@ -502,11 +526,13 @@
def evaluate(*args)
if Breakpoint.use_drb? then
result = old_evaluate(*args)
if args[0] != :no_proxy and
- not [true, false, nil].include?(result)
+ not [true, false, nil].include?(result) and
+ not result.is_a?(String) and
+ not result.is_a?(Numeric)
then
result.extend(DRbUndumped) rescue nil
end
return result
else
@@ -527,9 +553,10 @@
module DRb # :nodoc:
class DRbObject # :nodoc:
undef :inspect if method_defined?(:inspect)
undef :clone if method_defined?(:clone)
+ undef :to_yaml if method_defined?(:to_yaml)
end
end
# See Breakpoint.breakpoint
def breakpoint(id = nil, &block)