byebug 9.1.0 → 10.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (129) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +24 -3
  3. data/CONTRIBUTING.md +39 -18
  4. data/GUIDE.md +16 -17
  5. data/README.md +64 -52
  6. data/exe/byebug +6 -0
  7. data/ext/byebug/breakpoint.c +1 -1
  8. data/ext/byebug/byebug.c +16 -16
  9. data/ext/byebug/byebug.h +40 -26
  10. data/ext/byebug/context.c +26 -26
  11. data/ext/byebug/extconf.rb +7 -5
  12. data/ext/byebug/threads.c +8 -8
  13. data/lib/byebug.rb +3 -1
  14. data/lib/byebug/attacher.rb +17 -3
  15. data/lib/byebug/breakpoint.rb +25 -3
  16. data/lib/byebug/command.rb +20 -14
  17. data/lib/byebug/command_list.rb +3 -1
  18. data/lib/byebug/commands.rb +39 -37
  19. data/lib/byebug/commands/break.rb +33 -15
  20. data/lib/byebug/commands/catch.rb +16 -14
  21. data/lib/byebug/commands/condition.rb +11 -9
  22. data/lib/byebug/commands/continue.rb +9 -7
  23. data/lib/byebug/commands/debug.rb +7 -5
  24. data/lib/byebug/commands/delete.rb +11 -9
  25. data/lib/byebug/commands/disable.rb +8 -6
  26. data/lib/byebug/commands/disable/breakpoints.rb +7 -5
  27. data/lib/byebug/commands/disable/display.rb +7 -5
  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 +10 -8
  31. data/lib/byebug/commands/enable.rb +8 -6
  32. data/lib/byebug/commands/enable/breakpoints.rb +7 -5
  33. data/lib/byebug/commands/enable/display.rb +7 -5
  34. data/lib/byebug/commands/finish.rb +8 -6
  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.rb +11 -9
  39. data/lib/byebug/commands/info/breakpoints.rb +17 -11
  40. data/lib/byebug/commands/info/display.rb +16 -7
  41. data/lib/byebug/commands/info/file.rb +12 -10
  42. data/lib/byebug/commands/info/line.rb +5 -3
  43. data/lib/byebug/commands/info/program.rb +8 -6
  44. data/lib/byebug/commands/interrupt.rb +8 -4
  45. data/lib/byebug/commands/irb.rb +9 -7
  46. data/lib/byebug/commands/kill.rb +9 -7
  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 -8
  51. data/lib/byebug/commands/quit.rb +7 -5
  52. data/lib/byebug/commands/restart.rb +13 -11
  53. data/lib/byebug/commands/save.rb +9 -7
  54. data/lib/byebug/commands/set.rb +12 -10
  55. data/lib/byebug/commands/show.rb +7 -5
  56. data/lib/byebug/commands/source.rb +7 -5
  57. data/lib/byebug/commands/step.rb +8 -6
  58. data/lib/byebug/commands/thread.rb +11 -9
  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 -5
  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/tracevar.rb +10 -8
  65. data/lib/byebug/commands/undisplay.rb +10 -8
  66. data/lib/byebug/commands/untracevar.rb +8 -6
  67. data/lib/byebug/commands/up.rb +10 -8
  68. data/lib/byebug/commands/var.rb +12 -10
  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 -7
  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/where.rb +9 -7
  76. data/lib/byebug/context.rb +7 -5
  77. data/lib/byebug/core.rb +25 -25
  78. data/lib/byebug/errors.rb +4 -2
  79. data/lib/byebug/frame.rb +16 -16
  80. data/lib/byebug/helpers/bin.rb +28 -7
  81. data/lib/byebug/helpers/eval.rb +8 -6
  82. data/lib/byebug/helpers/file.rb +4 -2
  83. data/lib/byebug/helpers/frame.rb +5 -3
  84. data/lib/byebug/helpers/parse.rb +5 -3
  85. data/lib/byebug/helpers/path.rb +7 -5
  86. data/lib/byebug/helpers/reflection.rb +2 -0
  87. data/lib/byebug/helpers/string.rb +4 -2
  88. data/lib/byebug/helpers/thread.rb +10 -8
  89. data/lib/byebug/helpers/toggle.rb +10 -8
  90. data/lib/byebug/helpers/var.rb +8 -6
  91. data/lib/byebug/history.rb +7 -5
  92. data/lib/byebug/interface.rb +13 -11
  93. data/lib/byebug/interfaces/local_interface.rb +4 -4
  94. data/lib/byebug/interfaces/remote_interface.rb +21 -9
  95. data/lib/byebug/interfaces/script_interface.rb +2 -0
  96. data/lib/byebug/interfaces/test_interface.rb +5 -3
  97. data/lib/byebug/option_setter.rb +14 -12
  98. data/lib/byebug/printers/base.rb +6 -6
  99. data/lib/byebug/printers/plain.rb +8 -6
  100. data/lib/byebug/printers/texts/base.yml +3 -3
  101. data/lib/byebug/processors/command_processor.rb +11 -12
  102. data/lib/byebug/processors/control_processor.rb +4 -6
  103. data/lib/byebug/processors/post_mortem_processor.rb +4 -2
  104. data/lib/byebug/processors/script_processor.rb +7 -3
  105. data/lib/byebug/remote.rb +45 -65
  106. data/lib/byebug/remote/client.rb +55 -0
  107. data/lib/byebug/remote/server.rb +47 -0
  108. data/lib/byebug/runner.rb +26 -19
  109. data/lib/byebug/setting.rb +10 -4
  110. data/lib/byebug/settings/autoirb.rb +5 -3
  111. data/lib/byebug/settings/autolist.rb +5 -3
  112. data/lib/byebug/settings/autopry.rb +5 -3
  113. data/lib/byebug/settings/autosave.rb +4 -2
  114. data/lib/byebug/settings/basename.rb +4 -2
  115. data/lib/byebug/settings/callstyle.rb +3 -3
  116. data/lib/byebug/settings/fullpath.rb +4 -2
  117. data/lib/byebug/settings/histfile.rb +5 -3
  118. data/lib/byebug/settings/histsize.rb +4 -2
  119. data/lib/byebug/settings/linetrace.rb +4 -2
  120. data/lib/byebug/settings/listsize.rb +4 -2
  121. data/lib/byebug/settings/post_mortem.rb +4 -2
  122. data/lib/byebug/settings/savefile.rb +4 -2
  123. data/lib/byebug/settings/stack_on_error.rb +4 -2
  124. data/lib/byebug/settings/width.rb +3 -1
  125. data/lib/byebug/source_file_formatter.rb +71 -0
  126. data/lib/byebug/subcommands.rb +6 -4
  127. data/lib/byebug/version.rb +1 -1
  128. metadata +8 -5
  129. data/bin/byebug +0 -9
@@ -1,4 +1,6 @@
1
- require 'byebug/command'
1
+ # frozen_string_literal: true
2
+
3
+ require "byebug/command"
2
4
 
3
5
  module Byebug
4
6
  #
@@ -12,18 +14,20 @@ module Byebug
12
14
  end
13
15
 
14
16
  def self.description
15
- <<-EOD
17
+ <<-DESCRIPTION
16
18
  int[errupt]
17
19
 
18
20
  #{short_description}
19
- EOD
21
+ DESCRIPTION
20
22
  end
21
23
 
22
24
  def self.short_description
23
- 'Interrupts the program'
25
+ "Interrupts the program"
24
26
  end
25
27
 
26
28
  def execute
29
+ Byebug.start
30
+
27
31
  Byebug.thread_context(Thread.main).interrupt
28
32
  end
29
33
  end
@@ -1,6 +1,8 @@
1
- require 'byebug/command'
2
- require 'irb'
3
- require 'English'
1
+ # frozen_string_literal: true
2
+
3
+ require "byebug/command"
4
+ require "irb"
5
+ require "English"
4
6
 
5
7
  module Byebug
6
8
  #
@@ -14,20 +16,20 @@ module Byebug
14
16
  end
15
17
 
16
18
  def self.description
17
- <<-EOD
19
+ <<-DESCRIPTION
18
20
  irb
19
21
 
20
22
  #{short_description}
21
- EOD
23
+ DESCRIPTION
22
24
  end
23
25
 
24
26
  def self.short_description
25
- 'Starts an IRB session'
27
+ "Starts an IRB session"
26
28
  end
27
29
 
28
30
  def execute
29
31
  unless processor.interface.instance_of?(LocalInterface)
30
- return errmsg(pr('base.errors.only_local'))
32
+ return errmsg(pr("base.errors.only_local"))
31
33
  end
32
34
 
33
35
  # @todo IRB tries to parse $ARGV so we must clear it (see #197). Add a
@@ -1,4 +1,6 @@
1
- require 'byebug/command'
1
+ # frozen_string_literal: true
2
+
3
+ require "byebug/command"
2
4
 
3
5
  module Byebug
4
6
  #
@@ -12,17 +14,17 @@ module Byebug
12
14
  end
13
15
 
14
16
  def self.description
15
- <<-EOD
17
+ <<-DESCRIPTION
16
18
  kill[ signal]
17
19
 
18
20
  #{short_description}
19
21
 
20
22
  Equivalent of Process.kill(Process.pid)
21
- EOD
23
+ DESCRIPTION
22
24
  end
23
25
 
24
26
  def self.short_description
25
- 'Sends a signal to the current process'
27
+ "Sends a signal to the current process"
26
28
  end
27
29
 
28
30
  def execute
@@ -33,12 +35,12 @@ module Byebug
33
35
  return errmsg("signal name #{signame} is not a signal I know about\n")
34
36
  end
35
37
  else
36
- return unless confirm('Really kill? (y/n) ')
38
+ return unless confirm("Really kill? (y/n) ")
37
39
 
38
- signame = 'KILL'
40
+ signame = "KILL"
39
41
  end
40
42
 
41
- processor.interface.close if signame == 'KILL'
43
+ processor.interface.close if signame == "KILL"
42
44
  Process.kill(signame, Process.pid)
43
45
  end
44
46
  end
@@ -1,6 +1,9 @@
1
- require 'byebug/command'
2
- require 'byebug/helpers/file'
3
- require 'byebug/helpers/parse'
1
+ # frozen_string_literal: true
2
+
3
+ require "byebug/command"
4
+ require "byebug/source_file_formatter"
5
+ require "byebug/helpers/file"
6
+ require "byebug/helpers/parse"
4
7
 
5
8
  module Byebug
6
9
  #
@@ -17,7 +20,7 @@ module Byebug
17
20
  end
18
21
 
19
22
  def self.description
20
- <<-EOD
23
+ <<-DESCRIPTION
21
24
  l[ist][[-=]][ nn-mm]
22
25
 
23
26
  #{short_description}
@@ -27,20 +30,18 @@ module Byebug
27
30
  "list=" is specified, lists from current line regardless of where code
28
31
  was last listed. A line range can also be specified to list specific
29
32
  sections of code.
30
- EOD
33
+ DESCRIPTION
31
34
  end
32
35
 
33
36
  def self.short_description
34
- 'Lists lines of source code'
37
+ "Lists lines of source code"
35
38
  end
36
39
 
37
40
  def execute
38
41
  msg = "No sourcefile available for #{frame.file}"
39
42
  raise(msg) unless File.exist?(frame.file)
40
43
 
41
- max_lines = n_lines(frame.file)
42
- b, e = range(@match[2], max_lines)
43
- raise('Invalid line range') unless valid_range?(b, e, max_lines)
44
+ b, e = range(@match[2])
44
45
 
45
46
  display_lines(b, e)
46
47
 
@@ -56,42 +57,44 @@ module Byebug
56
57
  #
57
58
  # Otherwise it's automatically chosen.
58
59
  #
59
- def range(input, max_line)
60
- size = [Setting[:listsize], max_line].min
60
+ def range(input)
61
+ return auto_range(@match[1] || "+") unless input
61
62
 
62
- return set_range(size, max_line) unless input
63
+ b, e = parse_range(input)
64
+ raise("Invalid line range") unless valid_range?(b, e)
63
65
 
64
- parse_range(input, size, max_line)
66
+ [b, e]
65
67
  end
66
68
 
67
- def valid_range?(first, last, max)
68
- first <= last && (1..max).cover?(first) && (1..max).cover?(last)
69
+ def valid_range?(first, last)
70
+ first <= last && (1..max_line).cover?(first) && (1..max_line).cover?(last)
69
71
  end
70
72
 
71
73
  #
72
74
  # Set line range to be printed by list
73
75
  #
74
- # @param size - number of lines to be printed
75
- # @param max_line - max line number that can be printed
76
- #
77
76
  # @return first line number to list
78
77
  # @return last line number to list
79
78
  #
80
- def set_range(size, max_line)
81
- first = amend(lower(size, @match[1] || '+'), max_line - size + 1)
79
+ def auto_range(direction)
80
+ prev_line = processor.prev_line
82
81
 
83
- [first, move(first, size - 1)]
82
+ if direction == "=" || prev_line.nil?
83
+ source_file_formatter.range_around(frame.line)
84
+ else
85
+ source_file_formatter.range_from(move(prev_line, size, direction))
86
+ end
84
87
  end
85
88
 
86
- def parse_range(input, size, max_line)
87
- first, err = get_int(lower_bound(input), 'List', 1, max_line)
89
+ def parse_range(input)
90
+ first, err = get_int(lower_bound(input), "List", 1, max_line)
88
91
  raise(err) unless first
89
92
 
90
93
  if upper_bound(input)
91
- last, err = get_int(upper_bound(input), 'List', 1, max_line)
94
+ last, err = get_int(upper_bound(input), "List", 1, max_line)
92
95
  raise(err) unless last
93
96
 
94
- last = amend(last, max_line)
97
+ last = amend_final(last)
95
98
  else
96
99
  first -= (size / 2)
97
100
  end
@@ -99,20 +102,7 @@ module Byebug
99
102
  [first, last || move(first, size - 1)]
100
103
  end
101
104
 
102
- def amend(line, max_line)
103
- return 1 if line < 1
104
-
105
- [max_line, line].min
106
- end
107
-
108
- def lower(size, direction = '+')
109
- prev_line = processor.prev_line
110
- return frame.line - size / 2 if direction == '=' || prev_line.nil?
111
-
112
- move(prev_line, size, direction)
113
- end
114
-
115
- def move(line, size, direction = '+')
105
+ def move(line, size, direction = "+")
116
106
  line.send(direction, size)
117
107
  end
118
108
 
@@ -125,13 +115,7 @@ module Byebug
125
115
  def display_lines(min, max)
126
116
  puts "\n[#{min}, #{max}] in #{frame.file}"
127
117
 
128
- File.foreach(frame.file).with_index do |line, lineno|
129
- break if lineno + 1 > max
130
- next unless (min..max).cover?(lineno + 1)
131
-
132
- mark = lineno + 1 == frame.line ? '=> ' : ' '
133
- puts format("#{mark}%#{max.to_s.size}d: %s", lineno + 1, line)
134
- end
118
+ puts source_file_formatter.lines(min, max).join
135
119
  end
136
120
 
137
121
  #
@@ -160,5 +144,16 @@ module Byebug
160
144
  def split_range(str)
161
145
  str.split(/[-,]/)
162
146
  end
147
+
148
+ extend Forwardable
149
+
150
+ def_delegators :source_file_formatter, :amend_final, :size, :max_line
151
+
152
+ def source_file_formatter
153
+ @source_file_formatter ||= SourceFileFormatter.new(
154
+ frame.file,
155
+ ->(n) { n == frame.line ? "=>" : " " }
156
+ )
157
+ end
163
158
  end
164
159
  end
@@ -1,5 +1,7 @@
1
- require 'byebug/command'
2
- require 'byebug/helpers/eval'
1
+ # frozen_string_literal: true
2
+
3
+ require "byebug/command"
4
+ require "byebug/helpers/eval"
3
5
 
4
6
  module Byebug
5
7
  #
@@ -15,7 +17,7 @@ module Byebug
15
17
  end
16
18
 
17
19
  def self.description
18
- <<-EOD
20
+ <<-DESCRIPTION
19
21
  m[ethod] (i[nstance][ <obj>]|<class|module>)
20
22
 
21
23
  #{short_description}
@@ -25,11 +27,11 @@ module Byebug
25
27
 
26
28
  When invoked only with a class or module, shows class methods of the
27
29
  class or module specified as argument.
28
- EOD
30
+ DESCRIPTION
29
31
  end
30
32
 
31
33
  def self.short_description
32
- 'Shows methods of an object, class or module'
34
+ "Shows methods of an object, class or module"
33
35
  end
34
36
 
35
37
  def execute
@@ -37,11 +39,11 @@ module Byebug
37
39
 
38
40
  result =
39
41
  if @match[1]
40
- prc('method.methods', obj.methods.sort) { |item, _| { name: item } }
42
+ prc("method.methods", obj.methods.sort) { |item, _| { name: item } }
41
43
  elsif !obj.is_a?(Module)
42
- pr('variable.errors.not_module', object: @match.post_match)
44
+ pr("variable.errors.not_module", object: @match.post_match)
43
45
  else
44
- prc('method.methods', obj.instance_methods(false).sort) do |item, _|
46
+ prc("method.methods", obj.instance_methods(false).sort) do |item, _|
45
47
  { name: item }
46
48
  end
47
49
  end
@@ -1,5 +1,7 @@
1
- require 'byebug/command'
2
- require 'byebug/helpers/parse'
1
+ # frozen_string_literal: true
2
+
3
+ require "byebug/command"
4
+ require "byebug/helpers/parse"
3
5
 
4
6
  module Byebug
5
7
  #
@@ -16,19 +18,19 @@ module Byebug
16
18
  end
17
19
 
18
20
  def self.description
19
- <<-EOD
21
+ <<-DESCRIPTION
20
22
  n[ext][ nnn]
21
23
 
22
24
  #{short_description}
23
- EOD
25
+ DESCRIPTION
24
26
  end
25
27
 
26
28
  def self.short_description
27
- 'Runs one or more lines of code'
29
+ "Runs one or more lines of code"
28
30
  end
29
31
 
30
32
  def execute
31
- steps, err = parse_steps(@match[1], 'Next')
33
+ steps, err = parse_steps(@match[1], "Next")
32
34
  return errmsg(err) unless steps
33
35
 
34
36
  context.step_over(steps, context.frame.pos)
@@ -1,5 +1,7 @@
1
- require 'byebug/command'
2
- require 'byebug/helpers/eval'
1
+ # frozen_string_literal: true
2
+
3
+ require "byebug/command"
4
+ require "byebug/helpers/eval"
3
5
 
4
6
  module Byebug
5
7
  #
@@ -13,26 +15,26 @@ module Byebug
13
15
  end
14
16
 
15
17
  def self.description
16
- <<-EOD
18
+ <<-DESCRIPTION
17
19
  pry
18
20
 
19
21
  #{short_description}
20
- EOD
22
+ DESCRIPTION
21
23
  end
22
24
 
23
25
  def self.short_description
24
- 'Starts a Pry session'
26
+ "Starts a Pry session"
25
27
  end
26
28
 
27
29
  def execute
28
30
  unless processor.interface.instance_of?(LocalInterface)
29
- return errmsg(pr('base.errors.only_local'))
31
+ return errmsg(pr("base.errors.only_local"))
30
32
  end
31
33
 
32
34
  begin
33
- require 'pry'
35
+ require "pry"
34
36
  rescue LoadError
35
- return errmsg(pr('pry.errors.not_installed'))
37
+ return errmsg(pr("pry.errors.not_installed"))
36
38
  end
37
39
 
38
40
  Pry.start(context.frame._binding)
@@ -1,4 +1,6 @@
1
- require 'byebug/command'
1
+ # frozen_string_literal: true
2
+
3
+ require "byebug/command"
2
4
 
3
5
  module Byebug
4
6
  #
@@ -13,7 +15,7 @@ module Byebug
13
15
  end
14
16
 
15
17
  def self.description
16
- <<-EOD
18
+ <<-DESCRIPTION
17
19
  q[uit] [!|unconditionally]
18
20
 
19
21
  #{short_description}
@@ -21,15 +23,15 @@ module Byebug
21
23
  Normally we prompt before exiting. However if the parameter
22
24
  "unconditionally" is given or command is suffixed with !, we exit
23
25
  without asking further questions.
24
- EOD
26
+ DESCRIPTION
25
27
  end
26
28
 
27
29
  def self.short_description
28
- 'Exits byebug'
30
+ "Exits byebug"
29
31
  end
30
32
 
31
33
  def execute
32
- return unless @match[1] || confirm(pr('quit.confirmations.really'))
34
+ return unless @match[1] || confirm(pr("quit.confirmations.really"))
33
35
 
34
36
  processor.interface.autosave
35
37
  processor.interface.close
@@ -1,9 +1,11 @@
1
- require 'byebug/command'
2
- require 'byebug/helpers/bin'
3
- require 'byebug/helpers/path'
4
- require 'shellwords'
5
- require 'English'
6
- require 'rbconfig'
1
+ # frozen_string_literal: true
2
+
3
+ require "byebug/command"
4
+ require "byebug/helpers/bin"
5
+ require "byebug/helpers/path"
6
+ require "shellwords"
7
+ require "English"
8
+ require "rbconfig"
7
9
 
8
10
  module Byebug
9
11
  #
@@ -21,18 +23,18 @@ module Byebug
21
23
  end
22
24
 
23
25
  def self.description
24
- <<-EOD
26
+ <<-DESCRIPTION
25
27
  restart [args]
26
28
 
27
29
  #{short_description}
28
30
 
29
31
  This is a re-exec - all byebug state is lost. If command arguments are
30
32
  passed those are used.
31
- EOD
33
+ DESCRIPTION
32
34
  end
33
35
 
34
36
  def self.short_description
35
- 'Restarts the debugged program'
37
+ "Restarts the debugged program"
36
38
  end
37
39
 
38
40
  def execute
@@ -43,7 +45,7 @@ module Byebug
43
45
 
44
46
  cmd += (@match[:args] ? @match[:args].shellsplit : $ARGV)
45
47
 
46
- puts pr('restart.success', cmd: cmd.shelljoin)
48
+ puts pr("restart.success", cmd: cmd.shelljoin)
47
49
  Kernel.exec(*cmd)
48
50
  end
49
51
 
@@ -55,7 +57,7 @@ module Byebug
55
57
  end
56
58
 
57
59
  def prepend_ruby_bin(cmd)
58
- cmd.unshift(RbConfig.ruby) if which('ruby') != which(cmd.first)
60
+ cmd.unshift(RbConfig.ruby) if which("ruby") != which(cmd.first)
59
61
  cmd
60
62
  end
61
63
  end