ruby-debug 0.9.3 → 0.10.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 (64) hide show
  1. data/AUTHORS +1 -0
  2. data/CHANGES +41 -0
  3. data/ChangeLog +0 -0
  4. data/README +27 -13
  5. data/Rakefile +220 -0
  6. data/bin/rdebug +116 -42
  7. data/cli/ruby-debug.rb +33 -3
  8. data/cli/ruby-debug/command.rb +49 -12
  9. data/cli/ruby-debug/commands/breakpoints.rb +47 -64
  10. data/cli/ruby-debug/commands/control.rb +41 -13
  11. data/cli/ruby-debug/commands/display.rb +35 -18
  12. data/cli/ruby-debug/commands/enable.rb +159 -0
  13. data/cli/ruby-debug/commands/eval.rb +78 -4
  14. data/cli/ruby-debug/commands/frame.rb +67 -42
  15. data/cli/ruby-debug/commands/help.rb +21 -17
  16. data/cli/ruby-debug/commands/info.rb +210 -0
  17. data/cli/ruby-debug/commands/irb.rb +9 -1
  18. data/cli/ruby-debug/commands/list.rb +11 -8
  19. data/cli/ruby-debug/commands/method.rb +12 -23
  20. data/cli/ruby-debug/commands/script.rb +14 -9
  21. data/cli/ruby-debug/commands/settings.rb +174 -39
  22. data/cli/ruby-debug/commands/show.rb +193 -0
  23. data/cli/ruby-debug/commands/stepping.rb +15 -10
  24. data/cli/ruby-debug/commands/threads.rb +55 -56
  25. data/cli/ruby-debug/commands/variables.rb +27 -27
  26. data/cli/ruby-debug/helper.rb +134 -0
  27. data/cli/ruby-debug/interface.rb +46 -15
  28. data/cli/ruby-debug/processor.rb +156 -25
  29. data/doc/rdebug.1 +236 -0
  30. data/runner.sh +7 -0
  31. data/test/breakpoints.cmd +43 -0
  32. data/test/breakpoints.right +94 -0
  33. data/test/display.cmd +18 -0
  34. data/test/display.right +37 -0
  35. data/test/frame.cmd +21 -0
  36. data/test/frame.right +45 -0
  37. data/test/gcd.rb +18 -0
  38. data/test/help.cmd +12 -0
  39. data/test/help.right +4 -0
  40. data/test/helper.rb +87 -0
  41. data/test/info-var-bug.rb +45 -0
  42. data/test/info-var.cmd +23 -0
  43. data/test/info-var.right +47 -0
  44. data/test/info.cmd +12 -0
  45. data/test/info.right +35 -0
  46. data/test/quit.cmd +9 -0
  47. data/test/quit.right +22 -0
  48. data/test/setshow.cmd +44 -0
  49. data/test/setshow.right +73 -0
  50. data/test/stepping.cmd +17 -0
  51. data/test/stepping.right +40 -0
  52. data/test/tdebug.rb +196 -0
  53. data/test/test-breakpoints.rb +28 -0
  54. data/test/test-columnize.rb +46 -0
  55. data/test/test-display.rb +26 -0
  56. data/test/test-frame.rb +27 -0
  57. data/test/test-help.rb +44 -0
  58. data/test/test-info-var.rb +33 -0
  59. data/test/test-info.rb +28 -0
  60. data/test/test-quit.rb +28 -0
  61. data/test/test-ruby-debug-base.rb +76 -0
  62. data/test/test-setshow.rb +24 -0
  63. data/test/test-stepping.rb +26 -0
  64. metadata +63 -22
data/test/stepping.cmd ADDED
@@ -0,0 +1,17 @@
1
+ # ***************************************************
2
+ # This tests step, next, finish and continue
3
+ # ***************************************************
4
+ set debuggertesting on
5
+ set callstyle last
6
+ next
7
+ where
8
+ step a
9
+ step 2
10
+ where
11
+ n 2
12
+ step
13
+ where
14
+ step 3
15
+ where
16
+ # finish
17
+ quit
@@ -0,0 +1,40 @@
1
+ gcd.rb:4
2
+ def gcd(a, b)
3
+ # # ***************************************************
4
+ # # This tests step, next, finish and continue
5
+ # # ***************************************************
6
+ # set debuggertesting on
7
+ Currently testing the debugger is on.
8
+ # set callstyle last
9
+ Frame call-display style is last.
10
+ # next
11
+ gcd.rb:18
12
+ gcd(3,5)
13
+ # where
14
+ --> #0 at line gcd.rb:18
15
+ # step a
16
+ Step argument 'a' needs to be a number.
17
+ # step 2
18
+ gcd.rb:6
19
+ if a > b
20
+ # where
21
+ --> #0 Object.gcd(a#Fixnum, b#Fixnum) at line gcd.rb:6
22
+ #1 at line gcd.rb:18
23
+ # n 2
24
+ gcd.rb:10
25
+ return nil if a <= 0
26
+ # step
27
+ gcd.rb:12
28
+ if a == 1 or b-a == 0
29
+ # where
30
+ --> #0 Object.gcd(a#Fixnum, b#Fixnum) at line gcd.rb:12
31
+ #1 at line gcd.rb:18
32
+ # step 3
33
+ gcd.rb:6
34
+ if a > b
35
+ # where
36
+ --> #0 Object.gcd(a#Fixnum, b#Fixnum) at line gcd.rb:6
37
+ #1 Object.-(a#Fixnum, b#Fixnum) at line gcd.rb:15
38
+ #2 at line gcd.rb:18
39
+ # # finish
40
+ # quit
data/test/tdebug.rb ADDED
@@ -0,0 +1,196 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- Ruby -*-
3
+ # This is a hacked down copy of rdebug which can be used for testing
4
+
5
+ require 'stringio'
6
+ require 'rubygems'
7
+ require 'optparse'
8
+ require "ostruct"
9
+
10
+ TOP_SRC_DIR = File.join(File.expand_path(File.dirname(__FILE__), "..")) unless
11
+ defined?(TOP_SRC_DIR)
12
+
13
+ $: << File.join(TOP_SRC_DIR, "ext")
14
+ $: << File.join(TOP_SRC_DIR, "lib")
15
+ $: << File.join(TOP_SRC_DIR, "cli")
16
+
17
+ options = OpenStruct.new(
18
+ 'frame_bind' => false,
19
+ 'no-quit' => false,
20
+ 'no-stop' => false,
21
+ 'nx' => false,
22
+ 'post_mortem' => false,
23
+ 'script' => nil,
24
+ 'tracing' => false,
25
+ 'verbose_long'=> false,
26
+ 'wait' => false
27
+ )
28
+
29
+ require "ruby-debug"
30
+
31
+ program = File.basename($0)
32
+ opts = OptionParser.new do |opts|
33
+ opts.banner = <<EOB
34
+ #{program} #{Debugger::VERSION}
35
+ Usage: #{program} [options] <script.rb> -- <script.rb parameters>
36
+ EOB
37
+ opts.separator ""
38
+ opts.separator "Options:"
39
+ opts.on("-A", "--annotate LEVEL", Integer, "Set annotation level") do
40
+ |Debugger::annotate|
41
+ end
42
+ opts.on("-d", "--debug", "Set $DEBUG=true") {$DEBUG = true}
43
+ opts.on("--keep-frame-binding", "Keep frame bindings") do
44
+ options.frame_bind = true
45
+ end
46
+ opts.on("--no-control", "Do not automatically start control thread") do
47
+ options.control = false
48
+ end
49
+ opts.on("--no-quit", "Do not quit when script finishes") {
50
+ options.noquit = true
51
+ }
52
+ opts.on("-n", "--no-stop", "Do not stop when script is loaded") {options.nostop = true}
53
+ opts.on("-nx", "Not run debugger initialization files (e.g. .rdebugrc") do
54
+ options.nx = true
55
+ end
56
+ opts.on("-m", "--post-mortem", "Activate post-mortem mode") {options.post_mortem = true}
57
+ opts.on("-I", "--include PATH", String, "Add PATH to $LOAD_PATH") do |path|
58
+ $LOAD_PATH.unshift(path)
59
+ end
60
+ opts.on("-r", "--require SCRIPT", String,
61
+ "Require the library, before executing your script") do |name|
62
+ if name == 'debug'
63
+ puts "ruby-debug is not compatible with Ruby's 'debug' library. This option is ignored."
64
+ else
65
+ require name
66
+ end
67
+ end
68
+ opts.on("--script FILE", String, "Name of the script file to run") do |options.script|
69
+ unless File.exists?(options.script)
70
+ puts "Script file '#{options.script}' is not found"
71
+ exit
72
+ end
73
+ end
74
+ opts.on("-x", "--trace", "Turn on line tracing") {options.tracing = true}
75
+ ENV['EMACS'] = nil
76
+ opts.separator ""
77
+ opts.separator "Common options:"
78
+ opts.on_tail("--help", "Show this message") do
79
+ puts opts
80
+ exit
81
+ end
82
+ opts.on_tail("--version",
83
+ "Print the version") do
84
+ puts "ruby-debug #{Debugger::VERSION}"
85
+ exit
86
+ end
87
+ opts.on("--verbose", "Turn on verbose mode") do
88
+ $VERBOSE = true
89
+ options.verbose_long = true
90
+ end
91
+ opts.on_tail("-v",
92
+ "Print version number, then turn on verbose mode") do
93
+ puts "ruby-debug #{Debugger::VERSION}"
94
+ $VERBOSE = true
95
+ end
96
+ end
97
+
98
+ begin
99
+ if not defined? Debugger::ARGV
100
+ Debugger::ARGV = ARGV.clone
101
+ end
102
+ rdebug_path = File.expand_path($0)
103
+ if RUBY_PLATFORM =~ /mswin/
104
+ rdebug_path += ".cmd" unless rdebug_path =~ /\.cmd$/i
105
+ end
106
+ Debugger::RDEBUG_SCRIPT = rdebug_path
107
+ Debugger::INITIAL_DIR = Dir.pwd
108
+ opts.parse! ARGV
109
+ rescue StandardError => e
110
+ puts opts
111
+ puts
112
+ puts e.message
113
+ exit(-1)
114
+ end
115
+
116
+ if ARGV.empty?
117
+ exit if $VERBOSE and not options.verbose_long
118
+ puts opts
119
+ puts
120
+ puts "Must specify a script to run"
121
+ exit(-1)
122
+ end
123
+
124
+ # save script name
125
+ Debugger::PROG_SCRIPT = ARGV.shift
126
+
127
+ # install interruption handler
128
+ trap('INT') { Debugger.interrupt_last }
129
+
130
+ # set options
131
+ Debugger.wait_connection = false
132
+ Debugger.keep_frame_binding = options.frame_bind
133
+
134
+ # activate debugger
135
+ Debugger.start
136
+
137
+ # activate post-mortem
138
+ Debugger.post_mortem if options.post_mortem
139
+
140
+ # Set up an interface to read commands from a debugger script file.
141
+ Debugger.interface = Debugger::ScriptInterface.new(options.script,
142
+ STDOUT, true)
143
+ Debugger.tracing = options.nostop = true if options.tracing
144
+
145
+ # Make sure Ruby script syntax checks okay.
146
+ # Otherwise we get a load message that looks like rdebug has
147
+ # a problem.
148
+ output = `ruby -c #{Debugger::PROG_SCRIPT} 2>&1`
149
+ if $?.exitstatus != 0 and RUBY_PLATFORM !~ /mswin/
150
+ puts output
151
+ exit $?.exitstatus
152
+ end
153
+ # activate debugger
154
+ Debugger.start
155
+ # start control thread
156
+ Debugger.start_control(options.host, options.cport) if options.control
157
+
158
+ # load initrc script (e.g. .rdebugrc)
159
+ Debugger.run_init_script(StringIO.new) unless options.nx
160
+
161
+ # run startup script if specified
162
+ if options.script
163
+ Debugger.run_script(options.script)
164
+ end
165
+ # activate post-mortem
166
+ Debugger.post_mortem if options.post_mortem
167
+ Debugger.tracing = options.nostop = true if options.tracing
168
+
169
+ # Make sure Ruby script syntax checks okay.
170
+ # Otherwise we get a load message that looks like rdebug has
171
+ # a problem.
172
+ output = `ruby -c #{Debugger::PROG_SCRIPT} 2>&1`
173
+ if $?.exitstatus != 0 and RUBY_PLATFORM !~ /mswin/
174
+ puts output
175
+ exit $?.exitstatus
176
+ end
177
+ if options.noquit
178
+ while true do
179
+ Debugger.stop if Debugger.started?
180
+ begin
181
+ Debugger.debug_load Debugger::PROG_SCRIPT, !options.nostop
182
+ rescue
183
+ print $!.backtrace.map{|l| "\t#{l}"}.join("\n"), "\n"
184
+ print "Uncaught exception: #{$!}\n"
185
+ end
186
+ # FIXME: add status for whether we are interactive or not.
187
+ # if STDIN.tty? and !options.nostop
188
+ if !options.nostop
189
+ print "The program has finished and will be restarted.\n"
190
+ else
191
+ break
192
+ end
193
+ end
194
+ else
195
+ Debugger.debug_load Debugger::PROG_SCRIPT, !options.nostop
196
+ end
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env ruby
2
+ require "test/unit"
3
+ require "fileutils"
4
+
5
+ # require "rubygems"
6
+ # require "ruby-debug"
7
+ # Debugger.start
8
+
9
+ SRC_DIR = File.expand_path(File.dirname(__FILE__)) + "/" unless
10
+ defined?(SRC_DIR)
11
+
12
+ require File.join(SRC_DIR, "helper.rb")
13
+
14
+ include TestHelper
15
+
16
+ # Test frame commands
17
+ class TestBreakpoints < Test::Unit::TestCase
18
+ require 'stringio'
19
+
20
+ # Test commands in stepping.rb
21
+ def test_basic
22
+ Dir.chdir(SRC_DIR) do
23
+ assert_equal(true,
24
+ run_debugger("breakpoints",
25
+ "--script breakpoints.cmd -- gcd.rb 3 5"))
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env ruby
2
+ require "test/unit"
3
+
4
+ $: << File.expand_path(File.dirname(__FILE__)) + '/../ext'
5
+ $: << File.expand_path(File.dirname(__FILE__)) + '/../cli'
6
+ $: << File.expand_path(File.dirname(__FILE__)) + '/../cli/ruby-debug'
7
+ require "ruby_debug"
8
+
9
+ # Test of Columnize function. Note: Columnize is moving out of ruby-debug,
10
+ # so this test will disappear.
11
+ class TestColumnize < Test::Unit::TestCase
12
+ include Debugger
13
+
14
+ require "command.rb"
15
+ include ColumnizeFunctions
16
+ def test_columize
17
+ assert_equal("one two three\n", columnize(["one", "two", "three"]))
18
+ assert_equal("oneitem\n", columnize(["oneitem"]))
19
+ assert_equal(
20
+ "one 6hree 11o 16e 21ree 26o 31e 36ree 41o 46e three\n" +
21
+ "two 7ne 12ree 17o 22e 27ree 32o 37e 42ree 47o \n" +
22
+ "three 8wo 13e 18ree 23o 28e 33ree 38o 43e 48ree\n" +
23
+ "4ne 9hree 14o 19e 24ree 29o 34e 39ree 44o one \n" +
24
+ "5wo 10e 15ree 20o 25e 30ree 35o 40e 45ree two \n",
25
+ columnize([
26
+ "one", "two", "three",
27
+ "4ne", "5wo", "6hree",
28
+ "7ne", "8wo", "9hree",
29
+ "10e", "11o", "12ree",
30
+ "13e", "14o", "15ree",
31
+ "16e", "17o", "18ree",
32
+ "19e", "20o", "21ree",
33
+ "22e", "23o", "24ree",
34
+ "25e", "26o", "27ree",
35
+ "28e", "29o", "30ree",
36
+ "31e", "32o", "33ree",
37
+ "34e", "35o", "36ree",
38
+ "37e", "38o", "39ree",
39
+ "40e", "41o", "42ree",
40
+ "43e", "44o", "45ree",
41
+ "46e", "47o", "48ree",
42
+ "one", "two", "three"]))
43
+
44
+ end
45
+ end
46
+
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env ruby
2
+ require "test/unit"
3
+ require "fileutils"
4
+
5
+ # require "rubygems" ; require "ruby-debug"
6
+ # Debugger.start
7
+
8
+ SRC_DIR = File.expand_path(File.dirname(__FILE__)) + "/" unless
9
+ defined?(SRC_DIR)
10
+
11
+ require File.join(SRC_DIR, "helper.rb")
12
+ include TestHelper
13
+
14
+ # Test info commands
15
+ class TestDisplay < Test::Unit::TestCase
16
+ require 'stringio'
17
+
18
+ # Test commands in stepping.rb
19
+ def test_basic
20
+ Dir.chdir(SRC_DIR) do
21
+ assert_equal(true,
22
+ run_debugger("display",
23
+ "--script display.cmd -- gcd.rb 3 5"))
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+ require "test/unit"
3
+ require "fileutils"
4
+
5
+ # require "rubygems"
6
+ # require "ruby-debug"; Debugger.start
7
+
8
+ SRC_DIR = File.expand_path(File.dirname(__FILE__)) + "/" unless
9
+ defined?(SRC_DIR)
10
+
11
+ require File.join(SRC_DIR, "helper.rb")
12
+
13
+ include TestHelper
14
+
15
+ # Test frame commands
16
+ class TestFrame < Test::Unit::TestCase
17
+ require 'stringio'
18
+
19
+ # Test commands in stepping.rb
20
+ def test_basic
21
+ Dir.chdir(SRC_DIR) do
22
+ assert_equal(true,
23
+ run_debugger("frame",
24
+ "--script frame.cmd -- gcd.rb 3 5"))
25
+ end
26
+ end
27
+ end
data/test/test-help.rb ADDED
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # require "rubygems"
4
+ # require "ruby-debug" ; Debugger.start
5
+
6
+ require "test/unit"
7
+ SRC_DIR = File.expand_path(File.dirname(__FILE__)) + "/" unless
8
+ defined?(SRC_DIR)
9
+ %w(ext lib cli).each do |dir|
10
+ $: << File.join(SRC_DIR, "..", dir)
11
+ end
12
+ require "ruby_debug"
13
+ require SRC_DIR + "/../cli/ruby-debug.rb"
14
+
15
+ def cheap_diff(got_lines, correct_lines)
16
+ correct_lines.each_with_index do |line, i|
17
+ correct_lines[i].chomp!
18
+ if got_lines[i] != correct_lines[i]
19
+ puts "difference found at line #{i+1}"
20
+ puts "got : #{got_lines[i]}"
21
+ puts "need: #{correct_lines[i]}"
22
+ return false
23
+ end
24
+ return correct_lines.size == got_lines.size
25
+ end
26
+ end
27
+
28
+ # Test of C extension ruby_debug.so
29
+ class TestCmd < Test::Unit::TestCase
30
+ require 'stringio'
31
+
32
+ # Test initial variables and setting/getting state.
33
+ def test_basic
34
+ testbase = 'help'
35
+ op = StringIO.new("", "w")
36
+ script = File.join(SRC_DIR, "#{testbase}.cmd")
37
+ Debugger.const_set('Version', "unit testing")
38
+ Debugger.run_script(script, op)
39
+ got_lines = op.string.split("\n")
40
+ right_file = File.join(SRC_DIR, "#{testbase}.right")
41
+ correct_lines = File.readlines(right_file)
42
+ assert cheap_diff(got_lines, correct_lines)
43
+ end
44
+ end
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env ruby
2
+ require "test/unit"
3
+ require "fileutils"
4
+
5
+ # require "rubygems"
6
+ # require "ruby-debug" ; Debugger.start
7
+
8
+ SRC_DIR = File.expand_path(File.dirname(__FILE__)) + "/" unless
9
+ defined?(SRC_DIR)
10
+
11
+ require File.join(SRC_DIR, "helper.rb")
12
+ include TestHelper
13
+
14
+ # Test info variables command
15
+ class TestInfoVar < Test::Unit::TestCase
16
+
17
+ def test_info_variables
18
+
19
+ Dir.chdir(SRC_DIR) do
20
+
21
+ filter = Proc.new{|got_lines, correct_lines|
22
+ [got_lines[12], correct_lines[12]].each do |s|
23
+ s.sub!(/Mine:0x[0-9,a-f]+/, 'Mine:')
24
+ end
25
+ }
26
+
27
+ assert_equal(true,
28
+ run_debugger("info-var",
29
+ "--script info-var.cmd -- info-var-bug.rb",
30
+ nil, filter))
31
+ end
32
+ end
33
+ end