trepanning 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ChangeLog +4422 -0
- data/LICENSE +23 -0
- data/NEWS +12 -0
- data/README.textile +56 -0
- data/Rakefile +171 -0
- data/app/Makefile +7 -0
- data/app/breakpoint.rb +157 -0
- data/app/brkptmgr.rb +149 -0
- data/app/condition.rb +22 -0
- data/app/core.rb +203 -0
- data/app/default.rb +54 -0
- data/app/disassemble.rb +61 -0
- data/app/display.rb +148 -0
- data/app/file.rb +135 -0
- data/app/frame.rb +275 -0
- data/app/irb.rb +112 -0
- data/app/mock.rb +22 -0
- data/app/options.rb +122 -0
- data/app/run.rb +95 -0
- data/app/thread.rb +24 -0
- data/app/util.rb +32 -0
- data/bin/trepan +63 -0
- data/data/custom_require.rb +44 -0
- data/data/irbrc +55 -0
- data/data/prelude.rb +38 -0
- data/interface/base_intf.rb +95 -0
- data/interface/script.rb +103 -0
- data/interface/user.rb +90 -0
- data/io/base_io.rb +92 -0
- data/io/input.rb +111 -0
- data/io/string_array.rb +155 -0
- data/lib/Makefile +7 -0
- data/lib/trepanning.rb +277 -0
- data/processor/breakpoint.rb +108 -0
- data/processor/command/alias.rb +55 -0
- data/processor/command/backtrace.rb +95 -0
- data/processor/command/base/cmd.rb +97 -0
- data/processor/command/base/subcmd.rb +207 -0
- data/processor/command/base/submgr.rb +178 -0
- data/processor/command/base/subsubcmd.rb +102 -0
- data/processor/command/base/subsubmgr.rb +182 -0
- data/processor/command/break.rb +85 -0
- data/processor/command/condition.rb +64 -0
- data/processor/command/continue.rb +61 -0
- data/processor/command/debug.rb +85 -0
- data/processor/command/delete.rb +54 -0
- data/processor/command/directory.rb +43 -0
- data/processor/command/disable.rb +65 -0
- data/processor/command/disassemble.rb +103 -0
- data/processor/command/display.rb +81 -0
- data/processor/command/down.rb +56 -0
- data/processor/command/enable.rb +43 -0
- data/processor/command/exit.rb +54 -0
- data/processor/command/finish.rb +81 -0
- data/processor/command/frame.rb +117 -0
- data/processor/command/help.rb +146 -0
- data/processor/command/info.rb +28 -0
- data/processor/command/info_subcmd/args.rb +56 -0
- data/processor/command/info_subcmd/breakpoints.rb +162 -0
- data/processor/command/info_subcmd/file.rb +162 -0
- data/processor/command/info_subcmd/frame.rb +39 -0
- data/processor/command/info_subcmd/iseq.rb +83 -0
- data/processor/command/info_subcmd/locals.rb +88 -0
- data/processor/command/info_subcmd/program.rb +54 -0
- data/processor/command/info_subcmd/registers.rb +72 -0
- data/processor/command/info_subcmd/registers_subcmd/dfp.rb +38 -0
- data/processor/command/info_subcmd/registers_subcmd/helper.rb +40 -0
- data/processor/command/info_subcmd/registers_subcmd/lfp.rb +54 -0
- data/processor/command/info_subcmd/registers_subcmd/pc.rb +44 -0
- data/processor/command/info_subcmd/registers_subcmd/sp.rb +75 -0
- data/processor/command/info_subcmd/return.rb +40 -0
- data/processor/command/info_subcmd/thread.rb +106 -0
- data/processor/command/irb.rb +106 -0
- data/processor/command/kill.rb +58 -0
- data/processor/command/list.rb +327 -0
- data/processor/command/macro.rb +65 -0
- data/processor/command/next.rb +89 -0
- data/processor/command/nocache.rb +33 -0
- data/processor/command/print.rb +37 -0
- data/processor/command/ps.rb +40 -0
- data/processor/command/quit.rb +62 -0
- data/processor/command/raise.rb +47 -0
- data/processor/command/reload.rb +28 -0
- data/processor/command/reload_subcmd/command.rb +34 -0
- data/processor/command/restart.rb +57 -0
- data/processor/command/save.rb +60 -0
- data/processor/command/set.rb +47 -0
- data/processor/command/set_subcmd/auto.rb +27 -0
- data/processor/command/set_subcmd/auto_subcmd/eval.rb +67 -0
- data/processor/command/set_subcmd/auto_subcmd/irb.rb +49 -0
- data/processor/command/set_subcmd/auto_subcmd/list.rb +51 -0
- data/processor/command/set_subcmd/basename.rb +39 -0
- data/processor/command/set_subcmd/debug.rb +27 -0
- data/processor/command/set_subcmd/debug_subcmd/dbgr.rb +49 -0
- data/processor/command/set_subcmd/debug_subcmd/except.rb +35 -0
- data/processor/command/set_subcmd/debug_subcmd/macro.rb +35 -0
- data/processor/command/set_subcmd/debug_subcmd/skip.rb +35 -0
- data/processor/command/set_subcmd/debug_subcmd/stack.rb +45 -0
- data/processor/command/set_subcmd/different.rb +67 -0
- data/processor/command/set_subcmd/events.rb +71 -0
- data/processor/command/set_subcmd/max.rb +35 -0
- data/processor/command/set_subcmd/max_subcmd/list.rb +50 -0
- data/processor/command/set_subcmd/max_subcmd/stack.rb +60 -0
- data/processor/command/set_subcmd/max_subcmd/string.rb +53 -0
- data/processor/command/set_subcmd/max_subcmd/width.rb +50 -0
- data/processor/command/set_subcmd/return.rb +66 -0
- data/processor/command/set_subcmd/sp.rb +62 -0
- data/processor/command/set_subcmd/substitute.rb +25 -0
- data/processor/command/set_subcmd/substitute_subcmd/eval.rb +98 -0
- data/processor/command/set_subcmd/substitute_subcmd/path.rb +55 -0
- data/processor/command/set_subcmd/substitute_subcmd/string.rb +72 -0
- data/processor/command/set_subcmd/timer.rb +68 -0
- data/processor/command/set_subcmd/trace.rb +43 -0
- data/processor/command/set_subcmd/trace_subcmd/buffer.rb +56 -0
- data/processor/command/set_subcmd/trace_subcmd/print.rb +54 -0
- data/processor/command/set_subcmd/trace_subcmd/var.rb +61 -0
- data/processor/command/show.rb +27 -0
- data/processor/command/show_subcmd/alias.rb +50 -0
- data/processor/command/show_subcmd/args.rb +50 -0
- data/processor/command/show_subcmd/auto.rb +27 -0
- data/processor/command/show_subcmd/auto_subcmd/eval.rb +38 -0
- data/processor/command/show_subcmd/auto_subcmd/irb.rb +34 -0
- data/processor/command/show_subcmd/auto_subcmd/list.rb +36 -0
- data/processor/command/show_subcmd/basename.rb +28 -0
- data/processor/command/show_subcmd/debug.rb +27 -0
- data/processor/command/show_subcmd/debug_subcmd/dbgr.rb +31 -0
- data/processor/command/show_subcmd/debug_subcmd/except.rb +33 -0
- data/processor/command/show_subcmd/debug_subcmd/macro.rb +32 -0
- data/processor/command/show_subcmd/debug_subcmd/skip.rb +33 -0
- data/processor/command/show_subcmd/debug_subcmd/stack.rb +32 -0
- data/processor/command/show_subcmd/different.rb +37 -0
- data/processor/command/show_subcmd/events.rb +40 -0
- data/processor/command/show_subcmd/macro.rb +45 -0
- data/processor/command/show_subcmd/max.rb +31 -0
- data/processor/command/show_subcmd/max_subcmd/list.rb +39 -0
- data/processor/command/show_subcmd/max_subcmd/stack.rb +35 -0
- data/processor/command/show_subcmd/max_subcmd/string.rb +41 -0
- data/processor/command/show_subcmd/max_subcmd/width.rb +36 -0
- data/processor/command/show_subcmd/trace.rb +29 -0
- data/processor/command/show_subcmd/trace_subcmd/buffer.rb +84 -0
- data/processor/command/show_subcmd/trace_subcmd/print.rb +38 -0
- data/processor/command/source.rb +74 -0
- data/processor/command/step.rb +139 -0
- data/processor/command/stepi.rb +63 -0
- data/processor/command/unalias.rb +44 -0
- data/processor/command/undisplay.rb +63 -0
- data/processor/command/up.rb +92 -0
- data/processor/default.rb +45 -0
- data/processor/display.rb +17 -0
- data/processor/eval.rb +88 -0
- data/processor/eventbuf.rb +131 -0
- data/processor/frame.rb +230 -0
- data/processor/help.rb +72 -0
- data/processor/hook.rb +128 -0
- data/processor/load_cmds.rb +102 -0
- data/processor/location.rb +126 -0
- data/processor/main.rb +364 -0
- data/processor/mock.rb +100 -0
- data/processor/msg.rb +26 -0
- data/processor/running.rb +170 -0
- data/processor/subcmd.rb +159 -0
- data/processor/validate.rb +395 -0
- data/test/example/fname with blank.rb +1 -0
- data/test/example/gcd-xx.rb +18 -0
- data/test/example/gcd.rb +19 -0
- data/test/example/gcd1.rb +24 -0
- data/test/example/null.rb +1 -0
- data/test/example/thread1.rb +3 -0
- data/test/functional/fn_helper.rb +119 -0
- data/test/functional/test-break.rb +87 -0
- data/test/functional/test-condition.rb +59 -0
- data/test/functional/test-debugger-call-bug.rb +31 -0
- data/test/functional/test-delete.rb +71 -0
- data/test/functional/test-finish.rb +44 -0
- data/test/functional/test-immediate-step-bug.rb +35 -0
- data/test/functional/test-next.rb +77 -0
- data/test/functional/test-raise.rb +73 -0
- data/test/functional/test-return.rb +100 -0
- data/test/functional/test-step.rb +274 -0
- data/test/functional/test-stepbug.rb +40 -0
- data/test/functional/test-trace-var.rb +40 -0
- data/test/functional/tmp/b1.rb +5 -0
- data/test/functional/tmp/s1.rb +9 -0
- data/test/functional/tmp/t2.rb +6 -0
- data/test/integration/file-diff.rb +88 -0
- data/test/integration/helper.rb +52 -0
- data/test/integration/test-fname-with-blank.rb +11 -0
- data/test/integration/test-quit.rb +11 -0
- data/test/integration/try-test-enable.rb +11 -0
- data/test/unit/cmd-helper.rb +44 -0
- data/test/unit/test-app-brkpt.rb +30 -0
- data/test/unit/test-app-brkptmgr.rb +56 -0
- data/test/unit/test-app-disassemble.rb +60 -0
- data/test/unit/test-app-file.rb +46 -0
- data/test/unit/test-app-frame.rb +49 -0
- data/test/unit/test-app-options.rb +60 -0
- data/test/unit/test-app-run.rb +19 -0
- data/test/unit/test-app-thread.rb +25 -0
- data/test/unit/test-app-util.rb +17 -0
- data/test/unit/test-base-subcmd.rb +59 -0
- data/test/unit/test-bin-trepan.rb +48 -0
- data/test/unit/test-cmd-alias.rb +50 -0
- data/test/unit/test-cmd-break.rb +80 -0
- data/test/unit/test-cmd-endisable.rb +59 -0
- data/test/unit/test-cmd-help.rb +100 -0
- data/test/unit/test-cmd-kill.rb +47 -0
- data/test/unit/test-cmd-quit.rb +26 -0
- data/test/unit/test-cmd-step.rb +45 -0
- data/test/unit/test-intf-user.rb +45 -0
- data/test/unit/test-io-input.rb +26 -0
- data/test/unit/test-proc-eval.rb +26 -0
- data/test/unit/test-proc-frame.rb +77 -0
- data/test/unit/test-proc-help.rb +15 -0
- data/test/unit/test-proc-hook.rb +29 -0
- data/test/unit/test-proc-load_cmds.rb +40 -0
- data/test/unit/test-proc-main.rb +99 -0
- data/test/unit/test-proc-validate.rb +90 -0
- data/test/unit/test-subcmd-help.rb +48 -0
- metadata +358 -0
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
require 'test/unit'
|
|
3
|
+
require 'trace'
|
|
4
|
+
require_relative 'fn_helper'
|
|
5
|
+
|
|
6
|
+
class TestStep < Test::Unit::TestCase
|
|
7
|
+
|
|
8
|
+
include FnTestHelper
|
|
9
|
+
include Trace
|
|
10
|
+
|
|
11
|
+
def test_step_same_level
|
|
12
|
+
|
|
13
|
+
# See that we can step with parameter which is the same as 'step 1'
|
|
14
|
+
cmds = ['step', 'continue']
|
|
15
|
+
d = strarray_setup(cmds)
|
|
16
|
+
d.core.step_events = TEST_STEP_EVENT_MASK
|
|
17
|
+
|
|
18
|
+
d.start
|
|
19
|
+
########### t1 ###############
|
|
20
|
+
x = 5
|
|
21
|
+
y = 6
|
|
22
|
+
##############################
|
|
23
|
+
d.stop
|
|
24
|
+
out = ['-- ', 'x = 5', '-- ', 'y = 6']
|
|
25
|
+
compare_output(out, d, cmds)
|
|
26
|
+
|
|
27
|
+
# See that we can step with a computed count value
|
|
28
|
+
cmds = ['step 5-3', 'continue']
|
|
29
|
+
d = strarray_setup(cmds)
|
|
30
|
+
d.start
|
|
31
|
+
########### t2 ###############
|
|
32
|
+
x = 5
|
|
33
|
+
y = 6
|
|
34
|
+
z = 7
|
|
35
|
+
##############################
|
|
36
|
+
d.stop # ({:remove => true})
|
|
37
|
+
out = ['-- ', 'x = 5', '-- ', 'z = 7']
|
|
38
|
+
compare_output(out, d, cmds)
|
|
39
|
+
|
|
40
|
+
# Test step>
|
|
41
|
+
cmds = ['step>', 'continue']
|
|
42
|
+
d = strarray_setup(cmds)
|
|
43
|
+
d.start
|
|
44
|
+
########### t3 ###############
|
|
45
|
+
x = 5
|
|
46
|
+
def foo()
|
|
47
|
+
end
|
|
48
|
+
y = 6
|
|
49
|
+
foo
|
|
50
|
+
##############################
|
|
51
|
+
d.stop # {:remove => true})
|
|
52
|
+
out = ['-- ', 'x = 5', 'METHOD TestStep#foo()', '-> ', 'def foo()']
|
|
53
|
+
compare_output(out, d, cmds)
|
|
54
|
+
|
|
55
|
+
# Test step!
|
|
56
|
+
cmds = ['step!', 'continue']
|
|
57
|
+
d = strarray_setup(cmds)
|
|
58
|
+
d.start()
|
|
59
|
+
########### t4 ###############
|
|
60
|
+
x = 5
|
|
61
|
+
begin
|
|
62
|
+
y = 2
|
|
63
|
+
z = 1/0
|
|
64
|
+
rescue
|
|
65
|
+
end
|
|
66
|
+
##############################
|
|
67
|
+
d.stop # ({:remove => true})
|
|
68
|
+
out = ['-- ', 'x = 5',
|
|
69
|
+
'#<ZeroDivisionError: divided by 0>',
|
|
70
|
+
'!! ', 'z = 1/0']
|
|
71
|
+
compare_output(out, d, cmds)
|
|
72
|
+
|
|
73
|
+
# Test "step" with sets of events. Part 1
|
|
74
|
+
cmds = ['set events call raise',
|
|
75
|
+
'step', 's!']
|
|
76
|
+
d = strarray_setup(cmds)
|
|
77
|
+
d.start()
|
|
78
|
+
########### t5 ###############
|
|
79
|
+
x = 5
|
|
80
|
+
def foo1
|
|
81
|
+
y = 2
|
|
82
|
+
raise Exception
|
|
83
|
+
rescue Exception
|
|
84
|
+
end
|
|
85
|
+
foo1()
|
|
86
|
+
z = 1
|
|
87
|
+
##############################
|
|
88
|
+
d.stop # ({:remove => true})
|
|
89
|
+
out = ['-- ',
|
|
90
|
+
'x = 5',
|
|
91
|
+
'Trace events we may stop on:',
|
|
92
|
+
"\tbrkpt, call, raise",
|
|
93
|
+
'METHOD TestStep#foo1()',
|
|
94
|
+
'-> ',
|
|
95
|
+
'def foo1',
|
|
96
|
+
'#<Exception: Exception>',
|
|
97
|
+
'!! ',
|
|
98
|
+
'raise Exception']
|
|
99
|
+
|
|
100
|
+
got = filter_line_cmd(d.intf[-1].output.output)
|
|
101
|
+
out.pop if got.size+1 == out.size
|
|
102
|
+
compare_output(out, d, cmds)
|
|
103
|
+
|
|
104
|
+
# Test "step" will sets of events. Part 2
|
|
105
|
+
cmds = ['step> 1+0',
|
|
106
|
+
'step! 1', 'continue']
|
|
107
|
+
d = strarray_setup(cmds)
|
|
108
|
+
d.start()
|
|
109
|
+
########### t6 ###############
|
|
110
|
+
x = 5
|
|
111
|
+
begin
|
|
112
|
+
def foo2()
|
|
113
|
+
y = 2
|
|
114
|
+
raise Exception
|
|
115
|
+
end
|
|
116
|
+
foo2()
|
|
117
|
+
rescue Exception
|
|
118
|
+
end
|
|
119
|
+
z = 1
|
|
120
|
+
##############################
|
|
121
|
+
d.stop({:remove => true})
|
|
122
|
+
out = ['-- ',
|
|
123
|
+
'x = 5',
|
|
124
|
+
'METHOD TestStep#foo2()',
|
|
125
|
+
'-> ',
|
|
126
|
+
'def foo2()',
|
|
127
|
+
'TestStep',
|
|
128
|
+
'!! ',
|
|
129
|
+
'raise Exception']
|
|
130
|
+
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def test_step_between_fn
|
|
134
|
+
|
|
135
|
+
# Step into and out of a function
|
|
136
|
+
def sqr(x)
|
|
137
|
+
y = x * x
|
|
138
|
+
end
|
|
139
|
+
cmds = %w(step) * 4 + %w(continue)
|
|
140
|
+
out = ['-- ',
|
|
141
|
+
'x = sqr(4)',
|
|
142
|
+
'METHOD TestStep#sqr(x)',
|
|
143
|
+
'-> ',
|
|
144
|
+
'def sqr(x)',
|
|
145
|
+
'-- ',
|
|
146
|
+
'y = x * x',
|
|
147
|
+
'<- ',
|
|
148
|
+
'R=> 16',
|
|
149
|
+
'end',
|
|
150
|
+
'-- ',
|
|
151
|
+
'y = 5']
|
|
152
|
+
d = strarray_setup(cmds)
|
|
153
|
+
d.start
|
|
154
|
+
########### t7 ###############
|
|
155
|
+
x = sqr(4)
|
|
156
|
+
y = 5
|
|
157
|
+
##############################
|
|
158
|
+
d.stop # ({:remove => true})
|
|
159
|
+
compare_output(out, d, cmds)
|
|
160
|
+
|
|
161
|
+
cmds = ['set events call return',
|
|
162
|
+
'step', 'step', 'continue']
|
|
163
|
+
out = ['-- ',
|
|
164
|
+
'x = sqr(4)',
|
|
165
|
+
'Trace events we may stop on:',
|
|
166
|
+
"\tbrkpt, call, return",
|
|
167
|
+
'METHOD TestStep#sqr(x)',
|
|
168
|
+
'-> ',
|
|
169
|
+
'def sqr(x)',
|
|
170
|
+
'<- ',
|
|
171
|
+
'R=> 16',
|
|
172
|
+
'end']
|
|
173
|
+
d = strarray_setup(cmds)
|
|
174
|
+
d.start
|
|
175
|
+
########### t8 ###############
|
|
176
|
+
x = sqr(4)
|
|
177
|
+
y = 5
|
|
178
|
+
##############################
|
|
179
|
+
d.stop # ({:remove => true})
|
|
180
|
+
compare_output(out, d, cmds)
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
def test_step_in_exception
|
|
184
|
+
def boom(x)
|
|
185
|
+
y = 0/x
|
|
186
|
+
end
|
|
187
|
+
def bad(x)
|
|
188
|
+
boom(x)
|
|
189
|
+
y = x * x
|
|
190
|
+
end
|
|
191
|
+
cmds = %w(step! continue)
|
|
192
|
+
d = strarray_setup(cmds)
|
|
193
|
+
begin
|
|
194
|
+
d.start()
|
|
195
|
+
x = bad(0)
|
|
196
|
+
assert_equal(false, true, 'should have raised an exception')
|
|
197
|
+
rescue ZeroDivisionError
|
|
198
|
+
assert true, 'Got the exception'
|
|
199
|
+
ensure
|
|
200
|
+
d.stop({:remove => true})
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
out = ['-- ',
|
|
204
|
+
'x = bad(0)', # line event
|
|
205
|
+
'#<ZeroDivisionError: divided by 0>',
|
|
206
|
+
'!! ', # exception event
|
|
207
|
+
'y = 0/x']
|
|
208
|
+
|
|
209
|
+
compare_output(out, d, cmds)
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
def test_step_event
|
|
213
|
+
|
|
214
|
+
def fact(x)
|
|
215
|
+
return 1 if x <= 1
|
|
216
|
+
x = x * fact(x-1)
|
|
217
|
+
return x
|
|
218
|
+
end
|
|
219
|
+
cmds = ['step<', '1 == x', 'continue']
|
|
220
|
+
d = strarray_setup(cmds)
|
|
221
|
+
d.start
|
|
222
|
+
########### t9 ###############
|
|
223
|
+
x = fact(4)
|
|
224
|
+
y = 5
|
|
225
|
+
##############################
|
|
226
|
+
d.stop # ({:remove => true})
|
|
227
|
+
out = ['-- ',
|
|
228
|
+
'x = fact(4)',
|
|
229
|
+
'<- ',
|
|
230
|
+
'R=> 1',
|
|
231
|
+
'return 1 if x <= 1',
|
|
232
|
+
'D=> true']
|
|
233
|
+
compare_output(out, d, cmds)
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
def test_step_into_fun
|
|
237
|
+
|
|
238
|
+
# Bug was that we were stopping at a VM instruction before the fn
|
|
239
|
+
# call proper ('bar' below), and not getting a line number for it.
|
|
240
|
+
# So a subsequent 'step' when 'set different' in effect was to stay
|
|
241
|
+
# at the same place at the function call.
|
|
242
|
+
cmds = ['set different', 'set events call, class, line, return',
|
|
243
|
+
'step', 'step', 'step', 'step', 'continue']
|
|
244
|
+
d = strarray_setup(cmds)
|
|
245
|
+
d.start
|
|
246
|
+
########### t10 ###############
|
|
247
|
+
def bar
|
|
248
|
+
return 1
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
def foo
|
|
252
|
+
bar
|
|
253
|
+
return 5
|
|
254
|
+
end
|
|
255
|
+
foo
|
|
256
|
+
##############################
|
|
257
|
+
d.stop # ({:remove => true})
|
|
258
|
+
out = ['-- ',
|
|
259
|
+
'def bar',
|
|
260
|
+
'different is on.',
|
|
261
|
+
'Trace events we may stop on:',
|
|
262
|
+
"\tbrkpt, call, class, line, return",
|
|
263
|
+
'-- ',
|
|
264
|
+
'def foo',
|
|
265
|
+
'-- ',
|
|
266
|
+
'foo',
|
|
267
|
+
'METHOD TestStep#foo()',
|
|
268
|
+
'-> ',
|
|
269
|
+
'def foo',
|
|
270
|
+
'-- ',
|
|
271
|
+
'bar']
|
|
272
|
+
compare_output(out, d, cmds)
|
|
273
|
+
end
|
|
274
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
require 'test/unit'
|
|
3
|
+
require 'trace'
|
|
4
|
+
require_relative 'fn_helper'
|
|
5
|
+
|
|
6
|
+
class TestStep < Test::Unit::TestCase
|
|
7
|
+
|
|
8
|
+
include FnTestHelper
|
|
9
|
+
include Trace
|
|
10
|
+
|
|
11
|
+
def test_step_through_leave
|
|
12
|
+
|
|
13
|
+
# See that we can step with parameter which is the same as 'step 1'
|
|
14
|
+
cmds = ['step', 'step', 'step', 'step', 'step', 'step', 'continue']
|
|
15
|
+
d = strarray_setup(cmds)
|
|
16
|
+
d.core.step_events = TEST_STEP_EVENT_MASK
|
|
17
|
+
|
|
18
|
+
d.start
|
|
19
|
+
########### t1 ###############
|
|
20
|
+
x = 'class Foo
|
|
21
|
+
def bar
|
|
22
|
+
3
|
|
23
|
+
end
|
|
24
|
+
end'
|
|
25
|
+
eval(x)
|
|
26
|
+
f = Foo.new
|
|
27
|
+
# f.bar
|
|
28
|
+
##############################
|
|
29
|
+
d.stop
|
|
30
|
+
out = ["-- x = 'class Foo",
|
|
31
|
+
".. eval(x)",
|
|
32
|
+
".. eval(x)",
|
|
33
|
+
":: eval(x)",
|
|
34
|
+
"-- eval(x)"]
|
|
35
|
+
# compare_output(out, d, cmds)
|
|
36
|
+
assert true
|
|
37
|
+
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
require 'test/unit'
|
|
3
|
+
require 'trace'
|
|
4
|
+
require_relative 'fn_helper'
|
|
5
|
+
|
|
6
|
+
# See that we hande "set trace var" properly
|
|
7
|
+
class TestTraceVar < Test::Unit::TestCase
|
|
8
|
+
|
|
9
|
+
include FnTestHelper
|
|
10
|
+
include Trace
|
|
11
|
+
|
|
12
|
+
def test_basic
|
|
13
|
+
|
|
14
|
+
cmds = ['set trace var $my_var', 'continue', 'continue', 'continue']
|
|
15
|
+
d = strarray_setup(cmds)
|
|
16
|
+
d.core.step_events = TEST_STEP_EVENT_MASK
|
|
17
|
+
|
|
18
|
+
d.start
|
|
19
|
+
########### t1 ###############
|
|
20
|
+
x = 1
|
|
21
|
+
$my_var = 5
|
|
22
|
+
y = 2
|
|
23
|
+
$my_var = 6
|
|
24
|
+
z = 3
|
|
25
|
+
##############################
|
|
26
|
+
d.stop
|
|
27
|
+
out = ['-- ',
|
|
28
|
+
'x = 1',
|
|
29
|
+
'Tracing variable $my_var.',
|
|
30
|
+
'$V ',
|
|
31
|
+
'$my_var = 5',
|
|
32
|
+
'Note: we are stopped *after* the above location.',
|
|
33
|
+
'$V ',
|
|
34
|
+
'$my_var = 6',
|
|
35
|
+
'Note: we are stopped *after* the above location.',
|
|
36
|
+
]
|
|
37
|
+
compare_output(out, d, cmds)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
end
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
require 'diff/lcs'
|
|
2
|
+
|
|
3
|
+
# Consider turning this into 'diff/lcs/file' or some such thing.
|
|
4
|
+
|
|
5
|
+
module DiffFile
|
|
6
|
+
def find_next(sdiff, i)
|
|
7
|
+
i += 1 while i < sdiff.size && sdiff[i].action == '='
|
|
8
|
+
return i
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def find_pos(sdiff, i)
|
|
12
|
+
i += 1 while i < sdiff.size && sdiff[i].action != '='
|
|
13
|
+
return sdiff[i].old_position, sdiff[i].new_position
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# Unix style context diff using files.
|
|
17
|
+
def diff_file(from_file, to_file, context=3)
|
|
18
|
+
seq1 = File.open(from_file).readlines
|
|
19
|
+
from_mtime = File.stat(from_file).mtime
|
|
20
|
+
seq2 = File.open(to_file).readlines
|
|
21
|
+
to_mtime = File.stat(to_file).mtime
|
|
22
|
+
sdiff = Diff::LCS.sdiff(seq1, seq2)
|
|
23
|
+
diff_lines(seq1, seq2, from_file, to_file, from_mtime,
|
|
24
|
+
to_mtime, context)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# Unix style context diff with file/line stat info passed in.
|
|
28
|
+
|
|
29
|
+
# There may be some imprecision in position stuff here and there's a
|
|
30
|
+
# bug when context ranges overlap.
|
|
31
|
+
|
|
32
|
+
# FIXME: consider turning into an enumerator.
|
|
33
|
+
def diff_lines(seq1, seq2, from_file, to_file,
|
|
34
|
+
from_mtime, to_mtime, context=3)
|
|
35
|
+
sdiff = Diff::LCS.sdiff(seq1, seq2)
|
|
36
|
+
# PP.pp sdiff
|
|
37
|
+
# puts '-' * 40
|
|
38
|
+
started = false
|
|
39
|
+
result = []
|
|
40
|
+
i = 0
|
|
41
|
+
n = -(context+1)
|
|
42
|
+
while true do
|
|
43
|
+
i = find_next(sdiff, i)
|
|
44
|
+
break if i >= sdiff.size
|
|
45
|
+
if n < i-context
|
|
46
|
+
if started
|
|
47
|
+
result << '***************'
|
|
48
|
+
else
|
|
49
|
+
result << "*** #{from_file}\t#{from_mtime}"
|
|
50
|
+
result << "--- #{to_file}\t#{to_mtime}"
|
|
51
|
+
started = true
|
|
52
|
+
end
|
|
53
|
+
result << '*** %d,%d ****' % find_pos(sdiff, i)
|
|
54
|
+
context.downto(1) do |j|
|
|
55
|
+
result << ' ' + sdiff[i-j].new_element.chomp
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
i += 1
|
|
59
|
+
while i < sdiff.size && (action = sdiff[i-1].action) != '='
|
|
60
|
+
element =
|
|
61
|
+
if action == '+'
|
|
62
|
+
sdiff[i-1].new_element
|
|
63
|
+
else
|
|
64
|
+
sdiff[i-1].old_element
|
|
65
|
+
end
|
|
66
|
+
result << action + element.chomp
|
|
67
|
+
i += 1
|
|
68
|
+
end
|
|
69
|
+
-1.upto(context-2) do |j|
|
|
70
|
+
n = i+j
|
|
71
|
+
break if sdiff[n].action != '='
|
|
72
|
+
result << ' ' + sdiff[n].new_element.chomp
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
return result
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
if __FILE__ == $0
|
|
80
|
+
include DiffFile
|
|
81
|
+
eg_dir = File.join(File.dirname(__FILE__), %w(.. example))
|
|
82
|
+
filename = {}
|
|
83
|
+
%w(gcd gcd1 gcd-xx).each do |short|
|
|
84
|
+
filename[short] = File.join(eg_dir, short + '.rb')
|
|
85
|
+
end
|
|
86
|
+
puts diff_file(filename['gcd'], filename['gcd1']).join("\n")
|
|
87
|
+
puts diff_file(filename['gcd'], filename['gcd-xx']).join("\n")
|
|
88
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
require 'diff/lcs'
|
|
2
|
+
require 'fileutils'
|
|
3
|
+
|
|
4
|
+
def run_debugger(testname, ruby_file, dbgr_opts='', args='', outfile=nil)
|
|
5
|
+
|
|
6
|
+
srcdir = File.dirname(__FILE__)
|
|
7
|
+
datadir = File.join(srcdir, %w(.. data))
|
|
8
|
+
progdir = File.join(srcdir, %w(.. example))
|
|
9
|
+
|
|
10
|
+
dbgr_dir = File.join(srcdir, %w(.. ..))
|
|
11
|
+
dbgr_short = File.join(%w(bin trepan))
|
|
12
|
+
dbgr_path = File.join(dbgr_dir, dbgr_short)
|
|
13
|
+
|
|
14
|
+
rightfile = File.join(datadir, "#{testname}.right")
|
|
15
|
+
|
|
16
|
+
cmdfile = File.join(datadir, "#{testname}.cmd" % testname)
|
|
17
|
+
outfile = File.join(srcdir, "#{testname}.out" % testname)
|
|
18
|
+
programfile = ruby_file ? File.join(progdir, ruby_file) : ''
|
|
19
|
+
|
|
20
|
+
FileUtils.rm(outfile) if File.exist?(outfile)
|
|
21
|
+
|
|
22
|
+
cmd = "%s --nx --command %s %s '%s' %s >%s" %
|
|
23
|
+
[dbgr_path, cmdfile, dbgr_opts, programfile, args, outfile]
|
|
24
|
+
|
|
25
|
+
system(cmd)
|
|
26
|
+
from_file = rightfile
|
|
27
|
+
# fromdate = time.ctime(os.stat(fromfile).st_mtime)
|
|
28
|
+
from_lines = File.open(from_file).readlines()
|
|
29
|
+
to_file = outfile
|
|
30
|
+
# todate = time.ctime(os.stat(tofile).st_mtime)
|
|
31
|
+
to_lines = File.open(to_file).readlines()
|
|
32
|
+
|
|
33
|
+
# Seems to be a bug in LCS in that it will return a diff even if two
|
|
34
|
+
# files are the same.
|
|
35
|
+
return true if from_lines == to_lines
|
|
36
|
+
|
|
37
|
+
sdiffs = Diff::LCS.sdiff(from_lines, to_lines)
|
|
38
|
+
|
|
39
|
+
if sdiffs.empty?
|
|
40
|
+
FileUtils.rm(outfile)
|
|
41
|
+
else
|
|
42
|
+
puts cmd
|
|
43
|
+
sdiffs.each do |diff|
|
|
44
|
+
p diff
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
return sdiffs.empty?
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
if __FILE__ == $0
|
|
51
|
+
run_debugger('testing', 'gcd1.rb')
|
|
52
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
require 'test/unit'
|
|
3
|
+
require_relative 'helper'
|
|
4
|
+
|
|
5
|
+
class TestFnameWithBlank < Test::Unit::TestCase
|
|
6
|
+
@@NAME = File.basename(__FILE__, '.rb')[5..-1]
|
|
7
|
+
|
|
8
|
+
def test_it
|
|
9
|
+
assert_equal(true, run_debugger(@@NAME, 'fname with blank.rb'))
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
require_relative '../../app/core'
|
|
2
|
+
require_relative '../../app/mock'
|
|
3
|
+
require_relative '../../processor/main' # Have to include before frame!
|
|
4
|
+
# FIXME
|
|
5
|
+
require_relative '../../processor/frame'
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
module UnitHelper
|
|
9
|
+
|
|
10
|
+
def common_setup
|
|
11
|
+
@dbg = Trepan::MockDebugger.new(:nx => true)
|
|
12
|
+
@core = Trepan::Core.new(@dbg)
|
|
13
|
+
@cmdproc = @core.processor = Trepan::CmdProcessor.new(@core)
|
|
14
|
+
@cmds = @cmdproc.commands
|
|
15
|
+
|
|
16
|
+
def @cmdproc.msg(message)
|
|
17
|
+
@msgs << message
|
|
18
|
+
end
|
|
19
|
+
def @cmdproc.errmsg(message)
|
|
20
|
+
@errmsgs << message
|
|
21
|
+
end
|
|
22
|
+
def @cmdproc.errmsgs
|
|
23
|
+
@errmsgs
|
|
24
|
+
end
|
|
25
|
+
def @cmdproc.msgs
|
|
26
|
+
@msgs
|
|
27
|
+
end
|
|
28
|
+
reset_cmdproc_vars
|
|
29
|
+
end
|
|
30
|
+
module_function :common_setup
|
|
31
|
+
|
|
32
|
+
def reset_cmdproc_vars
|
|
33
|
+
@cmdproc.instance_variable_set('@msgs', [])
|
|
34
|
+
@cmdproc.instance_variable_set('@errmsgs', [])
|
|
35
|
+
end
|
|
36
|
+
module_function :reset_cmdproc_vars
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
if __FILE__ == $0
|
|
40
|
+
include UnitHelper
|
|
41
|
+
common_setup
|
|
42
|
+
p @cmdproc.msgs
|
|
43
|
+
p @dbg
|
|
44
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
require 'test/unit'
|
|
3
|
+
require_relative '../../app/breakpoint'
|
|
4
|
+
require 'thread_frame'
|
|
5
|
+
|
|
6
|
+
class TestAppBrkpt < Test::Unit::TestCase
|
|
7
|
+
|
|
8
|
+
def test_basic
|
|
9
|
+
tf = RubyVM::ThreadFrame.current
|
|
10
|
+
iseq = tf.iseq
|
|
11
|
+
b1 = Trepanning::Breakpoint.new(iseq, 0)
|
|
12
|
+
assert_equal(false, b1.temp?)
|
|
13
|
+
assert_equal(0, b1.hits)
|
|
14
|
+
assert_equal('B', b1.icon_char)
|
|
15
|
+
assert_equal(true, b1.condition?(tf.binding))
|
|
16
|
+
assert_equal(1, b1.hits)
|
|
17
|
+
assert_equal(b1.source_container, tf.source_container)
|
|
18
|
+
b1.enabled = false
|
|
19
|
+
assert_equal('b', b1.icon_char)
|
|
20
|
+
assert_raises TypeError do
|
|
21
|
+
Trepanning::Breakpoint.new(iseq, iseq.iseq_size, :temp => true)
|
|
22
|
+
end
|
|
23
|
+
assert_raises TypeError do
|
|
24
|
+
Trepanning::Breakpoint.new(0, 5)
|
|
25
|
+
end
|
|
26
|
+
require_relative '../../lib/trepanning.rb'
|
|
27
|
+
b2 = Trepanning::Breakpoint.new(iseq, 0, :temp => true)
|
|
28
|
+
assert_equal('t', b2.icon_char)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
require 'test/unit'
|
|
3
|
+
require_relative '../../app/brkptmgr'
|
|
4
|
+
require_relative '../../app/breakpoint'
|
|
5
|
+
require 'thread_frame'
|
|
6
|
+
|
|
7
|
+
class TestLibAppBrkptMgr < Test::Unit::TestCase
|
|
8
|
+
|
|
9
|
+
def setup
|
|
10
|
+
@brkpts = BreakpointMgr.new
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def test_basic
|
|
14
|
+
tf = RubyVM::ThreadFrame.current
|
|
15
|
+
iseq = tf.iseq
|
|
16
|
+
offsets = iseq.offsetlines.keys
|
|
17
|
+
offset = offsets[0]
|
|
18
|
+
assert_equal(0, @brkpts.size)
|
|
19
|
+
b1 = @brkpts.add(iseq, offset)
|
|
20
|
+
assert_equal(b1, @brkpts.find(iseq, offset, tf.binding))
|
|
21
|
+
assert_equal(1, @brkpts.size)
|
|
22
|
+
assert_equal(b1, @brkpts.find(iseq, offset, tf.binding))
|
|
23
|
+
assert_equal(b1, @brkpts.delete(b1.id))
|
|
24
|
+
assert_equal(0, @brkpts.size)
|
|
25
|
+
|
|
26
|
+
# Try adding via << rather than .add
|
|
27
|
+
b2 = @brkpts << Trepanning::Breakpoint.new(iseq, offsets[1], :temp => true)
|
|
28
|
+
|
|
29
|
+
assert_equal(nil, @brkpts.find(iseq, offset, tf.binding))
|
|
30
|
+
@brkpts.reset
|
|
31
|
+
assert_equal(0, @brkpts.size)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def test_multiple_brkpt_per_offset
|
|
35
|
+
tf = RubyVM::ThreadFrame.current
|
|
36
|
+
iseq = tf.iseq
|
|
37
|
+
offsets = iseq.offsetlines.keys
|
|
38
|
+
offset = offsets[0]
|
|
39
|
+
b1 = @brkpts.add(iseq, offset)
|
|
40
|
+
b2 = @brkpts.add(iseq, offset)
|
|
41
|
+
assert_equal(2, @brkpts.size)
|
|
42
|
+
assert_equal(1, @brkpts.set.size,
|
|
43
|
+
'Two breakpoints but only one iseq/offset')
|
|
44
|
+
@brkpts.delete_by_brkpt(b1)
|
|
45
|
+
assert_equal(1, @brkpts.size,
|
|
46
|
+
'One breakpoint after 2nd breakpoint deleted')
|
|
47
|
+
assert_equal(1, @brkpts.set.size,
|
|
48
|
+
'Two breakpoints, but only one iseq/offset')
|
|
49
|
+
@brkpts.delete_by_brkpt(b2)
|
|
50
|
+
assert_equal(0, @brkpts.size,
|
|
51
|
+
'Both breakpoints deleted')
|
|
52
|
+
assert_equal(0, @brkpts.set.size,
|
|
53
|
+
'Second breakpoint delete should delete iseq/offset')
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
end
|