ruby-debug 0.9.3 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
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/AUTHORS CHANGED
@@ -4,3 +4,4 @@ Kent Sibilev
4
4
  Contributers:
5
5
  Markus Barchfeld
6
6
  R. Bernstein
7
+ Anders Lindgren
data/CHANGES CHANGED
@@ -1,3 +1,44 @@
1
+ 0.10.0
2
+ - '-r' option can be used to require additional libraries.
3
+ - --noquit option added to stay in debugger when the program exits
4
+ - gdb-like --annotate option added. Can be used by front-ends to get information
5
+ without polling
6
+ - Fixed 'var const' command. Issue #10847.
7
+ - Using pretty-print for all var commands.
8
+ - Better error reporting for commands that require a numeric argument.
9
+ - Fixed Kernel#binding_n method
10
+ - Add option -d ($DEBUG = true) and --verbose. Make -v work like ruby.
11
+ - Remove debugger messages caused when warnings are turned on.
12
+ - "info" and "show" commands added. "set" made more like gdb's
13
+ set. subcommands can be abbreviated and are case insensitive.
14
+ - restart program if it terminates normally and we've got a tty and
15
+ we stop on the first statement.
16
+ - help is in tidy column format. method lists are shown that way as well.
17
+ the "width" setting ("set/show width") is used for the line width
18
+ - stack traces now show parameter names and types. "info args" lists just
19
+ the parameters (with the most recent values, not the values at call time).
20
+ - post-mortem "exit" bug fixed.
21
+ - More Emacs-friendly: rdebug-track.el will track location inside an Emacs
22
+ shell. Emacs position information is shown in breakpoints and catchpoints
23
+ similar to gdba. Commands to position in another window a unit test traceback
24
+ or ruby traceback. Much more work invisioned for Emacs.
25
+ - INCOMPATIBLE CHANGE: "break" now sets a breakpoint on the current line
26
+ (same as gdb). Use "info break" for a list of breakpoints.
27
+ - INCOMPATIBLE CHANGE: "script" command removed. Use "source" command instead
28
+ (same as gdb).
29
+ - Run .rdebugrc on Debugger.start. Look for a file in the current directory and
30
+ run that instead the one in $HOME if that exists. Again, inspired and compatible
31
+ with gdb.
32
+ - Changes compatible with Ruby 1.9. NOTE: this debugger will NOT work with
33
+ Ruby 1.9
34
+ - leaving irb shows position same as entering debugger; "list" position
35
+ is also cleared when leaving irb
36
+ - help "foo" gives message "Undefined command "foo" rather than a list
37
+ of help commands. (Message test is gdb's)
38
+ - Add set linetrace+ - similar step+ for linetrace
39
+ - Start unit tests.
40
+ - Start a reference guide.
41
+
1
42
  0.9.3
2
43
  - Fixed if..elsif..end stepping.
3
44
  - From irb session Ctrl-C or 'cont' command continues execution without showing the debugger prompt.
data/ChangeLog ADDED
File without changes
data/README CHANGED
@@ -9,9 +9,10 @@ The faster execution speed is achieved by utilizing a new hook Ruby C API.
9
9
 
10
10
  ruby-debug requires Ruby 1.8.4 or higher.
11
11
 
12
- If you are running Linux or Unix you'll need a C compiler so the extension
13
- can be compiled when it is installed.
14
-
12
+ Unless you get the packages as a binary (Microsoft Windows binaries
13
+ are sometimes available), you'll need a C compiler and Ruby
14
+ development headers, and a Make program so the extension in
15
+ ruby-debug-base can be compiled when it is installed.
15
16
 
16
17
  == Install
17
18
 
@@ -19,6 +20,18 @@ ruby-debug is provided as a RubyGem. To install:
19
20
 
20
21
  <tt>gem install ruby-debug</tt>
21
22
 
23
+ This should also pull in <tt>ruby-debug-base</tt> as a dependency.
24
+
25
+ For Emacs support and the Reference Manual, get
26
+ <tt>ruby-debug-extra</tt>. This is not a RubyGem, you'll need a Make
27
+ program and a POSIX shell. With this installed, run:
28
+
29
+ <pre>
30
+ sh ./configure
31
+ make
32
+ make install
33
+ </pre>
34
+
22
35
  == Usage
23
36
 
24
37
  There are two ways of running ruby-debug.
@@ -34,9 +47,9 @@ to set up your breakpoints.
34
47
  === ruby-debug API
35
48
 
36
49
  The second way is to use the ruby-debug API to interrupt your
37
- code execution at runtime.
50
+ code execution at run time.
38
51
 
39
- require 'ruby-debug'
52
+ require 'ruby-debug' ; Debugger.start
40
53
  ...
41
54
  def your_method
42
55
  ...
@@ -49,14 +62,15 @@ and you will be able to inspect and step through your code.
49
62
 
50
63
  == Performance
51
64
 
52
- The debug.rb script that comes with the standard library uses
53
- Kernel#set_trace_func API. This way it is possible to implement
54
- the debugger in pure Ruby, but has a negative effect on the speed
55
- of your program execution. For each trace call Ruby interpreter
56
- creates a Binding object, even though it is not being used most
57
- of the time. ruby-debug library moves most of the functionality
58
- of debug.rb to a native extension, this way significantly improving
59
- the execution of your program.
65
+ The debug.rb script that comes with the standard Ruby library uses
66
+ Kernel#set_trace_func API. Implementing the debugger in pure Ruby has
67
+ a negative impact on the speed of your program execution. This is
68
+ because the Ruby interpreter creates a Binding object each trace call,
69
+ even though it is not being used most of the time. ruby-debug moves
70
+ most of the functionality for Binding access and for breakpoint
71
+ testing to a native extension. Because this code is in C and because
72
+ and can be selectively enabled or disabled, the overhead in running
73
+ your program can be minimized.
60
74
 
61
75
  == License
62
76
 
data/Rakefile ADDED
@@ -0,0 +1,220 @@
1
+ #!/usr/bin/env rake
2
+ # -*- Ruby -*-
3
+ require 'rubygems'
4
+ require 'rake/gempackagetask'
5
+ require 'rake/rdoctask'
6
+ require 'rake/testtask'
7
+
8
+ SO_NAME = "ruby_debug.so"
9
+
10
+ # ------- Default Package ----------
11
+ RUBY_DEBUG_VERSION = open("ext/ruby_debug.c"){|f| f.grep(/^#define DEBUG_VERSION/).first[/"(.+)"/,1]}
12
+
13
+ COMMON_FILES = FileList[
14
+ 'AUTHORS',
15
+ 'CHANGES',
16
+ 'LICENSE',
17
+ 'README',
18
+ 'Rakefile',
19
+ ]
20
+
21
+ CLI_TEST_FILE_LIST = 'test/**/*test-*.rb'
22
+ CLI_FILES = COMMON_FILES + FileList[
23
+ "cli/**/*",
24
+ 'ChangeLog',
25
+ 'bin/*',
26
+ 'doc/rdebug.1',
27
+ 'test/**/*.cmd',
28
+ 'test/**/*.right',
29
+ 'test/**/gcd.rb',
30
+ 'test/**/helper.rb',
31
+ 'test/**/info-var-bug.rb',
32
+ 'test/**/tdebug.rb',
33
+ 'test/**/test-*.cmd',
34
+ 'runner.sh',
35
+ CLI_TEST_FILE_LIST,
36
+ ]
37
+
38
+ BASE_TEST_FILE_LIST = 'test/test-ruby-debug-base.rb'
39
+ BASE_FILES = COMMON_FILES + FileList[
40
+ 'lib/**/*',
41
+ 'ext/ChangeLog',
42
+ 'ext/ruby_debug.c',
43
+ 'ext/extconf.rb',
44
+ 'ext/win32/*',
45
+ BASE_TEST_FILE_LIST,
46
+ ]
47
+
48
+ desc "Test everything."
49
+ test_task = task :test => :lib do
50
+ Rake::TestTask.new(:test) do |t|
51
+ t.libs << ['./ext', './lib', './cli']
52
+ t.pattern = CLI_TEST_FILE_LIST
53
+ t.verbose = true
54
+ end
55
+ end
56
+
57
+ desc "Test everything - same as test."
58
+ task :check => :test
59
+
60
+ desc "Create the core ruby-debug shared library extension"
61
+ task :lib do
62
+ Dir.chdir("ext") do
63
+ system("#{Gem.ruby} extconf.rb && make")
64
+ end
65
+ end
66
+
67
+ desc "Compile Emacs code"
68
+ task :emacs => "emacs/rdebug.elc"
69
+ file "emacs/rdebug.elc" => ["emacs/elisp-comp", "emacs/rdebug.el"] do
70
+ Dir.chdir("emacs") do
71
+ system("./elisp-comp ./rdebug.el")
72
+ end
73
+ end
74
+
75
+ desc "Create a GNU-style ChangeLog via svn2cl"
76
+ task :ChangeLog do
77
+ system("svn2cl --authors=svn2cl_usermap svn://rubyforge.org/var/svn/ruby-debug/trunk")
78
+ system("svn2cl --authors=svn2cl_usermap svn://rubyforge.org/var/svn/ruby-debug/trunk/ext -o ext/ChangeLog")
79
+ system("svn2cl --authors=svn2cl_usermap svn://rubyforge.org/var/svn/ruby-debug/trunk/lib -o lib/ChangeLog")
80
+ end
81
+
82
+ # Base GEM Specification
83
+ base_spec = Gem::Specification.new do |spec|
84
+ spec.name = "ruby-debug-base"
85
+
86
+ spec.homepage = "http://rubyforge.org/projects/ruby-debug/"
87
+ spec.summary = "Fast Ruby debugger - core component"
88
+ spec.description = <<-EOF
89
+ ruby-debug is a fast implementation of the standard Ruby debugger debug.rb.
90
+ It is implemented by utilizing a new Ruby C API hook. The core component
91
+ provides support that front-ends can build on. It provides breakpoint
92
+ handling, bindings for stack frames among other things.
93
+ EOF
94
+
95
+ spec.version = RUBY_DEBUG_VERSION
96
+
97
+ spec.author = "Kent Sibilev"
98
+ spec.email = "ksibilev@yahoo.com"
99
+ spec.platform = Gem::Platform::RUBY
100
+ spec.require_path = "lib"
101
+ spec.extensions = ["ext/extconf.rb"]
102
+ spec.autorequire = "ruby-debug-base"
103
+ spec.files = BASE_FILES.to_a
104
+
105
+ spec.required_ruby_version = '>= 1.8.2'
106
+ spec.date = Time.now
107
+ spec.rubyforge_project = 'ruby-debug'
108
+
109
+ spec.test_files = FileList[BASE_TEST_FILE_LIST]
110
+
111
+ # rdoc
112
+ spec.has_rdoc = true
113
+ spec.extra_rdoc_files = ['README', 'ext/ruby_debug.c']
114
+ end
115
+
116
+ cli_spec = Gem::Specification.new do |spec|
117
+ spec.name = "ruby-debug"
118
+
119
+ spec.homepage = "http://rubyforge.org/projects/ruby-debug/"
120
+ spec.summary = "Command line interface (CLI) for ruby-debug-base"
121
+ spec.description = <<-EOF
122
+ A generic command line interface for ruby-debug.
123
+ EOF
124
+
125
+ spec.version = RUBY_DEBUG_VERSION
126
+
127
+ spec.author = "Kent Sibilev"
128
+ spec.email = "ksibilev@yahoo.com"
129
+ spec.platform = Gem::Platform::RUBY
130
+ spec.require_path = "cli"
131
+ spec.bindir = "bin"
132
+ spec.executables = ["rdebug"]
133
+ spec.autorequire = "ruby-debug"
134
+ spec.files = CLI_FILES.to_a
135
+
136
+ spec.required_ruby_version = '>= 1.8.2'
137
+ spec.date = Time.now
138
+ spec.rubyforge_project = 'ruby-debug'
139
+ spec.add_dependency('ruby-debug-base', RUBY_DEBUG_VERSION)
140
+
141
+ # FIXME: work out operational logistics for this
142
+ # spec.test_files = FileList[CLI_TEST_FILE_LIST]
143
+
144
+ # rdoc
145
+ spec.has_rdoc = true
146
+ spec.extra_rdoc_files = ['README']
147
+ end
148
+
149
+ # Rake task to build the default package
150
+ Rake::GemPackageTask.new(base_spec) do |pkg|
151
+ pkg.need_tar = true
152
+ end
153
+ Rake::GemPackageTask.new(cli_spec) do |pkg|
154
+ pkg.need_tar = true
155
+ end
156
+
157
+ task :default => [:package]
158
+
159
+ # Windows specification
160
+ win_spec = base_spec.clone
161
+ win_spec.extensions = []
162
+ win_spec.platform = Gem::Platform::WIN32
163
+ win_spec.files += ["lib/#{SO_NAME}"]
164
+
165
+ desc "Create Windows Gem"
166
+ task :win32_gem do
167
+ # Copy the win32 extension the top level directory
168
+ current_dir = File.expand_path(File.dirname(__FILE__))
169
+ source = File.join(current_dir, "ext", "win32", SO_NAME)
170
+ target = File.join(current_dir, "lib", SO_NAME)
171
+ cp(source, target)
172
+
173
+ # Create the gem, then move it to pkg
174
+ Gem::Builder.new(win_spec).build
175
+ gem_file = "#{win_spec.name}-#{win_spec.version}-#{win_spec.platform}.gem"
176
+ mv(gem_file, "pkg/#{gem_file}")
177
+
178
+ # Remove win extension fro top level directory
179
+ rm(target)
180
+ end
181
+
182
+ desc "Publish ruby-debug to RubyForge."
183
+ task :publish do
184
+ require 'rake/contrib/sshpublisher'
185
+
186
+ # Get ruby-debug path
187
+ ruby_debug_path = File.expand_path(File.dirname(__FILE__))
188
+
189
+ publisher = Rake::SshDirPublisher.new("kent@rubyforge.org",
190
+ "/var/www/gforge-projects/ruby-debug", ruby_debug_path)
191
+ end
192
+
193
+ desc "Remove built files"
194
+ task :clean do
195
+ cd "ext" do
196
+ if File.exists?("Makefile")
197
+ sh "make clean"
198
+ rm "Makefile"
199
+ end
200
+ derived_files = Dir.glob(".o") + Dir.glob("*.so")
201
+ rm derived_files unless derived_files.empty?
202
+ end
203
+ end
204
+
205
+ # --------- RDoc Documentation ------
206
+ desc "Generate rdoc documentation"
207
+ Rake::RDocTask.new("rdoc") do |rdoc|
208
+ rdoc.rdoc_dir = 'doc'
209
+ rdoc.title = "ruby-debug"
210
+ # Show source inline with line numbers
211
+ rdoc.options << "--inline-source" << "--line-numbers"
212
+ # Make the readme file the start page for the generated html
213
+ rdoc.options << '--main' << 'README'
214
+ rdoc.rdoc_files.include('bin/**/*',
215
+ 'lib/**/*.rb',
216
+ 'ext/**/ruby_debug.c',
217
+ 'README',
218
+ 'LICENSE')
219
+ end
220
+
data/bin/rdebug CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # -*- Ruby -*-
2
3
 
3
4
  require 'rubygems'
4
5
  require 'optparse'
@@ -6,75 +7,124 @@ require "ostruct"
6
7
  require 'ruby-debug'
7
8
 
8
9
  options = OpenStruct.new(
9
- 'server' => false,
10
+ 'annotate' => Debugger.annotate,
10
11
  'client' => false,
11
- 'debug_module'=> 'debug',
12
+ 'control' => true,
13
+ 'cport' => Debugger::PORT + 1,
14
+ 'frame_bind' => false,
12
15
  'host' => nil,
16
+ 'no-quit' => false,
17
+ 'no-stop' => false,
18
+ 'nx' => false,
13
19
  'port' => Debugger::PORT,
14
- 'cport' => Debugger::PORT + 1,
15
- 'control' => true,
16
- 'wait' => false,
17
- 'nostop' => false,
18
20
  'post_mortem' => false,
19
21
  'script' => nil,
22
+ 'server' => false,
20
23
  'tracing' => false,
21
- 'frame_bind' => false
24
+ 'verbose_long'=> false,
25
+ 'wait' => false
22
26
  )
23
27
 
28
+ program = File.basename($0)
24
29
  opts = OptionParser.new do |opts|
25
30
  opts.banner = <<EOB
26
- ruby-debug #{Debugger::VERSION}
27
- Usage: rdebug [options] <script.rb> -- <script.rb parameters>
31
+ #{program} #{Debugger::VERSION}
32
+ Usage: #{program} [options] <script.rb> -- <script.rb parameters>
28
33
  EOB
29
34
  opts.separator ""
30
35
  opts.separator "Options:"
31
- opts.on("-s", "--server", "Listen for remote connections") {options.server = true}
32
- opts.on("-w", "--wait", "Wait for a client connection, implies -s option") {options.wait = true}
33
- opts.on("-c", "--client", "Connect to remote debugger") {options.client = true}
34
- opts.on("-h", "--host HOST", "Host name used for remote debugging") {|options.host|}
35
- opts.on("-p", "--port PORT", Integer, "Port used for remote debugging") {|options.port|}
36
- opts.on("--cport PORT", Integer, "Port used for contol commands") {|options.cport|}
37
- opts.on("--no-control", "Do not automatically start control thread") {options.control = false}
38
- opts.on("-x", "--trace", "turn on line tracing") {options.tracing = true}
39
- opts.on("-n", "--nostop", "Do not stop when stript is loaded") {options.nostop = true}
40
- opts.on("-m", "--post-mortem", "Activate post-mortem mode") {options.post_mortem = true}
36
+ opts.on("-A", "--annotate LEVEL", Integer, "Set annotation level") do
37
+ |Debugger::annotate|
38
+ end
39
+ opts.on("-c", "--client", "Connect to remote debugger") do
40
+ options.client = true
41
+ end
42
+ opts.on("--cport PORT", Integer, "Port used for control commands") do
43
+ |options.cport|
44
+ end
45
+ opts.on("-d", "--debug", "Set $DEBUG=true") {$DEBUG = true}
46
+ opts.on("--emacs", "Activates emacs mode") {ENV['EMACS'] = '1'}
47
+ opts.on("-h", "--host HOST", "Host name used for remote debugging") do
48
+ |options.host|
49
+ end
41
50
  opts.on("-I", "--include PATH", String, "Add PATH to $LOAD_PATH") do |path|
42
51
  $LOAD_PATH.unshift(path)
43
52
  end
44
- opts.on("--script FILE", String, "Name of the script file to run") do |options.script|
53
+ opts.on("--keep-frame-binding", "Keep frame bindings") do
54
+ options.frame_bind = true
55
+ end
56
+ opts.on("-m", "--post-mortem", "Activate post-mortem mode") do
57
+ options.post_mortem = true
58
+ end
59
+ opts.on("--no-control", "Do not automatically start control thread") do
60
+ options.control = false
61
+ end
62
+ opts.on("--no-quit", "Do not quit when script finishes") do
63
+ options.noquit = true
64
+ end
65
+ opts.on("-n", "--no-stop", "Do not stop when script is loaded") do
66
+ options.nostop = true
67
+ end
68
+ opts.on("-nx", "Not run debugger initialization files (e.g. .rdebugrc") do
69
+ options.nx = true
70
+ end
71
+ opts.on("-p", "--port PORT", Integer, "Port used for remote debugging") do
72
+ |options.port|
73
+ end
74
+ opts.on("-r", "--require SCRIPT", String,
75
+ "Require the library, before executing your script") do |name|
76
+ if name == 'debug'
77
+ puts "ruby-debug is not compatible with Ruby's 'debug' library. This option is ignored."
78
+ else
79
+ require name
80
+ end
81
+ end
82
+ opts.on("--script FILE", String, "Name of the script file to run") do
83
+ |options.script|
45
84
  unless File.exists?(options.script)
46
85
  puts "Script file '#{options.script}' is not found"
47
86
  exit
48
87
  end
49
88
  end
50
- opts.on("-r", "--require debug", String,
51
- "Compatibility with Ruby-distributed debug module") do |options.debug_module|
52
- if options.debug_module != 'debug'
53
- puts "Use '-r' option only with 'debug' (You supplied '#{options.debug_module}'). " +
54
- "This option is ignored."
55
- end
89
+ opts.on("-s", "--server", "Listen for remote connections") do
90
+ options.server = true
56
91
  end
57
- opts.on("--keep-frame-binding", "Keep frame bindings") {options.frame_bind = true}
58
- opts.on("--emacs", "Activates emacs mode") {ENV['EMACS'] = '1'}
92
+ opts.on("-w", "--wait", "Wait for a client connection, implies -s option") do
93
+ options.wait = true
94
+ end
95
+ opts.on("-x", "--trace", "Turn on line tracing") {options.tracing = true}
59
96
  opts.separator ""
60
97
  opts.separator "Common options:"
61
98
  opts.on_tail("--help", "Show this message") do
62
99
  puts opts
63
100
  exit
64
101
  end
65
- opts.on_tail("-v", "--version", "Show version") do
102
+ opts.on_tail("--version",
103
+ "Print the version") do
66
104
  puts "ruby-debug #{Debugger::VERSION}"
67
105
  exit
68
106
  end
107
+ opts.on("--verbose", "Turn on verbose mode") do
108
+ $VERBOSE = true
109
+ options.verbose_long = true
110
+ end
111
+ opts.on_tail("-v",
112
+ "Print version number, then turn on verbose mode") do
113
+ puts "ruby-debug #{Debugger::VERSION}"
114
+ $VERBOSE = true
115
+ end
69
116
  end
70
117
 
71
118
  begin
72
- Debugger::ARGV = ARGV.clone
119
+ if not defined? Debugger::ARGV
120
+ Debugger::ARGV = ARGV.clone
121
+ end
73
122
  rdebug_path = File.expand_path($0)
74
123
  if RUBY_PLATFORM =~ /mswin/
75
124
  rdebug_path += ".cmd" unless rdebug_path =~ /\.cmd$/i
76
125
  end
77
126
  Debugger::RDEBUG_SCRIPT = rdebug_path
127
+ Debugger::INITIAL_DIR = Dir.pwd
78
128
  opts.parse! ARGV
79
129
  rescue StandardError => e
80
130
  puts opts
@@ -87,12 +137,13 @@ if options.client
87
137
  Debugger.start_client(options.host, options.port)
88
138
  else
89
139
  if ARGV.empty?
140
+ exit if $VERBOSE and not options.verbose_long
90
141
  puts opts
91
142
  puts
92
143
  puts "Must specify a script to run"
93
144
  exit(-1)
94
145
  end
95
-
146
+
96
147
  # save script name
97
148
  Debugger::PROG_SCRIPT = ARGV.shift
98
149
 
@@ -103,16 +154,12 @@ else
103
154
  Debugger.wait_connection = options.wait
104
155
  Debugger.keep_frame_binding = options.frame_bind
105
156
 
106
- load_initrc = lambda do
107
- script_file = "#{ENV["HOME"] || ENV["HOMEPATH" || "."]}/.rdebugrc"
108
- Debugger.run_script script_file, StringIO.new if File.exists?(script_file)
109
- end
110
-
111
157
  if options.server
112
158
  # start remote mode
113
- Debugger.start_remote(options.host, [options.port, options.cport], options.post_mortem) do
159
+ Debugger.start_remote(options.host, [options.port, options.cport],
160
+ options.post_mortem) do
114
161
  # load initrc script
115
- load_initrc.call
162
+ Debugger.run_init_script(StringIO.new) unless options.nx
116
163
  end
117
164
  # load script
118
165
  Debugger.debug_load Debugger::PROG_SCRIPT, !options.nostop
@@ -122,8 +169,8 @@ else
122
169
  # start control thread
123
170
  Debugger.start_control(options.host, options.cport) if options.control
124
171
 
125
- # load initrc script
126
- load_initrc.call
172
+ # load initrc script (e.g. .rdebugrc)
173
+ Debugger.run_init_script(StringIO.new) unless options.nx
127
174
 
128
175
  # run startup script if specified
129
176
  if options.script
@@ -132,7 +179,34 @@ else
132
179
  # activate post-mortem
133
180
  Debugger.post_mortem if options.post_mortem
134
181
  Debugger.tracing = options.nostop = true if options.tracing
135
- # load script
136
- Debugger.debug_load Debugger::PROG_SCRIPT, !options.nostop
182
+
183
+ # Make sure Ruby script syntax checks okay.
184
+ # Otherwise we get a load message that looks like rdebug has
185
+ # a problem.
186
+ output = `ruby -c #{Debugger::PROG_SCRIPT} 2>&1`
187
+ if $?.exitstatus != 0 and RUBY_PLATFORM !~ /mswin/
188
+ puts output
189
+ exit $?.exitstatus
190
+ end
191
+ if options.noquit
192
+ Debugger.stop if Debugger.started?
193
+ while true do
194
+ begin
195
+ Debugger.debug_load Debugger::PROG_SCRIPT, !options.nostop
196
+ rescue
197
+ print $!.backtrace.map{|l| "\t#{l}"}.join("\n"), "\n"
198
+ print "Uncaught exception: #{$!}\n"
199
+ end
200
+ # FIXME: add status for whether we are interactive or not.
201
+ # if STDIN.tty? and !options.nostop
202
+ if !options.nostop
203
+ print "The program has finished and will be restarted.\n"
204
+ else
205
+ break
206
+ end
207
+ end
208
+ else
209
+ Debugger.debug_load Debugger::PROG_SCRIPT, !options.nostop
210
+ end
137
211
  end
138
212
  end