Module: Ruined
- Includes:
- WEBrick
- Defined in:
- lib/ruined/ruinmain.rb
Defined Under Namespace
Classes: Context, DebugServlet, Thread
Constant Summary
collapse
- RUINED_VERSION =
'0.1.0'
- IGNORES =
[:$&, :$', :$+, :$_, :$`, :$~, :$KCODE, :$= ]
Class Method Summary
collapse
Class Method Details
.add_unbreakable(t) ⇒ Object
315
316
317
318
319
|
# File 'lib/ruined/ruinmain.rb', line 315
def self.add_unbreakable(t)
@monitor.synchronize {
@unbreakable_threads << t
}
end
|
.breakpoints ⇒ Object
229
230
231
|
# File 'lib/ruined/ruinmain.rb', line 229
def self.breakpoints
@breakpoints
end
|
.current_context ⇒ Object
224
225
226
227
|
# File 'lib/ruined/ruinmain.rb', line 224
def self.current_context
raise RuntimeException.new('bug: no context !!') unless @current
@current.to_hash
end
|
.global_vars ⇒ Object
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
|
# File 'lib/ruined/ruinmain.rb', line 255
def self.global_vars
script = <<EOD
(global_variables - Ruined::IGNORES).map do |v|
if v.to_s =~ /\\A\\$[1-9]/
nil
else
{ :name => v.to_s, :value => eval(v.to_s) }
end
end - [nil]
EOD
a = eval(script)
if @current
0.upto(a.size - 1) do |i|
if @current.tlses.has_key?(a[i][:name])
a[i][:value] = @current.tlses[a[i][:name]]
end
end
end
a
end
|
.local_call?(addr) ⇒ Boolean
333
334
335
|
# File 'lib/ruined/ruinmain.rb', line 333
def self.local_call?(addr)
['127.0.0.1', '::1'].include?(addr[3])
end
|
.local_vars ⇒ Object
233
234
235
236
237
238
239
240
|
# File 'lib/ruined/ruinmain.rb', line 233
def self.local_vars
script = <<EOD
local_variables.map do |_0|
(_0 == :_) ? nil : { :name => _0.to_s, :value => eval(_0.to_s) }
end - [nil]
EOD
(@current) ? eval(script, @current.binding) : []
end
|
.logger ⇒ Object
.output ⇒ Object
299
300
301
302
303
304
305
306
307
308
309
|
# File 'lib/ruined/ruinmain.rb', line 299
def self.output
return '' unless StringIO === $stdout
out = $stdout
$stdout = StringIO.new
out.pos = 0
ret = ''
out.each_line do |x|
ret << "#{HTMLUtils.escape(to_utf8(x.chomp))}<br/>"
end
ret
end
|
.release(t, obj = nil) ⇒ Object
290
291
292
293
294
295
296
297
|
# File 'lib/ruined/ruinmain.rb', line 290
def self.release(t, obj = nil)
return unless @queue
logger.debug("------------release #{t}")
@monitor.synchronize {
@queue[t].push obj
}
logger.debug("------------release exit #{t}")
end
|
.remove_unbreakable(t) ⇒ Object
321
322
323
324
325
|
# File 'lib/ruined/ruinmain.rb', line 321
def self.remove_unbreakable(t)
@monitor.synchronize {
@unbreakable_threads.delete t
}
end
|
.self_vars ⇒ Object
242
243
244
245
246
247
248
249
250
251
252
253
|
# File 'lib/ruined/ruinmain.rb', line 242
def self.self_vars
script = <<EOD
[{ :name => 'class', :value => self.class.to_s }] +
instance_variables.map do |v|
{ :name => v.to_s, :value => instance_eval(v.to_s) }
end +
self.class.class_variables.map do |v|
{ :name => v.to_s, :value => instance_eval(v.to_s) }
end
EOD
(@current) ? eval(script, @current.binding) : []
end
|
.set(var, val) ⇒ Object
276
277
278
|
# File 'lib/ruined/ruinmain.rb', line 276
def self.set(var, val)
eval("#{var} = #{val}", @current.binding)
end
|
.status_to_s(s) ⇒ Object
349
350
351
352
353
354
355
356
357
|
# File 'lib/ruined/ruinmain.rb', line 349
def self.status_to_s(s)
if s.nil?
'aborted'
elsif s == false
'dead'
else
s
end
end
|
.to_utf8(s) ⇒ Object
311
312
313
|
# File 'lib/ruined/ruinmain.rb', line 311
def self.to_utf8(s)
(s.encoding != Encoding::UTF_8) ? s.encode(Encoding::UTF_8) : s
end
|
.unbreakable?(t) ⇒ Boolean
327
328
329
330
331
|
# File 'lib/ruined/ruinmain.rb', line 327
def self.unbreakable?(t)
@monitor.synchronize {
@unbreakable_threads.include? t
}
end
|
.user_threads(current) ⇒ Object
337
338
339
340
341
342
343
344
345
346
347
|
# File 'lib/ruined/ruinmain.rb', line 337
def self.user_threads(current)
r = []
@monitor.synchronize {
@user_threads.each do |t, c|
r << [:file => File.basename(c.file), :line => c.line,
:self => (c == current),
:status => status_to_s(t.status)]
end
r
}
end
|
.wait(t) ⇒ Object
280
281
282
283
284
285
286
287
288
|
# File 'lib/ruined/ruinmain.rb', line 280
def self.wait(t)
return unless @queue
logger.debug("------------wait #{t}")
o = @queue[t].pop
if t == 1
@current = o
end
logger.debug("------------wait exit #{t}")
end
|