ruined 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog CHANGED
@@ -1,3 +1,6 @@
1
+ Mon Oct 11 18:38:00 2010 arton
2
+ * lib/ruined/ruinmain.rb
3
+ change version => 0.0.2 for new gem
1
4
  Mon Oct 11 15:51:00 2010 arton
2
5
  start brwoser (suggested by knu and n0kada, thanks)
3
6
  Mon Oct 11 01:37:00 2010 arton
@@ -92,6 +92,13 @@ function stepProc(command) {
92
92
  $('button').button('disable');
93
93
  return;
94
94
  }
95
+ if (data['break'] || data['event'] == 'exit') {
96
+ stopRun();
97
+ if (data['event'] == 'exit') {
98
+ $('button').button('disable');
99
+ alert('program exit');
100
+ }
101
+ }
95
102
  if (files[data.file] == null) {
96
103
  files[data.file] = addFile(data.file, data.line, command);
97
104
  } else {
@@ -105,9 +112,6 @@ function stepProc(command) {
105
112
  span = document.createElement('span');
106
113
  $('#stdout')[0].appendChild(span);
107
114
  span.scrollIntoView(true);
108
- if (data['break']) {
109
- stopRun();
110
- }
111
115
  });
112
116
  }
113
117
  function contProc(command) {
@@ -152,7 +156,11 @@ $(document).ready(function() {
152
156
  if (contTimer != null) {
153
157
  stopRun();
154
158
  }
155
- alert('error');
159
+ $('#vars').tabs({
160
+ show: function(envet, ui) {
161
+ alert('program terminated');
162
+ }
163
+ });
156
164
  });
157
165
  stepProc('stepping');
158
166
  });
@@ -194,6 +202,6 @@ $(document).ready(function() {
194
202
  <hr>
195
203
  <div id="waiting"></div>
196
204
  <address id="ruby-platform"></address>
197
- <!-- hhmts start --> Last modified: Mon Oct 11 12:42:26 +0900 2010 <!-- hhmts end -->
205
+ <!-- hhmts start --> Last modified: Mon Oct 11 17:22:50 +0900 2010 <!-- hhmts end -->
198
206
  </div>
199
207
  </body> </html>
@@ -1,243 +1,271 @@
1
- #!/usr/local/bin/ruby -Ku
2
- # coding: utf-8
3
-
4
- require 'webrick'
5
- require 'json'
6
- require 'thread'
7
- require 'monitor'
8
- require 'stringio'
9
-
10
- module Ruined
11
- RUINED_VERSION = '0.0.1'
12
-
13
- @queue = [Queue.new, Queue.new]
14
- @breakpoints = []
15
- @monitor = Monitor.new
16
- include WEBrick
17
- svr = HTTPServer.new(:Port => 8383,
18
- :ServerType => Thread,
19
- :Logger => ($DEBUG) ? Log.new(nil, BasicLog::DEBUG) : Log.new,
20
- :DocumentRoot => File.dirname(__FILE__))
21
- trap('INT') do
22
- svr.shutdown
23
- end
24
-
25
- class DebugServlet < HTTPServlet::AbstractServlet
26
- include WEBrick::HTMLUtils
27
- def service(req, res)
28
- if req.addr[3] == '127.0.0.1'
29
- super
30
- else
31
- bye(res)
32
- end
33
- end
34
- def do_GET(req, res)
35
- m = %r|/debug/([^/]+)/?(.*)\Z|.match(req.path)
36
- if m
37
- res.body = __send__(m[1].to_sym, *(m[2].split('/')))
38
- else
39
- bye(res)
40
- end
41
- end
42
-
43
- def break(*a)
44
- if a.size < 3
45
- bye(response)
46
- else
47
- point = [a[1..(a.size - 2)].join('/'), a[a.size - 1].to_i]
48
- if a[0] == 'true'
49
- Ruined.breakpoints << point
50
- else
51
- Ruined.breakpoints.delete point
52
- end
53
- JSON(point)
54
- end
55
- end
56
-
57
- def run(*a)
58
- end
59
-
60
- def stop(*a)
61
- end
62
-
63
- def stepping(*a)
64
- Ruined.wait 1
65
- JSON(Ruined.current)
66
- end
67
-
68
- def cont(*a)
69
- Ruined.release 0
70
- Ruined.wait 1
71
- JSON(Ruined.current)
72
- end
73
-
74
- def step(*a)
75
- cont(a)
76
- end
77
-
78
- def file(*a)
79
- r = '<table>'
80
- File.open(a.join('/')).each_line do |line|
81
- r << "<tr><td><pre>#{escape(line)}</pre></td></tr>"
82
- end.close
83
- r + '</table>'
84
- end
85
-
86
- def locals(*a)
87
- s = '<table class="vars"><tr><th>Name</th><th>Value</th></tr>'
88
- Ruined.local_vars.each do |e|
89
- s << "<tr><td>#{escape(e[:name])}</td><td>#{escape(e[:value].to_s)}</td></tr>"
90
- end
91
- s + '</table>'
92
- end
93
-
94
- def globals(*a)
95
- s = '<table class="vars"><tr><th>Name</th><th>Value</th></tr>'
96
- Ruined.global_vars.each do |e|
97
- s << "<tr><td>#{e[:name]}</td><td>#{escape(e[:value].to_s)}</td></tr>"
98
- end
99
- s + '</table>'
100
- end
101
-
102
- def self(*a)
103
- s = '<table class="vars"><tr><th>Name</th><th>Value</th></tr>'
104
- Ruined.self_vars.each do |e|
105
- s << "<tr><td>#{e[:name]}</td><td>#{escape(e[:value].to_s)}</td></tr>"
106
- end
107
- s + '</table>'
108
- end
109
-
110
- def start(*a)
111
- '<html>start</html>'
112
- end
113
-
114
- private
115
-
116
- def bye(res)
117
- res.status = 404
118
- res.body = '<html>bye</html>'
119
- end
120
- end
121
-
122
- def self.current
123
- @current
124
- end
125
-
126
- def self.breakpoints
127
- @breakpoints
128
- end
129
-
130
- def self.local_vars
131
- script = <<EOD
132
- local_variables.map do |v|
133
- (v == :_) ? nil : { :name => v.to_s, :value => eval(v.to_s) }
134
- end - [nil]
135
- EOD
136
- @current_binding ? eval(script, @current_binding) : []
137
- end
138
-
139
- def self.self_vars
140
- script = <<EOD
141
- [{ :name => 'class', :value => self.class.to_s }] +
142
- instance_variables.map do |v|
143
- { :name => v.to_s, :value => instance_eval(v.to_s) }
144
- end +
145
- self.class.class_variables.map do |v|
146
- { :name => v.to_s, :value => instance_eval(v.to_s) }
147
- end
148
- EOD
149
- @current_binding ? eval(script, @current_binding) : []
150
- end
151
-
152
- def self.global_vars
153
- script = <<EOD
154
- global_variables.map do |v|
155
- (v == :_) ? nil : { :name => v.to_s, :value => eval(v.to_s) }
156
- end
157
- EOD
158
- eval(script)
159
- end
160
-
161
- def self.wait(t)
162
- @monitor.synchronize {
163
- unless @queue[t].empty?
164
- @queue[t].clear
165
- logger.debug("------------not wait exit #{t}")
166
- return
167
- end
168
- }
169
- logger.debug("------------wait #{t}")
170
- @queue[t].pop
171
- logger.debug("------------wait exit #{t}")
172
- end
173
-
174
- def self.release(t)
175
- logger.debug("------------release #{t}")
176
- @monitor.synchronize {
177
- @queue[t].push nil
178
- }
179
- logger.debug("------------release exit #{t}")
180
- end
181
-
182
- def self.output
183
- return '' unless StringIO === $stdout
184
- out = $stdout
185
- $stdout = StringIO.new
186
- out.pos = 0
187
- ret = ''
188
- out.each_line do |x|
189
- ret << "#{x.chomp}<br/>"
190
- end
191
- ret
192
- end
193
-
194
- svr.mount('/debug', DebugServlet)
195
- svr.mount_proc('/quit') do |req, res|
196
- if req.addr[3] == '127.0.0.1'
197
- set_trace_func(nil)
198
- c = 0
199
- if req.path =~ %r|/(\d+)|
200
- c = $1.to_i
201
- end
202
- res.body = '<html>bye</html>'
203
- Thread.start do
204
- @monitor.synchronize {
205
- @queue = nil
206
- }
207
- Thread.pass
208
- svr.shutdown
209
- exit(c)
210
- end
211
- else
212
- res.status = 404
213
- end
214
- end
215
-
216
- define_method(:logger) do
217
- return svr.logger
218
- end
219
- module_function(:logger)
220
-
221
- svr.start
222
-
223
- main_thread = Thread.current
224
-
225
- set_trace_func Proc.new {|event, file, line, id, binding, klass|
226
- unless file =~ %r#(lib/ruby|webrick|internal)# || main_thread != Thread.current
227
- if event.index('c-') != 0
228
- if file == $0 && !$stdout.instance_of?(StringIO)
229
- $stdout = StringIO.new
230
- end
231
- b = breakpoints.include? [file, line]
232
- @current_binding = binding
233
- @current = { 'event' => event, 'file' => file, 'line' => line,
234
- 'id' => id.to_s, 'break' => b, 'stdout' => output }
235
- svr.logger.debug(@current.inspect)
236
- release 1
237
- wait 0
238
- svr.logger.debug('continue...')
239
- end
240
- end
241
- }
242
- end
243
-
1
+ #!/usr/local/bin/ruby -Ku
2
+ # coding: utf-8
3
+
4
+ require 'webrick'
5
+ require 'json'
6
+ require 'thread'
7
+ require 'monitor'
8
+ require 'stringio'
9
+
10
+ module Ruined
11
+ RUINED_VERSION = '0.0.2'
12
+
13
+ @queue = [Queue.new, Queue.new]
14
+ @breakpoints = []
15
+ @monitor = Monitor.new
16
+ @tlses = { '$!' => nil, '$?' => nil, '$@' => nil, '$SAFE' => nil}
17
+ IGNORES = [:$&, :$', :$+, :$_, :$`, :$~, :$KCODE, :$= ]
18
+
19
+ include WEBrick
20
+ svr = HTTPServer.new(:Port => 8383,
21
+ :ServerType => Thread,
22
+ :Logger => ($DEBUG) ? Log.new(nil, BasicLog::DEBUG) : Log.new,
23
+ :DocumentRoot => File.dirname(__FILE__))
24
+ trap('INT') do
25
+ svr.shutdown
26
+ end
27
+
28
+ class DebugServlet < HTTPServlet::AbstractServlet
29
+ include WEBrick::HTMLUtils
30
+ def service(req, res)
31
+ if req.addr[3] == '127.0.0.1'
32
+ super
33
+ else
34
+ bye(res)
35
+ end
36
+ end
37
+ def do_GET(req, res)
38
+ m = %r|/debug/([^/]+)/?(.*)\Z|.match(req.path)
39
+ if m
40
+ res.body = __send__(m[1].to_sym, *(m[2].split('/')))
41
+ else
42
+ bye(res)
43
+ end
44
+ end
45
+
46
+ def break(*a)
47
+ if a.size < 3
48
+ bye(response)
49
+ else
50
+ point = [a[1..(a.size - 2)].join('/'), a[a.size - 1].to_i]
51
+ if a[0] == 'true'
52
+ Ruined.breakpoints << point
53
+ else
54
+ Ruined.breakpoints.delete point
55
+ end
56
+ JSON(point)
57
+ end
58
+ end
59
+
60
+ def run(*a)
61
+ end
62
+
63
+ def stop(*a)
64
+ end
65
+
66
+ def stepping(*a)
67
+ Ruined.wait 1
68
+ JSON(Ruined.current)
69
+ end
70
+
71
+ def cont(*a)
72
+ Ruined.release 0
73
+ Ruined.wait 1
74
+ JSON(Ruined.current)
75
+ end
76
+
77
+ def step(*a)
78
+ cont(a)
79
+ end
80
+
81
+ def file(*a)
82
+ r = '<table>'
83
+ File.open(a.join('/')).each_line do |line|
84
+ r << "<tr><td><pre>#{escape(line)}</pre></td></tr>"
85
+ end.close
86
+ r + '</table>'
87
+ end
88
+
89
+ def locals(*a)
90
+ s = '<table class="vars"><tr><th>Name</th><th>Value</th></tr>'
91
+ Ruined.local_vars.each do |e|
92
+ s << "<tr><td>#{escape(e[:name])}</td><td>#{escape(e[:value].inspect)}</td></tr>"
93
+ end
94
+ s + '</table>'
95
+ end
96
+
97
+ def globals(*a)
98
+ s = '<table class="vars"><tr><th>Name</th><th>Value</th></tr>'
99
+ Ruined.global_vars.each do |e|
100
+ s << "<tr><td>#{e[:name]}</td><td>#{escape(e[:value].inspect)}</td></tr>"
101
+ end
102
+ s + '</table>'
103
+ end
104
+
105
+ def self(*a)
106
+ s = '<table class="vars"><tr><th>Name</th><th>Value</th></tr>'
107
+ Ruined.self_vars.each do |e|
108
+ s << "<tr><td>#{e[:name]}</td><td>#{escape(e[:value].inspect)}</td></tr>"
109
+ end
110
+ s + '</table>'
111
+ end
112
+
113
+ def start(*a)
114
+ '<html>start</html>'
115
+ end
116
+
117
+ private
118
+
119
+ def bye(res)
120
+ res.status = 404
121
+ res.body = '<html>bye</html>'
122
+ end
123
+ end
124
+
125
+ def self.current
126
+ @current
127
+ end
128
+
129
+ def self.breakpoints
130
+ @breakpoints
131
+ end
132
+
133
+ def self.local_vars
134
+ script = <<EOD
135
+ local_variables.map do |v|
136
+ (v == :_) ? nil : { :name => v.to_s, :value => eval(v.to_s) }
137
+ end - [nil]
138
+ EOD
139
+ @current_binding ? eval(script, @current_binding) : []
140
+ end
141
+
142
+ def self.self_vars
143
+ script = <<EOD
144
+ [{ :name => 'class', :value => self.class.to_s }] +
145
+ instance_variables.map do |v|
146
+ { :name => v.to_s, :value => instance_eval(v.to_s) }
147
+ end +
148
+ self.class.class_variables.map do |v|
149
+ { :name => v.to_s, :value => instance_eval(v.to_s) }
150
+ end
151
+ EOD
152
+ @current_binding ? eval(script, @current_binding) : []
153
+ end
154
+
155
+ def self.global_vars
156
+ script = <<EOD
157
+ (global_variables - Ruined::IGNORES).map do |v|
158
+ if v.to_s =~ /\\A\\$[1-9]/
159
+ nil
160
+ else
161
+ { :name => v.to_s, :value => eval(v.to_s) }
162
+ end
163
+ end - [nil]
164
+ EOD
165
+ a = eval(script)
166
+ 0.upto(a.size - 1) do |i|
167
+ if @tlses.has_key?(a[i][:name])
168
+ a[i][:value] = @tlses[a[i][:name]]
169
+ end
170
+ end
171
+ a
172
+ end
173
+
174
+ def self.tls_vars
175
+ @@tlses
176
+ end
177
+
178
+ def self.wait(t)
179
+ @monitor.synchronize {
180
+ unless @queue[t].empty?
181
+ @queue[t].clear
182
+ logger.debug("------------not wait exit #{t}")
183
+ return
184
+ end
185
+ }
186
+ logger.debug("------------wait #{t}")
187
+ @queue[t].pop
188
+ logger.debug("------------wait exit #{t}")
189
+ end
190
+
191
+ def self.release(t)
192
+ logger.debug("------------release #{t}")
193
+ @monitor.synchronize {
194
+ @queue[t].push nil
195
+ }
196
+ logger.debug("------------release exit #{t}")
197
+ end
198
+
199
+ def self.output
200
+ return '' unless StringIO === $stdout
201
+ out = $stdout
202
+ $stdout = StringIO.new
203
+ out.pos = 0
204
+ ret = ''
205
+ out.each_line do |x|
206
+ ret << "#{x.chomp}<br/>"
207
+ end
208
+ ret
209
+ end
210
+
211
+ svr.mount('/debug', DebugServlet)
212
+ svr.mount_proc('/quit') do |req, res|
213
+ if req.addr[3] == '127.0.0.1'
214
+ set_trace_func(nil)
215
+ c = 0
216
+ if req.path =~ %r|/(\d+)|
217
+ c = $1.to_i
218
+ end
219
+ res.body = '<html>bye</html>'
220
+ Thread.start do
221
+ @monitor.synchronize {
222
+ @queue = nil
223
+ }
224
+ Thread.pass
225
+ svr.shutdown
226
+ exit(c)
227
+ end
228
+ else
229
+ res.status = 404
230
+ end
231
+ end
232
+
233
+ define_method(:logger) do
234
+ return svr.logger
235
+ end
236
+ module_function(:logger)
237
+
238
+ svr.start
239
+
240
+ main_thread = Thread.current
241
+
242
+ set_trace_func Proc.new {|event, file, line, id, binding, klass|
243
+ unless file =~ %r#(lib/ruby|webrick|internal)# || main_thread != Thread.current
244
+ if event.index('c-') != 0
245
+ if file == $0 && !$stdout.instance_of?(StringIO)
246
+ $stdout = StringIO.new
247
+ end
248
+ @tlses.each do |k, v|
249
+ @tlses[k] = eval(k)
250
+ end
251
+ b = breakpoints.include? [file, line]
252
+ @current_binding = binding
253
+ @current = { 'event' => event, 'file' => file, 'line' => line,
254
+ 'id' => id.to_s, 'break' => b, 'stdout' => output }
255
+ svr.logger.debug(@current.inspect)
256
+ release 1
257
+ wait 0
258
+ svr.logger.debug('continue...')
259
+ end
260
+ end
261
+ }
262
+ at_exit {
263
+ if @current
264
+ @current['event'] = 'exit'
265
+ @current['stdout'] = output
266
+ release 1
267
+ wait 0
268
+ end
269
+ }
270
+ end
271
+
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruined
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - arton