rbx-trepanning 0.0.2-universal-rubinius-1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +376 -0
- data/LICENSE +25 -0
- data/NEWS +2 -0
- data/README.textile +35 -0
- data/Rakefile +165 -0
- data/THANKS +14 -0
- data/app/breakpoint.rb +218 -0
- data/app/breakpoint.rbc +3564 -0
- data/app/brkptmgr.rb +138 -0
- data/app/brkptmgr.rbc +2827 -0
- data/app/default.rb +61 -0
- data/app/default.rbc +1011 -0
- data/app/display.rb +35 -0
- data/app/display.rbc +968 -0
- data/app/frame.rb +98 -0
- data/app/frame.rbc +1808 -0
- data/app/irb.rb +112 -0
- data/app/irb.rbc +2111 -0
- data/app/iseq.rb +95 -0
- data/app/iseq.rbc +1801 -0
- data/app/method.rb +173 -0
- data/app/method.rbc +2492 -0
- data/app/mock.rb +13 -0
- data/app/mock.rbc +398 -0
- data/app/options.rb +123 -0
- data/app/options.rbc +2183 -0
- data/app/run.rb +86 -0
- data/app/run.rbc +1244 -0
- data/app/util.rb +49 -0
- data/app/util.rbc +1144 -0
- data/app/validate.rb +30 -0
- data/app/validate.rbc +676 -0
- data/bin/trepan.compiled.rbc +1043 -0
- data/bin/trepanx +63 -0
- data/bin/trepanx.compiled.rbc +985 -0
- data/interface/base_intf.rb +95 -0
- data/interface/base_intf.rbc +1742 -0
- data/interface/script.rb +104 -0
- data/interface/script.rbc +1642 -0
- data/interface/user.rb +91 -0
- data/interface/user.rbc +1418 -0
- data/io/base_io.rb +94 -0
- data/io/base_io.rbc +1404 -0
- data/io/input.rb +112 -0
- data/io/input.rbc +1979 -0
- data/io/null_output.rb +42 -0
- data/io/null_output.rbc +730 -0
- data/io/string_array.rb +156 -0
- data/io/string_array.rbc +2466 -0
- data/lib/trepanning.rb +398 -0
- data/lib/trepanning.rbc +6661 -0
- data/processor/breakpoint.rb +161 -0
- data/processor/command/alias.rb +55 -0
- data/processor/command/backtrace.rb +46 -0
- data/processor/command/base/cmd.rb +124 -0
- data/processor/command/base/subcmd.rb +213 -0
- data/processor/command/base/submgr.rb +179 -0
- data/processor/command/base/subsubcmd.rb +103 -0
- data/processor/command/base/subsubmgr.rb +184 -0
- data/processor/command/break.rb +100 -0
- data/processor/command/continue.rb +82 -0
- data/processor/command/delete.rb +30 -0
- data/processor/command/directory.rb +43 -0
- data/processor/command/disassemble.rb +103 -0
- data/processor/command/down.rb +54 -0
- data/processor/command/eval.rb +31 -0
- data/processor/command/exit.rb +58 -0
- data/processor/command/finish.rb +78 -0
- data/processor/command/frame.rb +89 -0
- data/processor/command/help.rb +146 -0
- data/processor/command/info.rb +28 -0
- data/processor/command/info_subcmd/breakpoints.rb +75 -0
- data/processor/command/info_subcmd/file.rb +153 -0
- data/processor/command/info_subcmd/method.rb +71 -0
- data/processor/command/info_subcmd/program.rb +59 -0
- data/processor/command/info_subcmd/variables.rb +40 -0
- data/processor/command/irb.rb +96 -0
- data/processor/command/kill.rb +70 -0
- data/processor/command/list.rb +296 -0
- data/processor/command/next.rb +66 -0
- data/processor/command/nexti.rb +59 -0
- data/processor/command/pr.rb +38 -0
- data/processor/command/ps.rb +40 -0
- data/processor/command/restart.rb +60 -0
- data/processor/command/set.rb +47 -0
- data/processor/command/set_subcmd/auto.rb +28 -0
- data/processor/command/set_subcmd/auto_subcmd/dis.rb +33 -0
- data/processor/command/set_subcmd/auto_subcmd/eval.rb +54 -0
- data/processor/command/set_subcmd/auto_subcmd/irb.rb +34 -0
- data/processor/command/set_subcmd/auto_subcmd/list.rb +34 -0
- data/processor/command/set_subcmd/basename.rb +26 -0
- data/processor/command/set_subcmd/debug.rb +27 -0
- data/processor/command/set_subcmd/debug_subcmd/dbgr.rb +36 -0
- data/processor/command/set_subcmd/debug_subcmd/skip.rb +23 -0
- data/processor/command/set_subcmd/debug_subcmd/step.rb +23 -0
- data/processor/command/set_subcmd/different.rb +60 -0
- data/processor/command/set_subcmd/hidelevel.rb +63 -0
- data/processor/command/set_subcmd/kernelstep.rb +61 -0
- data/processor/command/set_subcmd/max.rb +29 -0
- data/processor/command/set_subcmd/max_subcmd/list.rb +49 -0
- data/processor/command/set_subcmd/max_subcmd/stack.rb +50 -0
- data/processor/command/set_subcmd/max_subcmd/string.rb +54 -0
- data/processor/command/set_subcmd/max_subcmd/width.rb +49 -0
- data/processor/command/set_subcmd/substitute.rb +25 -0
- data/processor/command/set_subcmd/substitute_subcmd/path.rb +56 -0
- data/processor/command/set_subcmd/trace.rb +37 -0
- data/processor/command/set_subcmd/trace_subcmd/print.rb +57 -0
- data/processor/command/show.rb +27 -0
- data/processor/command/show_subcmd/alias.rb +43 -0
- data/processor/command/show_subcmd/args.rb +26 -0
- data/processor/command/show_subcmd/auto.rb +28 -0
- data/processor/command/show_subcmd/auto_subcmd/dis.rb +37 -0
- data/processor/command/show_subcmd/auto_subcmd/eval.rb +28 -0
- data/processor/command/show_subcmd/auto_subcmd/irb.rb +23 -0
- data/processor/command/show_subcmd/auto_subcmd/list.rb +22 -0
- data/processor/command/show_subcmd/basename.rb +22 -0
- data/processor/command/show_subcmd/debug.rb +27 -0
- data/processor/command/show_subcmd/debug_subcmd/dbgr.rb +21 -0
- data/processor/command/show_subcmd/debug_subcmd/skip.rb +22 -0
- data/processor/command/show_subcmd/debug_subcmd/step.rb +22 -0
- data/processor/command/show_subcmd/different.rb +27 -0
- data/processor/command/show_subcmd/hidelevel.rb +42 -0
- data/processor/command/show_subcmd/kernelstep.rb +37 -0
- data/processor/command/show_subcmd/max.rb +30 -0
- data/processor/command/show_subcmd/max_subcmd/list.rb +38 -0
- data/processor/command/show_subcmd/max_subcmd/stack.rb +36 -0
- data/processor/command/show_subcmd/max_subcmd/string.rb +42 -0
- data/processor/command/show_subcmd/max_subcmd/width.rb +37 -0
- data/processor/command/show_subcmd/trace.rb +29 -0
- data/processor/command/show_subcmd/trace_subcmd/print.rb +38 -0
- data/processor/command/source.rb +83 -0
- data/processor/command/step.rb +49 -0
- data/processor/command/tbreak.rb +19 -0
- data/processor/command/unalias.rb +44 -0
- data/processor/command/up.rb +87 -0
- data/processor/default.rb +56 -0
- data/processor/disassemble.rb +32 -0
- data/processor/eval.rb +96 -0
- data/processor/frame.rb +211 -0
- data/processor/help.rb +72 -0
- data/processor/hook.rb +133 -0
- data/processor/load_cmds.rb +101 -0
- data/processor/location.rb +128 -0
- data/processor/main.rb +394 -0
- data/processor/mock.rb +137 -0
- data/processor/msg.rb +28 -0
- data/processor/running.rb +230 -0
- data/processor/stepping.rb +115 -0
- data/processor/subcmd.rb +160 -0
- data/processor/validate.rb +355 -0
- data/test/data/enable.right +36 -0
- data/test/data/fname-with-blank.cmd +6 -0
- data/test/data/fname-with-blank.right +1 -0
- data/test/data/quit-Xdebug.right +3 -0
- data/test/data/quit.cmd +5 -0
- data/test/data/quit.right +0 -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 +112 -0
- data/test/functional/test-break-name.rb +52 -0
- data/test/functional/test-break.rb +51 -0
- data/test/functional/test-finish.rb +70 -0
- data/test/functional/test-fn_helper.rb +43 -0
- data/test/functional/test-list.rb +55 -0
- data/test/functional/test-next-bug.rb +49 -0
- data/test/functional/test-next.rb +101 -0
- data/test/functional/test-step.rb +272 -0
- data/test/functional/test-step2.rb +35 -0
- data/test/functional/test-tbreak.rb +41 -0
- data/test/integration/file-diff.rb +89 -0
- data/test/integration/helper.rb +78 -0
- data/test/integration/test-fname-with-blank.rb +12 -0
- data/test/integration/test-quit.rb +25 -0
- data/test/unit/cmd-helper.rb +46 -0
- data/test/unit/test-app-brkpt.rb +30 -0
- data/test/unit/test-app-brkptmgr.rb +51 -0
- data/test/unit/test-app-iseq.rb +49 -0
- data/test/unit/test-app-method.rb +54 -0
- data/test/unit/test-app-options.rb +61 -0
- data/test/unit/test-app-run.rb +16 -0
- data/test/unit/test-app-util.rb +28 -0
- data/test/unit/test-app-validate.rb +18 -0
- data/test/unit/test-base-subcmd.rb +61 -0
- data/test/unit/test-bin-trepanx.rb +48 -0
- data/test/unit/test-cmd-alias.rb +49 -0
- data/test/unit/test-cmd-break.rb +23 -0
- data/test/unit/test-cmd-exit.rb +27 -0
- data/test/unit/test-cmd-help.rb +101 -0
- data/test/unit/test-cmd-kill.rb +48 -0
- data/test/unit/test-intf-user.rb +46 -0
- data/test/unit/test-io-input.rb +27 -0
- data/test/unit/test-proc-eval.rb +37 -0
- data/test/unit/test-proc-frame.rb +79 -0
- data/test/unit/test-proc-help.rb +16 -0
- data/test/unit/test-proc-hook.rb +30 -0
- data/test/unit/test-proc-load_cmds.rb +41 -0
- data/test/unit/test-proc-location.rb +48 -0
- data/test/unit/test-proc-main.rb +96 -0
- data/test/unit/test-proc-validate.rb +91 -0
- data/test/unit/test-subcmd-help.rb +51 -0
- metadata +337 -0
@@ -0,0 +1,41 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'test/unit'
|
3
|
+
require 'rubygems'; require 'require_relative'
|
4
|
+
require_relative 'fn_helper'
|
5
|
+
|
6
|
+
class TestTBreak < Test::Unit::TestCase
|
7
|
+
|
8
|
+
include FnTestHelper
|
9
|
+
|
10
|
+
def foo
|
11
|
+
a = 3
|
12
|
+
b = 4
|
13
|
+
c = 5
|
14
|
+
d = 6
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_basic
|
18
|
+
# Check that temporary breaks are, well, temporary.
|
19
|
+
# The last "continue" below isn't used. It to make sure we finish
|
20
|
+
# the test even when the breakpoint isn't temporary.
|
21
|
+
cmds = ['tbreak TestTBreak#foo', 'continue', 'continue', 'continue']
|
22
|
+
d = strarray_setup(cmds)
|
23
|
+
d.start
|
24
|
+
##############################
|
25
|
+
2.times do
|
26
|
+
foo
|
27
|
+
end
|
28
|
+
##############################
|
29
|
+
d.stop # ({:remove => true})
|
30
|
+
out = ['-- ',
|
31
|
+
'2.times do ',
|
32
|
+
'Set temporary breakpoint 1: foo.rb:55 (@3)',
|
33
|
+
"x1 ",
|
34
|
+
'a = 3'
|
35
|
+
]
|
36
|
+
compare_output(out, d, cmds)
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'diff/lcs'
|
3
|
+
|
4
|
+
# Consider turning this into 'diff/lcs/file' or some such thing.
|
5
|
+
|
6
|
+
module DiffFile
|
7
|
+
def find_next(sdiff, i)
|
8
|
+
i += 1 while i < sdiff.size && sdiff[i].action == '='
|
9
|
+
return i
|
10
|
+
end
|
11
|
+
|
12
|
+
def find_pos(sdiff, i)
|
13
|
+
i += 1 while i < sdiff.size && sdiff[i].action != '='
|
14
|
+
return sdiff[i].old_position, sdiff[i].new_position
|
15
|
+
end
|
16
|
+
|
17
|
+
# Unix style context diff using files.
|
18
|
+
def diff_file(from_file, to_file, context=3)
|
19
|
+
seq1 = File.open(from_file).readlines
|
20
|
+
from_mtime = File.stat(from_file).mtime
|
21
|
+
seq2 = File.open(to_file).readlines
|
22
|
+
to_mtime = File.stat(to_file).mtime
|
23
|
+
sdiff = Diff::LCS.sdiff(seq1, seq2)
|
24
|
+
diff_lines(seq1, seq2, from_file, to_file, from_mtime,
|
25
|
+
to_mtime, context)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Unix style context diff with file/line stat info passed in.
|
29
|
+
|
30
|
+
# There may be some imprecision in position stuff here and there's a
|
31
|
+
# bug when context ranges overlap.
|
32
|
+
|
33
|
+
# FIXME: consider turning into an enumerator.
|
34
|
+
def diff_lines(seq1, seq2, from_file, to_file,
|
35
|
+
from_mtime, to_mtime, context=3)
|
36
|
+
sdiff = Diff::LCS.sdiff(seq1, seq2)
|
37
|
+
# PP.pp sdiff
|
38
|
+
# puts '-' * 40
|
39
|
+
started = false
|
40
|
+
result = []
|
41
|
+
i = 0
|
42
|
+
n = -(context+1)
|
43
|
+
while true do
|
44
|
+
i = find_next(sdiff, i)
|
45
|
+
break if i >= sdiff.size
|
46
|
+
if n < i-context
|
47
|
+
if started
|
48
|
+
result << '***************'
|
49
|
+
else
|
50
|
+
result << "*** #{from_file}\t#{from_mtime}"
|
51
|
+
result << "--- #{to_file}\t#{to_mtime}"
|
52
|
+
started = true
|
53
|
+
end
|
54
|
+
result << '*** %d,%d ****' % find_pos(sdiff, i)
|
55
|
+
context.downto(1) do |j|
|
56
|
+
result << ' ' + sdiff[i-j].new_element.chomp
|
57
|
+
end
|
58
|
+
end
|
59
|
+
i += 1
|
60
|
+
while i < sdiff.size && (action = sdiff[i-1].action) != '='
|
61
|
+
element =
|
62
|
+
if action == '+'
|
63
|
+
sdiff[i-1].new_element
|
64
|
+
else
|
65
|
+
sdiff[i-1].old_element
|
66
|
+
end
|
67
|
+
result << action + element.chomp
|
68
|
+
i += 1
|
69
|
+
end
|
70
|
+
-1.upto(context-2) do |j|
|
71
|
+
n = i+j
|
72
|
+
break if sdiff[n].action != '='
|
73
|
+
result << ' ' + sdiff[n].new_element.chomp
|
74
|
+
end
|
75
|
+
end
|
76
|
+
return result
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
if __FILE__ == $0
|
81
|
+
include DiffFile
|
82
|
+
eg_dir = File.join(File.dirname(__FILE__), %w(.. example))
|
83
|
+
filename = {}
|
84
|
+
%w(gcd gcd1 gcd-xx).each do |short|
|
85
|
+
filename[short] = File.join(eg_dir, short + '.rb')
|
86
|
+
end
|
87
|
+
puts diff_file(filename['gcd'], filename['gcd1']).join("\n")
|
88
|
+
puts diff_file(filename['gcd'], filename['gcd-xx']).join("\n")
|
89
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'diff/lcs'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'rubygems'; require 'require_relative'
|
4
|
+
require_relative '../../app/run' # for ruby_path
|
5
|
+
|
6
|
+
DEFAULT_DEBUGGER_OPTS = {
|
7
|
+
:args => '',
|
8
|
+
:dbgr => '',
|
9
|
+
:outfile => nil,
|
10
|
+
:short_cmd => nil,
|
11
|
+
:short_right => nil,
|
12
|
+
:do_diff => true,
|
13
|
+
}
|
14
|
+
|
15
|
+
def run_debugger(testname, ruby_file, opts={})
|
16
|
+
opts = DEFAULT_DEBUGGER_OPTS.merge(opts)
|
17
|
+
srcdir = File.dirname(__FILE__)
|
18
|
+
datadir = File.join(srcdir, %w(.. data))
|
19
|
+
progdir = File.join(srcdir, %w(.. example))
|
20
|
+
|
21
|
+
dbgr_dir = File.join(srcdir, %w(.. ..))
|
22
|
+
dbgr_short = File.join(%w(bin trepanx))
|
23
|
+
dbgr_path = File.join(dbgr_dir, dbgr_short)
|
24
|
+
|
25
|
+
short_right = "#{opts[:short_right] || testname}.right"
|
26
|
+
rightfile = File.join(datadir, short_right)
|
27
|
+
|
28
|
+
short_cmd = "#{opts[:short_cmd] || testname}.cmd"
|
29
|
+
cmdfile = File.join(datadir, short_cmd)
|
30
|
+
outfile = opts[:outfile] ||
|
31
|
+
File.join(srcdir, "#{testname}.out")
|
32
|
+
programfile = ruby_file ? File.join(progdir, ruby_file) : ''
|
33
|
+
|
34
|
+
FileUtils.rm(outfile) if File.exist?(outfile)
|
35
|
+
|
36
|
+
cmd =
|
37
|
+
if opts[:xdebug]
|
38
|
+
"%s -Xdebug '%s' %s >%s <%s" %
|
39
|
+
[Trepanning::ruby_path, programfile, opts[:args], outfile, cmdfile]
|
40
|
+
else
|
41
|
+
"%s %s --nx --command %s %s '%s' %s >%s" %
|
42
|
+
[Trepanning::ruby_path, dbgr_path, cmdfile, opts[:dbgr],
|
43
|
+
programfile, opts[:args], outfile]
|
44
|
+
end
|
45
|
+
|
46
|
+
system(cmd)
|
47
|
+
return false unless 0 == $?.exitstatus
|
48
|
+
if opts[:do_diff]
|
49
|
+
from_file = rightfile
|
50
|
+
# fromdate = time.ctime(os.stat(fromfile).st_mtime)
|
51
|
+
from_lines = File.open(from_file).readlines()
|
52
|
+
to_file = outfile
|
53
|
+
# todate = time.ctime(os.stat(tofile).st_mtime)
|
54
|
+
to_lines = File.open(to_file).readlines()
|
55
|
+
|
56
|
+
# Seems to be a bug in LCS in that it will return a diff even if two
|
57
|
+
# files are the same.
|
58
|
+
return true if from_lines == to_lines
|
59
|
+
|
60
|
+
sdiffs = Diff::LCS.sdiff(from_lines, to_lines)
|
61
|
+
|
62
|
+
if sdiffs.empty?
|
63
|
+
FileUtils.rm(outfile)
|
64
|
+
else
|
65
|
+
puts cmd
|
66
|
+
sdiffs.each do |diff|
|
67
|
+
p diff
|
68
|
+
end
|
69
|
+
end
|
70
|
+
return sdiffs.empty?
|
71
|
+
else
|
72
|
+
return true # We already tested for false above
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
if __FILE__ == $0
|
77
|
+
run_debugger('testing', 'gcd1.rb')
|
78
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'test/unit'
|
3
|
+
require 'rubygems'; require 'require_relative'
|
4
|
+
require_relative 'helper'
|
5
|
+
|
6
|
+
class TestFnameWithBlank < Test::Unit::TestCase
|
7
|
+
@@NAME = File.basename(__FILE__, '.rb')[5..-1]
|
8
|
+
|
9
|
+
def test_it
|
10
|
+
assert_equal(true, run_debugger(@@NAME, 'fname with blank.rb'))
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'test/unit'
|
3
|
+
require 'rubygems'; require 'require_relative'
|
4
|
+
require_relative 'helper'
|
5
|
+
|
6
|
+
class TestQuit < Test::Unit::TestCase
|
7
|
+
@@NAME = File.basename(__FILE__, '.rb')[5..-1]
|
8
|
+
|
9
|
+
def test_trepanx_call
|
10
|
+
assert_equal(true, run_debugger(@@NAME, 'null.rb'))
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_xcode_call
|
14
|
+
no_error = run_debugger('quit-Xdebug', 'null.rb',
|
15
|
+
{:xdebug => true,
|
16
|
+
:short_cmd => @@NAME,
|
17
|
+
:do_diff => false
|
18
|
+
})
|
19
|
+
assert_equal(true, no_error)
|
20
|
+
if no_error
|
21
|
+
outfile = File.join(File.dirname(__FILE__), 'quit-Xdebug.out')
|
22
|
+
FileUtils.rm(outfile)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'rubygems'; require 'require_relative'
|
2
|
+
# require_relative '../../app/core'
|
3
|
+
require_relative '../../processor/mock'
|
4
|
+
require_relative '../../processor/main' # Have to include before frame!
|
5
|
+
# FIXME
|
6
|
+
require_relative '../../processor/frame'
|
7
|
+
|
8
|
+
|
9
|
+
module UnitHelper
|
10
|
+
|
11
|
+
def common_setup
|
12
|
+
@dbg = MockDebugger::MockDebugger.new(:nx => true)
|
13
|
+
@cmdproc = Trepan::CmdProcessor.new(@dbg)
|
14
|
+
@cmdproc.frame_initialize
|
15
|
+
@cmdproc.dbgr = @dbg
|
16
|
+
@cmds = @cmdproc.commands
|
17
|
+
|
18
|
+
def @cmdproc.msg(message)
|
19
|
+
@msgs << message
|
20
|
+
end
|
21
|
+
def @cmdproc.errmsg(message)
|
22
|
+
@errmsgs << message
|
23
|
+
end
|
24
|
+
def @cmdproc.errmsgs
|
25
|
+
@errmsgs
|
26
|
+
end
|
27
|
+
def @cmdproc.msgs
|
28
|
+
@msgs
|
29
|
+
end
|
30
|
+
reset_cmdproc_vars
|
31
|
+
end
|
32
|
+
module_function :common_setup
|
33
|
+
|
34
|
+
def reset_cmdproc_vars
|
35
|
+
@cmdproc.instance_variable_set('@msgs', [])
|
36
|
+
@cmdproc.instance_variable_set('@errmsgs', [])
|
37
|
+
end
|
38
|
+
module_function :reset_cmdproc_vars
|
39
|
+
end
|
40
|
+
|
41
|
+
if __FILE__ == $0
|
42
|
+
include UnitHelper
|
43
|
+
common_setup
|
44
|
+
p @cmdproc.msgs
|
45
|
+
p @dbg
|
46
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'test/unit'
|
3
|
+
require 'rubygems'; require 'require_relative'
|
4
|
+
require_relative '../../app/breakpoint'
|
5
|
+
|
6
|
+
class TestAppBrkpt < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def test_basic
|
9
|
+
method = Rubinius::CompiledMethod.of_sender
|
10
|
+
b1 = Trepanning::Breakpoint.new('<start>', method, 1, 2, 0)
|
11
|
+
assert_equal(false, b1.temp?)
|
12
|
+
assert_equal(0, b1.hits)
|
13
|
+
assert_equal('B', b1.icon_char)
|
14
|
+
# assert_equal(true, b1.condition?)
|
15
|
+
# assert_equal(1, b1.hits)
|
16
|
+
# assert_equal(b1.source_container, tf.source_container)
|
17
|
+
b1.enabled = false
|
18
|
+
assert_equal('b', b1.icon_char)
|
19
|
+
# assert_raises TypeError do
|
20
|
+
# Trepanning::Breakpoint.new(iseq, iseq.iseq_size, :temp => true)
|
21
|
+
# end
|
22
|
+
# assert_raises TypeError do
|
23
|
+
# Trepanning::Breakpoint.new(0, 5)
|
24
|
+
# end
|
25
|
+
# require_relative '../../lib/trepanning.rb'
|
26
|
+
b2 = Trepanning::Breakpoint.new('temp brkpt', method, 2, 3, 0,
|
27
|
+
:temp => true)
|
28
|
+
assert_equal('t', b2.icon_char)
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'test/unit'
|
3
|
+
require 'rubygems'; require 'require_relative'
|
4
|
+
require_relative '../../app/brkptmgr'
|
5
|
+
require_relative '../../app/breakpoint'
|
6
|
+
|
7
|
+
class TestLibAppBrkptMgr < Test::Unit::TestCase
|
8
|
+
|
9
|
+
def setup
|
10
|
+
@meth = Rubinius::CompiledMethod.of_sender
|
11
|
+
@brkpts = BreakpointMgr.new
|
12
|
+
@offset = 0
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_basic
|
16
|
+
assert_equal(0, @brkpts.size)
|
17
|
+
b1 = @brkpts.add("<start>", @meth, @offset, 0, 1)
|
18
|
+
assert_equal(b1, @brkpts.find(@meth, @offset))
|
19
|
+
assert_equal(1, @brkpts.size)
|
20
|
+
# require 'trepanning'
|
21
|
+
# dbgr = Trepan.new(:set_restart => true); dbgr.start
|
22
|
+
assert_equal(b1, @brkpts.delete(b1.id))
|
23
|
+
assert_equal(0, @brkpts.size)
|
24
|
+
|
25
|
+
# Try adding via << rather than .add
|
26
|
+
b2 = @brkpts << Trepanning::Breakpoint.new(@meth, 5, nil, :temp => true)
|
27
|
+
|
28
|
+
assert_equal(nil, @brkpts.find(@meth, 6))
|
29
|
+
@brkpts.reset
|
30
|
+
assert_equal(0, @brkpts.size)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_multiple_brkpt_per_offset
|
34
|
+
b1 = @brkpts.add("b1", @meth, @offset, 5, 2)
|
35
|
+
b2 = @brkpts.add("b2", @meth, @offset, 5, 2)
|
36
|
+
assert_equal(2, @brkpts.size)
|
37
|
+
assert_equal(1, @brkpts.set.size,
|
38
|
+
'Two breakpoints but only one @meth/offset')
|
39
|
+
@brkpts.delete_by_brkpt(b1)
|
40
|
+
assert_equal(1, @brkpts.size,
|
41
|
+
'One breakpoint after 2nd breakpoint deleted')
|
42
|
+
assert_equal(1, @brkpts.set.size,
|
43
|
+
'Two breakpoints, but only one @meth/offset')
|
44
|
+
@brkpts.delete_by_brkpt(b2)
|
45
|
+
assert_equal(0, @brkpts.size,
|
46
|
+
'Both breakpoints deleted')
|
47
|
+
assert_equal(0, @brkpts.set.size,
|
48
|
+
'Second breakpoint delete should delete @meth/offset')
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'test/unit'
|
3
|
+
require 'rubygems'; require 'require_relative'
|
4
|
+
require_relative '../../app/iseq'
|
5
|
+
|
6
|
+
class TestAppISeq < Test::Unit::TestCase
|
7
|
+
include Trepanning::ISeq
|
8
|
+
|
9
|
+
def test_disasm_prefix
|
10
|
+
meth = Rubinius::VM.backtrace(0, true)[0].method
|
11
|
+
assert_equal(' -->', disasm_prefix(0, 0, meth))
|
12
|
+
assert_equal(' ', disasm_prefix(0, 1, meth))
|
13
|
+
meth.set_breakpoint(0, nil)
|
14
|
+
assert_equal('B-->', disasm_prefix(0, 0, meth))
|
15
|
+
assert_equal('B ', disasm_prefix(0, 1, meth))
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_basic
|
19
|
+
|
20
|
+
def single_return
|
21
|
+
meth = Rubinius::VM.backtrace(0, true)[0].method
|
22
|
+
first, last = [meth.lines.first, meth.lines.last]
|
23
|
+
[last, yield_or_return_between(meth, first, last)]
|
24
|
+
end
|
25
|
+
|
26
|
+
def branching(bool)
|
27
|
+
meth = Rubinius::VM.backtrace(0, true)[0].method
|
28
|
+
first, last = [meth.lines.first, meth.lines.last]
|
29
|
+
if bool
|
30
|
+
x = 5
|
31
|
+
else
|
32
|
+
x = 6
|
33
|
+
end
|
34
|
+
goto_between(meth, first, last)
|
35
|
+
end
|
36
|
+
|
37
|
+
def no_branching
|
38
|
+
meth = Rubinius::VM.backtrace(0, true)[0].method
|
39
|
+
first, last = [meth.lines.first, meth.lines.last]
|
40
|
+
goto_between(meth, first, last)
|
41
|
+
end
|
42
|
+
|
43
|
+
last, return_ips = single_return
|
44
|
+
assert_equal([last-1], return_ips)
|
45
|
+
assert_equal(-2, no_branching)
|
46
|
+
assert_equal(2, branching(true).size)
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'test/unit'
|
3
|
+
require 'rubygems'; require 'require_relative'
|
4
|
+
require_relative '../../app/method'
|
5
|
+
|
6
|
+
class TestAppMethod < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def test_find_method_with_line
|
9
|
+
method = Rubinius::VM.backtrace(0, true)[0].method
|
10
|
+
line = __LINE__
|
11
|
+
##############################
|
12
|
+
def foo # line + 2
|
13
|
+
a = 5 # line + 3
|
14
|
+
b = 6 # line + 4
|
15
|
+
end # line + 5
|
16
|
+
1.times do # line + 6
|
17
|
+
1.times do # line + 7
|
18
|
+
x = 11 # line + 8
|
19
|
+
foo # line + 9
|
20
|
+
end # line + 10
|
21
|
+
c = 14 # line + 11
|
22
|
+
end # line + 12
|
23
|
+
################################################
|
24
|
+
meths = [] # line + 14
|
25
|
+
expect = Array.new(22, true) # line + 15
|
26
|
+
[5, 10, 12, 13, 18].each do |i|
|
27
|
+
expect[i] = false # line + 17
|
28
|
+
end # line + 18
|
29
|
+
(2..21).each do |l| # line + 19
|
30
|
+
meth = Trepanning::Method.find_method_with_line(method, line+l)
|
31
|
+
meths << meth # line + 21
|
32
|
+
assert_equal(expect[l], !!meth, "Mismatched line #{line+l}")
|
33
|
+
end
|
34
|
+
pairs = [[1,2], [0,4], [5,9], [6,7], [14,15], [20,21]]
|
35
|
+
pairs.each do |pair|
|
36
|
+
assert_equal(meths[pair[0]].inspect, meths[pair[1]].inspect,
|
37
|
+
"Method compare")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
def test_valid_ip?
|
41
|
+
meth = Rubinius::VM.backtrace(0, true)[0].method
|
42
|
+
ip = Trepanning::Method.locate_line( __LINE__, meth)[1]
|
43
|
+
assert_equal(true, ip.kind_of?(Fixnum),
|
44
|
+
"locate line of #{__LINE__} should have gotten an IP;" +
|
45
|
+
" got: #{ip.inspect}")
|
46
|
+
[[-1, false],
|
47
|
+
[ 0, true],
|
48
|
+
[ip, true],
|
49
|
+
[100000, false]].each do |ip, expect|
|
50
|
+
assert_equal expect, Trepanning::Method.valid_ip?(meth, ip)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'test/unit'
|
3
|
+
require 'stringio'
|
4
|
+
require 'tempfile'
|
5
|
+
require 'rubygems'; require 'require_relative'
|
6
|
+
require_relative '../../app/options'
|
7
|
+
|
8
|
+
# To have something to work with.
|
9
|
+
load 'tmpdir.rb'
|
10
|
+
|
11
|
+
class TestAppStringIO < Test::Unit::TestCase
|
12
|
+
include Trepanning
|
13
|
+
|
14
|
+
def setup
|
15
|
+
@options = DEFAULT_CMDLINE_SETTINGS.clone
|
16
|
+
@stderr = StringIO.new
|
17
|
+
@stdout = StringIO.new
|
18
|
+
@options = copy_default_options
|
19
|
+
@opts = setup_options(@options, @stdout, @stderr)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_cd
|
23
|
+
rest = @opts.parse(['--cd', Dir.tmpdir])
|
24
|
+
assert_equal(Dir.tmpdir, @options[:chdir])
|
25
|
+
assert_equal('', @stderr.string)
|
26
|
+
assert_equal('', @stdout.string)
|
27
|
+
|
28
|
+
setup
|
29
|
+
tf = Tempfile.new("delete-me")
|
30
|
+
orig_cd = @options[:chdir]
|
31
|
+
rest = @opts.parse(['--cd', tf.path])
|
32
|
+
assert_equal(orig_cd, @options[:chdir])
|
33
|
+
assert_not_equal('', @stderr.string)
|
34
|
+
assert_equal('', @stdout.string)
|
35
|
+
# FIXME: add test where directory isn't executable.
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_binary_opts
|
39
|
+
%w(nx).each do |name|
|
40
|
+
setup
|
41
|
+
o = ["--#{name}"]
|
42
|
+
rest = @opts.parse o
|
43
|
+
assert_equal('', @stderr.string)
|
44
|
+
assert_equal(true, @options[name.to_sym])
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_help_and_version_opts
|
49
|
+
%w(help version).each do |name|
|
50
|
+
setup
|
51
|
+
o = ["--#{name}"]
|
52
|
+
rest = @opts.parse o
|
53
|
+
assert_not_equal('', @stdout.string)
|
54
|
+
assert_equal('', @stderr.string)
|
55
|
+
assert_equal(true, @options[name.to_sym])
|
56
|
+
other_sym = 'help' == name ? :version : :help
|
57
|
+
assert_equal(false, @options.member?(other_sym))
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'test/unit'
|
3
|
+
require 'rubygems'; require 'require_relative'
|
4
|
+
require_relative '../../app/run'
|
5
|
+
|
6
|
+
class TestAppRun < Test::Unit::TestCase
|
7
|
+
include Trepanning
|
8
|
+
def test_basic
|
9
|
+
assert_equal(true, File.executable?(whence_file('irb')))
|
10
|
+
ng = whence_file('probably-does-not-exist')
|
11
|
+
assert_equal(true, File.executable?(ng) || ng == 'probably-does-not-exist')
|
12
|
+
rp = ruby_path
|
13
|
+
assert_equal(true, File.executable?(rp))
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'test/unit'
|
3
|
+
require 'rubygems'; require 'require_relative'
|
4
|
+
require_relative '../../app/util'
|
5
|
+
|
6
|
+
class TestAppUtil < Test::Unit::TestCase
|
7
|
+
include Trepan::Util
|
8
|
+
def test_safe_repr
|
9
|
+
string = 'The time has come to talk of many things.'
|
10
|
+
assert_equal(string, safe_repr(string, 50))
|
11
|
+
assert_equal('The time... things.', safe_repr(string, 17))
|
12
|
+
assert_equal('"The tim... things."', safe_repr(string.inspect, 17))
|
13
|
+
string = "'The time has come to talk of many things.'"
|
14
|
+
assert_equal("'The tim... things.'", safe_repr(string, 17))
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_find_main_script
|
18
|
+
locs = Rubinius::VM.backtrace(0, true)
|
19
|
+
i = find_main_script(locs)
|
20
|
+
assert_equal(true, !!i)
|
21
|
+
j = locs.size - i
|
22
|
+
if j > 0
|
23
|
+
locs = Rubinius::VM.backtrace(j, true)
|
24
|
+
assert_equal(false, !!find_main_script(locs))
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'test/unit'
|
3
|
+
require 'rubygems'; require 'require_relative'
|
4
|
+
require_relative '../../app/validate'
|
5
|
+
|
6
|
+
class TestAppValidate < Test::Unit::TestCase
|
7
|
+
include Trepan::Validate
|
8
|
+
def test_line_or_ip
|
9
|
+
[['o1', [1, nil]],
|
10
|
+
['O2', [2, nil]],
|
11
|
+
['oink', [nil, nil]],
|
12
|
+
['1' , [nil, 1]],
|
13
|
+
['12', [nil, 12]],
|
14
|
+
['-12', [nil, -12]]].each do |arg, expect|
|
15
|
+
assert_equal(line_or_ip(arg), expect)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'test/unit'
|
3
|
+
require 'rubygems'; require 'require_relative'
|
4
|
+
# require_relative '../../app/core'
|
5
|
+
require_relative '../../processor/main'
|
6
|
+
require_relative '../../processor/command/exit'
|
7
|
+
require_relative '../../processor/command/base/subcmd'
|
8
|
+
|
9
|
+
# Mock debugger stub. FIXME: put in comment helper routine.
|
10
|
+
class Trepan
|
11
|
+
end
|
12
|
+
|
13
|
+
$errors = []
|
14
|
+
class TestBaseCommandHelp < Test::Unit::TestCase
|
15
|
+
|
16
|
+
Trepan::Subcommand.const_set(:NAME, 'bogus')
|
17
|
+
def setup
|
18
|
+
$errors = []
|
19
|
+
$msgs = []
|
20
|
+
@dbgr = Trepan.new
|
21
|
+
# @core = Trepan::Core.new(@dbgr)
|
22
|
+
@cmdproc = Trepan::CmdProcessor.new(@dbgr)
|
23
|
+
@cmds = @cmdproc.instance_variable_get('@commands')
|
24
|
+
@exit_cmd = @cmds['exit']
|
25
|
+
@exit_subcmd = Trepan::Subcommand.new(@exit_cmd)
|
26
|
+
def @exit_subcmd.msg(message)
|
27
|
+
$msgs << message
|
28
|
+
end
|
29
|
+
def @exit_subcmd.errmsg(message)
|
30
|
+
$errors << message
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_base_subcommand
|
35
|
+
assert @exit_subcmd
|
36
|
+
assert_raises RuntimeError do
|
37
|
+
@exit_subcmd.run
|
38
|
+
end
|
39
|
+
assert_equal([], $errors)
|
40
|
+
@exit_subcmd.run_set_int('', 'testing 1 2 3')
|
41
|
+
assert_equal(1, $errors.size)
|
42
|
+
assert_equal(Fixnum, @exit_subcmd.settings[:maxwidth].class)
|
43
|
+
@cmds.each do |cmd_name, cmd_obj|
|
44
|
+
next unless cmd_obj.is_a?(Trepan::SubcommandMgr)
|
45
|
+
cmd_obj.subcmds.subcmds.each do |subcmd_name, subcmd_obj|
|
46
|
+
%w(HELP NAME PREFIX).each do |attr|
|
47
|
+
assert_equal(true, subcmd_obj.class.constants.member?(attr),
|
48
|
+
"Constant #{attr} should be defined in \"#{cmd_obj.name} #{subcmd_obj.class::NAME}\"")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_show_on_off
|
56
|
+
assert_equal('on', @exit_subcmd.show_onoff(true))
|
57
|
+
assert_equal('off', @exit_subcmd.show_onoff(false))
|
58
|
+
assert_equal('unset', @exit_subcmd.show_onoff(nil))
|
59
|
+
assert_equal('??', @exit_subcmd.show_onoff(5))
|
60
|
+
end
|
61
|
+
end
|