byebug 3.0.0 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (125) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +15 -0
  3. data/GUIDE.md +2 -2
  4. data/LICENSE +3 -3
  5. data/README.md +5 -4
  6. data/byebug.gemspec +1 -1
  7. data/ext/byebug/byebug.c +20 -19
  8. data/lib/byebug.rb +2 -53
  9. data/lib/byebug/command.rb +9 -109
  10. data/lib/byebug/commands/breakpoints.rb +1 -1
  11. data/lib/byebug/commands/control.rb +20 -21
  12. data/lib/byebug/commands/display.rb +2 -3
  13. data/lib/byebug/commands/eval.rb +6 -16
  14. data/lib/byebug/commands/finish.rb +1 -1
  15. data/lib/byebug/commands/frame.rb +9 -9
  16. data/lib/byebug/commands/help.rb +2 -3
  17. data/lib/byebug/commands/history.rb +28 -0
  18. data/lib/byebug/commands/info.rb +3 -3
  19. data/lib/byebug/commands/list.rb +2 -13
  20. data/lib/byebug/commands/method.rb +5 -45
  21. data/lib/byebug/commands/reload.rb +1 -12
  22. data/lib/byebug/commands/repl.rb +6 -15
  23. data/lib/byebug/commands/save.rb +2 -7
  24. data/lib/byebug/commands/set.rb +45 -116
  25. data/lib/byebug/commands/show.rb +22 -126
  26. data/lib/byebug/commands/stepping.rb +1 -1
  27. data/lib/byebug/commands/trace.rb +14 -25
  28. data/lib/byebug/commands/variables.rb +3 -41
  29. data/lib/byebug/helper.rb +11 -42
  30. data/lib/byebug/history.rb +5 -13
  31. data/lib/byebug/processors/command_processor.rb +6 -6
  32. data/lib/byebug/setting.rb +82 -0
  33. data/lib/byebug/settings/autoeval.rb +20 -0
  34. data/lib/byebug/settings/autoirb.rb +19 -0
  35. data/lib/byebug/settings/autolist.rb +19 -0
  36. data/lib/byebug/settings/autoreload.rb +11 -0
  37. data/lib/byebug/settings/autosave.rb +11 -0
  38. data/lib/byebug/settings/basename.rb +7 -0
  39. data/lib/byebug/settings/callstyle.rb +15 -0
  40. data/lib/byebug/settings/forcestep.rb +11 -0
  41. data/lib/byebug/settings/fullpath.rb +11 -0
  42. data/lib/byebug/settings/histfile.rb +16 -0
  43. data/lib/byebug/settings/histsize.rb +18 -0
  44. data/lib/byebug/settings/linetrace.rb +15 -0
  45. data/lib/byebug/settings/listsize.rb +15 -0
  46. data/lib/byebug/settings/post_mortem.rb +15 -0
  47. data/lib/byebug/settings/stack_on_error.rb +7 -0
  48. data/lib/byebug/settings/testing.rb +7 -0
  49. data/lib/byebug/settings/tracing_plus.rb +7 -0
  50. data/lib/byebug/settings/verbose.rb +7 -0
  51. data/lib/byebug/settings/width.rb +29 -0
  52. data/lib/byebug/version.rb +1 -1
  53. data/test/breakpoints_test.rb +345 -324
  54. data/test/conditions_test.rb +61 -48
  55. data/test/continue_test.rb +38 -27
  56. data/test/debugger_alias_test.rb +5 -3
  57. data/test/display_test.rb +103 -92
  58. data/test/edit_test.rb +42 -34
  59. data/test/eval_test.rb +91 -75
  60. data/test/finish_test.rb +51 -40
  61. data/test/frame_test.rb +197 -184
  62. data/test/help_test.rb +47 -38
  63. data/test/history_test.rb +54 -0
  64. data/test/info_test.rb +306 -293
  65. data/test/interrupt_test.rb +44 -38
  66. data/test/kill_test.rb +40 -31
  67. data/test/list_test.rb +166 -133
  68. data/test/method_test.rb +67 -60
  69. data/test/post_mortem_test.rb +56 -48
  70. data/test/quit_test.rb +44 -35
  71. data/test/reload_test.rb +36 -24
  72. data/test/repl_test.rb +57 -47
  73. data/test/restart_test.rb +56 -69
  74. data/test/save_test.rb +62 -53
  75. data/test/set_test.rb +140 -118
  76. data/test/show_test.rb +68 -201
  77. data/test/source_test.rb +39 -29
  78. data/test/stepping_test.rb +163 -136
  79. data/test/support/test_dsl.rb +9 -11
  80. data/test/test_helper.rb +2 -7
  81. data/test/thread_test.rb +121 -107
  82. data/test/trace_test.rb +86 -83
  83. data/test/variables_test.rb +104 -98
  84. metadata +27 -86
  85. data/test/examples/breakpoint.rb +0 -6
  86. data/test/examples/breakpoint_deep.rb +0 -4
  87. data/test/examples/conditions.rb +0 -4
  88. data/test/examples/continue.rb +0 -5
  89. data/test/examples/display.rb +0 -5
  90. data/test/examples/edit.rb +0 -4
  91. data/test/examples/eval.rb +0 -4
  92. data/test/examples/finish.rb +0 -3
  93. data/test/examples/frame.rb +0 -4
  94. data/test/examples/frame_deep.rb +0 -1
  95. data/test/examples/gcd.rb +0 -15
  96. data/test/examples/hanoi.rb +0 -34
  97. data/test/examples/help.rb +0 -1
  98. data/test/examples/info.rb +0 -6
  99. data/test/examples/info2.rb +0 -3
  100. data/test/examples/interrupt.rb +0 -8
  101. data/test/examples/kill.rb +0 -2
  102. data/test/examples/list.rb +0 -23
  103. data/test/examples/method.rb +0 -4
  104. data/test/examples/post_mortem.rb +0 -4
  105. data/test/examples/primes.rb +0 -25
  106. data/test/examples/quit.rb +0 -2
  107. data/test/examples/reload.rb +0 -6
  108. data/test/examples/repl.rb +0 -6
  109. data/test/examples/restart.rb +0 -6
  110. data/test/examples/save.rb +0 -3
  111. data/test/examples/set.rb +0 -3
  112. data/test/examples/settings.rb +0 -1
  113. data/test/examples/show.rb +0 -1
  114. data/test/examples/source.rb +0 -3
  115. data/test/examples/stepping.rb +0 -8
  116. data/test/examples/stepping_raise_from_c_method.rb +0 -3
  117. data/test/examples/stepping_raise_from_ruby_method.rb +0 -3
  118. data/test/examples/test-triangle.rb +0 -14
  119. data/test/examples/thread.rb +0 -5
  120. data/test/examples/tmate.rb +0 -10
  121. data/test/examples/trace.rb +0 -8
  122. data/test/examples/tri3.rb +0 -6
  123. data/test/examples/triangle.rb +0 -13
  124. data/test/examples/variables.rb +0 -4
  125. data/test/timeout_test.rb +0 -9
@@ -1,5 +1,4 @@
1
1
  module Byebug
2
-
3
2
  module DisplayFunctions
4
3
  def display_expression(exp)
5
4
  print "#{exp} = #{bb_warning_eval(exp).inspect}\n"
@@ -81,13 +80,13 @@ module Byebug
81
80
 
82
81
  def execute
83
82
  unless pos = @match[1]
84
- if confirm("Clear all expressions? (y/n) ")
83
+ if confirm('Clear all expressions? (y/n) ')
85
84
  for d in @state.display
86
85
  d[0] = false
87
86
  end
88
87
  end
89
88
  else
90
- pos = get_int(pos, "Undisplay")
89
+ pos = get_int(pos, 'Undisplay')
91
90
  return unless pos
92
91
  if @state.display[pos-1]
93
92
  @state.display[pos-1][0] = nil
@@ -11,16 +11,6 @@ module Byebug
11
11
  class EvalCommand < Command
12
12
  self.allow_in_control = true
13
13
 
14
- register_setting_get(:autoeval) do
15
- EvalCommand.unknown
16
- end
17
- register_setting_set(:autoeval) do |value|
18
- EvalCommand.unknown = value
19
- end
20
-
21
- # Set default value
22
- Command.settings[:autoeval] = true
23
-
24
14
  def match(input)
25
15
  @input = input
26
16
  super
@@ -33,7 +23,7 @@ module Byebug
33
23
  def execute
34
24
  expr = @match ? @match.post_match : @input
35
25
  run_with_binding do |b|
36
- if Command.settings[:stack_on_error]
26
+ if Setting[:stack_on_error]
37
27
  print "#{bb_eval(expr, b).inspect}\n"
38
28
  else
39
29
  print "#{bb_warning_eval(expr, b).inspect}\n"
@@ -68,7 +58,7 @@ module Byebug
68
58
  def execute
69
59
  out = StringIO.new
70
60
  run_with_binding do |b|
71
- if Command.settings[:stack_on_error]
61
+ if Setting[:stack_on_error]
72
62
  PP.pp(bb_eval(@match.post_match, b), out)
73
63
  else
74
64
  PP.pp(bb_warning_eval(@match.post_match, b), out)
@@ -101,14 +91,14 @@ module Byebug
101
91
  def execute
102
92
  out = StringIO.new
103
93
  run_with_binding do |b|
104
- if Command.settings[:stack_on_error]
94
+ if Setting[:stack_on_error]
105
95
  vals = bb_eval(@match.post_match, b)
106
96
  else
107
97
  vals = bb_warning_eval(@match.post_match, b)
108
98
  end
109
99
  if vals.is_a?(Array)
110
100
  vals = vals.map{|item| item.to_s}
111
- print "#{columnize(vals, Command.settings[:width])}\n"
101
+ print "#{columnize(vals, Setting[:width])}\n"
112
102
  else
113
103
  PP.pp(vals, out)
114
104
  print out.string
@@ -142,14 +132,14 @@ module Byebug
142
132
  def execute
143
133
  out = StringIO.new
144
134
  run_with_binding do |b|
145
- if Command.settings[:stack_on_error]
135
+ if Setting[:stack_on_error]
146
136
  vals = bb_eval(@match.post_match, b)
147
137
  else
148
138
  vals = bb_warning_eval(@match.post_match, b)
149
139
  end
150
140
  if vals.is_a?(Array)
151
141
  vals = vals.map{|item| item.to_s}
152
- print "#{columnize(vals.sort!, Command.settings[:width])}\n"
142
+ print "#{columnize(vals.sort!, Setting[:width])}\n"
153
143
  else
154
144
  PP.pp(vals, out)
155
145
  print out.string
@@ -10,7 +10,7 @@ module Byebug
10
10
 
11
11
  def execute
12
12
  max_frames = Context.stack_size - @state.frame_pos
13
- n_frames = get_int(@match[1], "finish", 0, max_frames - 1, 1)
13
+ n_frames = get_int(@match[1], 'finish', 0, max_frames - 1, 1)
14
14
  return nil unless n_frames
15
15
 
16
16
  force = n_frames == 0 ? true : false
@@ -86,12 +86,12 @@ module Byebug
86
86
 
87
87
  def get_frame_call(prefix, pos)
88
88
  frame_block, frame_method = get_frame_block_and_method(pos)
89
- frame_class = get_frame_class(Command.settings[:callstyle], pos)
90
- frame_args = get_frame_args(Command.settings[:callstyle], pos)
89
+ frame_class = get_frame_class(Setting[:callstyle], pos)
90
+ frame_args = get_frame_args(Setting[:callstyle], pos)
91
91
 
92
92
  call_str = frame_block + frame_class + frame_method + frame_args
93
93
 
94
- max_call_str_size = Command.settings[:width] - prefix.size
94
+ max_call_str_size = Setting[:width] - prefix.size
95
95
  if call_str.size > max_call_str_size
96
96
  call_str = call_str[0..max_call_str_size - 5] + "...)"
97
97
  end
@@ -122,7 +122,7 @@ module Byebug
122
122
  file = @state.context.frame_file pos
123
123
  line = @state.context.frame_line pos
124
124
 
125
- unless Command.settings[:fullpath]
125
+ unless Setting[:fullpath]
126
126
  path_components = file.split(/[\\\/]/)
127
127
  if path_components.size > 3
128
128
  path_components[0...-3] = '...'
@@ -140,7 +140,7 @@ module Byebug
140
140
  frame_str += sprintf "#%-2d ", pos
141
141
  frame_str += get_frame_call frame_str, pos
142
142
  file_line = "at #{CommandProcessor.canonic_file(file)}:#{line}"
143
- if frame_str.size + file_line.size + 1 > Command.settings[:width]
143
+ if frame_str.size + file_line.size + 1 > Setting[:width]
144
144
  frame_str += "\n #{file_line}\n"
145
145
  else
146
146
  frame_str += " #{file_line}\n"
@@ -162,7 +162,7 @@ module Byebug
162
162
 
163
163
  class << self
164
164
  def names
165
- %w(where backtrace)
165
+ %w(where backtrace bt)
166
166
  end
167
167
 
168
168
  def description
@@ -184,7 +184,7 @@ module Byebug
184
184
  end
185
185
 
186
186
  def execute
187
- pos = get_int(@match[1], "Up")
187
+ pos = get_int(@match[1], 'Up')
188
188
  return unless pos
189
189
  adjust_frame(pos, false)
190
190
  end
@@ -206,7 +206,7 @@ module Byebug
206
206
  end
207
207
 
208
208
  def execute
209
- pos = get_int(@match[1], "Down")
209
+ pos = get_int(@match[1], 'Down')
210
210
  return unless pos
211
211
  adjust_frame(-pos, false)
212
212
  end
@@ -229,7 +229,7 @@ module Byebug
229
229
 
230
230
  def execute
231
231
  return print_frame @state.frame_pos unless @match[1]
232
- return unless pos = get_int(@match[1], "Frame")
232
+ return unless pos = get_int(@match[1], 'Frame')
233
233
  adjust_frame(pos, true)
234
234
  end
235
235
 
@@ -26,13 +26,12 @@ module Byebug
26
26
  end
27
27
  end
28
28
 
29
- print "byebug help v#{Byebug::VERSION}\n" unless
30
- Command.settings[:testing]
29
+ print "byebug help v#{Byebug::VERSION}\n" unless Setting[:testing]
31
30
 
32
31
  print "Type \"help <command-name>\" for help on a specific command\n\n"
33
32
  print "Available commands:\n"
34
33
  cmds = @state.commands.map{ |cmd| cmd.names }.flatten.uniq.sort
35
- print columnize(cmds, Command.settings[:width])
34
+ print columnize(cmds, Setting[:width])
36
35
  end
37
36
 
38
37
  class << self
@@ -0,0 +1,28 @@
1
+ module Byebug
2
+ class HistoryCommand < Command
3
+ def regexp
4
+ /^\s* hist(?:ory)? (?:\s+(?<num_cmds>.+))? \s*$/x
5
+ end
6
+
7
+ def execute
8
+ if Byebug::Setting[:autosave]
9
+ if arg = @match[:num_cmds]
10
+ size = get_int(@match[:num_cmds], 'history', 1, Byebug::Setting[:histsize])
11
+ end
12
+ print Byebug::History.to_s(size || Byebug::Setting[:histsize])
13
+ else
14
+ errmsg "Not currently saving history. Enable it with \"set autosave\"\n"
15
+ end
16
+ end
17
+
18
+ class << self
19
+ def names
20
+ %w(history)
21
+ end
22
+
23
+ def description
24
+ %{hist[ory] [num_cmds]\t\tShow byebug's command history}
25
+ end
26
+ end
27
+ end
28
+ end
@@ -89,7 +89,7 @@ module Byebug
89
89
 
90
90
  args.map do |_, name|
91
91
  s = "#{name} = #{locals[name].inspect}"
92
- pad_with_dots(s)
92
+ s[Setting[:width]-3..-1] = "..." if s.size > Setting[:width]
93
93
  print "#{s}\n"
94
94
  end
95
95
  end
@@ -150,7 +150,7 @@ module Byebug
150
150
  breakpoints = LineCache.trace_line_numbers(file)
151
151
  if breakpoints
152
152
  print "\tbreakpoint line numbers:\n"
153
- print columnize(breakpoints.to_a.sort, Command.settings[:width])
153
+ print columnize(breakpoints.to_a.sort, Setting[:width])
154
154
  end
155
155
  end
156
156
  private :info_file_breakpoints
@@ -219,7 +219,7 @@ module Byebug
219
219
  s = "#{name} = *Error in evaluation*"
220
220
  end
221
221
  end
222
- pad_with_dots(s)
222
+ s[Setting[:width]-3..-1] = "..." if s.size > Setting[:width]
223
223
  print "#{s}\n"
224
224
  end
225
225
  end
@@ -2,30 +2,19 @@ module Byebug
2
2
 
3
3
  # Implements byebug "list" command.
4
4
  class ListCommand < Command
5
-
6
- register_setting_get(:autolist) do
7
- ListCommand.always_run
8
- end
9
- register_setting_set(:autolist) do |value|
10
- ListCommand.always_run = value
11
- end
12
-
13
- # Set default value
14
- Command.settings[:autolist] = 1
15
-
16
5
  def regexp
17
6
  /^\s* l(?:ist)? (?:\s*([-=])|\s+(\S+))? \s*$/x
18
7
  end
19
8
 
20
9
  def execute
21
- Byebug.source_reload if Command.settings[:autoreload]
10
+ Byebug.source_reload if Setting[:autoreload]
22
11
  lines = getlines(@state.file, @state.line)
23
12
  if !lines
24
13
  errmsg "No sourcefile available for #{@state.file}\n"
25
14
  return @state.previous_line
26
15
  end
27
16
 
28
- b, e = set_line_range(Command.settings[:listsize], lines.size)
17
+ b, e = set_line_range(Setting[:listsize], lines.size)
29
18
  return @state.previous_line if b < 0
30
19
 
31
20
  print "\n[#{b}, #{e}] in #{@state.file}\n"
@@ -1,42 +1,4 @@
1
1
  module Byebug
2
-
3
- begin
4
- require 'methodsig'
5
- have_methodsig = true
6
- rescue LoadError
7
- have_methodsig = false
8
- end
9
-
10
- # Implements byebug's 'method sig' command.
11
- class MethodSigCommand < Command
12
- def regexp
13
- /^\s* m(?:ethod)? \s+ sig(?:nature)? \s+ (\S+) \s*$/x
14
- end
15
-
16
- def execute
17
- obj = bb_eval('method(:%s)' % @match[1])
18
- if obj.is_a?(Method)
19
- begin
20
- print "%s\n", obj.signature.to_s
21
- rescue
22
- errmsg("Can't get signature for '#{@match[1]}'\n")
23
- end
24
- else
25
- errmsg("Can't make method out of '#{@match[1]}'\n")
26
- end
27
- end
28
-
29
- class << self
30
- def names
31
- %w(method)
32
- end
33
-
34
- def description
35
- %{m[ethod] sig[nature] <obj>\tshow the signature of a method}
36
- end
37
- end
38
- end if have_methodsig
39
-
40
2
  # Implements byebug's 'method' command.
41
3
  class MethodCommand < Command
42
4
  include Columnize
@@ -47,17 +9,16 @@ module Byebug
47
9
 
48
10
  def execute
49
11
  obj = bb_eval(@match.post_match)
50
- if @match[1] == "iv"
12
+ if @match[1] == 'iv'
51
13
  obj.instance_variables.sort.each do |v|
52
14
  print "#{v} = #{obj.instance_variable_get(v).inspect}\n"
53
15
  end
54
16
  elsif @match[1]
55
- print "#{columnize(obj.methods.sort(), Command.settings[:width])}\n"
17
+ print "#{columnize(obj.methods.sort(), Setting[:width])}\n"
18
+ elsif !obj.kind_of?(Module)
19
+ print "Should be Class/Module: #{@match.post_match}\n"
56
20
  else
57
- return print "Should be Class/Module: #{@match.post_match}\n" unless
58
- obj.kind_of? Module
59
- print "#{columnize(obj.instance_methods(false).sort(),
60
- Command.settings[:width])}\n"
21
+ print "#{columnize(obj.instance_methods(false).sort(), Setting[:width])}\n"
61
22
  end
62
23
  end
63
24
 
@@ -73,5 +34,4 @@ module Byebug
73
34
  end
74
35
  end
75
36
  end
76
-
77
37
  end
@@ -16,15 +16,6 @@ module Byebug
16
16
  self.allow_in_control = true
17
17
  self.allow_in_post_mortem = false
18
18
 
19
- register_setting_get(:autoreload) do
20
- Byebug.class_variable_get(:@@autoreload)
21
- end
22
-
23
- register_setting_set(:autoreload) do |value|
24
- Byebug.class_variable_set(:@@autoreload, value)
25
- end
26
- Command.settings[:autoreload] = true
27
-
28
19
  def regexp
29
20
  /^\s* r(?:eload)? \s*$/x
30
21
  end
@@ -32,11 +23,9 @@ module Byebug
32
23
  def execute
33
24
  Byebug.source_reload
34
25
  print "Source code is reloaded. Automatic reloading is " \
35
- "#{Command.settings[:autoreload] ? 'on' : 'off'}.\n"
26
+ "#{Setting[:autoreload] ? 'on' : 'off'}.\n"
36
27
  end
37
28
 
38
- private
39
-
40
29
  class << self
41
30
  def names
42
31
  %w(reload)
@@ -18,9 +18,9 @@ module IRB
18
18
  end
19
19
 
20
20
  require 'irb'
21
- ExtendCommandBundle.def_extend_command "cont", :Continue
22
- ExtendCommandBundle.def_extend_command "n", :Next
23
- ExtendCommandBundle.def_extend_command "step", :Step
21
+ ExtendCommandBundle.def_extend_command 'cont', :Continue
22
+ ExtendCommandBundle.def_extend_command 'next', :Next
23
+ ExtendCommandBundle.def_extend_command 'step', :Step
24
24
 
25
25
  def self.start_session(binding)
26
26
  unless @__initialized ||= false
@@ -37,7 +37,7 @@ module IRB
37
37
  @CONF[:IRB_RC].call(irb.context) if @CONF[:IRB_RC]
38
38
  @CONF[:MAIN_CONTEXT] = irb.context
39
39
 
40
- trap("SIGINT") do
40
+ trap('SIGINT') do
41
41
  irb.signal_handle
42
42
  end
43
43
 
@@ -51,13 +51,6 @@ module Byebug
51
51
 
52
52
  # Implements byebug's "irb" command.
53
53
  class IrbCommand < Command
54
- register_setting_get(:autoirb) do
55
- IrbCommand.always_run
56
- end
57
- register_setting_set(:autoirb) do |value|
58
- IrbCommand.always_run = value
59
- end
60
-
61
54
  def regexp
62
55
  /^\s* irb \s*$/x
63
56
  end
@@ -73,11 +66,11 @@ module Byebug
73
66
  when :cont
74
67
  @state.proceed
75
68
  when :step
76
- force = Command.settings[:forcestep]
69
+ force = Setting[:forcestep]
77
70
  @state.context.step_into 1, force
78
71
  @state.proceed
79
72
  when :next
80
- force = Command.settings[:forcestep]
73
+ force = Setting[:forcestep]
81
74
  @state.context.step_over 1, @state.frame_pos, force
82
75
  @state.proceed
83
76
  else
@@ -86,7 +79,6 @@ module Byebug
86
79
  end
87
80
  end
88
81
 
89
-
90
82
  class << self
91
83
  def names
92
84
  %w(irb)
@@ -134,5 +126,4 @@ module Byebug
134
126
  end
135
127
  end
136
128
  end if has_pry
137
-
138
129
  end
@@ -38,13 +38,8 @@ module Byebug
38
38
 
39
39
  def save_settings(file)
40
40
  # FIXME put routine in set
41
- %w(autoeval basename testing).each do |setting|
42
- on_off = show_onoff(Command.settings[setting.to_sym])
43
- file.puts "set #{setting} #{on_off}"
44
- end
45
- %w(autolist autoirb).each do |setting|
46
- on_off = show_onoff(Command.settings[setting.to_sym] > 0)
47
- file.puts "set #{setting} #{on_off}"
41
+ %w(autoeval autoirb autolist basename testing).each do |setting|
42
+ file.puts "set #{setting} #{Setting[setting.to_sym]}"
48
43
  end
49
44
  end
50
45