public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Search Repo:
Went back to original breakpointing as I couldnt make the patches from 
flgr work

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@425 
5ecf4fe2-1ee6-0310-87b1-e25e094e27de
dhh (author)
Sat Jan 15 13:28:02 -0800 2005
commit  e59f1b52497ce3a74bb1f396c06141524f0b6b85
tree    84cdba6290a62ef63d46e036edb22453daeaea21
parent  c46e390920950f273bdfc1c664f5e672f59e3a21
...
21
22
23
24
25
26
27
28
29
...
136
137
138
139
140
141
 
 
 
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
 
 
 
 
157
158
159
...
187
188
189
190
191
192
193
...
292
293
294
295
 
296
297
298
...
303
304
305
306
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
307
308
309
...
496
497
498
499
500
 
 
501
502
503
...
21
22
23
 
 
 
24
25
26
...
133
134
135
 
 
 
136
137
138
139
140
 
 
 
 
 
 
 
 
 
 
 
 
 
141
142
143
144
145
146
147
...
175
176
177
 
178
179
180
...
279
280
281
 
282
283
284
285
...
290
291
292
 
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
...
507
508
509
 
 
510
511
512
513
514
0
@@ -21,9 +21,6 @@ require 'drb'
0
 require 'drb/acl'
0
 
0
 module Breakpoint
0
- id = %q$Id$
0
- Version = id.split(" ")[2].to_i
0
-
0
   extend self
0
 
0
   # This will pop up an interactive ruby session at a
0
@@ -136,24 +133,15 @@ module Breakpoint
0
       end
0
 
0
       # Will execute the specified statement at the client.
0
- def method_missing(method, *args, &block)
0
- if args.empty? and not block
0
- result = eval "#{method}"
0
+ def method_missing(method, *args)
0
+ if args.empty?
0
+ result = eval("#{method}")
0
         else
0
           result = eval("#{method}(*Marshal.load(#{Marshal.dump(args).inspect}))")
0
- # This is a bit ugly. The alternative would be using an
0
- # eval context instead of an eval handler for executing
0
- # the code at the client. The problem with that approach
0
- # is that we would have to handle special expressions
0
- # like "self", "nil" or constants ourself which is hard.
0
- remote = eval %{
0
- result = lambda { |block, *args| #{method}(*args, &block) }
0
- def result.call_with_block(*args, &block)
0
- call(block, *args)
0
- end
0
- result
0
- }
0
- remote.call_with_block(*args, &block)
0
+ end
0
+
0
+ unless [true, false, nil].include?(result)
0
+ result.extend(DRbUndumped) if result
0
         end
0
 
0
         return result
0
@@ -187,7 +175,6 @@ module Breakpoint
0
     # client.File.open("temp.txt", "w") { |f| f.puts "Hello" }
0
     def client()
0
       if Breakpoint.use_drb? then
0
- sleep(0.5) until Breakpoint.drb_service.eval_handler
0
         Client.new(Breakpoint.drb_service.eval_handler)
0
       else
0
         Client.new(lambda { |code| eval(code, TOPLEVEL_BINDING) })
0
@@ -292,7 +279,7 @@ module Breakpoint
0
       @collision_handler.call
0
     end
0
 
0
- def ping() end
0
+ def ping; end
0
 
0
     def add_breakpoint(context, message)
0
       workspace = IRB::WorkSpace.new(context)
0
@@ -303,7 +290,31 @@ module Breakpoint
0
       @handler.call(workspace, message)
0
     end
0
 
0
- attr_accessor :handler, :eval_handler, :collision_handler
0
+ def register_handler(&block)
0
+ @handler = block
0
+ end
0
+
0
+ def unregister_handler
0
+ @handler = nil
0
+ end
0
+
0
+ attr_reader :eval_handler
0
+
0
+ def register_eval_handler(&block)
0
+ @eval_handler = block
0
+ end
0
+
0
+ def unregister_eval_handler
0
+ @eval_handler = lambda { }
0
+ end
0
+
0
+ def register_collision_handler(&block)
0
+ @collision_handler = block
0
+ end
0
+
0
+ def unregister_collision_handler
0
+ @collision_handler = lambda { }
0
+ end
0
   end
0
 
0
   # Will run Breakpoint in DRb mode. This will spawn a server
0
@@ -496,8 +507,8 @@ end
0
 
0
 module DRb # :nodoc:
0
   class DRbObject#:nodoc:
0
- undef :inspect if method_defined?(:inspect)
0
- undef :clone if method_defined?(:clone)
0
+ undef :inspect
0
+ undef :clone
0
   end
0
 end
0
 
...
1
2
3
4
...
1
2
 
3
0
@@ -1,4 +1,3 @@
0
 #!/usr/local/bin/ruby
0
 $LOAD_PATH << File.dirname(__FILE__) + '/../vendor/railties/lib'
0
-$LOAD_PATH << File.dirname(__FILE__) + '/../vendor/activerecord/lib/support'
0
 require 'breakpoint_client'
...
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
...
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
...
153
154
155
156
157
158
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
159
160
161
...
170
171
172
173
174
175
 
176
177
178
...
57
58
59
 
 
 
 
 
 
 
 
 
60
61
62
...
68
69
70
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
72
73
...
90
91
92
 
 
 
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
...
153
154
155
 
 
 
156
157
158
159
0
@@ -57,15 +57,6 @@ ARGV.options do |opts|
0
     "Show this help message."
0
   ) { puts opts; exit }
0
 
0
- opts.on("-v", "--version",
0
- "Display the version information."
0
- ) do
0
- id = %q$Id$
0
- puts id.sub("Id: ", "")
0
- puts "(Breakpoint::Version = #{Breakpoint::Version})"
0
- exit
0
- end
0
-
0
   opts.parse!
0
 end
0
 
0
@@ -77,60 +68,6 @@ trap("INT"){$running = false}
0
 
0
 puts "Waiting for initial breakpoint..."
0
 
0
-module Handlers
0
- extend self
0
-
0
- def breakpoint_handler(workspace, message)
0
- puts message
0
- IRB.start(nil, nil, workspace)
0
- puts "", "Resumed execution. Waiting for next breakpoint...", ""
0
- end
0
-
0
- def eval_handler(code)
0
- result = eval(code, TOPLEVEL_BINDING)
0
- if result then
0
- DRbObject.new(result)
0
- else
0
- result
0
- end
0
- end
0
-
0
- def collision_handler()
0
- msg = [
0
- " *** Breakpoint service collision ***",
0
- " Another Breakpoint service tried to use the",
0
- " port already occupied by this one. It will",
0
- " keep waiting until this Breakpoint service",
0
- " is shut down.",
0
- " ",
0
- " If you are using the Breakpoint library for",
0
- " debugging a Rails or other CGI application",
0
- " this likely means that this Breakpoint",
0
- " session belongs to an earlier, outdated",
0
- " request and should be shut down via 'exit'."
0
- ].join("\n")
0
-
0
- if RUBY_PLATFORM["win"] then
0
- # This sucks. Sorry, I'm not doing this because
0
- # I like funky message boxes -- I need to do this
0
- # because on Windows I have no way of displaying
0
- # my notification via puts() when gets() is still
0
- # being performed on STDIN. I have not found a
0
- # better solution.
0
- begin
0
- require 'tk'
0
- root = TkRoot.new { withdraw }
0
- Tk.messageBox('message' => msg, 'type' => 'ok')
0
- root.destroy
0
- rescue Exception
0
- puts "", msg, ""
0
- end
0
- else
0
- puts "", msg, ""
0
- end
0
- end
0
-end
0
-
0
 loop do
0
   DRb.start_service(options[:ClientURI])
0
 
0
@@ -153,9 +90,55 @@ loop do
0
     end
0
 
0
     begin
0
- service.eval_handler = Handlers.method(:eval_handler)
0
- service.collision_handler = Handlers.method(:collision_handler)
0
- service.handler = Handlers.method(:breakpoint_handler)
0
+ service.register_eval_handler do |code|
0
+ result = eval(code, TOPLEVEL_BINDING)
0
+ if result
0
+ DRbObject.new(result)
0
+ else
0
+ result
0
+ end
0
+ end
0
+
0
+ service.register_collision_handler do
0
+ msg = [
0
+ " *** Breakpoint service collision ***",
0
+ " Another Breakpoint service tried to use the",
0
+ " port already occupied by this one. It will",
0
+ " keep waiting until this Breakpoint service",
0
+ " is shut down.",
0
+ " ",
0
+ " If you are using the Breakpoint library for",
0
+ " debugging a Rails or other CGI application",
0
+ " this likely means that this Breakpoint",
0
+ " session belongs to an earlier, outdated",
0
+ " request and should be shut down via 'exit'."
0
+ ].join("\n")
0
+
0
+ if RUBY_PLATFORM["win"] then
0
+ # This sucks. Sorry, I'm not doing this because
0
+ # I like funky message boxes -- I need to do this
0
+ # because on Windows I have no way of displaying
0
+ # my notification via puts() when gets() is still
0
+ # being performed on STDIN. I have not found a
0
+ # better solution.
0
+ begin
0
+ require 'tk'
0
+ root = TkRoot.new { withdraw }
0
+ Tk.messageBox('message' => msg, 'type' => 'ok')
0
+ root.destroy
0
+ rescue Exception
0
+ puts "", msg, ""
0
+ end
0
+ else
0
+ puts "", msg, ""
0
+ end
0
+ end
0
+
0
+ service.register_handler do |workspace, message|
0
+ puts message
0
+ IRB.start(nil, nil, workspace)
0
+ puts "", "Resumed execution. Waiting for next breakpoint...", ""
0
+ end
0
 
0
       puts "Connection established. Waiting for breakpoint...", "" if options[:Verbose]
0
 
0
@@ -170,9 +153,7 @@ loop do
0
         sleep(0.5)
0
       end
0
     ensure
0
- service.eval_handler = nil
0
- service.collision_handler = nil
0
- service.handler = nil
0
+ service.unregister_handler
0
     end
0
   rescue Exception => error
0
     break unless $running

Comments

    No one has commented yet.