ruined 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (28) hide show
  1. data/ChangeLog +4 -0
  2. data/gpl-3.0.txt +674 -0
  3. data/lib/ruined/css/ruin.css +58 -0
  4. data/lib/ruined/css/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  5. data/lib/ruined/css/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  6. data/lib/ruined/css/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  7. data/lib/ruined/css/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  8. data/lib/ruined/css/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  9. data/lib/ruined/css/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  10. data/lib/ruined/css/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  11. data/lib/ruined/css/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  12. data/lib/ruined/css/smoothness/images/ui-icons_222222_256x240.png +0 -0
  13. data/lib/ruined/css/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
  14. data/lib/ruined/css/smoothness/images/ui-icons_454545_256x240.png +0 -0
  15. data/lib/ruined/css/smoothness/images/ui-icons_888888_256x240.png +0 -0
  16. data/lib/ruined/css/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
  17. data/lib/ruined/css/smoothness/jquery-ui-1.8.5.custom.css +572 -0
  18. data/lib/ruined/html/header.html +31 -0
  19. data/lib/ruined/html/index.html +11 -0
  20. data/lib/ruined/html/main.html +199 -0
  21. data/lib/ruined/html/waitclient.html +28 -0
  22. data/lib/ruined/index.html +8 -0
  23. data/lib/ruined/js/jquery-1.4.2.min.js +154 -0
  24. data/lib/ruined/js/jquery-ui-1.8.5.custom.min.js +778 -0
  25. data/lib/ruined/ruinmain.rb +243 -0
  26. data/lib/uined.rb +89 -0
  27. data/test/test.rb +12 -0
  28. metadata +97 -0
@@ -0,0 +1,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.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
+
data/lib/uined.rb ADDED
@@ -0,0 +1,89 @@
1
+ #!/usr/local/bin/ruby -Ku
2
+ # coding: utf-8
3
+
4
+ require 'webrick/log'
5
+
6
+ def run_app()
7
+ argv = $DEBUG ? ['-d'] : []
8
+ argv += ['-rruined/ruinmain', $0]
9
+ argv += ARGV
10
+ spawn "#{RbConfig::ruby}", *argv
11
+ end
12
+
13
+ def kill_child()
14
+ open('http://localhost:8383/quit') do |h|
15
+ h.read
16
+ end
17
+ end
18
+
19
+ def quit_svr(c, svr)
20
+ Thread.start do
21
+ sleep(1)
22
+ svr.shutdown
23
+ puts 'svr stopped'
24
+ end
25
+ end
26
+
27
+ if $0 == __FILE__
28
+ $stderr.puts 'usage: ruby -ruined target [target-args]'
29
+ else
30
+ require 'webrick'
31
+ require 'open-uri'
32
+ require 'mkmf'
33
+
34
+ include WEBrick
35
+ svr = HTTPServer.new(:Port => 8384,
36
+ :DocumentRoot => "#{File.dirname(__FILE__)}/ruined")
37
+ trap('INT') do
38
+ svr.shutdown
39
+ end
40
+ svr.mount_proc('/restart') do |req, res|
41
+ begin
42
+ kill_child
43
+ rescue
44
+ svr.logger.error 'failed to kill child (restart)'
45
+ end
46
+ sleep(1.5)
47
+ run_app
48
+ res.body = '<html>restart</html>'
49
+ end
50
+ svr.mount_proc('/quit') do |req, res|
51
+ begin
52
+ kill_child
53
+ rescue
54
+ svr.logger.error 'failed to kill child (quit)'
55
+ end
56
+ c = 0
57
+ if req.path =~ %r|/(\d+)|
58
+ c = $1.to_i
59
+ end
60
+ quit_svr(c, svr)
61
+ res.body = '<html>bye</html>'
62
+ end
63
+ svr.mount_proc('/connect') do |req, res|
64
+ begin
65
+ open('http://127.0.0.1:8383/debug/start') do |http|
66
+ http.read
67
+ end
68
+ rescue
69
+ res.status = 404
70
+ end
71
+ res.body = '<html></html>'
72
+ end
73
+
74
+ Thread.start do
75
+ run_app
76
+ if RUBY_PLATFORM =~ /win32/
77
+ system('start http://localhost.:8384/html/index.html')
78
+ elsif RUBY_PLATFORM =~ /cygwin/
79
+ system('cygstart http://localhost.:8384/html/index.html')
80
+ else
81
+ unless system('open', 'http://localhost.:8384/html/index.html')
82
+ $stderr.puts 'open http://localhost:8384/ on your web browser'
83
+ end
84
+ end
85
+ end
86
+ svr.start
87
+ puts 'debugger exit'
88
+ exit(0)
89
+ end
data/test/test.rb ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/local/ruby -Ku
2
+ # coding: utf-8
3
+ # $Id:$
4
+
5
+ require 'test/unit'
6
+ require 'webrick'
7
+
8
+ class Test
9
+ def test_none
10
+ assert true
11
+ end
12
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruined
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - arton
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-10-11 00:00:00 +09:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: |
23
+ ruined is Ruby Source Level Debugger for educational purpose.
24
+
25
+ email: artonx@gmail.com
26
+ executables: []
27
+
28
+ extensions: []
29
+
30
+ extra_rdoc_files: []
31
+
32
+ files:
33
+ - lib/ruined/ruinmain.rb
34
+ - lib/uined.rb
35
+ - test/test.rb
36
+ - lib/ruined/index.html
37
+ - lib/ruined/html/header.html
38
+ - lib/ruined/html/main.html
39
+ - lib/ruined/html/waitclient.html
40
+ - lib/ruined/html/index.html
41
+ - lib/ruined/css/smoothness/jquery-ui-1.8.5.custom.css
42
+ - lib/ruined/css/ruin.css
43
+ - lib/ruined/css/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png
44
+ - lib/ruined/css/smoothness/images/ui-icons_888888_256x240.png
45
+ - lib/ruined/css/smoothness/images/ui-bg_glass_75_dadada_1x400.png
46
+ - lib/ruined/css/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png
47
+ - lib/ruined/css/smoothness/images/ui-icons_2e83ff_256x240.png
48
+ - lib/ruined/css/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png
49
+ - lib/ruined/css/smoothness/images/ui-icons_222222_256x240.png
50
+ - lib/ruined/css/smoothness/images/ui-bg_glass_65_ffffff_1x400.png
51
+ - lib/ruined/css/smoothness/images/ui-icons_454545_256x240.png
52
+ - lib/ruined/css/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png
53
+ - lib/ruined/css/smoothness/images/ui-icons_cd0a0a_256x240.png
54
+ - lib/ruined/css/smoothness/images/ui-bg_flat_75_ffffff_40x100.png
55
+ - lib/ruined/css/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png
56
+ - lib/ruined/js/jquery-1.4.2.min.js
57
+ - lib/ruined/js/jquery-ui-1.8.5.custom.min.js
58
+ - gpl-3.0.txt
59
+ - ChangeLog
60
+ has_rdoc: true
61
+ homepage: http://github.com/arton/ruined
62
+ licenses: []
63
+
64
+ post_install_message:
65
+ rdoc_options: []
66
+
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ hash: 49
75
+ segments:
76
+ - 1
77
+ - 9
78
+ - 1
79
+ version: 1.9.1
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ hash: 3
86
+ segments:
87
+ - 0
88
+ version: "0"
89
+ requirements:
90
+ - none
91
+ rubyforge_project:
92
+ rubygems_version: 1.3.7
93
+ signing_key:
94
+ specification_version: 3
95
+ summary: Ruby UI Debugger
96
+ test_files:
97
+ - test/test.rb