ruby-debug 0.10.0 → 0.10.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +94 -2
- data/ChangeLog +5225 -0
- data/README +30 -1
- data/Rakefile +55 -24
- data/bin/rdebug +249 -128
- data/cli/ruby-debug/command.rb +30 -3
- data/cli/ruby-debug/commands/breakpoints.rb +54 -24
- data/cli/ruby-debug/commands/catchpoint.rb +13 -12
- data/cli/ruby-debug/commands/condition.rb +49 -0
- data/cli/ruby-debug/commands/continue.rb +32 -0
- data/cli/ruby-debug/commands/control.rb +19 -43
- data/cli/ruby-debug/commands/disassemble.RB +38 -0
- data/cli/ruby-debug/commands/display.rb +1 -1
- data/cli/ruby-debug/commands/edit.rb +48 -0
- data/cli/ruby-debug/commands/enable.rb +78 -35
- data/cli/ruby-debug/commands/eval.rb +6 -5
- data/cli/ruby-debug/commands/finish.rb +42 -0
- data/cli/ruby-debug/commands/frame.rb +64 -33
- data/cli/ruby-debug/commands/help.rb +19 -15
- data/cli/ruby-debug/commands/info.rb +295 -36
- data/cli/ruby-debug/commands/irb.rb +3 -1
- data/cli/ruby-debug/commands/list.rb +27 -50
- data/cli/ruby-debug/commands/quit.rb +38 -0
- data/cli/ruby-debug/commands/reload.rb +40 -0
- data/cli/ruby-debug/commands/save.rb +80 -0
- data/cli/ruby-debug/commands/{settings.rb → set.rb} +50 -12
- data/cli/ruby-debug/commands/show.rb +83 -27
- data/cli/ruby-debug/commands/source.rb +36 -0
- data/cli/ruby-debug/commands/stepping.rb +36 -72
- data/cli/ruby-debug/commands/threads.rb +32 -23
- data/cli/ruby-debug/commands/variables.rb +34 -4
- data/cli/ruby-debug/helper.rb +10 -75
- data/cli/ruby-debug/interface.rb +72 -9
- data/cli/ruby-debug/processor.rb +203 -100
- data/doc/rdebug.1 +7 -2
- data/rdbg.rb +33 -0
- data/test/{test-ruby-debug-base.rb → base/base.rb} +27 -29
- data/test/base/binding.rb +31 -0
- data/test/base/catchpoint.rb +26 -0
- data/test/base/load.rb +40 -0
- data/test/data/annotate.cmd +29 -0
- data/test/data/annotate.right +137 -0
- data/test/data/break_bad.cmd +18 -0
- data/test/data/break_bad.right +28 -0
- data/test/data/breakpoints.cmd +38 -0
- data/test/data/breakpoints.right +98 -0
- data/test/data/condition.cmd +28 -0
- data/test/data/condition.right +65 -0
- data/test/data/ctrl.cmd +23 -0
- data/test/data/ctrl.right +69 -0
- data/test/{display.cmd → data/display.cmd} +7 -1
- data/test/{display.right → data/display.right} +13 -6
- data/test/data/dollar-0.right +2 -0
- data/test/data/dollar-0a.right +2 -0
- data/test/data/dollar-0b.right +2 -0
- data/test/data/edit.cmd +12 -0
- data/test/data/edit.right +19 -0
- data/test/{breakpoints.cmd → data/emacs_basic.cmd} +0 -0
- data/test/{breakpoints.right → data/emacs_basic.right} +24 -12
- data/test/data/enable.cmd +20 -0
- data/test/data/enable.right +36 -0
- data/test/data/finish.cmd +16 -0
- data/test/data/finish.right +43 -0
- data/test/{frame.cmd → data/frame.cmd} +2 -0
- data/test/{frame.right → data/frame.right} +8 -2
- data/test/{help.cmd → data/help.cmd} +8 -0
- data/test/data/help.right +21 -0
- data/test/data/history.right +7 -0
- data/test/data/info-thread.cmd +13 -0
- data/test/data/info-thread.right +37 -0
- data/test/data/info-var-bug2.cmd +5 -0
- data/test/data/info-var-bug2.right +10 -0
- data/test/{info-var.cmd → data/info-var.cmd} +3 -3
- data/test/{info-var.right → data/info-var.right} +20 -15
- data/test/{info.cmd → data/info.cmd} +10 -1
- data/test/data/info.right +65 -0
- data/test/data/linetrace.cmd +6 -0
- data/test/data/linetrace.right +32 -0
- data/test/data/linetracep.cmd +7 -0
- data/test/data/linetracep.right +25 -0
- data/test/data/list.cmd +19 -0
- data/test/data/list.right +127 -0
- data/test/data/noquit.right +1 -0
- data/test/data/output.cmd +6 -0
- data/test/data/output.right +41 -0
- data/test/data/post-mortem-next.cmd +8 -0
- data/test/data/post-mortem-next.right +14 -0
- data/test/data/post-mortem-osx.right +31 -0
- data/test/data/post-mortem.cmd +13 -0
- data/test/data/post-mortem.right +31 -0
- data/test/{quit.cmd → data/quit.cmd} +2 -5
- data/test/data/quit.right +9 -0
- data/test/data/raise.cmd +11 -0
- data/test/data/raise.right +26 -0
- data/test/{setshow.cmd → data/setshow.cmd} +0 -1
- data/test/{setshow.right → data/setshow.right} +0 -1
- data/test/data/source.cmd +5 -0
- data/test/data/source.right +15 -0
- data/test/{stepping.cmd → data/stepping.cmd} +6 -2
- data/test/{stepping.right → data/stepping.right} +13 -3
- data/test/data/test-init-cygwin.right +7 -0
- data/test/data/test-init-osx.right +4 -0
- data/test/data/test-init.right +5 -0
- data/test/data/trace.right +23 -0
- data/test/dollar-0.rb +5 -0
- data/test/except-bug2.rb +7 -0
- data/test/gcd-dbg-nox.rb +31 -0
- data/test/gcd-dbg.rb +30 -0
- data/test/helper.rb +44 -14
- data/test/info-var-bug.rb +2 -0
- data/test/info-var-bug2.rb +2 -0
- data/test/null.rb +1 -0
- data/test/output.rb +2 -0
- data/test/pm-base.rb +22 -0
- data/test/pm.rb +11 -0
- data/test/raise.rb +3 -0
- data/test/tdebug.rb +88 -40
- data/test/test-annotate.rb +25 -0
- data/test/test-break-bad.rb +25 -0
- data/test/test-breakpoints.rb +14 -17
- data/test/test-condition.rb +25 -0
- data/test/test-ctrl.rb +54 -0
- data/test/test-display.rb +15 -15
- data/test/test-dollar-0.rb +39 -0
- data/test/test-edit.rb +26 -0
- data/test/test-emacs-basic.rb +26 -0
- data/test/test-enable.rb +25 -0
- data/test/test-finish.rb +34 -0
- data/test/test-frame.rb +15 -16
- data/test/test-help.rb +34 -18
- data/test/test-hist.rb +68 -0
- data/test/test-info-thread.rb +32 -0
- data/test/test-info-var.rb +28 -14
- data/test/test-info.rb +15 -17
- data/test/test-init.rb +41 -0
- data/test/test-list.rb +25 -0
- data/test/test-output.rb +26 -0
- data/test/test-pm.rb +46 -0
- data/test/test-quit.rb +19 -17
- data/test/test-raise.rb +25 -0
- data/test/test-setshow.rb +14 -13
- data/test/test-source.rb +25 -0
- data/test/test-stepping.rb +14 -14
- data/test/test-trace.rb +63 -0
- data/test/thread1.rb +26 -0
- metadata +125 -31
- data/cli/ruby-debug/commands/script.rb +0 -64
- data/runner.sh +0 -7
- data/test/help.right +0 -4
- data/test/info.right +0 -35
- data/test/quit.right +0 -22
- data/test/test-columnize.rb +0 -46
data/README
CHANGED
@@ -14,6 +14,12 @@ are sometimes available), you'll need a C compiler and Ruby
|
|
14
14
|
development headers, and a Make program so the extension in
|
15
15
|
ruby-debug-base can be compiled when it is installed.
|
16
16
|
|
17
|
+
To install on Microsoft Windows, unless you run under cygwin or mingw
|
18
|
+
you'll need Microsoft Visual C++ 6.0 also known as VC6.
|
19
|
+
http://rubyforge.org/tracker/index.php?func=detail&aid=16774&group_id=1900&atid=7436
|
20
|
+
suggests why.
|
21
|
+
|
22
|
+
|
17
23
|
== Install
|
18
24
|
|
19
25
|
ruby-debug is provided as a RubyGem. To install:
|
@@ -22,6 +28,10 @@ ruby-debug is provided as a RubyGem. To install:
|
|
22
28
|
|
23
29
|
This should also pull in <tt>ruby-debug-base</tt> as a dependency.
|
24
30
|
|
31
|
+
(If you install ruby-debug-base explicitly, you can add in the secret
|
32
|
+
--test option after "install" to have the regression test run before
|
33
|
+
installing.)
|
34
|
+
|
25
35
|
For Emacs support and the Reference Manual, get
|
26
36
|
<tt>ruby-debug-extra</tt>. This is not a RubyGem, you'll need a Make
|
27
37
|
program and a POSIX shell. With this installed, run:
|
@@ -29,9 +39,28 @@ program and a POSIX shell. With this installed, run:
|
|
29
39
|
<pre>
|
30
40
|
sh ./configure
|
31
41
|
make
|
32
|
-
make
|
42
|
+
make test # optional, but a good idea
|
43
|
+
sudo make install
|
33
44
|
</pre>
|
34
45
|
|
46
|
+
==== Install on MS Windows
|
47
|
+
|
48
|
+
Compiling under cygwin or mingw works like it does on Unix.
|
49
|
+
|
50
|
+
* Have Microsoft Visual C++ 6.0 (VC6) installed - exactly that version.
|
51
|
+
|
52
|
+
* Set the appropriate environment variables.
|
53
|
+
|
54
|
+
* run `nmake'.
|
55
|
+
|
56
|
+
* Copy ruby_debug.so to `win32'.
|
57
|
+
|
58
|
+
* Go to the ruby_debug root.
|
59
|
+
|
60
|
+
* rake win32_gem
|
61
|
+
|
62
|
+
* The file is in named `rdebug-debug-base-0.10.0-mswin32.gem'.
|
63
|
+
|
35
64
|
== Usage
|
36
65
|
|
37
66
|
There are two ways of running ruby-debug.
|
data/Rakefile
CHANGED
@@ -8,7 +8,9 @@ require 'rake/testtask'
|
|
8
8
|
SO_NAME = "ruby_debug.so"
|
9
9
|
|
10
10
|
# ------- Default Package ----------
|
11
|
-
RUBY_DEBUG_VERSION = open("ext/ruby_debug.c")
|
11
|
+
RUBY_DEBUG_VERSION = open("ext/ruby_debug.c") do |f|
|
12
|
+
f.grep(/^#define DEBUG_VERSION/).first[/"(.+)"/,1]
|
13
|
+
end
|
12
14
|
|
13
15
|
COMMON_FILES = FileList[
|
14
16
|
'AUTHORS',
|
@@ -18,35 +20,35 @@ COMMON_FILES = FileList[
|
|
18
20
|
'Rakefile',
|
19
21
|
]
|
20
22
|
|
21
|
-
CLI_TEST_FILE_LIST = 'test
|
23
|
+
CLI_TEST_FILE_LIST = 'test/test-*.rb'
|
22
24
|
CLI_FILES = COMMON_FILES + FileList[
|
23
25
|
"cli/**/*",
|
24
26
|
'ChangeLog',
|
25
27
|
'bin/*',
|
26
28
|
'doc/rdebug.1',
|
27
|
-
'test
|
28
|
-
'test
|
29
|
-
'test
|
30
|
-
'
|
31
|
-
'test/**/info-var-bug.rb',
|
32
|
-
'test/**/tdebug.rb',
|
33
|
-
'test/**/test-*.cmd',
|
34
|
-
'runner.sh',
|
29
|
+
'test/**/data/*.cmd',
|
30
|
+
'test/**/data/*.right',
|
31
|
+
'test/**/*.rb',
|
32
|
+
'rdbg.rb',
|
35
33
|
CLI_TEST_FILE_LIST,
|
36
34
|
]
|
37
35
|
|
38
|
-
BASE_TEST_FILE_LIST =
|
36
|
+
BASE_TEST_FILE_LIST = %w(
|
37
|
+
test/base/base.rb
|
38
|
+
test/base/binding.rb
|
39
|
+
test/base/catchpoint.rb)
|
39
40
|
BASE_FILES = COMMON_FILES + FileList[
|
40
|
-
'
|
41
|
-
'ext/ChangeLog',
|
42
|
-
'ext/ruby_debug.c',
|
41
|
+
'ext/breakpoint.c',
|
43
42
|
'ext/extconf.rb',
|
43
|
+
'ext/ruby_debug.c',
|
44
|
+
'ext/ruby_debug.h',
|
44
45
|
'ext/win32/*',
|
46
|
+
'lib/**/*',
|
45
47
|
BASE_TEST_FILE_LIST,
|
46
48
|
]
|
47
49
|
|
48
50
|
desc "Test everything."
|
49
|
-
test_task = task :test => :lib do
|
51
|
+
test_task = task :test => [:lib, :test_base] do
|
50
52
|
Rake::TestTask.new(:test) do |t|
|
51
53
|
t.libs << ['./ext', './lib', './cli']
|
52
54
|
t.pattern = CLI_TEST_FILE_LIST
|
@@ -54,6 +56,15 @@ test_task = task :test => :lib do
|
|
54
56
|
end
|
55
57
|
end
|
56
58
|
|
59
|
+
desc "Test ruby-debug-base."
|
60
|
+
test_task = task :test_base => :lib do
|
61
|
+
Rake::TestTask.new(:test_base) do |t|
|
62
|
+
t.libs << ['./ext', './lib']
|
63
|
+
t.test_files = FileList[BASE_TEST_FILE_LIST]
|
64
|
+
t.verbose = true
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
57
68
|
desc "Test everything - same as test."
|
58
69
|
task :check => :test
|
59
70
|
|
@@ -99,12 +110,12 @@ EOF
|
|
99
110
|
spec.platform = Gem::Platform::RUBY
|
100
111
|
spec.require_path = "lib"
|
101
112
|
spec.extensions = ["ext/extconf.rb"]
|
102
|
-
spec.autorequire = "ruby-debug-base"
|
103
113
|
spec.files = BASE_FILES.to_a
|
104
114
|
|
105
115
|
spec.required_ruby_version = '>= 1.8.2'
|
106
116
|
spec.date = Time.now
|
107
117
|
spec.rubyforge_project = 'ruby-debug'
|
118
|
+
spec.add_dependency('linecache', '>= 0.3')
|
108
119
|
|
109
120
|
spec.test_files = FileList[BASE_TEST_FILE_LIST]
|
110
121
|
|
@@ -130,12 +141,12 @@ EOF
|
|
130
141
|
spec.require_path = "cli"
|
131
142
|
spec.bindir = "bin"
|
132
143
|
spec.executables = ["rdebug"]
|
133
|
-
spec.autorequire = "ruby-debug"
|
134
144
|
spec.files = CLI_FILES.to_a
|
135
145
|
|
136
146
|
spec.required_ruby_version = '>= 1.8.2'
|
137
147
|
spec.date = Time.now
|
138
148
|
spec.rubyforge_project = 'ruby-debug'
|
149
|
+
spec.add_dependency('columnize', '>= 0.1')
|
139
150
|
spec.add_dependency('ruby-debug-base', RUBY_DEBUG_VERSION)
|
140
151
|
|
141
152
|
# FIXME: work out operational logistics for this
|
@@ -159,7 +170,8 @@ task :default => [:package]
|
|
159
170
|
# Windows specification
|
160
171
|
win_spec = base_spec.clone
|
161
172
|
win_spec.extensions = []
|
162
|
-
win_spec.platform = Gem::Platform::WIN32
|
173
|
+
## win_spec.platform = Gem::Platform::WIN32 # deprecated
|
174
|
+
win_spec.platform = 'mswin32'
|
163
175
|
win_spec.files += ["lib/#{SO_NAME}"]
|
164
176
|
|
165
177
|
desc "Create Windows Gem"
|
@@ -170,20 +182,20 @@ task :win32_gem do
|
|
170
182
|
target = File.join(current_dir, "lib", SO_NAME)
|
171
183
|
cp(source, target)
|
172
184
|
|
173
|
-
# Create the gem, then move it to pkg
|
174
|
-
|
175
|
-
|
185
|
+
# Create the gem, then move it to pkg.
|
186
|
+
Gem::Builder.new(win_spec).build
|
187
|
+
gem_file = "#{win_spec.name}-#{win_spec.version}-#{win_spec.platform}.gem"
|
176
188
|
mv(gem_file, "pkg/#{gem_file}")
|
177
189
|
|
178
|
-
# Remove win extension
|
179
|
-
|
190
|
+
# Remove win extension from top level directory.
|
191
|
+
rm(target)
|
180
192
|
end
|
181
193
|
|
182
194
|
desc "Publish ruby-debug to RubyForge."
|
183
195
|
task :publish do
|
184
196
|
require 'rake/contrib/sshpublisher'
|
185
197
|
|
186
|
-
# Get ruby-debug path
|
198
|
+
# Get ruby-debug path.
|
187
199
|
ruby_debug_path = File.expand_path(File.dirname(__FILE__))
|
188
200
|
|
189
201
|
publisher = Rake::SshDirPublisher.new("kent@rubyforge.org",
|
@@ -218,3 +230,22 @@ Rake::RDocTask.new("rdoc") do |rdoc|
|
|
218
230
|
'LICENSE')
|
219
231
|
end
|
220
232
|
|
233
|
+
desc "Publish the release files to RubyForge."
|
234
|
+
task :rubyforge_upload do
|
235
|
+
`rubyforge login`
|
236
|
+
release_command = "rubyforge add_release #{PKG_NAME} #{PKG_NAME} '#{PKG_NAME}-#{PKG_VERSION}' pkg/#{PKG_NAME}-#{PKG_VERSION}.gem"
|
237
|
+
puts release_command
|
238
|
+
system(release_command)
|
239
|
+
end
|
240
|
+
|
241
|
+
PKG_NAME = 'ruby-debug'
|
242
|
+
desc "Publish the release files to RubyForge."
|
243
|
+
task :rubyforge_upload do
|
244
|
+
`rubyforge login`
|
245
|
+
for pkg_name in ['ruby-debug', 'ruby-debug-base'] do
|
246
|
+
pkg_file_name = "#{pkg_name}-#{pkg_version}"
|
247
|
+
release_command = "rubyforge add_release ruby-debug #{pkg_name} '#{pkg_file_name}' pkg/#{pkg_file_name}.gem"
|
248
|
+
puts release_command
|
249
|
+
system(release_command)
|
250
|
+
end
|
251
|
+
end
|
data/bin/rdebug
CHANGED
@@ -3,127 +3,243 @@
|
|
3
3
|
|
4
4
|
require 'rubygems'
|
5
5
|
require 'optparse'
|
6
|
-
require
|
6
|
+
require 'ostruct'
|
7
7
|
require 'ruby-debug'
|
8
8
|
|
9
|
+
def debug_program(options)
|
10
|
+
# Make sure Ruby script syntax checks okay.
|
11
|
+
# Otherwise we get a load message that looks like rdebug has
|
12
|
+
# a problem.
|
13
|
+
output = `ruby -c #{Debugger::PROG_SCRIPT} 2>&1`
|
14
|
+
if $?.exitstatus != 0 and RUBY_PLATFORM !~ /mswin/
|
15
|
+
puts output
|
16
|
+
exit $?.exitstatus
|
17
|
+
end
|
18
|
+
print "\032\032starting\n" if Debugger.annotate and Debugger.annotate > 2
|
19
|
+
unless options.no_rewrite_program
|
20
|
+
# Set $0 so things like __FILE == $0 work.
|
21
|
+
# A more reliable way to do this is to put $0 = __FILE__ *after*
|
22
|
+
# loading the script to be debugged. For this, adding a debug hook
|
23
|
+
# for the first time and then switching to the debug hook that's
|
24
|
+
# normally used would be helpful. Doing this would also help other
|
25
|
+
# first-time initializations such as reloading debugger state
|
26
|
+
# after a restart.
|
27
|
+
|
28
|
+
# However This is just a little more than I want to take on right
|
29
|
+
# now, so I think I'll stick with the slightly hacky approach.
|
30
|
+
$RDEBUG_0 = $0
|
31
|
+
|
32
|
+
# cygwin does some sort of funky truncation on $0 ./abcdef => ./ab
|
33
|
+
# probably something to do with 3-letter extension truncation.
|
34
|
+
# The hacky workaround is to do slice assignment. Ugh.
|
35
|
+
d0 = if '.' == File.dirname(Debugger::PROG_SCRIPT) and
|
36
|
+
Debugger::PROG_SCRIPT[0..0] != '.'
|
37
|
+
File.join('.', Debugger::PROG_SCRIPT)
|
38
|
+
else
|
39
|
+
Debugger::PROG_SCRIPT
|
40
|
+
end
|
41
|
+
$0[0..-1] = d0
|
42
|
+
end
|
43
|
+
bt = Debugger.debug_load(Debugger::PROG_SCRIPT, options.stop)
|
44
|
+
if bt
|
45
|
+
if options.post_mortem
|
46
|
+
Debugger.handle_post_mortem(bt)
|
47
|
+
else
|
48
|
+
print bt.backtrace.map{|l| "\t#{l}"}.join("\n"), "\n"
|
49
|
+
print "Uncaught exception: #{bt}\n"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# Do a shell-like path lookup for prog_script and return the results.
|
55
|
+
# If we can't find anything return prog_script.
|
56
|
+
def whence_file(prog_script)
|
57
|
+
if prog_script.index(File::SEPARATOR)
|
58
|
+
# Don't search since this name has path separator components
|
59
|
+
return prog_script
|
60
|
+
end
|
61
|
+
for dirname in ENV['PATH'].split(File::PATH_SEPARATOR) do
|
62
|
+
prog_script_try = File.join(dirname, prog_script)
|
63
|
+
return prog_script_try if File.exist?(prog_script_try)
|
64
|
+
end
|
65
|
+
# Failure
|
66
|
+
return prog_script
|
67
|
+
end
|
68
|
+
|
9
69
|
options = OpenStruct.new(
|
10
|
-
'annotate'
|
11
|
-
'client'
|
12
|
-
'control'
|
13
|
-
'cport'
|
14
|
-
'frame_bind'
|
15
|
-
'host'
|
16
|
-
'
|
17
|
-
'
|
18
|
-
'
|
19
|
-
'
|
20
|
-
'
|
21
|
-
'
|
22
|
-
'
|
23
|
-
'
|
24
|
-
'
|
25
|
-
'
|
70
|
+
'annotate' => Debugger.annotate,
|
71
|
+
'client' => false,
|
72
|
+
'control' => true,
|
73
|
+
'cport' => Debugger::PORT + 1,
|
74
|
+
'frame_bind' => false,
|
75
|
+
'host' => nil,
|
76
|
+
'quit' => true,
|
77
|
+
'no_rewrite_program' => false,
|
78
|
+
'stop' => true,
|
79
|
+
'nx' => false,
|
80
|
+
'port' => Debugger::PORT,
|
81
|
+
'post_mortem' => false,
|
82
|
+
'restart_script' => nil,
|
83
|
+
'script' => nil,
|
84
|
+
'server' => false,
|
85
|
+
'tracing' => false,
|
86
|
+
'verbose_long' => false,
|
87
|
+
'wait' => false
|
26
88
|
)
|
27
89
|
|
28
|
-
|
29
|
-
|
30
|
-
opts
|
90
|
+
def process_options(options)
|
91
|
+
program = File.basename($0)
|
92
|
+
opts = OptionParser.new do |opts|
|
93
|
+
opts.banner = <<EOB
|
31
94
|
#{program} #{Debugger::VERSION}
|
32
95
|
Usage: #{program} [options] <script.rb> -- <script.rb parameters>
|
33
96
|
EOB
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
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
|
50
|
-
opts.on("-I", "--include PATH", String, "Add PATH to $LOAD_PATH") do |path|
|
51
|
-
$LOAD_PATH.unshift(path)
|
52
|
-
end
|
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
|
97
|
+
opts.separator ""
|
98
|
+
opts.separator "Options:"
|
99
|
+
opts.on("-A", "--annotate LEVEL", Integer, "Set annotation level") do
|
100
|
+
|annotate|
|
101
|
+
Debugger.annotate = annotate
|
80
102
|
end
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
103
|
+
opts.on("-c", "--client", "Connect to remote debugger") do
|
104
|
+
options.client = true
|
105
|
+
end
|
106
|
+
opts.on("--cport PORT", Integer, "Port used for control commands") do
|
107
|
+
|cport|
|
108
|
+
options.cport = cport
|
109
|
+
end
|
110
|
+
opts.on("-d", "--debug", "Set $DEBUG=true") {$DEBUG = true}
|
111
|
+
opts.on("--emacs LEVEL", Integer,
|
112
|
+
"Activates full Emacs support at annotation level LEVEL") do
|
113
|
+
|level|
|
114
|
+
Debugger.annotate = level.to_i
|
115
|
+
ENV['EMACS'] = '1'
|
116
|
+
ENV['COLUMNS'] = '120' if ENV['COLUMNS'].to_i < 120
|
117
|
+
options.control = false
|
118
|
+
options.quit = false
|
119
|
+
options.post_mortem = true
|
120
|
+
end
|
121
|
+
opts.on('--emacs-basic', 'Activates basic Emacs mode') do
|
122
|
+
ENV['EMACS'] = '1'
|
123
|
+
end
|
124
|
+
opts.on('-h', '--host HOST', 'Host name used for remote debugging') do
|
125
|
+
|host|
|
126
|
+
options.host = host
|
127
|
+
end
|
128
|
+
opts.on('-I', '--include PATH', String, 'Add PATH to $LOAD_PATH') do |path|
|
129
|
+
$LOAD_PATH.unshift(path)
|
130
|
+
end
|
131
|
+
opts.on('--keep-frame-binding', 'Keep frame bindings') do
|
132
|
+
options.frame_bind = true
|
133
|
+
end
|
134
|
+
opts.on('-m', '--post-mortem', 'Activate post-mortem mode') do
|
135
|
+
options.post_mortem = true
|
136
|
+
end
|
137
|
+
opts.on('--no-control', 'Do not automatically start control thread') do
|
138
|
+
options.control = false
|
139
|
+
end
|
140
|
+
opts.on('--no-quit', 'Do not quit when script finishes') do
|
141
|
+
options.quit = false
|
142
|
+
end
|
143
|
+
opts.on('--no-rewrite-program',
|
144
|
+
'Do not set $0 to the program being debugged') do
|
145
|
+
options.no_rewrite_program = true
|
146
|
+
end
|
147
|
+
opts.on('--no-stop', 'Do not stop when script is loaded') do
|
148
|
+
options.stop = false
|
149
|
+
end
|
150
|
+
opts.on('-nx', 'Not run debugger initialization files (e.g. .rdebugrc') do
|
151
|
+
options.nx = true
|
152
|
+
end
|
153
|
+
opts.on('-p', '--port PORT', Integer, 'Port used for remote debugging') do
|
154
|
+
|port|
|
155
|
+
options.port = port
|
156
|
+
end
|
157
|
+
opts.on('-r', '--require SCRIPT', String,
|
158
|
+
'Require the library, before executing your script') do |name|
|
159
|
+
if name == 'debug'
|
160
|
+
puts "ruby-debug is not compatible with Ruby's 'debug' library. This option is ignored."
|
161
|
+
else
|
162
|
+
require name
|
163
|
+
end
|
164
|
+
end
|
165
|
+
opts.on('--restart-script FILE', String,
|
166
|
+
'Name of the script file to run. Erased after read') do
|
167
|
+
|restart_script|
|
168
|
+
options.restart_script = restart_script
|
169
|
+
unless File.exists?(options.restart_script)
|
170
|
+
puts "Script file '#{options.restart_script}' is not found"
|
171
|
+
exit
|
172
|
+
end
|
173
|
+
end
|
174
|
+
opts.on('--script FILE', String, 'Name of the script file to run') do
|
175
|
+
|script|
|
176
|
+
options.script = script
|
177
|
+
unless File.exists?(options.script)
|
178
|
+
puts "Script file '#{options.script}' is not found"
|
179
|
+
exit
|
180
|
+
end
|
181
|
+
end
|
182
|
+
opts.on('-s', '--server', 'Listen for remote connections') do
|
183
|
+
options.server = true
|
184
|
+
end
|
185
|
+
opts.on('-w', '--wait', 'Wait for a client connection, implies -s option') do
|
186
|
+
options.wait = true
|
187
|
+
end
|
188
|
+
opts.on('-x', '--trace', 'Turn on line tracing') {options.tracing = true}
|
189
|
+
opts.separator ''
|
190
|
+
opts.separator 'Common options:'
|
191
|
+
opts.on_tail('--help', 'Show this message') do
|
192
|
+
puts opts
|
86
193
|
exit
|
87
194
|
end
|
195
|
+
opts.on_tail('--version',
|
196
|
+
'Print the version') do
|
197
|
+
puts "ruby-debug #{Debugger::VERSION}"
|
198
|
+
exit
|
199
|
+
end
|
200
|
+
opts.on('--verbose', 'Turn on verbose mode') do
|
201
|
+
$VERBOSE = true
|
202
|
+
options.verbose_long = true
|
203
|
+
end
|
204
|
+
opts.on_tail('-v',
|
205
|
+
'Print version number, then turn on verbose mode') do
|
206
|
+
puts "ruby-debug #{Debugger::VERSION}"
|
207
|
+
$VERBOSE = true
|
208
|
+
end
|
88
209
|
end
|
89
|
-
opts
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
opts.on_tail("--version",
|
103
|
-
"Print the version") do
|
104
|
-
puts "ruby-debug #{Debugger::VERSION}"
|
105
|
-
exit
|
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
|
210
|
+
return opts
|
211
|
+
end
|
212
|
+
|
213
|
+
# What file is used for debugger startup commands.
|
214
|
+
unless defined?(OPTS_INITFILE)
|
215
|
+
if RUBY_PLATFORM =~ /mswin/
|
216
|
+
# Of course MS Windows has to be different
|
217
|
+
OPTS_INITFILE = 'rdbopt.ini'
|
218
|
+
HOME_DIR = (ENV['HOME'] ||
|
219
|
+
ENV['HOMEDRIVE'].to_s + ENV['HOMEPATH'].to_s).to_s
|
220
|
+
else
|
221
|
+
OPTS_INITFILE = '.rdboptrc'
|
222
|
+
HOME_DIR = ENV['HOME'].to_s
|
115
223
|
end
|
116
224
|
end
|
225
|
+
begin
|
226
|
+
initfile = File.join(HOME_DIR, OPTS_INITFILE)
|
227
|
+
eval(File.read(initfile)) if
|
228
|
+
File.exist?(initfile)
|
229
|
+
rescue
|
230
|
+
end
|
117
231
|
|
232
|
+
opts = process_options(options)
|
118
233
|
begin
|
119
234
|
if not defined? Debugger::ARGV
|
120
235
|
Debugger::ARGV = ARGV.clone
|
121
236
|
end
|
122
237
|
rdebug_path = File.expand_path($0)
|
123
238
|
if RUBY_PLATFORM =~ /mswin/
|
124
|
-
rdebug_path +=
|
239
|
+
rdebug_path += '.cmd' unless rdebug_path =~ /\.cmd$/i
|
125
240
|
end
|
126
241
|
Debugger::RDEBUG_SCRIPT = rdebug_path
|
242
|
+
Debugger::RDEBUG_FILE = __FILE__
|
127
243
|
Debugger::INITIAL_DIR = Dir.pwd
|
128
244
|
opts.parse! ARGV
|
129
245
|
rescue StandardError => e
|
@@ -140,12 +256,14 @@ else
|
|
140
256
|
exit if $VERBOSE and not options.verbose_long
|
141
257
|
puts opts
|
142
258
|
puts
|
143
|
-
puts
|
259
|
+
puts 'Must specify a script to run'
|
144
260
|
exit(-1)
|
145
261
|
end
|
146
262
|
|
147
263
|
# save script name
|
148
|
-
|
264
|
+
prog_script = ARGV.shift
|
265
|
+
prog_script = whence_file(prog_script) unless File.exist?(prog_script)
|
266
|
+
Debugger::PROG_SCRIPT = prog_script
|
149
267
|
|
150
268
|
# install interruption handler
|
151
269
|
trap('INT') { Debugger.interrupt_last }
|
@@ -161,8 +279,7 @@ else
|
|
161
279
|
# load initrc script
|
162
280
|
Debugger.run_init_script(StringIO.new) unless options.nx
|
163
281
|
end
|
164
|
-
|
165
|
-
Debugger.debug_load Debugger::PROG_SCRIPT, !options.nostop
|
282
|
+
debug_program(options)
|
166
283
|
else
|
167
284
|
# activate debugger
|
168
285
|
Debugger.start
|
@@ -172,41 +289,45 @@ else
|
|
172
289
|
# load initrc script (e.g. .rdebugrc)
|
173
290
|
Debugger.run_init_script(StringIO.new) unless options.nx
|
174
291
|
|
292
|
+
# run restore-settings startup script if specified
|
293
|
+
if options.restart_script
|
294
|
+
require 'fileutils'
|
295
|
+
Debugger.run_script(options.restart_script)
|
296
|
+
FileUtils.rm(options.restart_script)
|
297
|
+
end
|
298
|
+
|
175
299
|
# run startup script if specified
|
176
300
|
if options.script
|
177
301
|
Debugger.run_script(options.script)
|
178
302
|
end
|
303
|
+
|
179
304
|
# activate post-mortem
|
180
305
|
Debugger.post_mortem if options.post_mortem
|
181
|
-
|
306
|
+
options.stop = false if options.tracing
|
307
|
+
Debugger.tracing = options.tracing
|
182
308
|
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
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
|
309
|
+
if !options.quit
|
310
|
+
if Debugger.started?
|
311
|
+
until Debugger.stop do end
|
312
|
+
end
|
313
|
+
begin
|
314
|
+
debug_program(options)
|
315
|
+
rescue SyntaxError
|
316
|
+
puts $!.backtrace.map{|l| "\t#{l}"}.join("\n")
|
317
|
+
puts "Uncaught Syntax Error\n"
|
318
|
+
rescue
|
319
|
+
print $!.backtrace.map{|l| "\t#{l}"}.join("\n"), "\n"
|
320
|
+
print "Uncaught exception: #{$!}\n"
|
207
321
|
end
|
322
|
+
print "The program finished.\n" unless
|
323
|
+
Debugger.annotate.to_i > 1 # annotate has its own way
|
324
|
+
interface = Debugger::LocalInterface.new
|
325
|
+
# Not sure if ControlCommandProcessor is really the right
|
326
|
+
# thing to use. CommandProcessor requires a state.
|
327
|
+
processor = Debugger::ControlCommandProcessor.new(interface)
|
328
|
+
processor.process_commands
|
208
329
|
else
|
209
|
-
|
330
|
+
debug_program(options)
|
210
331
|
end
|
211
332
|
end
|
212
333
|
end
|