ruby-debug 0.10.5.rc1 → 0.10.5.rc2
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +54 -0
- data/Rakefile +34 -239
- metadata +15 -182
- data/test/base/base.rb +0 -77
- data/test/base/binding.rb +0 -22
- data/test/base/catchpoint.rb +0 -19
- data/test/base/load.rb +0 -44
- data/test/base/reload_bug.rb +0 -8
- data/test/cli/commands/catchpoint_test.rb +0 -24
- data/test/cli/commands/unit/regexp.rb +0 -36
- data/test/config.yaml +0 -8
- data/test/data/annotate.cmd +0 -29
- data/test/data/annotate.right +0 -139
- data/test/data/at-exit.cmd +0 -4
- data/test/data/at-exit.right +0 -12
- data/test/data/break_bad.cmd +0 -16
- data/test/data/break_bad.right +0 -26
- data/test/data/break_loop_bug.cmd +0 -5
- data/test/data/break_loop_bug.right +0 -15
- data/test/data/break_tracelines.cmd +0 -9
- data/test/data/break_tracelines.right +0 -17
- data/test/data/breakpoints-basename.cmd +0 -2
- data/test/data/breakpoints-basename.right +0 -10
- data/test/data/breakpoints.cmd +0 -37
- data/test/data/breakpoints.right +0 -96
- data/test/data/brkpt-class-bug.cmd +0 -9
- data/test/data/brkpt-class-bug.right +0 -18
- data/test/data/catch.cmd +0 -18
- data/test/data/catch.right +0 -41
- data/test/data/condition.cmd +0 -29
- data/test/data/condition.right +0 -67
- data/test/data/continue_bad.cmd +0 -4
- data/test/data/continue_bad.right +0 -9
- data/test/data/ctrl.cmd +0 -23
- data/test/data/ctrl.right +0 -70
- data/test/data/display.cmd +0 -24
- data/test/data/display.right +0 -44
- data/test/data/dollar-0.right +0 -3
- data/test/data/dollar-0a.right +0 -3
- data/test/data/dollar-0b.right +0 -3
- data/test/data/edit.cmd +0 -12
- data/test/data/edit.right +0 -19
- data/test/data/emacs_basic.cmd +0 -10
- data/test/data/emacs_basic.right +0 -24
- data/test/data/enable.cmd +0 -20
- data/test/data/enable.right +0 -36
- data/test/data/except-bug1.cmd +0 -7
- data/test/data/except-bug1.right +0 -13
- data/test/data/file-with-space.cmd +0 -7
- data/test/data/file-with-space.right +0 -9
- data/test/data/finish.cmd +0 -16
- data/test/data/finish.right +0 -31
- data/test/data/frame.cmd +0 -29
- data/test/data/frame.right +0 -62
- data/test/data/help.cmd +0 -20
- data/test/data/help.right +0 -21
- data/test/data/history.right +0 -7
- data/test/data/info-file-break.cmd +0 -4
- data/test/data/info-file-break.right +0 -11
- data/test/data/info-thread.cmd +0 -13
- data/test/data/info-thread.right +0 -37
- data/test/data/info-var-bug2.cmd +0 -5
- data/test/data/info-var-bug2.right +0 -10
- data/test/data/info-var.cmd +0 -23
- data/test/data/info-var.right +0 -52
- data/test/data/info.cmd +0 -21
- data/test/data/info.right +0 -80
- data/test/data/linetrace-jruby.right +0 -23
- data/test/data/linetrace.cmd +0 -6
- data/test/data/linetrace.right +0 -32
- data/test/data/linetracep.cmd +0 -7
- data/test/data/linetracep.right +0 -25
- data/test/data/list.cmd +0 -19
- data/test/data/list.right +0 -127
- data/test/data/method.cmd +0 -10
- data/test/data/method.right +0 -21
- data/test/data/methodsig.cmd +0 -10
- data/test/data/methodsig.right +0 -20
- data/test/data/noquit.right +0 -1
- data/test/data/output.cmd +0 -6
- data/test/data/output.right +0 -31
- data/test/data/pm-bug.cmd +0 -7
- data/test/data/pm-bug.right +0 -12
- data/test/data/post-mortem-next.cmd +0 -8
- data/test/data/post-mortem-next.right +0 -14
- data/test/data/post-mortem-osx.right +0 -32
- data/test/data/post-mortem.cmd +0 -13
- data/test/data/post-mortem.right +0 -32
- data/test/data/quit.cmd +0 -6
- data/test/data/quit.right +0 -9
- data/test/data/raise-jruby.right +0 -26
- data/test/data/raise.cmd +0 -11
- data/test/data/raise.right +0 -26
- data/test/data/save.cmd +0 -34
- data/test/data/save.right +0 -61
- data/test/data/setshow.cmd +0 -46
- data/test/data/setshow.right +0 -80
- data/test/data/source.cmd +0 -5
- data/test/data/source.right +0 -15
- data/test/data/stepping.cmd +0 -21
- data/test/data/stepping.right +0 -50
- data/test/data/test-init-cygwin.right +0 -7
- data/test/data/test-init-osx.right +0 -4
- data/test/data/test-init.right +0 -5
- data/test/data/trace-jruby.right +0 -14
- data/test/data/trace.right +0 -23
- data/test/example/a/example.rb +0 -1
- data/test/example/at-exit.rb +0 -3
- data/test/example/b/example.rb +0 -1
- data/test/example/bp_loop_issue.rb +0 -3
- data/test/example/breakpoints-basename.rb +0 -2
- data/test/example/brkpt-class-bug.rb +0 -8
- data/test/example/classes.rb +0 -11
- data/test/example/dollar-0.rb +0 -6
- data/test/example/except-bug1.rb +0 -4
- data/test/example/file with space.rb +0 -1
- data/test/example/gcd.rb +0 -18
- data/test/example/info-var-bug.rb +0 -47
- data/test/example/info-var-bug2.rb +0 -2
- data/test/example/null.rb +0 -1
- data/test/example/output.rb +0 -2
- data/test/example/pm-bug.rb +0 -3
- data/test/example/pm.rb +0 -11
- data/test/example/raise.rb +0 -3
- data/test/gcd-dbg-nox.rb +0 -31
- data/test/gcd-dbg.rb +0 -30
- data/test/helper.rb +0 -167
- data/test/pm-base.rb +0 -22
- data/test/rdebug-save.1 +0 -7
- data/test/tdebug.rb +0 -252
- data/test/test-annotate.rb +0 -13
- data/test/test-at-exit.rb +0 -13
- data/test/test-break-bad.rb +0 -25
- data/test/test-breakpoints.rb +0 -24
- data/test/test-brkpt-class-bug.rb +0 -13
- data/test/test-catch.rb +0 -13
- data/test/test-condition.rb +0 -13
- data/test/test-ctrl.rb +0 -55
- data/test/test-display.rb +0 -14
- data/test/test-dollar-0.rb +0 -33
- data/test/test-edit.rb +0 -14
- data/test/test-emacs-basic.rb +0 -13
- data/test/test-enable.rb +0 -13
- data/test/test-except-bug1.rb +0 -16
- data/test/test-file-with-space.rb +0 -18
- data/test/test-finish.rb +0 -22
- data/test/test-frame.rb +0 -28
- data/test/test-help.rb +0 -60
- data/test/test-hist.rb +0 -64
- data/test/test-info-thread.rb +0 -24
- data/test/test-info-var.rb +0 -30
- data/test/test-info.rb +0 -27
- data/test/test-init.rb +0 -49
- data/test/test-list.rb +0 -14
- data/test/test-method.rb +0 -20
- data/test/test-output.rb +0 -13
- data/test/test-pm.rb +0 -37
- data/test/test-quit.rb +0 -13
- data/test/test-raise.rb +0 -13
- data/test/test-save.rb +0 -22
- data/test/test-setshow.rb +0 -13
- data/test/test-source.rb +0 -13
- data/test/test-stepping.rb +0 -14
- data/test/test-trace.rb +0 -40
- data/test/thread1.rb +0 -26
- data/test/trunc-call.rb +0 -31
@@ -1 +0,0 @@
|
|
1
|
-
puts 'Ha!'
|
data/test/example/gcd.rb
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
class Lousy_inspect
|
2
|
-
attr_accessor :var
|
3
|
-
def inspect # An unhelpful inspect
|
4
|
-
throw "Foo" # Raises an exception
|
5
|
-
end
|
6
|
-
def initialize
|
7
|
-
@var = 'initialized'
|
8
|
-
end
|
9
|
-
end
|
10
|
-
class Lousy_inspect_and_to_s
|
11
|
-
attr_accessor :var
|
12
|
-
def inspect # An unhelpful inspect
|
13
|
-
throw "Foo" # Raises an exception
|
14
|
-
end
|
15
|
-
def to_s # An unhelpful to_s
|
16
|
-
throw "bar" # Raises an exception
|
17
|
-
end
|
18
|
-
def initialize
|
19
|
-
@var = 'initialized' # Something to inspect
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
# Something that will be passed objects with
|
24
|
-
# bad inspect or to_s methods
|
25
|
-
class UnsuspectingClass
|
26
|
-
@@Const = 'A constant'
|
27
|
-
@@var = 'a class variable'
|
28
|
-
def initialize(a)
|
29
|
-
@a = a # "info locals" will try to use
|
30
|
-
# inspect or to_s here
|
31
|
-
@b = 5
|
32
|
-
end
|
33
|
-
end
|
34
|
-
def test_Lousy_inspect
|
35
|
-
x = Lousy_inspect.new
|
36
|
-
return x
|
37
|
-
end
|
38
|
-
def test_lousy_inspect_and_to_s
|
39
|
-
x = Lousy_inspect_and_to_s.new
|
40
|
-
return x
|
41
|
-
end
|
42
|
-
x = test_Lousy_inspect
|
43
|
-
y = test_lousy_inspect_and_to_s
|
44
|
-
UnsuspectingClass.new(10)
|
45
|
-
UnsuspectingClass.new(x)
|
46
|
-
UnsuspectingClass.new(y)
|
47
|
-
y = 2
|
data/test/example/null.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
# Nothing here. Move along.
|
data/test/example/output.rb
DELETED
data/test/example/pm-bug.rb
DELETED
data/test/example/pm.rb
DELETED
data/test/example/raise.rb
DELETED
data/test/gcd-dbg-nox.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
# This program is *NOT* supposed to be executable, but called
|
2
|
-
# via ruby (in order to test that restart provides a funky $:).
|
3
|
-
# This program is used to test that 'restart' works when we didn't call
|
4
|
-
# the debugger initially.
|
5
|
-
|
6
|
-
TOP_SRC_DIR = File.join(File.expand_path(File.dirname(__FILE__), '..')) unless
|
7
|
-
defined?(TOP_SRC_DIR)
|
8
|
-
|
9
|
-
$:.unshift File.join(TOP_SRC_DIR, 'ext')
|
10
|
-
$:.unshift File.join(TOP_SRC_DIR, 'lib')
|
11
|
-
$:.unshift File.join(TOP_SRC_DIR, 'cli')
|
12
|
-
require 'ruby-debug'
|
13
|
-
Debugger.init
|
14
|
-
|
15
|
-
# GCD. We assume positive numbers
|
16
|
-
def gcd(a, b)
|
17
|
-
# Make: a <= b
|
18
|
-
debugger
|
19
|
-
if a > b
|
20
|
-
a, b = [b, a]
|
21
|
-
end
|
22
|
-
|
23
|
-
return nil if a <= 0
|
24
|
-
|
25
|
-
if a == 1 or b-a == 0
|
26
|
-
return a
|
27
|
-
end
|
28
|
-
return gcd(b-a, a)
|
29
|
-
end
|
30
|
-
|
31
|
-
gcd(3,5)
|
data/test/gcd-dbg.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# This program is used to test that 'restart' works when we didn't call
|
3
|
-
# the debugger initially.
|
4
|
-
|
5
|
-
TOP_SRC_DIR = File.join(File.expand_path(File.dirname(__FILE__), "..")) unless
|
6
|
-
defined?(TOP_SRC_DIR)
|
7
|
-
|
8
|
-
$:.unshift File.join(TOP_SRC_DIR, "ext")
|
9
|
-
$:.unshift File.join(TOP_SRC_DIR, "lib")
|
10
|
-
$:.unshift File.join(TOP_SRC_DIR, "cli")
|
11
|
-
require 'ruby-debug'
|
12
|
-
Debugger.start
|
13
|
-
|
14
|
-
# GCD. We assume positive numbers
|
15
|
-
def gcd(a, b)
|
16
|
-
# Make: a <= b
|
17
|
-
debugger
|
18
|
-
if a > b
|
19
|
-
a, b = [b, a]
|
20
|
-
end
|
21
|
-
|
22
|
-
return nil if a <= 0
|
23
|
-
|
24
|
-
if a == 1 or b-a == 0
|
25
|
-
return a
|
26
|
-
end
|
27
|
-
return gcd(b-a, a)
|
28
|
-
end
|
29
|
-
|
30
|
-
gcd(3,5)
|
data/test/helper.rb
DELETED
@@ -1,167 +0,0 @@
|
|
1
|
-
# Some common routines used in testing.
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require 'test/unit'
|
5
|
-
|
6
|
-
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
|
7
|
-
$LOAD_PATH.unshift File.expand_path("../../cli", __FILE__)
|
8
|
-
require 'ruby-debug'
|
9
|
-
|
10
|
-
require 'fileutils'
|
11
|
-
require 'yaml'
|
12
|
-
|
13
|
-
# begin require 'rubygems' rescue LoadError end
|
14
|
-
# require 'ruby-debug'; Debugger.start
|
15
|
-
|
16
|
-
module TestHelper
|
17
|
-
def run_debugger(testname, args = '', opts = {})
|
18
|
-
Dir.chdir(File.dirname(__FILE__)) do
|
19
|
-
rightfile = opts[:rightfile] || rightfile(testname)
|
20
|
-
outfile = opts[:outfile] || "#{testname}.out"
|
21
|
-
debug_pgm = opts[:runner] || 'tdebug.rb'
|
22
|
-
filter = opts[:filter]
|
23
|
-
|
24
|
-
if File.exists?(outfile)
|
25
|
-
FileUtils.rm(outfile)
|
26
|
-
end
|
27
|
-
|
28
|
-
ENV['RDEBUG'] = debug_pgm
|
29
|
-
ENV['TERM'] = ''
|
30
|
-
|
31
|
-
# The EMACS environment variable(s) cause output to
|
32
|
-
# get prefaced with null which will mess up file compares.
|
33
|
-
# So turn off EMACS output processing.
|
34
|
-
ENV['EMACS'] = ENV['INSIDE_EMACS'] = nil
|
35
|
-
|
36
|
-
cmd = "#{load_ruby} #{load_params} ../rdbg.rb #{args} > #{outfile}"
|
37
|
-
puts "'#{cmd}'" if $DEBUG
|
38
|
-
`#{cmd}`
|
39
|
-
|
40
|
-
got_lines = File.read(outfile).split(/\n/)
|
41
|
-
correct_lines = File.read(rightfile).split(/\n/)
|
42
|
-
filter.call(got_lines, correct_lines) if filter
|
43
|
-
|
44
|
-
if cheap_diff(got_lines, correct_lines)
|
45
|
-
FileUtils.rm(outfile)
|
46
|
-
return true
|
47
|
-
end
|
48
|
-
|
49
|
-
false
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def rightfile(testname)
|
54
|
-
jruby_file = File.join('data', "#{testname}-jruby.right")
|
55
|
-
if defined?(JRUBY_VERSION) && File.exists?(jruby_file)
|
56
|
-
jruby_file
|
57
|
-
else
|
58
|
-
File.join('data', "#{testname}.right")
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def cheap_diff(got_lines, correct_lines)
|
63
|
-
if $DEBUG
|
64
|
-
got_lines.each_with_index do |line, i|
|
65
|
-
printf "%3d %s\n", i+1, line
|
66
|
-
end
|
67
|
-
end
|
68
|
-
correct_lines.each_with_index do |line, i|
|
69
|
-
correct_lines[i].chomp!
|
70
|
-
if got_lines[i] != correct_lines[i]
|
71
|
-
puts "difference found at line #{i+1}"
|
72
|
-
puts "got : #{got_lines[i]}"
|
73
|
-
puts "need: #{correct_lines[i]}"
|
74
|
-
return false
|
75
|
-
end
|
76
|
-
end
|
77
|
-
if correct_lines.size != got_lines.size
|
78
|
-
puts("difference in number of lines: " +
|
79
|
-
"#{correct_lines.size} vs. #{got_lines.size}")
|
80
|
-
return false
|
81
|
-
end
|
82
|
-
return true
|
83
|
-
end
|
84
|
-
|
85
|
-
# FIXME: using this causes the same test to get run several times
|
86
|
-
# and some tests fail probably because of a lack of environment isolation.
|
87
|
-
# Many tests follow a basic pattern: run the debugger with a given
|
88
|
-
# debugger script and compare output produced. The following creates
|
89
|
-
# this kind of test.
|
90
|
-
def add_test(base_name, src_dir, script_name=nil, cmd=nil, test_name=nil)
|
91
|
-
puts "+++ Adding #{base_name} ++++" if $DEBUG
|
92
|
-
test_name = File.join('.', 'example', base_name) unless test_name
|
93
|
-
script_name = File.join('data', test_name + '.cmd') unless script_name
|
94
|
-
cmd = 'gcd.rb 3 5' unless cmd
|
95
|
-
eval <<-EOF
|
96
|
-
def test_#{test_name}
|
97
|
-
Dir.chdir(\"#{src_dir}\") do
|
98
|
-
assert_equal(true,
|
99
|
-
run_debugger(\"#{base_name}\",
|
100
|
-
\"--script #{script_name} -- #{cmd}\"))
|
101
|
-
end
|
102
|
-
end
|
103
|
-
EOF
|
104
|
-
end
|
105
|
-
module_function :add_test
|
106
|
-
|
107
|
-
# Adapted from the Ruby Cookbook, Section 6.10: Comparing two files.
|
108
|
-
# def diff_as_string(rightfile, checkfile, format=:unified, context_lines=3)
|
109
|
-
# right_data = File.read(rightfile)
|
110
|
-
# check_data = File.read(checkfile)
|
111
|
-
# output = ''
|
112
|
-
# diffs = Diff::LCS.diff(right_data, check_data)
|
113
|
-
# return output if diffs.empty?
|
114
|
-
# oldhunk = hunk = nil
|
115
|
-
# file_length_difference = 0
|
116
|
-
# diffs.each do |piece|
|
117
|
-
# begin
|
118
|
-
# hunk = Diff::LCS::Hunk.new(right_data, check_data, piece,
|
119
|
-
# context_lines, file_length_difference)
|
120
|
-
# next unless oldhunk
|
121
|
-
#
|
122
|
-
# # Hunks may overlap, which is why we need to be careful when our
|
123
|
-
# # diff includes lines of context. Otherwise, we might print
|
124
|
-
# # redundant lines.
|
125
|
-
# if (context_lines > 0) and hunk.overlaps?(oldhunk)
|
126
|
-
# hunk.unshift(oldhunk)
|
127
|
-
# else
|
128
|
-
# output << oldhunk.diff(format)
|
129
|
-
# end
|
130
|
-
# ensure
|
131
|
-
# oldhunk = hunk
|
132
|
-
# output << '\n'
|
133
|
-
# end
|
134
|
-
# end
|
135
|
-
|
136
|
-
# # Handle the last remaining hunk
|
137
|
-
# output << oldhunk.diff(format) << '\n'
|
138
|
-
# end
|
139
|
-
|
140
|
-
# Loads key from the _config_._yaml_ file.
|
141
|
-
def config_load(key, may_be_nil=false, default_value='')
|
142
|
-
conf = File.join('config.private.yaml') # try private first
|
143
|
-
unless File.exists?(conf)
|
144
|
-
if defined?(JRUBY_VERSION)
|
145
|
-
conf = File.join('config.jruby.yaml')
|
146
|
-
else
|
147
|
-
conf = File.join('config.yaml')
|
148
|
-
end
|
149
|
-
end
|
150
|
-
value = YAML.load_file(conf)[key]
|
151
|
-
assert_not_nil(value, "#{key} is set in config.yaml") unless may_be_nil
|
152
|
-
value || default_value
|
153
|
-
end
|
154
|
-
module_function :config_load
|
155
|
-
|
156
|
-
def load_ruby
|
157
|
-
config_load('ruby', true)
|
158
|
-
end
|
159
|
-
module_function :load_ruby
|
160
|
-
|
161
|
-
def load_params
|
162
|
-
config_load('ruby_params', true)
|
163
|
-
end
|
164
|
-
module_function :load_params
|
165
|
-
|
166
|
-
end
|
167
|
-
|
data/test/pm-base.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# Test post-mortem handling using only ruby-debug-base.
|
3
|
-
src_dir = File.dirname(__FILE__)
|
4
|
-
%w(ext lib cli).each do |dir|
|
5
|
-
$:.unshift File.join(src_dir, '..', dir)
|
6
|
-
end
|
7
|
-
require 'ruby-debug-base'
|
8
|
-
|
9
|
-
class CommandProcessor
|
10
|
-
def at_line(context, file, line)
|
11
|
-
puts 'file: %s, line: %s' % [ File.basename(file), line ]
|
12
|
-
exit!
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
Debugger.start(:post_mortem => true)
|
17
|
-
Debugger.handler = CommandProcessor.new
|
18
|
-
def zero_div
|
19
|
-
1/0
|
20
|
-
end
|
21
|
-
zero_div
|
22
|
-
|
data/test/rdebug-save.1
DELETED
data/test/tdebug.rb
DELETED
@@ -1,252 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# -*- Ruby -*-
|
3
|
-
# This is a hacked down copy of rdebug which can be used for testing
|
4
|
-
# FIXME: use the real rdebug script - DRY.
|
5
|
-
|
6
|
-
require 'stringio'
|
7
|
-
require 'rubygems'
|
8
|
-
require 'optparse'
|
9
|
-
require "ostruct"
|
10
|
-
|
11
|
-
TOP_SRC_DIR = File.join(File.dirname(__FILE__), "..") unless
|
12
|
-
defined?(TOP_SRC_DIR)
|
13
|
-
|
14
|
-
$:.unshift File.join(TOP_SRC_DIR, "ext")
|
15
|
-
$:.unshift File.join(TOP_SRC_DIR, "lib")
|
16
|
-
$:.unshift File.join(TOP_SRC_DIR, "cli")
|
17
|
-
|
18
|
-
def debug_program(options)
|
19
|
-
# Make sure Ruby script syntax checks okay.
|
20
|
-
# Otherwise we get a load message that looks like rdebug has
|
21
|
-
# a problem.
|
22
|
-
output = `ruby -c #{Debugger::PROG_SCRIPT.inspect} 2>&1`
|
23
|
-
if $?.exitstatus != 0 and RUBY_PLATFORM !~ /mswin/
|
24
|
-
puts output
|
25
|
-
exit $?.exitstatus
|
26
|
-
end
|
27
|
-
print "\032\032starting\n" if Debugger.annotate and Debugger.annotate > 2
|
28
|
-
unless options.no_rewrite_program
|
29
|
-
# Set $0 so things like __FILE == $0 work.
|
30
|
-
# A more reliable way to do this is to put $0 = __FILE__ *after*
|
31
|
-
# loading the script to be debugged. For this, adding a debug hook
|
32
|
-
# for the first time and then switching to the debug hook that's
|
33
|
-
# normally used would be helpful. Doing this would also help other
|
34
|
-
# first-time initializations such as reloading debugger state
|
35
|
-
# after a restart.
|
36
|
-
|
37
|
-
# However This is just a little more than I want to take on right
|
38
|
-
# now, so I think I'll stick with the slightly hacky approach.
|
39
|
-
$RDEBUG_0 = $0
|
40
|
-
|
41
|
-
# cygwin does some sort of funky truncation on $0 ./abcdef => ./ab
|
42
|
-
# probably something to do with 3-letter extension truncation.
|
43
|
-
# The hacky workaround is to do slice assignment. Ugh.
|
44
|
-
d0 = if '.' == File.dirname(Debugger::PROG_SCRIPT) and
|
45
|
-
Debugger::PROG_SCRIPT[0..0] != '.'
|
46
|
-
File.join('.', Debugger::PROG_SCRIPT)
|
47
|
-
else
|
48
|
-
Debugger::PROG_SCRIPT
|
49
|
-
end
|
50
|
-
if $0.frozen?
|
51
|
-
$0 = d0
|
52
|
-
else
|
53
|
-
$0[0..-1] = d0
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
# Record where we are we can know if the call stack has been
|
58
|
-
# truncated or not.
|
59
|
-
Debugger.start_sentinal=caller(0)[1]
|
60
|
-
|
61
|
-
bt = Debugger.debug_load(Debugger::PROG_SCRIPT, !options.nostop, false)
|
62
|
-
if bt
|
63
|
-
if options.post_mortem
|
64
|
-
Debugger.handle_post_mortem(bt)
|
65
|
-
else
|
66
|
-
print bt.backtrace.map{|l| "\t#{l}"}.join("\n"), "\n"
|
67
|
-
print "Uncaught exception: #{bt}\n"
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
options = OpenStruct.new(
|
73
|
-
'annotate' => false,
|
74
|
-
'emacs' => false,
|
75
|
-
'frame_bind' => false,
|
76
|
-
'no-quit' => false,
|
77
|
-
'no-stop' => false,
|
78
|
-
'nx' => false,
|
79
|
-
'post_mortem' => false,
|
80
|
-
'script' => nil,
|
81
|
-
'tracing' => false,
|
82
|
-
'verbose_long'=> false,
|
83
|
-
'wait' => false
|
84
|
-
)
|
85
|
-
|
86
|
-
require "ruby-debug"
|
87
|
-
|
88
|
-
program = File.basename($0)
|
89
|
-
opts = OptionParser.new do |opts|
|
90
|
-
opts.banner = <<EOB
|
91
|
-
#{program} #{Debugger::VERSION}
|
92
|
-
Usage: #{program} [options] <script.rb> -- <script.rb parameters>
|
93
|
-
EOB
|
94
|
-
opts.separator ""
|
95
|
-
opts.separator "Options:"
|
96
|
-
opts.on("-A", "--annotate LEVEL", Integer, "Set annotation level") do
|
97
|
-
|Debugger.annotate|
|
98
|
-
end
|
99
|
-
opts.on("-d", "--debug", "Set $DEBUG=true") {$DEBUG = true}
|
100
|
-
opts.on("--emacs-basic", "Activates basic Emacs mode") do
|
101
|
-
ENV['EMACS'] = '1'
|
102
|
-
options.emacs = true
|
103
|
-
end
|
104
|
-
opts.on("--keep-frame-binding", "Keep frame bindings") do
|
105
|
-
options.frame_bind = true
|
106
|
-
end
|
107
|
-
opts.on("-m", "--post-mortem", "Activate post-mortem mode") do
|
108
|
-
options.post_mortem = true
|
109
|
-
end
|
110
|
-
opts.on("--no-control", "Do not automatically start control thread") do
|
111
|
-
options.control = false
|
112
|
-
end
|
113
|
-
opts.on("--no-quit", "Do not quit when script finishes") do
|
114
|
-
options.noquit = true
|
115
|
-
end
|
116
|
-
opts.on("--no-stop", "Do not stop when script is loaded") do
|
117
|
-
options.nostop = true
|
118
|
-
end
|
119
|
-
opts.on("-nx", "Not run debugger initialization files (e.g. .rdebugrc") do
|
120
|
-
options.nx = true
|
121
|
-
end
|
122
|
-
opts.on("-I", "--include PATH", String, "Add PATH to $LOAD_PATH") do |path|
|
123
|
-
$LOAD_PATH.unshift(path)
|
124
|
-
end
|
125
|
-
opts.on("-r", "--require SCRIPT", String,
|
126
|
-
"Require the library, before executing your script") do |name|
|
127
|
-
if name == 'debug'
|
128
|
-
puts "ruby-debug is not compatible with Ruby's 'debug' library. This option is ignored."
|
129
|
-
else
|
130
|
-
require name
|
131
|
-
end
|
132
|
-
end
|
133
|
-
opts.on("--script FILE", String, "Name of the script file to run") do |options.script|
|
134
|
-
unless File.exists?(options.script)
|
135
|
-
puts "Script file '#{options.script}' is not found"
|
136
|
-
exit
|
137
|
-
end
|
138
|
-
end
|
139
|
-
opts.on("-x", "--trace", "Turn on line tracing") {options.tracing = true}
|
140
|
-
ENV['EMACS'] = nil unless options.emacs
|
141
|
-
opts.separator ""
|
142
|
-
opts.separator "Common options:"
|
143
|
-
opts.on_tail("--help", "Show this message") do
|
144
|
-
puts opts
|
145
|
-
exit
|
146
|
-
end
|
147
|
-
opts.on_tail("--version",
|
148
|
-
"Print the version") do
|
149
|
-
puts "ruby-debug #{Debugger::VERSION}"
|
150
|
-
exit
|
151
|
-
end
|
152
|
-
opts.on("--verbose", "Turn on verbose mode") do
|
153
|
-
$VERBOSE = true
|
154
|
-
options.verbose_long = true
|
155
|
-
end
|
156
|
-
opts.on_tail("-v",
|
157
|
-
"Print version number, then turn on verbose mode") do
|
158
|
-
puts "ruby-debug #{Debugger::VERSION}"
|
159
|
-
$VERBOSE = true
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
begin
|
164
|
-
if not defined? Debugger::ARGV
|
165
|
-
Debugger::ARGV = ARGV.clone
|
166
|
-
end
|
167
|
-
rdebug_path = File.expand_path($0)
|
168
|
-
if RUBY_PLATFORM =~ /mswin/
|
169
|
-
rdebug_path += '.cmd' unless rdebug_path =~ /\.cmd$/i
|
170
|
-
end
|
171
|
-
Debugger::RDEBUG_SCRIPT = rdebug_path
|
172
|
-
Debugger::RDEBUG_FILE = __FILE__
|
173
|
-
Debugger::INITIAL_DIR = Dir.pwd
|
174
|
-
opts.parse! ARGV
|
175
|
-
rescue StandardError => e
|
176
|
-
puts opts
|
177
|
-
puts
|
178
|
-
puts e.message
|
179
|
-
exit(-1)
|
180
|
-
end
|
181
|
-
|
182
|
-
if ARGV.empty?
|
183
|
-
exit if $VERBOSE and not options.verbose_long
|
184
|
-
puts opts
|
185
|
-
puts
|
186
|
-
puts 'Must specify a script to run'
|
187
|
-
exit(-1)
|
188
|
-
end
|
189
|
-
|
190
|
-
# save script name
|
191
|
-
Debugger::PROG_SCRIPT = ARGV.shift
|
192
|
-
|
193
|
-
# install interruption handler
|
194
|
-
trap('INT') { Debugger.interrupt_last }
|
195
|
-
|
196
|
-
# set options
|
197
|
-
Debugger.wait_connection = false
|
198
|
-
Debugger.keep_frame_binding = options.frame_bind
|
199
|
-
|
200
|
-
# Add Debugger trace hook.
|
201
|
-
Debugger.start
|
202
|
-
|
203
|
-
# start control thread
|
204
|
-
Debugger.start_control(options.host, options.cport) if options.control
|
205
|
-
|
206
|
-
# activate post-mortem
|
207
|
-
Debugger.post_mortem if options.post_mortem
|
208
|
-
|
209
|
-
# Set up an interface to read commands from a debugger script file.
|
210
|
-
if options.script
|
211
|
-
Debugger.interface = Debugger::ScriptInterface.new(options.script,
|
212
|
-
STDOUT, true)
|
213
|
-
end
|
214
|
-
options.nostop = true if options.tracing
|
215
|
-
Debugger.tracing = options.tracing
|
216
|
-
|
217
|
-
# Make sure Ruby script syntax checks okay.
|
218
|
-
# Otherwise we get a load message that looks like rdebug has
|
219
|
-
# a problem.
|
220
|
-
output = `ruby -c #{Debugger::PROG_SCRIPT.inspect} 2>&1`
|
221
|
-
if $?.exitstatus != 0 and RUBY_PLATFORM !~ /mswin/
|
222
|
-
puts output
|
223
|
-
exit $?.exitstatus
|
224
|
-
end
|
225
|
-
|
226
|
-
# load initrc script (e.g. .rdebugrc)
|
227
|
-
Debugger.run_init_script(StringIO.new) unless options.nx
|
228
|
-
|
229
|
-
# run startup script if specified
|
230
|
-
if options.script
|
231
|
-
Debugger.run_script(options.script)
|
232
|
-
end
|
233
|
-
# activate post-mortem
|
234
|
-
Debugger.post_mortem if options.post_mortem
|
235
|
-
options.stop = false if options.tracing
|
236
|
-
Debugger.tracing = options.tracing
|
237
|
-
|
238
|
-
if options.noquit
|
239
|
-
if Debugger.started?
|
240
|
-
until Debugger.stop do end
|
241
|
-
end
|
242
|
-
debug_program(options)
|
243
|
-
print "The program finished.\n" unless
|
244
|
-
Debugger.annotate.to_i > 1 # annotate has its own way
|
245
|
-
interface = Debugger::LocalInterface.new
|
246
|
-
# Not sure if ControlCommandProcessor is really the right
|
247
|
-
# thing to use. CommandProcessor requires a state.
|
248
|
-
processor = Debugger::ControlCommandProcessor.new(interface)
|
249
|
-
processor.process_commands
|
250
|
-
else
|
251
|
-
debug_program(options)
|
252
|
-
end
|