Permalink
Browse files

Added preliminary remote breakpoint support

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@102 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 3236e15 commit bf0e37b3cf8288779d63e67459bc261b13a13ca3 @dhh dhh committed Dec 9, 2004
View
@@ -21,7 +21,8 @@ TEST_DIRS = %w( fixtures unit functional mocks mocks/development mocks/testing
LOG_FILES = %w( apache.log development.log test.log production.log )
HTML_FILES = %w( 404.html 500.html index.html )
-SCRIPT_FILES = %w( generate )
+SCRIPT_FILES = %w( generate breakpoint_client envcon )
+BIN_FILES = %w( breakpointing envcon )
GENERATORS = %w( controller mailer model scaffold )
VENDOR_LIBS = %w( actionpack activerecord actionmailer railties )
@@ -96,7 +97,7 @@ end
desc "Make copies of all the default content of ties"
task :copy_ties_content => [
:copy_rootfiles, :copy_dispatches, :copy_html_files, :copy_abstract_application,
- :copy_configs, :copy_generators, :copy_test_helpers, :copy_docs_in_public,
+ :copy_configs, :copy_generators, :copy_binfiles, :copy_test_helpers, :copy_docs_in_public,
:copy_app_doc_readme ]
task :copy_dispatches do
@@ -150,6 +151,14 @@ task :copy_generators do
end
end
+task :copy_binfiles do
+ BIN_FILES.each do |file|
+ dest_file = File.join(PKG_DESTINATION, 'script', file)
+ cp File.join('bin', file), dest_file
+ chmod 0755, dest_file
+ end
+end
+
task :copy_rootfiles do
cp "fresh_rakefile", "#{PKG_DESTINATION}/Rakefile"
cp "README", "#{PKG_DESTINATION}/README"
@@ -0,0 +1,2 @@
+#!/usr/local/bin/ruby
+require 'breakpoint_client'
@@ -1,3 +1,12 @@
ActionController::Base.consider_all_requests_local = true
ActionController::Base.reload_dependencies = true
ActiveRecord::Base.reload_associations = true
+
+require 'breakpoint'
+require 'irb/completion'
+# Change the port (default: 42531) here in case you are
+# on shared hosting. Note that you should set up a SSH
+# tunnel when you want to connect from a different
+# computer over the internet. See the documentation of
+# Breakpoint.activate_drb for how to do that.
+Breakpoint.activate_drb('druby://localhost:42531')
View
@@ -43,6 +43,7 @@ Rake::RDocTask.new("apidoc") { |rdoc|
rdoc.title = "Rails Framework Documentation"
rdoc.options << '--line-numbers --inline-source'
rdoc.rdoc_files.include('README')
+ rdoc.rdoc_files.include('lib/breakpoint.rb')
rdoc.rdoc_files.include('vendor/railties/CHANGELOG')
rdoc.rdoc_files.include('vendor/railties/MIT-LICENSE')
rdoc.rdoc_files.include('vendor/activerecord/README')
@@ -0,0 +1,81 @@
+begin
+ require 'simplecc'
+rescue LoadError
+ def Continuation.create(*args, &block)
+ cc = nil; result = callcc {|c| cc = c; block.call(cc) if block and args.empty?}
+ result ||= args
+ return *[cc, *result]
+ end
+end
+
+# This method returns the binding of the method that called your
+# method. It will raise an Exception when you're not inside a method.
+#
+# It's used like this:
+# def inc_counter(amount = 1)
+# Binding.of_caller do |binding|
+# # Create a lambda that will increase the variable 'counter'
+# # in the caller of this method when called.
+# inc = eval("lambda { |arg| counter += arg }", binding)
+# # We can refer to amount from inside this block safely.
+# inc.call(amount)
+# end
+# # No other statements can go here. Put them inside the block.
+# end
+# counter = 0
+# 2.times { inc_counter }
+# counter # => 2
+#
+# Binding.of_caller must be the last statement in the method.
+# This means that you will have to put everything you want to
+# do after the call to Binding.of_caller into the block of it.
+# This should be no problem however, because Ruby has closures.
+# If you don't do this an Exception will be raised. Because of
+# the way that Binding.of_caller is implemented it has to be
+# done this way.
+def Binding.of_caller(&block)
+ old_critical = Thread.critical
+ Thread.critical = true
+ count = 0
+ cc, result, error, extra_data = Continuation.create(nil, nil)
+ error.call if error
+
+ tracer = lambda do |*args|
+ type, context, extra_data = args[0], args[4], args
+ if type == "return"
+ count += 1
+ # First this method and then calling one will return --
+ # the trace event of the second event gets the context
+ # of the method which called the method that called this
+ # method.
+ if count == 2
+ # It would be nice if we could restore the trace_func
+ # that was set before we swapped in our own one, but
+ # this is impossible without overloading set_trace_func
+ # in current Ruby.
+ set_trace_func(nil)
+ cc.call(eval("binding", context), nil, extra_data)
+ end
+ elsif type == "line" then
+ nil
+ elsif type == "c-return" and extra_data[3] == :set_trace_func then
+ nil
+ else
+ set_trace_func(nil)
+ error_msg = "Binding.of_caller used in non-method context or " +
+ "trailing statements of method using it aren't in the block."
+ cc.call(nil, lambda { raise(ArgumentError, error_msg) }, nil)
+ end
+ end
+
+ unless result
+ set_trace_func(tracer)
+ return nil
+ else
+ Thread.critical = old_critical
+ case block.arity
+ when 1 then yield(result)
+ else yield(result, extra_data)
+ end
+ end
+end
Oops, something went wrong.

0 comments on commit bf0e37b

Please sign in to comment.