byebug 4.0.5 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +72 -34
  3. data/CONTRIBUTING.md +26 -31
  4. data/README.md +3 -3
  5. data/lib/byebug/breakpoint.rb +2 -1
  6. data/lib/byebug/command.rb +27 -49
  7. data/lib/byebug/commands/break.rb +21 -15
  8. data/lib/byebug/commands/catch.rb +9 -15
  9. data/lib/byebug/commands/condition.rb +12 -15
  10. data/lib/byebug/commands/continue.rb +8 -11
  11. data/lib/byebug/commands/delete.rb +9 -12
  12. data/lib/byebug/commands/disable.rb +32 -0
  13. data/lib/byebug/commands/disable/breakpoints.rb +38 -0
  14. data/lib/byebug/commands/disable/display.rb +39 -0
  15. data/lib/byebug/commands/display.rb +18 -51
  16. data/lib/byebug/commands/down.rb +39 -0
  17. data/lib/byebug/commands/edit.rb +8 -14
  18. data/lib/byebug/commands/enable.rb +25 -0
  19. data/lib/byebug/commands/enable/breakpoints.rb +38 -0
  20. data/lib/byebug/commands/enable/display.rb +39 -0
  21. data/lib/byebug/commands/eval.rb +10 -192
  22. data/lib/byebug/commands/finish.rb +11 -12
  23. data/lib/byebug/commands/frame.rb +17 -182
  24. data/lib/byebug/commands/help.rb +18 -18
  25. data/lib/byebug/commands/history.rb +9 -10
  26. data/lib/byebug/commands/info.rb +17 -190
  27. data/lib/byebug/commands/info/args.rb +39 -0
  28. data/lib/byebug/commands/info/breakpoints.rb +59 -0
  29. data/lib/byebug/commands/info/catch.rb +39 -0
  30. data/lib/byebug/commands/info/display.rb +42 -0
  31. data/lib/byebug/commands/info/file.rb +81 -0
  32. data/lib/byebug/commands/info/line.rb +31 -0
  33. data/lib/byebug/commands/info/program.rb +51 -0
  34. data/lib/byebug/commands/interrupt.rb +5 -9
  35. data/lib/byebug/commands/irb.rb +5 -9
  36. data/lib/byebug/commands/kill.rb +6 -12
  37. data/lib/byebug/commands/list.rb +47 -19
  38. data/lib/byebug/commands/method.rb +8 -14
  39. data/lib/byebug/commands/next.rb +36 -0
  40. data/lib/byebug/commands/pp.rb +41 -0
  41. data/lib/byebug/commands/pry.rb +5 -9
  42. data/lib/byebug/commands/ps.rb +44 -0
  43. data/lib/byebug/commands/putl.rb +43 -0
  44. data/lib/byebug/commands/quit.rb +8 -12
  45. data/lib/byebug/commands/restart.rb +6 -12
  46. data/lib/byebug/commands/save.rb +30 -39
  47. data/lib/byebug/commands/set.rb +19 -21
  48. data/lib/byebug/commands/show.rb +10 -16
  49. data/lib/byebug/commands/source.rb +6 -12
  50. data/lib/byebug/commands/step.rb +36 -0
  51. data/lib/byebug/commands/thread.rb +13 -130
  52. data/lib/byebug/commands/thread/current.rb +35 -0
  53. data/lib/byebug/commands/thread/list.rb +41 -0
  54. data/lib/byebug/commands/thread/resume.rb +45 -0
  55. data/lib/byebug/commands/thread/stop.rb +41 -0
  56. data/lib/byebug/commands/thread/switch.rb +43 -0
  57. data/lib/byebug/commands/tracevar.rb +8 -14
  58. data/lib/byebug/commands/undisplay.rb +12 -15
  59. data/lib/byebug/commands/untracevar.rb +5 -11
  60. data/lib/byebug/commands/up.rb +39 -0
  61. data/lib/byebug/commands/var.rb +15 -94
  62. data/lib/byebug/commands/var/all.rb +37 -0
  63. data/lib/byebug/commands/var/const.rb +38 -0
  64. data/lib/byebug/commands/var/global.rb +33 -0
  65. data/lib/byebug/commands/var/instance.rb +35 -0
  66. data/lib/byebug/commands/var/local.rb +35 -0
  67. data/lib/byebug/commands/where.rb +47 -0
  68. data/lib/byebug/core.rb +10 -0
  69. data/lib/byebug/helpers/eval.rb +47 -0
  70. data/lib/byebug/helpers/file.rb +46 -0
  71. data/lib/byebug/helpers/frame.rb +76 -0
  72. data/lib/byebug/helpers/parse.rb +74 -0
  73. data/lib/byebug/helpers/string.rb +24 -0
  74. data/lib/byebug/helpers/thread.rb +53 -0
  75. data/lib/byebug/helpers/toggle.rb +56 -0
  76. data/lib/byebug/helpers/var.rb +45 -0
  77. data/lib/byebug/history.rb +2 -4
  78. data/lib/byebug/interface.rb +5 -3
  79. data/lib/byebug/interfaces/local_interface.rb +3 -1
  80. data/lib/byebug/interfaces/remote_interface.rb +3 -1
  81. data/lib/byebug/interfaces/test_interface.rb +6 -2
  82. data/lib/byebug/printers/plain.rb +1 -1
  83. data/lib/byebug/processors/command_processor.rb +9 -11
  84. data/lib/byebug/processors/control_command_processor.rb +1 -1
  85. data/lib/byebug/remote.rb +3 -0
  86. data/lib/byebug/runner.rb +5 -3
  87. data/lib/byebug/setting.rb +2 -18
  88. data/lib/byebug/settings/savefile.rb +21 -0
  89. data/lib/byebug/states/regular_state.rb +15 -6
  90. data/lib/byebug/subcommand_list.rb +33 -0
  91. data/lib/byebug/subcommands.rb +53 -0
  92. data/lib/byebug/version.rb +1 -1
  93. metadata +45 -6
  94. data/lib/byebug/commands/enable_disable.rb +0 -132
  95. data/lib/byebug/commands/stepping.rb +0 -75
  96. data/lib/byebug/helper.rb +0 -131
@@ -0,0 +1,38 @@
1
+ require 'byebug/helpers/toggle'
2
+
3
+ module Byebug
4
+ #
5
+ # Reopens the +enable+ command to define the +breakpoints+ subcommand
6
+ #
7
+ class EnableCommand < Command
8
+ #
9
+ # Enables all or specific breakpoints
10
+ #
11
+ class BreakpointsSubcommand < Command
12
+ include Helpers::ToggleHelper
13
+
14
+ def regexp
15
+ /^\s* b(?:reakpoints)? (?:\s+ (.+))? \s*$/x
16
+ end
17
+
18
+ def execute
19
+ enable_disable_breakpoints('enable', @match[1])
20
+ end
21
+
22
+ def short_description
23
+ 'Disable all or specific breakpoints'
24
+ end
25
+
26
+ def description
27
+ <<-EOD
28
+ en[able] b[reakpoints][ <ids>]
29
+
30
+ #{short_description}
31
+
32
+ Give breakpoint numbers (separated by spaces) as arguments or no
33
+ argument at all if you want to enable every breakpoint.
34
+ EOD
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,39 @@
1
+ require 'byebug/helpers/toggle'
2
+
3
+ module Byebug
4
+ #
5
+ # Reopens the +enable+ command to define the +display+ subcommand
6
+ #
7
+ class EnableCommand < Command
8
+ #
9
+ # Enables all or specific displays
10
+ #
11
+ class DisplaySubcommand < Command
12
+ include Helpers::ToggleHelper
13
+
14
+ def regexp
15
+ /^\s* d(?:isplay)? (?:\s+ (.+))? \s*$/x
16
+ end
17
+
18
+ def execute
19
+ enable_disable_display('enable', @match[1])
20
+ end
21
+
22
+ def short_description
23
+ 'Enables expressions to be displayed when program stops.'
24
+ end
25
+
26
+ def description
27
+ <<-EOD
28
+ en[able] d[isplay][ <id1> <id2> .. <idn>]
29
+
30
+ #{short_description}
31
+
32
+ Arguments are the code numbers of the expressions to enable. Do "info
33
+ display" to see the current list of code numbers. If no arguments are
34
+ specified, all displays are enabled.
35
+ EOD
36
+ end
37
+ end
38
+ end
39
+ end
@@ -1,60 +1,13 @@
1
- require 'byebug/command'
2
-
3
1
  require 'English'
4
- require 'pp'
2
+ require 'byebug/command'
3
+ require 'byebug/helpers/eval'
5
4
 
6
5
  module Byebug
7
- #
8
- # Utilities used by the eval command
9
- #
10
- module EvalFunctions
11
- #
12
- # Run block temporarily ignoring all TracePoint events.
13
- #
14
- # Used to evaluate stuff within Byebug's prompt. Otherwise, any code
15
- # creating new threads won't be properly evaluated because new threads will
16
- # get blocked by byebug's main thread.
17
- #
18
- def allowing_other_threads
19
- Byebug.unlock
20
- res = yield
21
- Byebug.lock
22
- res
23
- end
24
-
25
- #
26
- # Get current binding and yield it to the given block
27
- #
28
- def run_with_binding
29
- binding = get_binding
30
- yield binding
31
- end
32
-
33
- #
34
- # Evaluate +expression+ using +binding+
35
- #
36
- # @param binding [Binding] Context where to evaluate the expression
37
- # @param expression [String] Expression to evaluation
38
- # @param stack_on_error [Boolean] Whether to show a stack trace on error.
39
- #
40
- def eval_with_setting(binding, expression, stack_on_error)
41
- allowing_other_threads do
42
- if stack_on_error
43
- bb_eval(expression, binding)
44
- else
45
- bb_warning_eval(expression, binding)
46
- end
47
- end
48
- end
49
- end
50
-
51
6
  #
52
7
  # Evaluation of expressions from byebug's prompt.
53
8
  #
54
9
  class EvalCommand < Command
55
- include EvalFunctions
56
-
57
- self.allow_in_control = true
10
+ include Helpers::EvalHelper
58
11
 
59
12
  def match(input)
60
13
  @input = input
@@ -76,150 +29,15 @@ module Byebug
76
29
  puts "#{$ERROR_INFO.class} Exception: #{$ERROR_INFO.message}"
77
30
  end
78
31
 
79
- class << self
80
- def names
81
- %w(eval)
82
- end
83
-
84
- def description
85
- prettify <<-EOD
86
- e[val] <expression>
87
-
88
- Evaluates <expression> and prints its value.
89
-
90
- * NOTE - unknown input is automatically evaluated, to turn this off
91
- use 'set noautoeval'.
92
- EOD
93
- end
94
- end
95
- end
96
-
97
- #
98
- # Evaluation and pretty printing from byebug's prompt.
99
- #
100
- class PPCommand < Command
101
- include EvalFunctions
102
-
103
- self.allow_in_control = true
104
-
105
- def regexp
106
- /^\s* pp \s+/x
107
- end
108
-
109
- def execute
110
- out = StringIO.new
111
- run_with_binding do |b|
112
- if Setting[:stack_on_error]
113
- PP.pp(bb_eval(@match.post_match, b), out)
114
- else
115
- PP.pp(bb_warning_eval(@match.post_match, b), out)
116
- end
117
- end
118
- puts out.string
119
- rescue
120
- out.puts $ERROR_INFO.message
121
- end
122
-
123
- class << self
124
- def names
125
- %w(pp)
126
- end
127
-
128
- def description
129
- prettify <<-EOD
130
- pp <expression>
32
+ def description
33
+ <<-EOD
34
+ e[val] <expression>
131
35
 
132
- Evaluates <expression> and pretty-prints its value.
133
- EOD
134
- end
135
- end
136
- end
36
+ Evaluates <expression> and prints its value.
137
37
 
138
- #
139
- # Evaluation, pretty printing and columnizing from byebug's prompt.
140
- #
141
- class PutLCommand < Command
142
- include EvalFunctions
143
- include Columnize
144
-
145
- self.allow_in_control = true
146
-
147
- def regexp
148
- /^\s* putl \s+/x
149
- end
150
-
151
- def execute
152
- out = StringIO.new
153
- run_with_binding do |b|
154
- res = eval_with_setting(b, @match.post_match, Setting[:stack_on_error])
155
-
156
- if res.is_a?(Array)
157
- puts "#{columnize(res.map(&:to_s), Setting[:width])}"
158
- else
159
- PP.pp(res, out)
160
- puts out.string
161
- end
162
- end
163
- rescue
164
- out.puts $ERROR_INFO.message
165
- end
166
-
167
- class << self
168
- def names
169
- %w(putl)
170
- end
171
-
172
- def description
173
- prettify <<-EOD
174
- putl <expression>
175
-
176
- Evaluates <expression>, an array, and columnize its value.
177
- EOD
178
- end
179
- end
180
- end
181
-
182
- #
183
- # Evaluation, pretty printing, columnizing and sorting from byebug's prompt
184
- #
185
- class PSCommand < Command
186
- include EvalFunctions
187
- include Columnize
188
-
189
- self.allow_in_control = true
190
-
191
- def regexp
192
- /^\s* ps \s+/x
193
- end
194
-
195
- def execute
196
- out = StringIO.new
197
- run_with_binding do |b|
198
- res = eval_with_setting(b, @match.post_match, Setting[:stack_on_error])
199
-
200
- if res.is_a?(Array)
201
- puts "#{columnize(res.map(&:to_s).sort!, Setting[:width])}"
202
- else
203
- PP.pp(res, out)
204
- puts out.string
205
- end
206
- end
207
- rescue
208
- out.puts $ERROR_INFO.message
209
- end
210
-
211
- class << self
212
- def names
213
- %w(ps)
214
- end
215
-
216
- def description
217
- prettify <<-EOD
218
- ps <expression>
219
-
220
- Evaluates <expression>, an array, sort and columnize its value.
221
- EOD
222
- end
38
+ * NOTE - unknown input is automatically evaluated, to turn this off use
39
+ 'set noautoeval'.
40
+ EOD
223
41
  end
224
42
  end
225
43
  end
@@ -1,4 +1,5 @@
1
1
  require 'byebug/command'
2
+ require 'byebug/helpers/parse'
2
3
 
3
4
  module Byebug
4
5
  #
@@ -7,6 +8,8 @@ module Byebug
7
8
  # Allows the user to continue execution until certain frames are finished.
8
9
  #
9
10
  class FinishCommand < Command
11
+ include Helpers::ParseHelper
12
+
10
13
  self.allow_in_post_mortem = false
11
14
 
12
15
  def regexp
@@ -28,20 +31,16 @@ module Byebug
28
31
  @state.proceed
29
32
  end
30
33
 
31
- class << self
32
- def names
33
- %w(finish)
34
- end
34
+ def description
35
+ <<-EOD
36
+ fin[ish][ n_frames]
35
37
 
36
- def description
37
- prettify <<-EOD
38
- fin[ish][ n_frames] Execute until frame returns.
38
+ Execute until frame returns.
39
39
 
40
- If no number is given, we run until the current frame returns. If a
41
- number of frames `n_frames` is given, then we run until `n_frames`
42
- return from the current position.
43
- EOD
44
- end
40
+ If no number is given, we run until the current frame returns. If a
41
+ number of frames `n_frames` is given, then we run until `n_frames`
42
+ return from the current position.
43
+ EOD
45
44
  end
46
45
  end
47
46
  end
@@ -1,177 +1,17 @@
1
- require 'byebug/command'
2
-
3
1
  # encoding: utf-8
4
2
 
5
3
  require 'pathname'
4
+ require 'byebug/command'
5
+ require 'byebug/helpers/frame'
6
+ require 'byebug/helpers/parse'
6
7
 
7
8
  module Byebug
8
- #
9
- # Mixin to assist command parsing
10
- #
11
- module FrameFunctions
12
- def switch_to_frame(frame_no)
13
- frame_no >= 0 ? frame_no : @state.context.stack_size + frame_no
14
- end
15
-
16
- def navigate_to_frame(jump_no)
17
- return if jump_no == 0
18
- total_jumps, current_jumps, new_pos = jump_no.abs, 0, @state.frame
19
- step = jump_no / total_jumps # +1 (up) or -1 (down)
20
-
21
- loop do
22
- new_pos += step
23
- break if new_pos < 0 || new_pos >= @state.context.stack_size
24
-
25
- next if @state.c_frame?(new_pos)
26
-
27
- current_jumps += 1
28
- break if current_jumps == total_jumps
29
- end
30
- new_pos
31
- end
32
-
33
- def adjust_frame(frame, absolute)
34
- if absolute
35
- abs_frame = switch_to_frame(frame)
36
- return errmsg(pr('frame.errors.c_frame')) if @state.c_frame?(abs_frame)
37
- else
38
- abs_frame = navigate_to_frame(frame)
39
- end
40
-
41
- if abs_frame >= @state.context.stack_size
42
- return errmsg(pr('frame.errors.too_low'))
43
- elsif abs_frame < 0
44
- return errmsg(pr('frame.errors.too_high'))
45
- end
46
-
47
- @state.frame = abs_frame
48
- @state.file = @state.context.frame_file(@state.frame)
49
- @state.line = @state.context.frame_line(@state.frame)
50
- @state.prev_line = nil
51
-
52
- ListCommand.new(@state).execute if Setting[:autolist]
53
- end
54
-
55
- def get_pr_arguments(frame_no)
56
- file = @state.frame_file(frame_no)
57
- line = @state.frame_line(frame_no)
58
- call = @state.frame_call(frame_no)
59
- mark = @state.frame_mark(frame_no)
60
- pos = @state.frame_pos(frame_no)
61
-
62
- { mark: mark, pos: pos, call: call, file: file, line: line }
63
- end
64
- end
65
-
66
- #
67
- # Show current backtrace.
68
- #
69
- class WhereCommand < Command
70
- include FrameFunctions
71
-
72
- def regexp
73
- /^\s* (?:w(?:here)?|bt|backtrace) \s*$/x
74
- end
75
-
76
- def execute
77
- print_backtrace
78
- end
79
-
80
- class << self
81
- def names
82
- %w(where backtrace bt)
83
- end
84
-
85
- def description
86
- prettify <<-EOD
87
- w[here]|bt|backtrace Display stack frames.
88
-
89
- Print the entire stack frame. Each frame is numbered; the most recent
90
- frame is 0. A frame number can be referred to in the "frame" command;
91
- "up" and "down" add or subtract respectively to frame numbers shown.
92
- The position of the current frame is marked with -->. C-frames hang
93
- from their most immediate Ruby frame to indicate that they are not
94
- navigable.
95
- EOD
96
- end
97
- end
98
-
99
- private
100
-
101
- def print_backtrace
102
- bt = prc('frame.line', (0...@state.context.stack_size)) do |_, index|
103
- get_pr_arguments(index)
104
- end
105
-
106
- print(bt)
107
- end
108
- end
109
-
110
- #
111
- # Move the current frame up in the backtrace.
112
- #
113
- class UpCommand < Command
114
- include FrameFunctions
115
-
116
- def regexp
117
- /^\s* u(?:p)? (?:\s+(\S+))? \s*$/x
118
- end
119
-
120
- def execute
121
- pos, err = parse_steps(@match[1], 'Up')
122
- return errmsg(err) unless pos
123
-
124
- adjust_frame(pos, false)
125
- end
126
-
127
- class << self
128
- def names
129
- %w(up)
130
- end
131
-
132
- def description
133
- prettify <<-EOD
134
- up[ count] Move to higher frame.
135
- EOD
136
- end
137
- end
138
- end
139
-
140
- #
141
- # Move the current frame down in the backtrace.
142
- #
143
- class DownCommand < Command
144
- include FrameFunctions
145
-
146
- def regexp
147
- /^\s* down (?:\s+(\S+))? \s*$/x
148
- end
149
-
150
- def execute
151
- pos, err = parse_steps(@match[1], 'Down')
152
- return errmsg(err) unless pos
153
-
154
- adjust_frame(-pos, false)
155
- end
156
-
157
- class << self
158
- def names
159
- %w(down)
160
- end
161
-
162
- def description
163
- prettify <<-EOD
164
- down[ count] Move to lower frame.
165
- EOD
166
- end
167
- end
168
- end
169
-
170
9
  #
171
10
  # Move to specific frames in the backtrace.
172
11
  #
173
12
  class FrameCommand < Command
174
- include FrameFunctions
13
+ include Helpers::FrameHelper
14
+ include Helpers::ParseHelper
175
15
 
176
16
  def regexp
177
17
  /^\s* f(?:rame)? (?:\s+(\S+))? \s*$/x
@@ -189,27 +29,22 @@ module Byebug
189
29
  adjust_frame(pos, true)
190
30
  end
191
31
 
192
- class << self
193
- def names
194
- %w(frame)
195
- end
32
+ def description
33
+ <<-EOD
34
+ f[rame][ frame-number]
196
35
 
197
- def description
198
- prettify <<-EOD
199
- f[rame][ frame-number]
36
+ Move the current frame to the specified frame number, or the 0 if no
37
+ frame-number has been given.
200
38
 
201
- Move the current frame to the specified frame number, or the 0 if no
202
- frame-number has been given.
39
+ A negative number indicates position from the other end, so "frame -1"
40
+ moves to the oldest frame, and "frame 0" moves to the newest frame.
203
41
 
204
- A negative number indicates position from the other end, so
205
- "frame -1" moves to the oldest frame, and "frame 0" moves to the
206
- newest frame.
42
+ Without an argument, the command prints the current stack frame. Since
43
+ the current position is redisplayed, it may trigger a resyncronization
44
+ if there is a front end also watching over things.
207
45
 
208
- Without an argument, the command prints the current stack frame. Since
209
- the current position is redisplayed, it may trigger a resyncronization
210
- if there is a front end also watching over things.
211
- EOD
212
- end
46
+ Use the "bt" command to find out where you want to go.
47
+ EOD
213
48
  end
214
49
  end
215
50
  end