trepanning 0.0.9 → 0.1.0

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.
Files changed (108) hide show
  1. data/ChangeLog +237 -0
  2. data/NEWS +8 -0
  3. data/Rakefile +3 -2
  4. data/app/breakpoint.rb +8 -8
  5. data/app/brkptmgr.rb +86 -85
  6. data/app/client.rb +60 -0
  7. data/app/core.rb-consider +198 -0
  8. data/app/default.rb +17 -7
  9. data/app/disassemble.rb +12 -2
  10. data/app/options.rb +51 -20
  11. data/app/yarv.rb +183 -0
  12. data/bin/trepan +15 -9
  13. data/data/custom_require.rb +44 -0
  14. data/data/irbrc +41 -0
  15. data/data/prelude.rb +38 -0
  16. data/interface/base_intf.rb +10 -4
  17. data/interface/client.rb +79 -0
  18. data/interface/comcodes.rb +18 -0
  19. data/interface/server.rb +142 -0
  20. data/io/base_io.rb +57 -3
  21. data/io/tcpclient.rb +122 -0
  22. data/io/tcpfns.rb +31 -0
  23. data/io/tcpserver.rb +137 -0
  24. data/lib/trepanning.rb +57 -28
  25. data/processor/command/base/cmd.rb +10 -6
  26. data/processor/command/base/subcmd.rb +13 -1
  27. data/processor/command/directory.rb +15 -8
  28. data/processor/command/disassemble.rb +3 -2
  29. data/processor/command/help.rb +71 -19
  30. data/processor/command/info_subcmd/args.rb +2 -3
  31. data/processor/command/info_subcmd/breakpoints.rb +2 -3
  32. data/processor/command/info_subcmd/file.rb +2 -3
  33. data/processor/command/info_subcmd/frame.rb +2 -3
  34. data/processor/command/info_subcmd/iseq.rb +4 -5
  35. data/processor/command/info_subcmd/locals.rb +2 -3
  36. data/processor/command/info_subcmd/program.rb +2 -3
  37. data/processor/command/info_subcmd/registers.rb +2 -3
  38. data/processor/command/info_subcmd/return.rb +2 -3
  39. data/processor/command/info_subcmd/thread.rb +2 -3
  40. data/processor/command/list.rb +10 -6
  41. data/processor/command/reload.rb +1 -1
  42. data/processor/command/reload_subcmd/command.rb +29 -16
  43. data/processor/command/server.rb +70 -0
  44. data/processor/command/set_subcmd/auto.rb +2 -3
  45. data/processor/command/set_subcmd/basename.rb +2 -3
  46. data/processor/command/set_subcmd/debug.rb +2 -3
  47. data/processor/command/set_subcmd/different.rb +2 -3
  48. data/processor/command/set_subcmd/events.rb +2 -3
  49. data/processor/command/set_subcmd/hidelevel.rb +6 -7
  50. data/processor/command/set_subcmd/highlight.rb +32 -0
  51. data/processor/command/set_subcmd/max.rb +2 -3
  52. data/processor/command/set_subcmd/return.rb +2 -3
  53. data/processor/command/set_subcmd/sp.rb +2 -3
  54. data/processor/command/set_subcmd/substitute.rb +2 -3
  55. data/processor/command/set_subcmd/timer.rb +2 -3
  56. data/processor/command/set_subcmd/trace.rb +3 -4
  57. data/processor/command/show_subcmd/alias.rb +3 -3
  58. data/processor/command/show_subcmd/args.rb +2 -3
  59. data/processor/command/show_subcmd/auto.rb +1 -2
  60. data/processor/command/show_subcmd/basename.rb +2 -3
  61. data/processor/command/show_subcmd/debug.rb +1 -2
  62. data/processor/command/show_subcmd/different.rb +2 -1
  63. data/processor/command/show_subcmd/events.rb +2 -2
  64. data/processor/command/show_subcmd/hidelevel.rb +2 -3
  65. data/processor/command/show_subcmd/highlight.rb +23 -0
  66. data/processor/command/show_subcmd/macro.rb +2 -1
  67. data/processor/command/show_subcmd/max.rb +2 -3
  68. data/processor/command/show_subcmd/trace.rb +2 -3
  69. data/processor/command/source.rb +78 -28
  70. data/processor/default.rb +3 -2
  71. data/processor/load_cmds.rb +39 -19
  72. data/processor/location.rb +11 -7
  73. data/processor/main.rb +31 -15
  74. data/processor/mock.rb +22 -7
  75. data/processor/msg.rb +24 -8
  76. data/test/data/fname-with-blank.right +3 -0
  77. data/test/data/quit.right +2 -0
  78. data/test/functional/test-break-long.rb +87 -0
  79. data/test/functional/tmp/b3.rb +5 -0
  80. data/test/functional/tmp/immediate-bug1.rb +9 -0
  81. data/test/integration/helper.rb +14 -11
  82. data/test/integration/test-fname-with-blank.rb +5 -1
  83. data/test/integration/test-quit.rb +6 -2
  84. data/test/unit/cmd-helper.rb +9 -4
  85. data/test/unit/mock-helper.rb +9 -0
  86. data/test/unit/test-app-brkpt.rb +4 -4
  87. data/test/unit/test-app-brkptmgr.rb +2 -2
  88. data/test/unit/test-app-file.rb +0 -1
  89. data/test/unit/test-app-options.rb +26 -5
  90. data/test/unit/test-base-subcmd.rb +0 -1
  91. data/test/unit/test-cmd-alias.rb +0 -1
  92. data/test/unit/test-cmd-break.rb +0 -4
  93. data/test/unit/test-cmd-endisable.rb +1 -3
  94. data/test/unit/test-cmd-help.rb +0 -1
  95. data/test/unit/test-cmd-kill.rb +4 -5
  96. data/test/unit/test-cmd-quit.rb +4 -7
  97. data/test/unit/test-cmd-source.rb +33 -0
  98. data/test/unit/test-cmd-step.rb +0 -2
  99. data/test/unit/test-io-tcp.rb +32 -0
  100. data/test/unit/test-io-tcpclient.rb +53 -0
  101. data/test/unit/test-io-tcpserver.rb +49 -0
  102. data/test/unit/test-proc-main.rb +2 -2
  103. metadata +195 -175
  104. data/processor/command/stepi.rb +0 -63
  105. data/test/functional/tmp/b1.rb +0 -5
  106. data/test/functional/tmp/s1.rb +0 -9
  107. data/test/functional/tmp/t2.rb +0 -6
  108. data/test/integration/try-test-enable.rb +0 -11
@@ -0,0 +1,5 @@
1
+ a = 1
2
+ b = 2
3
+ c = 3
4
+ d = 4
5
+ e = 5
@@ -0,0 +1,9 @@
1
+ # require_relative '../../../lib/rbdbgr'
2
+ require 'rbdbgr'
3
+ # cmds = ['step', 'continue']
4
+ d = Debugger.new
5
+ 2.times do
6
+ x = 1
7
+ d.debugger(:immediate => true)
8
+ y = 2
9
+ end
@@ -32,25 +32,28 @@ def run_debugger(testname, ruby_file, opts={})
32
32
 
33
33
  FileUtils.rm(outfile) if File.exist?(outfile)
34
34
 
35
- cmd = "%s %s --nx --command %s %s '%s' %s >%s" %
36
- [Trepanning::ruby_path, dbgr_path, cmdfile, opts[:dbgr],
37
- programfile, opts[:args], outfile]
35
+ cmd =
36
+ if opts[:standalone]
37
+ "%s %s %s >%s 2>&1" %
38
+ [Trepanning::ruby_path, programfile, opts[:args], outfile]
39
+ else
40
+ "%s %s --nx --command %s %s '%s' %s >%s 2>&1" %
41
+ [Trepanning::ruby_path, dbgr_path, cmdfile, opts[:dbgr],
42
+ programfile, opts[:args], outfile]
43
+ end
38
44
 
39
45
  system(cmd)
40
46
  return false unless 0 == $?.exitstatus
41
47
  if opts[:do_diff]
42
- from_file = rightfile
43
- # fromdate = time.ctime(os.stat(fromfile).st_mtime)
44
- from_lines = File.open(from_file).readlines()
45
- to_file = outfile
46
- # todate = time.ctime(os.stat(tofile).st_mtime)
47
- to_lines = File.open(to_file).readlines()
48
+ expected_lines = File.open(rightfile).readlines()
49
+ got_lines = File.open(outfile).readlines()
50
+ opts[:filter].call(got_lines, expected_lines) if opts[:filter]
48
51
 
49
52
  # Seems to be a bug in LCS in that it will return a diff even if two
50
53
  # files are the same.
51
- return true if from_lines == to_lines
54
+ return true if expected_lines == got_lines
52
55
 
53
- sdiffs = Diff::LCS.sdiff(from_lines, to_lines)
56
+ sdiffs = Diff::LCS.sdiff(expected_lines, got_lines)
54
57
 
55
58
  if sdiffs.empty?
56
59
  FileUtils.rm(outfile)
@@ -6,6 +6,10 @@ class TestFnameWithBlank < Test::Unit::TestCase
6
6
  @@NAME = File.basename(__FILE__, '.rb')[5..-1]
7
7
 
8
8
  def test_it
9
- assert_equal(true, run_debugger(@@NAME, 'fname with blank.rb'))
9
+ opts = {}
10
+ opts[:filter] = Proc.new{|got_lines, correct_lines|
11
+ got_lines[0] = "-> (fname with blank.rb:1 @0)\n"
12
+ }
13
+ assert_equal(true, run_debugger(@@NAME, 'fname with blank.rb', opts))
10
14
  end
11
15
  end
@@ -5,7 +5,11 @@ require_relative 'helper'
5
5
  class TestQuit < Test::Unit::TestCase
6
6
  @@NAME = File.basename(__FILE__, '.rb')[5..-1]
7
7
 
8
- def test_it
9
- assert_equal(true, run_debugger(@@NAME, 'null.rb'))
8
+ def test_trepan_call
9
+ opts = {}
10
+ opts[:filter] = Proc.new{|got_lines, correct_lines|
11
+ got_lines[0] = "-> (null.rb:1 @0)\n"
12
+ }
13
+ assert_equal(true, run_debugger(@@NAME, 'null.rb', opts))
10
14
  end
11
15
  end
@@ -1,3 +1,5 @@
1
+ require 'test/unit'
2
+ require 'thread_frame'
1
3
  require_relative '../../app/core'
2
4
  require_relative '../../app/mock'
3
5
  require_relative '../../processor/main' # Have to include before frame!
@@ -13,17 +15,20 @@ module UnitHelper
13
15
  @cmdproc = @core.processor = Trepan::CmdProcessor.new(@core)
14
16
  @cmds = @cmdproc.commands
15
17
 
16
- def @cmdproc.msg(message)
18
+ def @cmdproc.msg(message, opts={})
17
19
  @msgs << message
18
20
  end
19
- def @cmdproc.errmsg(message)
21
+ def @cmdproc.msgs
22
+ @msgs
23
+ end
24
+ def @cmdproc.errmsg(message, opts={})
20
25
  @errmsgs << message
21
26
  end
22
27
  def @cmdproc.errmsgs
23
28
  @errmsgs
24
29
  end
25
- def @cmdproc.msgs
26
- @msgs
30
+ def @cmdproc.section(message, opts={})
31
+ @msgs << message
27
32
  end
28
33
  reset_cmdproc_vars
29
34
  end
@@ -0,0 +1,9 @@
1
+ require 'test/unit'
2
+ require_relative '../../processor/mock'
3
+
4
+ module MockUnitHelper
5
+ def common_setup(name)
6
+ @dbg, @cmd = MockDebugger::setup(name, false)
7
+ end
8
+ end
9
+
@@ -8,7 +8,7 @@ class TestAppBrkpt < Test::Unit::TestCase
8
8
  def test_basic
9
9
  tf = RubyVM::ThreadFrame.current
10
10
  iseq = tf.iseq
11
- b1 = Trepanning::Breakpoint.new(iseq, 0)
11
+ b1 = Trepan::Breakpoint.new(iseq, 0)
12
12
  assert_equal(false, b1.temp?)
13
13
  assert_equal(0, b1.hits)
14
14
  assert_equal('B', b1.icon_char)
@@ -18,13 +18,13 @@ class TestAppBrkpt < Test::Unit::TestCase
18
18
  b1.enabled = false
19
19
  assert_equal('b', b1.icon_char)
20
20
  assert_raises TypeError do
21
- Trepanning::Breakpoint.new(iseq, iseq.iseq_size, :temp => true)
21
+ Trepan::Breakpoint.new(iseq, iseq.iseq_size, :temp => true)
22
22
  end
23
23
  assert_raises TypeError do
24
- Trepanning::Breakpoint.new(0, 5)
24
+ Trepan::Breakpoint.new(0, 5)
25
25
  end
26
26
  require_relative '../../lib/trepanning.rb'
27
- b2 = Trepanning::Breakpoint.new(iseq, 0, :temp => true)
27
+ b2 = Trepan::Breakpoint.new(iseq, 0, :temp => true)
28
28
  assert_equal('t', b2.icon_char)
29
29
  end
30
30
  end
@@ -7,7 +7,7 @@ require 'thread_frame'
7
7
  class TestLibAppBrkptMgr < Test::Unit::TestCase
8
8
 
9
9
  def setup
10
- @brkpts = BreakpointMgr.new
10
+ @brkpts = Trepan::BreakpointMgr.new
11
11
  end
12
12
 
13
13
  def test_basic
@@ -24,7 +24,7 @@ class TestLibAppBrkptMgr < Test::Unit::TestCase
24
24
  assert_equal(0, @brkpts.size)
25
25
 
26
26
  # Try adding via << rather than .add
27
- b2 = @brkpts << Trepanning::Breakpoint.new(iseq, offsets[1], :temp => true)
27
+ b2 = @brkpts << Trepan::Breakpoint.new(iseq, offsets[1], :temp => true)
28
28
 
29
29
  assert_equal(nil, @brkpts.find(iseq, offset, tf.binding))
30
30
  @brkpts.reset
@@ -26,7 +26,6 @@ class TestAppFile < Test::Unit::TestCase
26
26
 
27
27
  def test_find_iseqs
28
28
  iseqs = find_iseqs(ISEQS__, "tmpdir")
29
- p ISEQS__.keys
30
29
  assert_equal(false, iseqs.empty?)
31
30
  iseqs = find_iseqs(ISEQS__, "tmpdir@#{__FILE__}")
32
31
  assert_equal(true, iseqs.empty?)
@@ -7,15 +7,14 @@ require_relative '../../app/options'
7
7
  # To have something to work with.
8
8
  load 'tmpdir.rb'
9
9
 
10
- class TestAppStringIO < Test::Unit::TestCase
11
- include Trepanning
10
+ class TestAppOptions < Test::Unit::TestCase
12
11
 
13
12
  def setup
14
- @options = DEFAULT_CMDLINE_SETTINGS.clone
13
+ @options = Trepan::DEFAULT_CMDLINE_SETTINGS.clone
15
14
  @stderr = StringIO.new
16
15
  @stdout = StringIO.new
17
- @options = copy_default_options
18
- @opts = setup_options(@options, @stdout, @stderr)
16
+ @options = Trepan::copy_default_options
17
+ @opts = Trepan::setup_options(@options, @stdout, @stderr)
19
18
  end
20
19
 
21
20
  def test_cd
@@ -57,4 +56,26 @@ class TestAppStringIO < Test::Unit::TestCase
57
56
  end
58
57
  end
59
58
 
59
+ def test_both_client_server_opts
60
+ # Try each of --client and --server options separately
61
+ %w(client server).each do |name|
62
+ setup
63
+ o = ["--#{name}"]
64
+ rest = @opts.parse o
65
+ assert_equal('', @stdout.string)
66
+ assert_equal('', @stderr.string)
67
+ assert_equal(true, @options[name.to_sym])
68
+ end
69
+
70
+ # Try both --client and --server together. Should give a warning
71
+ setup
72
+ o = %w(--client --server)
73
+ rest = @opts.parse o
74
+ assert_not_equal('', @stderr.string)
75
+ assert_equal('', @stdout.string)
76
+ assert_equal(true, @options[:client])
77
+ assert_equal(false, @options[:server])
78
+
79
+ end
80
+
60
81
  end
@@ -12,7 +12,6 @@ end
12
12
  $errors = []
13
13
  class TestBaseCommandHelp < Test::Unit::TestCase
14
14
 
15
- Trepan::Subcommand.const_set(:NAME, 'bogus')
16
15
  def setup
17
16
  $errors = []
18
17
  $msgs = []
@@ -1,5 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
- require 'test/unit'
3
2
  require_relative 'cmd-helper'
4
3
  require_relative '../../processor/command/alias'
5
4
  require_relative '../../processor/command/unalias'
@@ -1,8 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
- require 'test/unit'
3
- require 'thread_frame'
4
- require 'fileutils' # To test FileUtils.cp
5
-
6
2
  require_relative 'cmd-helper'
7
3
 
8
4
  class TestCommandBreak < Test::Unit::TestCase
@@ -1,5 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
- require 'test/unit'
3
2
  require_relative 'cmd-helper'
4
3
  require_relative '../../app/breakpoint'
5
4
 
@@ -7,7 +6,7 @@ class TestCommandEnableDisable < Test::Unit::TestCase
7
6
 
8
7
  include UnitHelper
9
8
  def setup
10
- Trepanning::Breakpoint::reset
9
+ Trepan::Breakpoint::reset
11
10
  common_setup
12
11
  @break_cmd = @cmds['break']
13
12
  @disable_cmd = @cmds['disable']
@@ -35,7 +34,6 @@ class TestCommandEnableDisable < Test::Unit::TestCase
35
34
  reset_cmdproc_vars
36
35
  end
37
36
 
38
- require 'thread_frame'
39
37
  tf = RubyVM::ThreadFrame.current
40
38
  @cmdproc.frame_setup(tf)
41
39
  pc_offset = tf.pc_offset
@@ -1,5 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
- require 'test/unit'
3
2
  require_relative 'cmd-helper'
4
3
  require_relative '../../processor/command/help'
5
4
 
@@ -1,13 +1,12 @@
1
1
  #!/usr/bin/env ruby
2
- require 'test/unit'
3
- require_relative '../../processor/mock'
2
+ require_relative './mock-helper'
4
3
  require_relative '../../processor/command/kill'
5
4
 
6
5
  class TestCommandKill < Test::Unit::TestCase
7
-
6
+ include MockUnitHelper
8
7
  def setup
9
- @name = File.basename(__FILE__, '.rb').split(/-/)[2]
10
- @dbg, @cmd = MockDebugger::setup(@name, false)
8
+ @name = File.basename(__FILE__, '.rb').split(/-/)[2]
9
+ common_setup(@name)
11
10
  def @cmd.msg(message)
12
11
  @msgs << message
13
12
  end
@@ -1,13 +1,12 @@
1
1
  #!/usr/bin/env ruby
2
- require 'test/unit'
3
- require_relative '../../processor/mock'
2
+ require_relative './mock-helper'
4
3
  require_relative '../../processor/command/quit'
5
4
 
6
5
  class TestCommandQuit < Test::Unit::TestCase
7
-
6
+ include MockUnitHelper
8
7
  def setup
9
- @name = File.basename(__FILE__, '.rb').split(/-/)[2]
10
- @dbg, @cmd = MockDebugger::setup(@name, false)
8
+ @name = File.basename(__FILE__, '.rb').split(/-/)[2]
9
+ common_setup(@name)
11
10
  end
12
11
 
13
12
  def test_basic
@@ -21,6 +20,4 @@ class TestCommandQuit < Test::Unit::TestCase
21
20
  # should test 'confirm' gets run; and should test that
22
21
  # 'unconditional' is handled correctly.
23
22
  end
24
-
25
-
26
23
  end
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative './mock-helper'
3
+ require_relative '../../processor/command/source'
4
+
5
+ # Test command source
6
+ class TestCommandSource < Test::Unit::TestCase
7
+
8
+ include MockUnitHelper
9
+ def setup
10
+ @name = File.basename(__FILE__, '.rb').split(/-/)[2]
11
+ common_setup(@name)
12
+ end
13
+
14
+ def test_source_opts
15
+
16
+ [['--quiet', :verbose, false],
17
+ ['-q', :quiet, true],
18
+ ['--no-quiet', :quiet, false],
19
+ ['--continue', :abort_on_error, false],
20
+ ['--no-continue', :abort_on_error, true],
21
+ ['-c', :abort_on_error, false],
22
+ ['-v', :verbose, true],
23
+ ['--verbose', :verbose, true],
24
+ ['--no-verbose', :verbose, false]
25
+ ].each do |opt, key, expect|
26
+ options =
27
+ @cmd.parse_options(Trepan::Command::SourceCommand::DEFAULT_OPTIONS.dup,
28
+ opt)
29
+ assert_equal(expect, options[key],
30
+ "Option #{opt} using key #{key} failure")
31
+ end
32
+ end
33
+ end
@@ -1,5 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
- require 'test/unit'
3
2
  require_relative 'cmd-helper'
4
3
  require_relative '../../processor/command/step'
5
4
 
@@ -41,5 +40,4 @@ class TestCommandStep < Test::Unit::TestCase
41
40
  @my_cmd.run([@name, '1+foo'])
42
41
  assert_equal(false, @cmdproc.leave_cmd_loop)
43
42
  end
44
-
45
43
  end
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env ruby
2
+ require 'test/unit'
3
+
4
+ # Unit test for io/tcpclient.rb and io/tcpserver.rb together
5
+ require_relative '../../io/tcpfns'
6
+ require_relative '../../io/tcpclient'
7
+ require_relative '../../io/tcpserver'
8
+
9
+ # Tests TCPServer together with and TCPClient
10
+ class TestTCPClientServer < Test::Unit::TestCase
11
+
12
+ def test_client_server
13
+ server = Trepan::TCPDbgServer.new({ :open => true,
14
+ :port => 1028,
15
+ :host => 'localhost'
16
+ })
17
+ client = Trepan::TCPDbgClient.new({ :open => true,
18
+ :port => 1028,
19
+ :host => 'localhost'
20
+ })
21
+ %w(one, two, three).each do |line|
22
+ server.writeline(line)
23
+ assert_equal line, client.read_msg.chomp
24
+ end
25
+ %w(four, five, six).each do |line|
26
+ client.writeline(line)
27
+ assert_equal line, server.read_msg.chomp
28
+ end
29
+ client.close
30
+ server.close
31
+ end
32
+ end
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/env ruby
2
+ require 'test/unit'
3
+
4
+ # Unit test for io/tcpclient.rb
5
+ require_relative '../../io/tcpfns'
6
+ require_relative '../../io/tcpclient'
7
+
8
+ class TestTCPDbgClient < Test::Unit::TestCase
9
+
10
+ include Trepanning::TCPPacking
11
+
12
+ def test_basic
13
+ client = Trepan::TCPDbgClient.new({ :open => false,
14
+ :port => 1027,
15
+ :host => 'localhost'
16
+ })
17
+ threads = []
18
+ Thread.new do
19
+ server = TCPServer.new('localhost', 1027)
20
+ session = server.accept
21
+ while 'quit' != (line = session.gets)
22
+ session.puts line
23
+ end
24
+ session.close
25
+ end
26
+ threads << Thread.new do
27
+ # require 'trepanning'; debugger
28
+ 3.times do
29
+ begin
30
+ client.open
31
+ rescue IOError
32
+ end
33
+ break
34
+ end
35
+ assert client
36
+ msgs = %w(four five six)
37
+ msgs.each do |mess|
38
+ begin
39
+ client.writeline(mess)
40
+ assert_equal mess, client.read_msg.chomp
41
+ rescue EOFError
42
+ puts "Got EOF"
43
+ break
44
+ rescue Exception => e
45
+ puts "Got #{e}"
46
+ break
47
+ end
48
+ end
49
+ client.close
50
+ end
51
+ threads.each {|t| t.join }
52
+ end
53
+ end