byebug 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/README.md +1 -1
- data/bin/byebug +1 -2
- data/byebug.gemspec +1 -1
- data/ext/byebug/byebug.c +50 -35
- data/ext/byebug/context.c +99 -45
- data/lib/byebug.rb +5 -10
- data/lib/byebug/command.rb +20 -12
- data/lib/byebug/commands/breakpoints.rb +1 -1
- data/lib/byebug/commands/control.rb +14 -21
- data/lib/byebug/commands/display.rb +4 -4
- data/lib/byebug/commands/enable.rb +20 -19
- data/lib/byebug/commands/eval.rb +1 -1
- data/lib/byebug/commands/finish.rb +4 -5
- data/lib/byebug/commands/info.rb +118 -116
- data/lib/byebug/commands/list.rb +72 -48
- data/lib/byebug/commands/reload.rb +4 -3
- data/lib/byebug/commands/set.rb +7 -16
- data/lib/byebug/commands/show.rb +2 -2
- data/lib/byebug/commands/threads.rb +7 -6
- data/lib/byebug/context.rb +10 -2
- data/lib/byebug/helper.rb +3 -3
- data/lib/byebug/processor.rb +1 -1
- data/lib/byebug/version.rb +1 -1
- data/old_doc/byebug.texi +45 -51
- data/test/breakpoints_test.rb +180 -195
- data/test/display_test.rb +59 -53
- data/test/eval_test.rb +0 -2
- data/test/examples/info.rb +5 -5
- data/test/examples/info_threads.rb +1 -1
- data/test/finish_test.rb +16 -15
- data/test/info_test.rb +9 -10
- data/test/irb_test.rb +64 -65
- data/test/list_test.rb +76 -50
- data/test/method_test.rb +10 -5
- data/test/post_mortem_test.rb +27 -25
- data/test/reload_test.rb +31 -31
- data/test/restart_test.rb +106 -110
- data/test/show_test.rb +8 -16
- data/test/stepping_test.rb +4 -2
- data/test/support/test_dsl.rb +37 -76
- data/test/test_helper.rb +0 -1
- data/test/variables_test.rb +9 -12
- metadata +4 -4
data/lib/byebug/commands/list.rb
CHANGED
@@ -18,37 +18,19 @@ module Byebug
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def execute
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
b = if @state.previous_line
|
28
|
-
if @state.previous_line > 0
|
29
|
-
@state.previous_line - listsize
|
30
|
-
else
|
31
|
-
@state.previous_line
|
32
|
-
end
|
33
|
-
else
|
34
|
-
@state.line - (listsize/2)
|
35
|
-
end
|
36
|
-
e = b + listsize - 1
|
37
|
-
elsif @match[1] == '='
|
38
|
-
@state.previous_line = nil
|
39
|
-
b = @state.line - (listsize/2)
|
40
|
-
e = b + listsize -1
|
41
|
-
else
|
42
|
-
b, e = @match[2].split(/[-,]/)
|
43
|
-
if e
|
44
|
-
b = b.to_i
|
45
|
-
e = e.to_i
|
46
|
-
else
|
47
|
-
b = b.to_i - (listsize/2)
|
48
|
-
e = b + listsize - 1
|
49
|
-
end
|
21
|
+
Byebug.source_reload if Command.settings[:reload_source_on_change]
|
22
|
+
lines = LineCache::getlines(@state.file,
|
23
|
+
Command.settings[:reload_source_on_change])
|
24
|
+
if !lines
|
25
|
+
errmsg "No sourcefile available for #{@state.file}\n"
|
26
|
+
return @state.previous_line
|
50
27
|
end
|
51
|
-
|
28
|
+
|
29
|
+
b, e = set_line_range(Command.settings[:listsize], lines.size)
|
30
|
+
return @state.previous_line if b < 0
|
31
|
+
|
32
|
+
print "[#{b}, #{e}] in #{@state.file}\n"
|
33
|
+
@state.previous_line = display_list(b, e, lines, @state.line)
|
52
34
|
end
|
53
35
|
|
54
36
|
class << self
|
@@ -69,28 +51,70 @@ module Byebug
|
|
69
51
|
|
70
52
|
private
|
71
53
|
|
72
|
-
|
73
|
-
#
|
74
|
-
#
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
if
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
54
|
+
##
|
55
|
+
# Set line range to be printed by list
|
56
|
+
#
|
57
|
+
# @param listsize - number of lines to be printed
|
58
|
+
# @param maxline - max line number that can be printed
|
59
|
+
#
|
60
|
+
def set_line_range(listsize, maxline)
|
61
|
+
if !@match || !(@match[1] || @match[2])
|
62
|
+
b = @state.previous_line ?
|
63
|
+
@state.previous_line + listsize : @state.line - (listsize/2)
|
64
|
+
elsif @match[1] == '-'
|
65
|
+
b = if @state.previous_line
|
66
|
+
if @state.previous_line > 0
|
67
|
+
@state.previous_line - listsize
|
68
|
+
else
|
69
|
+
@state.previous_line
|
70
|
+
end
|
86
71
|
else
|
87
|
-
|
72
|
+
@state.line - (listsize/2)
|
88
73
|
end
|
74
|
+
elsif @match[1] == '='
|
75
|
+
@state.previous_line = nil
|
76
|
+
b = @state.line - (listsize/2)
|
77
|
+
else
|
78
|
+
b, e = @match[2].split(/[-,]/)
|
79
|
+
if e
|
80
|
+
b = b.to_i
|
81
|
+
e = e.to_i
|
82
|
+
else
|
83
|
+
b = b.to_i - (listsize/2)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
if b > maxline
|
88
|
+
errmsg "Invalid line range"
|
89
|
+
return [ -1, -1 ]
|
90
|
+
end
|
91
|
+
|
92
|
+
b = [1, b].max
|
93
|
+
e ||= b + listsize - 1
|
94
|
+
|
95
|
+
if e > maxline
|
96
|
+
e = maxline
|
97
|
+
b = e - listsize + 1
|
98
|
+
b = [1, b].max
|
99
|
+
end
|
100
|
+
|
101
|
+
return [ b, e ]
|
102
|
+
end
|
103
|
+
|
104
|
+
##
|
105
|
+
# Show file lines in LINES from line B to line E where CURRENT is the
|
106
|
+
# current line number. If we can show from B to E then we return B,
|
107
|
+
# otherwise we return the previous line @state.previous_line.
|
108
|
+
#
|
109
|
+
def display_list(b, e, lines, current)
|
110
|
+
b.upto(e) do |n|
|
111
|
+
if n > 0 && lines[n-1]
|
112
|
+
if n == current
|
113
|
+
print "=> %d %s\n", n, lines[n-1].chomp
|
114
|
+
else
|
115
|
+
print " %d %s\n", n, lines[n-1].chomp
|
89
116
|
end
|
90
117
|
end
|
91
|
-
else
|
92
|
-
errmsg "No sourcefile available for %s\n", file
|
93
|
-
return @state.previous_line
|
94
118
|
end
|
95
119
|
return e == lines.size ? @state.previous_line : b
|
96
120
|
end
|
@@ -5,12 +5,13 @@ module Byebug
|
|
5
5
|
self.allow_in_control = true
|
6
6
|
|
7
7
|
register_setting_get(:reload_source_on_change) do
|
8
|
-
Byebug.reload_source_on_change
|
8
|
+
Byebug.class_variable_get(:@@reload_source_on_change)
|
9
9
|
end
|
10
10
|
|
11
11
|
register_setting_set(:reload_source_on_change) do |value|
|
12
|
-
Byebug.reload_source_on_change
|
12
|
+
Byebug.class_variable_set(:@@reload_source_on_change, value)
|
13
13
|
end
|
14
|
+
Command.settings[:reload_source_on_change] = true
|
14
15
|
|
15
16
|
def regexp
|
16
17
|
/^\s*r(?:eload)?$/
|
@@ -24,7 +25,7 @@ module Byebug
|
|
24
25
|
private
|
25
26
|
|
26
27
|
def source_reloading
|
27
|
-
|
28
|
+
Command.settings[:reload_source_on_change] ? 'on' : 'off'
|
28
29
|
end
|
29
30
|
|
30
31
|
class << self
|
data/lib/byebug/commands/set.rb
CHANGED
@@ -74,15 +74,12 @@ module Byebug
|
|
74
74
|
else
|
75
75
|
return
|
76
76
|
end
|
77
|
-
|
78
|
-
|
77
|
+
when /^args$/
|
78
|
+
if defined?(Byebug::BYEBUG_SCRIPT)
|
79
79
|
Command.settings[:argv][1..-1] = args
|
80
80
|
else
|
81
|
-
# byebug wasn't called initially. 1st arg is not script name.
|
82
81
|
Command.settings[:argv] = args
|
83
82
|
end
|
84
|
-
when /^args$/
|
85
|
-
Command.settings[:argv][1..-1] = args
|
86
83
|
when /^autolist$/
|
87
84
|
Command.settings[:autolist] = (set_on ? 1 : 0)
|
88
85
|
when /^autoeval$/
|
@@ -142,19 +139,13 @@ module Byebug
|
|
142
139
|
Command.settings[:tracing] = set_on
|
143
140
|
when /^listsize$/
|
144
141
|
listsize = get_int(args[0], "Set listsize", 1, nil, 10)
|
145
|
-
|
146
|
-
|
147
|
-
else
|
148
|
-
return
|
149
|
-
end
|
142
|
+
return unless listsize
|
143
|
+
self.class.settings[:listsize] = listsize
|
150
144
|
when /^width$/
|
151
145
|
width = get_int(args[0], "Set width", 10, nil, 80)
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
else
|
156
|
-
return
|
157
|
-
end
|
146
|
+
return unless width
|
147
|
+
self.class.settings[:width] = width
|
148
|
+
ENV['COLUMNS'] = width.to_s
|
158
149
|
else
|
159
150
|
return print "Unknown setting #{@match[1]}.\n"
|
160
151
|
end
|
data/lib/byebug/commands/show.rb
CHANGED
@@ -10,7 +10,7 @@ module Byebug
|
|
10
10
|
return ("Annotation level is #{Byebug.annotate}")
|
11
11
|
when /^args$/
|
12
12
|
if Command.settings[:argv] and Command.settings[:argv].size > 0
|
13
|
-
if defined?(Byebug::
|
13
|
+
if defined?(Byebug::BYEBUG_SCRIPT)
|
14
14
|
# byebug was called initially. 1st arg is script name.
|
15
15
|
args = Command.settings[:argv][1..-1].join(' ')
|
16
16
|
else
|
@@ -129,7 +129,7 @@ module Byebug
|
|
129
129
|
end
|
130
130
|
when /^listsize$/
|
131
131
|
listlines = Command.settings[:listsize]
|
132
|
-
return "Number of source lines to list
|
132
|
+
return "Number of source lines to list is #{listlines}."
|
133
133
|
when /^port$/
|
134
134
|
return "server port is #{Byebug::PORT}."
|
135
135
|
when /^trace$/
|
@@ -1,5 +1,6 @@
|
|
1
1
|
module Byebug
|
2
|
-
|
2
|
+
|
3
|
+
module ThreadFunctions
|
3
4
|
def display_context(c, show_top_frame=true)
|
4
5
|
c_flag = c.thread == Thread.current ? '+' : ' '
|
5
6
|
c_flag = '$' if c.suspended?
|
@@ -41,7 +42,7 @@ module Byebug
|
|
41
42
|
end
|
42
43
|
end
|
43
44
|
|
44
|
-
class ThreadListCommand < Command
|
45
|
+
class ThreadListCommand < Command
|
45
46
|
self.allow_in_control = true
|
46
47
|
|
47
48
|
def regexp
|
@@ -67,7 +68,7 @@ module Byebug
|
|
67
68
|
end
|
68
69
|
end
|
69
70
|
|
70
|
-
class ThreadStopCommand < Command
|
71
|
+
class ThreadStopCommand < Command
|
71
72
|
self.allow_in_control = true
|
72
73
|
self.allow_in_post_mortem = false
|
73
74
|
self.need_context = true
|
@@ -96,7 +97,7 @@ module Byebug
|
|
96
97
|
end
|
97
98
|
end
|
98
99
|
|
99
|
-
class ThreadResumeCommand < Command
|
100
|
+
class ThreadResumeCommand < Command
|
100
101
|
self.allow_in_post_mortem = false
|
101
102
|
self.allow_in_control = true
|
102
103
|
self.need_context = true
|
@@ -132,7 +133,7 @@ module Byebug
|
|
132
133
|
# Thread switch Must come after "Thread resume" because "switch" is
|
133
134
|
# optional
|
134
135
|
|
135
|
-
class ThreadSwitchCommand < Command
|
136
|
+
class ThreadSwitchCommand < Command
|
136
137
|
self.allow_in_control = true
|
137
138
|
self.allow_in_post_mortem = false
|
138
139
|
self.need_context = true
|
@@ -163,7 +164,7 @@ module Byebug
|
|
163
164
|
end
|
164
165
|
end
|
165
166
|
|
166
|
-
class ThreadCurrentCommand < Command
|
167
|
+
class ThreadCurrentCommand < Command
|
167
168
|
self.need_context = true
|
168
169
|
|
169
170
|
def regexp
|
data/lib/byebug/context.rb
CHANGED
@@ -8,8 +8,16 @@ module Byebug
|
|
8
8
|
end
|
9
9
|
|
10
10
|
class Context
|
11
|
-
def
|
12
|
-
|
11
|
+
def frame_args(frame_no=0)
|
12
|
+
bind = frame_binding(frame_no)
|
13
|
+
return [] unless eval "__method__", bind
|
14
|
+
begin
|
15
|
+
eval "self.method(__method__).parameters.map{|(attr, mid)| mid}", bind
|
16
|
+
rescue NameError => e
|
17
|
+
print "(WARNING: retreving args from frame #{frame_no} => " \
|
18
|
+
"#{e.class} Exception: #{e.message})\n "
|
19
|
+
return []
|
20
|
+
end
|
13
21
|
end
|
14
22
|
|
15
23
|
def interrupt
|
data/lib/byebug/helper.rb
CHANGED
@@ -11,15 +11,15 @@ module Byebug
|
|
11
11
|
begin
|
12
12
|
int = Integer(str)
|
13
13
|
if min and int < min
|
14
|
-
print "
|
14
|
+
print "#{cmd} argument \"#{str}\" needs to be at least #{min}.\n"
|
15
15
|
return nil
|
16
16
|
elsif max and int > max
|
17
|
-
print "
|
17
|
+
print "#{cmd} argument \"#{str}\" needs to be at most #{max}.\n"
|
18
18
|
return nil
|
19
19
|
end
|
20
20
|
return int
|
21
21
|
rescue
|
22
|
-
print "
|
22
|
+
print "#{cmd} argument \"#{str}\" needs to be a number.\n"
|
23
23
|
return nil
|
24
24
|
end
|
25
25
|
end
|
data/lib/byebug/processor.rb
CHANGED
@@ -147,7 +147,7 @@ module Byebug
|
|
147
147
|
|
148
148
|
def at_tracing(context, file, line)
|
149
149
|
# Don't trace ourselves
|
150
|
-
return if defined?(Byebug::
|
150
|
+
return if defined?(Byebug::BYEBUG_SCRIPT) && Byebug::BYEBUG_SCRIPT == file
|
151
151
|
|
152
152
|
file = CommandProcessor.canonic_file(file)
|
153
153
|
tracing_plus = Command.settings[:tracing_plus]
|
data/lib/byebug/version.rb
CHANGED
data/old_doc/byebug.texi
CHANGED
@@ -314,14 +314,13 @@ mark, e.g.\@code{q!}.
|
|
314
314
|
@node Second Sample Session
|
315
315
|
@section Sample Session 2: Delving Deeper (@code{where}, @code{frame}, @code{restart}, @code{autoeval}, @code{break}, @code{ps})
|
316
316
|
|
317
|
-
In this section we'll introduce breakpoints, the call stack and
|
318
|
-
|
319
|
-
|
320
|
-
here's the program.
|
317
|
+
In this section we'll introduce breakpoints, the call stack and restarting. So
|
318
|
+
far we've been doing pretty good in that we've not encountered a bug to fix.
|
319
|
+
Let's try another simple example. Okay here's the program.
|
321
320
|
|
322
|
-
Below we will debug a simple Ruby program to solve the classic Towers
|
323
|
-
|
324
|
-
|
321
|
+
Below we will debug a simple Ruby program to solve the classic Towers of Hanoi
|
322
|
+
puzzle. It is augmented by the bane of programming: some command-parameter
|
323
|
+
processing with error checking.
|
325
324
|
|
326
325
|
@smallexample
|
327
326
|
$ @b{byebug hanoi.rb}
|
@@ -1115,9 +1114,9 @@ Restart byebug when your program terminates normally.
|
|
1115
1114
|
|
1116
1115
|
@item --no-rewrite-program
|
1117
1116
|
@cindex @option{--no-rewrite-program}
|
1118
|
-
Normally @code{byebug} will reset the program name @code{$0} from its
|
1119
|
-
|
1120
|
-
|
1117
|
+
Normally @code{byebug} will reset the program name @code{$0} from its name to
|
1118
|
+
the debugged program, and set the its name in variable @code{$BYEBUG_SCRIPT}. In
|
1119
|
+
the unlikely even you don't want this use this option.
|
1121
1120
|
|
1122
1121
|
@item --no-stop
|
1123
1122
|
@cindex @option{--no-stop}
|
@@ -2074,19 +2073,18 @@ frames in @value{DBG} commands.
|
|
2074
2073
|
@cindex backtraces
|
2075
2074
|
@cindex tracebacks
|
2076
2075
|
@cindex stack traces
|
2077
|
-
A backtrace is essentially the same as the call stack: a summary of
|
2078
|
-
|
2079
|
-
|
2080
|
-
|
2076
|
+
A backtrace is essentially the same as the call stack: a summary of how your
|
2077
|
+
script got where it is. It shows one line per frame, for many frames, starting
|
2078
|
+
with the place that you are stopped at (frame zero), followed by its caller
|
2079
|
+
(frame one), and on up the stack.
|
2081
2080
|
|
2082
2081
|
@table @code
|
2083
2082
|
@kindex where
|
2084
2083
|
@kindex w @r{(@code{where})}
|
2085
2084
|
@itemx where
|
2086
2085
|
Print the entire stack frame; @code{info stack} is an alias for this command.
|
2087
|
-
Each frame is numbered and can be referred to in the @code{frame}
|
2088
|
-
|
2089
|
-
frame numbers shown. The position of the current frame is marked with
|
2086
|
+
Each frame is numbered and can be referred to in the @code{frame} command;
|
2087
|
+
@code{up} and @code{down} add or subtract respectively to frame numbers shown. The position of the current frame is marked with
|
2090
2088
|
@code{-->}.
|
2091
2089
|
|
2092
2090
|
@smallexample
|
@@ -2113,33 +2111,30 @@ Similar, but print only the outermost @var{n} frames.
|
|
2113
2111
|
@node Selection
|
2114
2112
|
@subsection Selecting a frame (@samp{up}, @samp{down}, @samp{frame})
|
2115
2113
|
|
2116
|
-
Commands for listing source code in your script work on whichever
|
2117
|
-
|
2118
|
-
|
2119
|
-
description of the stack frame just selected.
|
2114
|
+
Commands for listing source code in your script work on whichever stack frame is
|
2115
|
+
selected at the moment. Here are the commands for selecting a stack frame; all
|
2116
|
+
of them finish by printing a brief description of the stack frame just selected.
|
2120
2117
|
|
2121
2118
|
@table @code
|
2122
2119
|
@kindex up @ovar{n}
|
2123
2120
|
@item up @ovar{n}
|
2124
|
-
Move @var{n} frames up the stack. For positive numbers @var{n}, this
|
2125
|
-
|
2126
|
-
|
2127
|
-
|
2128
|
-
|
2129
|
-
|
2130
|
-
a front end also watching over things.
|
2121
|
+
Move @var{n} frames up the stack. For positive numbers @var{n}, this advances
|
2122
|
+
toward the outermost frame, to higher frame numbers, to frames that have existed
|
2123
|
+
longer. Using a negative @var{n} is the same thing as issuing a @code{down}
|
2124
|
+
command of the absolute value of the @var{n}. Using zero for @var{n} does no
|
2125
|
+
frame adjustment, but since the current position is redisplayed, it may trigger
|
2126
|
+
a resynchronization if there is a front end also watching over things.
|
2131
2127
|
|
2132
2128
|
@var{n} defaults to one. You may abbreviate @code{up} as @code{u}.
|
2133
2129
|
|
2134
2130
|
@kindex down @ovar{n}
|
2135
2131
|
@item down @ovar{n}
|
2136
|
-
Move @var{n} frames down the stack. For positive numbers @var{n}, this
|
2137
|
-
|
2138
|
-
|
2139
|
-
|
2140
|
-
|
2141
|
-
|
2142
|
-
a front end also watching over things.
|
2132
|
+
Move @var{n} frames down the stack. For positive numbers @var{n}, this advances
|
2133
|
+
toward the innermost frame, to lower frame numbers, to frames that were created
|
2134
|
+
more recently. Using a negative @var{n} is the same as issuing a @code{up}
|
2135
|
+
command of the absolute value of the @var{n}. Using zero for @var{n} does no
|
2136
|
+
frame adjustment, but since the current position is redisplayed, it may trigger
|
2137
|
+
a resynchronization if there is a front end also watching over things.
|
2143
2138
|
|
2144
2139
|
@var{n} defaults to one.
|
2145
2140
|
@end table
|
@@ -2148,22 +2143,21 @@ a front end also watching over things.
|
|
2148
2143
|
@kindex frame @r{[}@ovar{n} @r{[}thread @var{thread-num}@r{]}@r{]}
|
2149
2144
|
@cindex current stack frame
|
2150
2145
|
@item frame @ovar{n} @r{[}thread @var{thread-num}@r{]}
|
2151
|
-
The @code{frame} command allows you to move from one stack frame to
|
2152
|
-
|
2153
|
-
|
2154
|
-
|
2155
|
-
|
2156
|
-
If a negative number is given, counting is from the other end of the
|
2157
|
-
|
2158
|
-
|
2159
|
-
|
2160
|
-
Without an argument, @code{frame} prints the current stack
|
2161
|
-
|
2162
|
-
|
2163
|
-
|
2164
|
-
|
2165
|
-
|
2166
|
-
expressions to that frame of that thread.
|
2146
|
+
The @code{frame} command allows you to move from one stack frame to another, and
|
2147
|
+
to print the stack frame you select. @var{n} is the the stack frame number or 0
|
2148
|
+
if no frame number is given; @code{frame 0} then will always show the current
|
2149
|
+
and most recent stack frame.
|
2150
|
+
|
2151
|
+
If a negative number is given, counting is from the other end of the stack
|
2152
|
+
frame, so @code{frame -1} shows the least-recent, outermost or most ``main''
|
2153
|
+
stack frame.
|
2154
|
+
|
2155
|
+
Without an argument, @code{frame} prints the current stack frame. Since the
|
2156
|
+
current position is redisplayed, it may trigger a resynchronization if there is
|
2157
|
+
a front end also watching over things.
|
2158
|
+
|
2159
|
+
If a thread number is given then we set the context for evaluating expressions
|
2160
|
+
to that frame of that thread.
|
2167
2161
|
@end table
|
2168
2162
|
|
2169
2163
|
@node Stopping
|