byebug 9.0.5 → 11.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (133) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +399 -264
  3. data/CONTRIBUTING.md +12 -19
  4. data/GUIDE.md +40 -26
  5. data/LICENSE +18 -18
  6. data/README.md +103 -74
  7. data/exe/byebug +6 -0
  8. data/ext/byebug/breakpoint.c +2 -2
  9. data/ext/byebug/byebug.c +26 -31
  10. data/ext/byebug/byebug.h +44 -28
  11. data/ext/byebug/context.c +45 -32
  12. data/ext/byebug/extconf.rb +7 -5
  13. data/ext/byebug/locker.c +4 -4
  14. data/ext/byebug/threads.c +12 -12
  15. data/lib/byebug/attacher.rb +18 -4
  16. data/lib/byebug/breakpoint.rb +26 -6
  17. data/lib/byebug/command.rb +20 -14
  18. data/lib/byebug/command_list.rb +3 -1
  19. data/lib/byebug/commands/break.rb +36 -22
  20. data/lib/byebug/commands/catch.rb +16 -18
  21. data/lib/byebug/commands/condition.rb +11 -11
  22. data/lib/byebug/commands/continue.rb +32 -12
  23. data/lib/byebug/commands/debug.rb +7 -5
  24. data/lib/byebug/commands/delete.rb +13 -11
  25. data/lib/byebug/commands/disable/breakpoints.rb +7 -5
  26. data/lib/byebug/commands/disable/display.rb +7 -5
  27. data/lib/byebug/commands/disable.rb +8 -6
  28. data/lib/byebug/commands/display.rb +11 -9
  29. data/lib/byebug/commands/down.rb +10 -8
  30. data/lib/byebug/commands/edit.rb +11 -8
  31. data/lib/byebug/commands/enable/breakpoints.rb +7 -5
  32. data/lib/byebug/commands/enable/display.rb +7 -5
  33. data/lib/byebug/commands/enable.rb +8 -6
  34. data/lib/byebug/commands/finish.rb +9 -7
  35. data/lib/byebug/commands/frame.rb +11 -9
  36. data/lib/byebug/commands/help.rb +7 -5
  37. data/lib/byebug/commands/history.rb +7 -5
  38. data/lib/byebug/commands/info/breakpoints.rb +18 -14
  39. data/lib/byebug/commands/info/display.rb +16 -9
  40. data/lib/byebug/commands/info/file.rb +13 -14
  41. data/lib/byebug/commands/info/line.rb +5 -3
  42. data/lib/byebug/commands/info/program.rb +8 -6
  43. data/lib/byebug/commands/info.rb +11 -9
  44. data/lib/byebug/commands/interrupt.rb +8 -4
  45. data/lib/byebug/commands/irb.rb +13 -12
  46. data/lib/byebug/commands/kill.rb +11 -11
  47. data/lib/byebug/commands/list.rb +41 -46
  48. data/lib/byebug/commands/method.rb +10 -8
  49. data/lib/byebug/commands/next.rb +8 -6
  50. data/lib/byebug/commands/pry.rb +10 -10
  51. data/lib/byebug/commands/quit.rb +10 -8
  52. data/lib/byebug/commands/restart.rb +30 -11
  53. data/lib/byebug/commands/save.rb +10 -8
  54. data/lib/byebug/commands/set.rb +13 -11
  55. data/lib/byebug/commands/show.rb +7 -5
  56. data/lib/byebug/commands/skip.rb +85 -0
  57. data/lib/byebug/commands/source.rb +7 -7
  58. data/lib/byebug/commands/step.rb +8 -6
  59. data/lib/byebug/commands/thread/current.rb +6 -4
  60. data/lib/byebug/commands/thread/list.rb +7 -5
  61. data/lib/byebug/commands/thread/resume.rb +7 -7
  62. data/lib/byebug/commands/thread/stop.rb +6 -4
  63. data/lib/byebug/commands/thread/switch.rb +6 -4
  64. data/lib/byebug/commands/thread.rb +11 -9
  65. data/lib/byebug/commands/tracevar.rb +10 -11
  66. data/lib/byebug/commands/undisplay.rb +12 -11
  67. data/lib/byebug/commands/untracevar.rb +8 -6
  68. data/lib/byebug/commands/up.rb +10 -8
  69. data/lib/byebug/commands/var/all.rb +7 -5
  70. data/lib/byebug/commands/var/args.rb +6 -4
  71. data/lib/byebug/commands/var/const.rb +9 -9
  72. data/lib/byebug/commands/var/global.rb +5 -3
  73. data/lib/byebug/commands/var/instance.rb +6 -4
  74. data/lib/byebug/commands/var/local.rb +6 -4
  75. data/lib/byebug/commands/var.rb +12 -10
  76. data/lib/byebug/commands/where.rb +9 -7
  77. data/lib/byebug/commands.rb +40 -37
  78. data/lib/byebug/context.rb +7 -5
  79. data/lib/byebug/core.rb +26 -25
  80. data/lib/byebug/errors.rb +4 -2
  81. data/lib/byebug/frame.rb +19 -22
  82. data/lib/byebug/helpers/bin.rb +47 -0
  83. data/lib/byebug/helpers/eval.rb +15 -13
  84. data/lib/byebug/helpers/file.rb +6 -4
  85. data/lib/byebug/helpers/frame.rb +7 -5
  86. data/lib/byebug/helpers/parse.rb +5 -5
  87. data/lib/byebug/helpers/path.rb +9 -11
  88. data/lib/byebug/helpers/reflection.rb +2 -0
  89. data/lib/byebug/helpers/string.rb +11 -2
  90. data/lib/byebug/helpers/thread.rb +10 -8
  91. data/lib/byebug/helpers/toggle.rb +28 -27
  92. data/lib/byebug/helpers/var.rb +9 -7
  93. data/lib/byebug/history.rb +20 -11
  94. data/lib/byebug/interface.rb +13 -11
  95. data/lib/byebug/interfaces/local_interface.rb +25 -7
  96. data/lib/byebug/interfaces/remote_interface.rb +21 -9
  97. data/lib/byebug/interfaces/script_interface.rb +4 -1
  98. data/lib/byebug/interfaces/test_interface.rb +5 -3
  99. data/lib/byebug/option_setter.rb +14 -12
  100. data/lib/byebug/printers/base.rb +10 -10
  101. data/lib/byebug/printers/plain.rb +9 -8
  102. data/lib/byebug/printers/texts/base.yml +7 -3
  103. data/lib/byebug/printers/texts/plain.yml +1 -1
  104. data/lib/byebug/processors/command_processor.rb +11 -12
  105. data/lib/byebug/processors/control_processor.rb +4 -6
  106. data/lib/byebug/processors/post_mortem_processor.rb +4 -2
  107. data/lib/byebug/processors/script_processor.rb +7 -3
  108. data/lib/byebug/remote/client.rb +57 -0
  109. data/lib/byebug/remote/server.rb +47 -0
  110. data/lib/byebug/remote.rb +46 -66
  111. data/lib/byebug/runner.rb +43 -49
  112. data/lib/byebug/setting.rb +11 -5
  113. data/lib/byebug/settings/autoirb.rb +7 -5
  114. data/lib/byebug/settings/autolist.rb +7 -5
  115. data/lib/byebug/settings/autopry.rb +7 -5
  116. data/lib/byebug/settings/autosave.rb +4 -2
  117. data/lib/byebug/settings/basename.rb +4 -2
  118. data/lib/byebug/settings/callstyle.rb +4 -3
  119. data/lib/byebug/settings/fullpath.rb +4 -2
  120. data/lib/byebug/settings/histfile.rb +5 -3
  121. data/lib/byebug/settings/histsize.rb +4 -2
  122. data/lib/byebug/settings/linetrace.rb +6 -4
  123. data/lib/byebug/settings/listsize.rb +4 -2
  124. data/lib/byebug/settings/post_mortem.rb +6 -4
  125. data/lib/byebug/settings/savefile.rb +4 -2
  126. data/lib/byebug/settings/stack_on_error.rb +4 -2
  127. data/lib/byebug/settings/width.rb +3 -1
  128. data/lib/byebug/source_file_formatter.rb +71 -0
  129. data/lib/byebug/subcommands.rb +6 -4
  130. data/lib/byebug/version.rb +2 -1
  131. data/lib/byebug.rb +3 -1
  132. metadata +22 -20
  133. data/bin/byebug +0 -7
data/lib/byebug/frame.rb CHANGED
@@ -1,6 +1,6 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
- require 'byebug/helpers/file'
3
+ require_relative "helpers/file"
4
4
 
5
5
  module Byebug
6
6
  #
@@ -47,13 +47,10 @@ module Byebug
47
47
  #
48
48
  # Gets local variables for the frame.
49
49
  #
50
- # @todo Use `Binding#local_variables` directly once we drop 2.1 support
51
- # since it's a public method since ruby 2.2
52
- #
53
50
  def locals
54
51
  return [] unless _binding
55
52
 
56
- _binding.eval('local_variables').each_with_object({}) do |e, a|
53
+ _binding.local_variables.each_with_object({}) do |e, a|
57
54
  a[e] = _binding.local_variable_get(e)
58
55
  a
59
56
  end
@@ -73,11 +70,11 @@ module Byebug
73
70
  # +callstyle+ setting is 'short'
74
71
  #
75
72
  def deco_class
76
- Setting[:callstyle] == 'short' || _class.to_s.empty? ? '' : "#{_class}."
73
+ Setting[:callstyle] == "short" || _class.to_s.empty? ? "" : "#{_class}."
77
74
  end
78
75
 
79
76
  def deco_block
80
- _method[/(?:block(?: \(\d+ levels\))?|rescue) in /] || ''
77
+ _method[/(?:block(?: \(\d+ levels\))?|rescue) in /] || ""
81
78
  end
82
79
 
83
80
  def deco_method
@@ -90,12 +87,12 @@ module Byebug
90
87
  # setting
91
88
  #
92
89
  def deco_args
93
- return '' if args.empty?
90
+ return "" if args.empty?
94
91
 
95
92
  my_args = args.map do |arg|
96
93
  prefix, default = prefix_and_default(arg[0])
97
94
 
98
- kls = use_short_style?(arg) ? '' : "##{locals[arg[1]].class}"
95
+ kls = use_short_style?(arg) ? "" : "##{locals[arg[1]].class}"
99
96
 
100
97
  "#{prefix}#{arg[1] || default}#{kls}"
101
98
  end
@@ -121,7 +118,7 @@ module Byebug
121
118
  # Properly formatted frame number of frame
122
119
  #
123
120
  def deco_pos
124
- format('%-2d', pos)
121
+ format("%-2<pos>d", pos: pos)
125
122
  end
126
123
 
127
124
  #
@@ -132,10 +129,10 @@ module Byebug
132
129
  # marks regular frames
133
130
  #
134
131
  def mark
135
- return '-->' if current?
136
- return ' ͱ--' if c_frame?
132
+ return "-->" if current?
133
+ return " ͱ--" if c_frame?
137
134
 
138
- ' '
135
+ " "
139
136
  end
140
137
 
141
138
  #
@@ -159,30 +156,30 @@ module Byebug
159
156
  private
160
157
 
161
158
  def c_args
162
- return [] unless _self.to_s != 'main'
159
+ return [] unless _self.to_s != "main"
163
160
 
164
- _self.method(_method).parameters
161
+ _class.instance_method(_method).parameters
165
162
  end
166
163
 
167
164
  def ruby_args
168
- meth_name = _binding.eval('__method__')
165
+ meth_name = _binding.eval("__method__")
169
166
  return [] unless meth_name
170
167
 
171
- meth_obj = _self.method(meth_name)
168
+ meth_obj = _class.instance_method(meth_name)
172
169
  return [] unless meth_obj
173
170
 
174
171
  meth_obj.parameters
175
172
  end
176
173
 
177
174
  def use_short_style?(arg)
178
- Setting[:callstyle] == 'short' || arg[1].nil? || locals.empty?
175
+ Setting[:callstyle] == "short" || arg[1].nil? || locals.empty?
179
176
  end
180
177
 
181
178
  def prefix_and_default(arg_type)
182
- return ['&', 'block'] if arg_type == :block
183
- return ['*', 'args'] if arg_type == :rest
179
+ return ["&", "block"] if arg_type == :block
180
+ return ["*", "args"] if arg_type == :rest
184
181
 
185
- ['', nil]
182
+ ["", nil]
186
183
  end
187
184
  end
188
185
  end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Byebug
4
+ module Helpers
5
+ #
6
+ # Utilities for interaction with executables
7
+ #
8
+ module BinHelper
9
+ #
10
+ # Cross-platform way of finding an executable in the $PATH.
11
+ # Adapted from: https://gist.github.com/steakknife/88b6c3837a5e90a08296
12
+ #
13
+ def which(cmd)
14
+ return File.expand_path(cmd) if File.exist?(cmd)
15
+
16
+ [nil, *search_paths].each do |path|
17
+ exe = find_executable(path, cmd)
18
+ return exe if exe
19
+ end
20
+
21
+ nil
22
+ end
23
+
24
+ def find_executable(path, cmd)
25
+ executable_file_extensions.each do |ext|
26
+ exe = File.expand_path(cmd + ext, path)
27
+
28
+ return exe if real_executable?(exe)
29
+ end
30
+
31
+ nil
32
+ end
33
+
34
+ def search_paths
35
+ ENV["PATH"].split(File::PATH_SEPARATOR)
36
+ end
37
+
38
+ def executable_file_extensions
39
+ ENV["PATHEXT"] ? ENV["PATHEXT"].split(";") : [""]
40
+ end
41
+
42
+ def real_executable?(file)
43
+ File.executable?(file) && !File.directory?(file)
44
+ end
45
+ end
46
+ end
47
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Byebug
2
4
  module Helpers
3
5
  #
@@ -56,27 +58,27 @@ module Byebug
56
58
  private
57
59
 
58
60
  def safe_eval(str, binding)
59
- binding.eval(str.gsub(/\Aeval /, ''), '(byebug)', 1)
61
+ binding.eval(str.gsub(/\Aeval /, ""), "(byebug)", 1)
60
62
  rescue StandardError, ScriptError => e
61
63
  yield(e)
62
64
  end
63
65
 
64
- def msg(e)
65
- msg = Setting[:stack_on_error] ? error_msg(e) : warning_msg(e)
66
+ def msg(exception)
67
+ msg = Setting[:stack_on_error] ? error_msg(exception) : warning_msg(exception)
66
68
 
67
- pr('eval.exception', text_message: msg)
69
+ pr("eval.exception", text_message: msg)
68
70
  end
69
71
 
70
- def error_msg(e)
71
- at = e.backtrace
72
+ def error_msg(exception)
73
+ at = exception.backtrace
72
74
 
73
- locations = ["#{at.shift}: #{warning_msg(e)}"]
75
+ locations = ["#{at.shift}: #{warning_msg(exception)}"]
74
76
  locations += at.map { |path| " from #{path}" }
75
77
  locations.join("\n")
76
78
  end
77
79
 
78
- def warning_msg(e)
79
- "#{e.class} Exception: #{e.message}"
80
+ def warning_msg(exception)
81
+ "#{exception.class} Exception: #{exception.message}"
80
82
  end
81
83
 
82
84
  #
@@ -98,7 +100,7 @@ module Byebug
98
100
 
99
101
  #
100
102
  # Runs the given block in a new thread, waits for it to finish and
101
- # returns the new thred's result.
103
+ # returns the new thread's result.
102
104
  #
103
105
  def in_new_thread
104
106
  res = nil
@@ -110,14 +112,14 @@ module Byebug
110
112
 
111
113
  def safe_inspect(var)
112
114
  var.inspect
113
- rescue
115
+ rescue StandardError
114
116
  safe_to_s(var)
115
117
  end
116
118
 
117
119
  def safe_to_s(var)
118
120
  var.to_s
119
- rescue
120
- '*Error in evaluation*'
121
+ rescue StandardError
122
+ "*Error in evaluation*"
121
123
  end
122
124
  end
123
125
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Byebug
2
4
  module Helpers
3
5
  #
@@ -8,7 +10,7 @@ module Byebug
8
10
  # Reads lines of source file +filename+ into an array
9
11
  #
10
12
  def get_lines(filename)
11
- File.foreach(filename).reduce([]) { |a, e| a << e.chomp }
13
+ File.foreach(filename).reduce([]) { |acc, elem| acc << elem.chomp }
12
14
  end
13
15
 
14
16
  #
@@ -26,7 +28,7 @@ module Byebug
26
28
  # one-line-at-a-time way.
27
29
  #
28
30
  def n_lines(filename)
29
- File.foreach(filename).reduce(0) { |a, _e| a + 1 }
31
+ File.foreach(filename).reduce(0) { |acc, _elem| acc + 1 }
30
32
  end
31
33
 
32
34
  #
@@ -47,14 +49,14 @@ module Byebug
47
49
  components = Pathname(fullpath).each_filename.to_a
48
50
  return fullpath if components.size <= 2
49
51
 
50
- File.join('...', components[-3..-1])
52
+ File.join("...", components[-3..-1])
51
53
  end
52
54
 
53
55
  #
54
56
  # True for special files like -e, false otherwise
55
57
  #
56
58
  def virtual_file?(name)
57
- ['(irb)', '-e', '(byebug)', '(eval)'].include?(name)
59
+ ["(irb)", "-e", "(byebug)", "(eval)"].include?(name)
58
60
  end
59
61
  end
60
62
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Byebug
2
4
  module Helpers
3
5
  #
@@ -6,7 +8,7 @@ module Byebug
6
8
  module FrameHelper
7
9
  def switch_to_frame(frame)
8
10
  new_frame = index_from_start(frame)
9
- return frame_err('c_frame') if Frame.new(context, new_frame).c_frame?
11
+ return frame_err("c_frame") if Frame.new(context, new_frame).c_frame?
10
12
 
11
13
  adjust_frame(new_frame)
12
14
  end
@@ -18,8 +20,8 @@ module Byebug
18
20
  private
19
21
 
20
22
  def adjust_frame(new_frame)
21
- return frame_err('too_low') if new_frame >= context.stack_size
22
- return frame_err('too_high') if new_frame < 0
23
+ return frame_err("too_low") if new_frame >= context.stack_size
24
+ return frame_err("too_high") if new_frame.negative?
23
25
 
24
26
  context.frame = new_frame
25
27
  processor.prev_line = nil
@@ -65,8 +67,8 @@ module Byebug
65
67
  #
66
68
  # @param i [Integer] Integer to be converted in a proper positive index.
67
69
  #
68
- def index_from_start(i)
69
- i >= 0 ? i : context.stack_size + i
70
+ def index_from_start(index)
71
+ index >= 0 ? index : context.stack_size + index
70
72
  end
71
73
  end
72
74
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Byebug
2
4
  module Helpers
3
5
  #
@@ -13,16 +15,14 @@ module Byebug
13
15
  # purpose.
14
16
  #
15
17
  def get_int(str, cmd, min = nil, max = nil)
16
- if str !~ /\A-?[0-9]+\z/
17
- return nil, pr('parse.errors.int.not_number', cmd: cmd, str: str)
18
- end
18
+ return nil, pr("parse.errors.int.not_number", cmd: cmd, str: str) unless /\A-?[0-9]+\z/.match?(str)
19
19
 
20
20
  int = str.to_i
21
21
  if min && int < min
22
- err = pr('parse.errors.int.too_low', cmd: cmd, str: str, min: min)
22
+ err = pr("parse.errors.int.too_low", cmd: cmd, str: str, min: min)
23
23
  return nil, err
24
24
  elsif max && int > max
25
- err = pr('parse.errors.int.too_high', cmd: cmd, str: str, max: max)
25
+ err = pr("parse.errors.int.too_high", cmd: cmd, str: str, max: max)
26
26
  return nil, err
27
27
  end
28
28
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Byebug
2
4
  module Helpers
3
5
  #
@@ -5,27 +7,23 @@ module Byebug
5
7
  #
6
8
  module PathHelper
7
9
  def bin_file
8
- @bin_file ||= Gem.bin_path('byebug', 'byebug')
10
+ @bin_file ||= File.join(root_path, "exe", "byebug")
9
11
  end
10
12
 
11
13
  def root_path
12
- @root_path ||= File.expand_path('../..', bin_file)
14
+ @root_path ||= File.expand_path(File.join("..", "..", ".."), __dir__)
13
15
  end
14
16
 
15
17
  def lib_files
16
- @lib_files ||= expand_from_root('lib/**/*.{rb,yml}')
17
- end
18
-
19
- def ext_files
20
- @ext_files ||= expand_from_root('ext/**/*.{c,h,rb}')
18
+ @lib_files ||= glob_for("lib")
21
19
  end
22
20
 
23
21
  def test_files
24
- @test_files ||= expand_from_root('test/**/*.rb')
22
+ @test_files ||= glob_for("test")
25
23
  end
26
24
 
27
25
  def gem_files
28
- @gem_files ||= [bin_file] + lib_files + ext_files
26
+ @gem_files ||= [bin_file] + lib_files
29
27
  end
30
28
 
31
29
  def all_files
@@ -34,8 +32,8 @@ module Byebug
34
32
 
35
33
  private
36
34
 
37
- def expand_from_root(glob)
38
- Dir.glob(File.expand_path(glob, root_path))
35
+ def glob_for(dir)
36
+ Dir.glob(File.join(root_path, dir, "**", "*.rb"))
39
37
  end
40
38
  end
41
39
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Byebug
2
4
  module Helpers
3
5
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Byebug
2
4
  module Helpers
3
5
  #
@@ -9,7 +11,7 @@ module Byebug
9
11
  # ACamelizedString.
10
12
  #
11
13
  def camelize(str)
12
- str.dup.split(/[_-]/).map(&:capitalize).join('')
14
+ str.dup.split(/[_-]/).map(&:capitalize).join("")
13
15
  end
14
16
 
15
17
  #
@@ -17,7 +19,14 @@ module Byebug
17
19
  # command prompt.
18
20
  #
19
21
  def prettify(str)
20
- "\n" + str.gsub(/^ {6}/, '') + "\n"
22
+ "\n" + deindent(str) + "\n"
23
+ end
24
+
25
+ #
26
+ # Removes a number of leading whitespace for each input line.
27
+ #
28
+ def deindent(str, leading_spaces: 6)
29
+ str.gsub(/^ {#{leading_spaces}}/, "")
21
30
  end
22
31
  end
23
32
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Byebug
2
4
  module Helpers
3
5
  #
@@ -5,7 +7,7 @@ module Byebug
5
7
  #
6
8
  module ThreadHelper
7
9
  def display_context(ctx)
8
- puts pr('thread.context', thread_arguments(ctx))
10
+ puts pr("thread.context", thread_arguments(ctx))
9
11
  end
10
12
 
11
13
  def thread_arguments(ctx)
@@ -29,11 +31,11 @@ module Byebug
29
31
  ctx = Byebug.contexts.find { |c| c.thnum.to_s == thnum }
30
32
 
31
33
  err = if ctx.nil?
32
- pr('thread.errors.no_thread')
34
+ pr("thread.errors.no_thread")
33
35
  elsif ctx == context
34
- pr('thread.errors.current_thread')
36
+ pr("thread.errors.current_thread")
35
37
  elsif ctx.ignored?
36
- pr('thread.errors.ignored', arg: thnum)
38
+ pr("thread.errors.ignored", arg: thnum)
37
39
  end
38
40
 
39
41
  [ctx, err]
@@ -46,19 +48,19 @@ module Byebug
46
48
  return context.location if ctx == Byebug.current_context
47
49
 
48
50
  backtrace = ctx.thread.backtrace_locations
49
- return '' unless backtrace && backtrace[0]
51
+ return "" unless backtrace && backtrace[0]
50
52
 
51
53
  "#{backtrace[0].path}:#{backtrace[0].lineno}"
52
54
  end
53
55
 
54
56
  def status_flag(ctx)
55
- return '$' if ctx.suspended?
57
+ return "$" if ctx.suspended?
56
58
 
57
- current_thread?(ctx) ? '+' : ' '
59
+ current_thread?(ctx) ? "+" : " "
58
60
  end
59
61
 
60
62
  def debug_flag(ctx)
61
- ctx.ignored? ? '!' : ' '
63
+ ctx.ignored? ? "!" : " "
62
64
  end
63
65
  end
64
66
  end
@@ -1,4 +1,6 @@
1
- require 'byebug/helpers/parse'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "parse"
2
4
 
3
5
  module Byebug
4
6
  module Helpers
@@ -9,50 +11,49 @@ module Byebug
9
11
  include ParseHelper
10
12
 
11
13
  def enable_disable_breakpoints(is_enable, args)
12
- return errmsg(pr('toggle.errors.no_breakpoints')) if Breakpoint.none?
13
-
14
- all_breakpoints = Byebug.breakpoints.sort_by(&:id)
15
- if args.nil?
16
- selected_breakpoints = all_breakpoints
17
- else
18
- selected_ids = []
19
- args.split(/ +/).each do |pos|
20
- last_id = all_breakpoints.last.id
21
- pos, err = get_int(pos, "#{is_enable} breakpoints", 1, last_id)
22
- return errmsg(err) unless pos
23
-
24
- selected_ids << pos
25
- end
26
- selected_breakpoints = all_breakpoints.select do |b|
27
- selected_ids.include?(b.id)
28
- end
29
- end
14
+ raise pr("toggle.errors.no_breakpoints") if Breakpoint.none?
30
15
 
31
- selected_breakpoints.each do |b|
32
- enabled = ('enable' == is_enable)
33
- if enabled && !syntax_valid?(b.expr)
34
- return errmsg(pr('toggle.errors.expression', expr: b.expr))
35
- end
16
+ select_breakpoints(is_enable, args).each do |b|
17
+ enabled = (is_enable == "enable")
18
+ raise pr("toggle.errors.expression", expr: b.expr) if enabled && !syntax_valid?(b.expr)
36
19
 
20
+ puts pr("toggle.messages.toggled", bpnum: b.id,
21
+ endis: enabled ? "en" : "dis")
37
22
  b.enabled = enabled
38
23
  end
39
24
  end
40
25
 
41
26
  def enable_disable_display(is_enable, args)
42
- return errmsg(pr('toggle.errors.no_display')) if 0 == n_displays
27
+ raise pr("toggle.errors.no_display") if n_displays.zero?
43
28
 
44
29
  selected_displays = args ? args.split(/ +/) : [1..n_displays + 1]
45
30
 
46
31
  selected_displays.each do |pos|
47
32
  pos, err = get_int(pos, "#{is_enable} display", 1, n_displays)
48
- return errmsg(err) unless err.nil?
33
+ raise err unless err.nil?
49
34
 
50
- Byebug.displays[pos - 1][0] = ('enable' == is_enable)
35
+ Byebug.displays[pos - 1][0] = (is_enable == "enable")
51
36
  end
52
37
  end
53
38
 
54
39
  private
55
40
 
41
+ def select_breakpoints(is_enable, args)
42
+ all_breakpoints = Byebug.breakpoints.sort_by(&:id)
43
+ return all_breakpoints if args.nil?
44
+
45
+ selected_ids = []
46
+ args.split(/ +/).each do |pos|
47
+ last_id = all_breakpoints.last.id
48
+ pos, err = get_int(pos, "#{is_enable} breakpoints", 1, last_id)
49
+ raise(ArgumentError, err) unless pos
50
+
51
+ selected_ids << pos
52
+ end
53
+
54
+ all_breakpoints.select { |b| selected_ids.include?(b.id) }
55
+ end
56
+
56
57
  def n_displays
57
58
  Byebug.displays.size
58
59
  end
@@ -1,4 +1,6 @@
1
- require 'byebug/helpers/eval'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "eval"
2
4
 
3
5
  module Byebug
4
6
  module Helpers
@@ -13,19 +15,19 @@ module Byebug
13
15
  [name, safe_inspect(silent_eval(name.to_s, binding))]
14
16
  end
15
17
 
16
- puts prv(vars, 'instance')
18
+ puts prv(vars, "instance")
17
19
  end
18
20
 
19
21
  def var_global
20
22
  globals = global_variables.reject do |v|
21
- [:$IGNORECASE, :$=, :$KCODE, :$-K, :$binding].include?(v)
23
+ %i[$IGNORECASE $= $KCODE $-K $binding].include?(v)
22
24
  end
23
25
 
24
26
  var_list(globals)
25
27
  end
26
28
 
27
29
  def var_instance(str)
28
- obj = warning_eval(str || 'self')
30
+ obj = warning_eval(str || "self")
29
31
 
30
32
  var_list(obj.instance_variables, obj.instance_eval { binding })
31
33
  end
@@ -33,8 +35,8 @@ module Byebug
33
35
  def var_local
34
36
  locals = context.frame.locals
35
37
  cur_self = context.frame._self
36
- locals[:self] = cur_self unless cur_self.to_s == 'main'
37
- puts prv(locals.keys.sort.map { |k| [k, locals[k]] }, 'instance')
38
+ locals[:self] = cur_self unless cur_self.to_s == "main"
39
+ puts prv(locals.keys.sort.map { |k| [k, locals[k]] }, "instance")
38
40
  end
39
41
 
40
42
  def var_args
@@ -45,7 +47,7 @@ module Byebug
45
47
  arg_values = args.map { |arg| arg[1] }
46
48
 
47
49
  locals = all_locals.select { |k, _| arg_values.include?(k) }
48
- puts prv(locals.keys.sort.map { |k| [k, locals[k]] }, 'instance')
50
+ puts prv(locals.keys.sort.map { |k| [k, locals[k]] }, "instance")
49
51
  end
50
52
  end
51
53
  end
@@ -1,11 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  begin
2
- require 'readline'
4
+ require "readline"
3
5
  rescue LoadError
4
- warn <<-EOW
6
+ warn <<-MESSAGE
5
7
  Sorry, you can't use byebug without Readline. To solve this, you need to
6
8
  rebuild Ruby with Readline support. If using Ubuntu, try `sudo apt-get
7
9
  install libreadline-dev` and then reinstall your Ruby.
8
- EOW
10
+ MESSAGE
9
11
 
10
12
  raise
11
13
  end
@@ -21,6 +23,13 @@ module Byebug
21
23
  self.size = 0
22
24
  end
23
25
 
26
+ #
27
+ # Array holding the list of commands in history
28
+ #
29
+ def buffer
30
+ Readline::HISTORY.to_a
31
+ end
32
+
24
33
  #
25
34
  # Restores history from disk.
26
35
  #
@@ -36,7 +45,7 @@ module Byebug
36
45
  def save
37
46
  n_cmds = Setting[:histsize] > size ? size : Setting[:histsize]
38
47
 
39
- open(Setting[:histfile], 'w') do |file|
48
+ File.open(Setting[:histfile], "w") do |file|
40
49
  n_cmds.times { file.puts(pop) }
41
50
  end
42
51
 
@@ -74,18 +83,18 @@ module Byebug
74
83
  def to_s(n_cmds)
75
84
  show_size = n_cmds ? specific_max_size(n_cmds) : default_max_size
76
85
 
77
- commands = Readline::HISTORY.to_a.last(show_size)
86
+ commands = buffer.last(show_size)
78
87
 
79
88
  last_ids(show_size).zip(commands).map do |l|
80
- format('%5d %s', l[0], l[1])
89
+ format("%<position>5d %<command>s", position: l[0], command: l[1])
81
90
  end.join("\n") + "\n"
82
91
  end
83
92
 
84
93
  #
85
- # Array of ids of the last n commands.
94
+ # Array of ids of the last +number+ commands.
86
95
  #
87
- def last_ids(n)
88
- (1 + size - n..size).to_a
96
+ def last_ids(number)
97
+ (1 + size - number..size).to_a
89
98
  end
90
99
 
91
100
  #
@@ -112,10 +121,10 @@ module Byebug
112
121
  # For now, empty lines and consecutive duplicates.
113
122
  #
114
123
  def ignore?(buf)
115
- return true if /^\s*$/ =~ buf
124
+ return true if /^\s*$/.match?(buf)
116
125
  return false if Readline::HISTORY.empty?
117
126
 
118
- Readline::HISTORY[Readline::HISTORY.length - 1] == buf
127
+ buffer[Readline::HISTORY.length - 1] == buf
119
128
  end
120
129
  end
121
130
  end