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
@@ -7,7 +7,9 @@ module Byebug
7
7
 
8
8
  def initialize
9
9
  super()
10
- @input, @output, @error = [], [], []
10
+ @input = []
11
+ @output = []
12
+ @error = []
11
13
  end
12
14
 
13
15
  def errmsg(message)
@@ -32,7 +34,9 @@ module Byebug
32
34
  end
33
35
 
34
36
  def clear
35
- @input, @output, @error = [], [], []
37
+ @input = []
38
+ @output = []
39
+ @error = []
36
40
  history.clear
37
41
  end
38
42
 
@@ -24,7 +24,7 @@ module Byebug
24
24
  end
25
25
  end
26
26
 
27
- def print_variables(variables)
27
+ def print_variables(variables, *_)
28
28
  print_collection('variable.variable', variables) do |(key, value), _|
29
29
  value = value.nil? ? 'nil' : value.to_s
30
30
  if "#{key} = #{value}".size > Setting[:width]
@@ -1,10 +1,13 @@
1
1
  require 'byebug/states/regular_state'
2
+ require 'byebug/helpers/file'
2
3
 
3
4
  module Byebug
4
5
  #
5
6
  # Processes commands in regular mode
6
7
  #
7
8
  class CommandProcessor < Processor
9
+ include Helpers::FileHelper
10
+
8
11
  attr_reader :display, :state
9
12
 
10
13
  def initialize(interface = LocalInterface.new)
@@ -20,8 +23,6 @@ module Byebug
20
23
  @interface = interface
21
24
  end
22
25
 
23
- include FileFunctions
24
-
25
26
  def at_breakpoint(_context, breakpoint)
26
27
  n = Byebug.breakpoints.index(breakpoint) + 1
27
28
  file = normalize(breakpoint.source)
@@ -75,9 +76,11 @@ module Byebug
75
76
  Setting[:autolist] = false if ['(irb)', '-e'].include?(file)
76
77
 
77
78
  # Bind commands to the current state.
78
- Command.commands.each do |cmd|
79
- cmd.new(state).execute if cmd.always_run >= run_level
80
- end
79
+ commands.each { |cmd| cmd.execute if cmd.class.always_run >= run_level }
80
+ end
81
+
82
+ def commands
83
+ Byebug.commands.map { |cmd| cmd.new(state) }
81
84
  end
82
85
 
83
86
  #
@@ -145,12 +148,7 @@ module Byebug
145
148
  # Finds a matches the command matching the input
146
149
  #
147
150
  def match_cmd(input)
148
- Command.commands.each do |c|
149
- cmd = c.new(state)
150
- return cmd if cmd.match(input)
151
- end
152
-
153
- nil
151
+ commands.find { |cmd| cmd.match(input) }
154
152
  end
155
153
 
156
154
  #
@@ -12,7 +12,7 @@ module Byebug
12
12
  end
13
13
 
14
14
  def commands
15
- Command.commands.select(&:allow_in_control).map { |cmd| cmd.new(state) }
15
+ Byebug.commands.select(&:allow_in_control).map { |cmd| cmd.new(state) }
16
16
  end
17
17
 
18
18
  def process_commands
@@ -37,6 +37,7 @@ module Byebug
37
37
 
38
38
  server = TCPServer.new(host, port)
39
39
  self.actual_port = server.addr[1]
40
+
40
41
  @thread = DebugThread.new do
41
42
  while (session = server.accept)
42
43
  handler.interface = RemoteInterface.new(session)
@@ -51,12 +52,14 @@ module Byebug
51
52
  return @actual_control_port if @control_thread
52
53
  server = TCPServer.new(host, ctrl_port)
53
54
  @actual_control_port = server.addr[1]
55
+
54
56
  @control_thread = DebugThread.new do
55
57
  while (session = server.accept)
56
58
  handler.interface = RemoteInterface.new(session)
57
59
  ControlCommandProcessor.new(handler.interface).process_commands
58
60
  end
59
61
  end
62
+
60
63
  @actual_control_port
61
64
  end
62
65
 
@@ -1,13 +1,15 @@
1
1
  require 'optparse'
2
2
  require 'English'
3
3
  require 'byebug/core'
4
- require 'byebug/helper'
4
+ require 'byebug/helpers/parse'
5
5
 
6
6
  module Byebug
7
7
  #
8
8
  # Responsible for starting the debugger when started from the command line.
9
9
  #
10
10
  class Runner
11
+ include Helpers::ParseHelper
12
+
11
13
  #
12
14
  # Error class signaling absence of a script to debug
13
15
  #
@@ -36,7 +38,8 @@ module Byebug
36
38
  # finishing the program.
37
39
  #
38
40
  def initialize(stop = true, quit = true)
39
- @stop, @quit = stop, quit
41
+ @stop = stop
42
+ @quit = quit
40
43
  end
41
44
 
42
45
  #
@@ -155,7 +158,6 @@ module Byebug
155
158
  $PROGRAM_NAME = program
156
159
  end
157
160
 
158
- include ParseFunctions
159
161
  #
160
162
  # Debugs a script only if syntax checks okay.
161
163
  #
@@ -1,4 +1,4 @@
1
- require 'byebug/helper'
1
+ require 'byebug/helpers/string'
2
2
 
3
3
  module Byebug
4
4
  #
@@ -24,7 +24,7 @@ module Byebug
24
24
  end
25
25
 
26
26
  def help
27
- "\n #{banner}.\n\n"
27
+ prettify(banner)
28
28
  end
29
29
 
30
30
  def to_sym
@@ -37,8 +37,6 @@ module Byebug
37
37
  end
38
38
 
39
39
  class << self
40
- include StringFunctions
41
-
42
40
  def settings
43
41
  @settings ||= {}
44
42
  end
@@ -67,20 +65,6 @@ module Byebug
67
65
  end
68
66
  output + "\n"
69
67
  end
70
-
71
- def help(cmd, subcmd)
72
- unless subcmd
73
- command = Byebug.const_get("#{cmd.capitalize}Command")
74
- return command.description + help_all
75
- end
76
-
77
- setting = find(subcmd)
78
- prettify <<-EOS
79
- #{cmd} #{setting.to_sym} <value>
80
-
81
- #{setting.banner}.
82
- EOS
83
- end
84
68
  end
85
69
  end
86
70
  end
@@ -0,0 +1,21 @@
1
+ require 'byebug/setting'
2
+
3
+ module Byebug
4
+ #
5
+ # Setting to customize the file where byebug's history is saved.
6
+ #
7
+ class SavefileSetting < Setting
8
+ DEFAULT = File.expand_path("#{ENV['HOME'] || '.'}/.byebug_save")
9
+
10
+ def banner
11
+ <<-EOB
12
+ File where save commands saves current settings to. Default:
13
+ ~/.byebug_save
14
+ EOB
15
+ end
16
+
17
+ def to_s
18
+ "The command history file is #{value}\n"
19
+ end
20
+ end
21
+ end
@@ -1,10 +1,13 @@
1
1
  require 'byebug/state'
2
+ require 'byebug/helpers/file'
2
3
 
3
4
  module Byebug
4
5
  #
5
6
  # Controls state of Byebug's REPL when in normal mode
6
7
  #
7
8
  class RegularState < State
9
+ include Helpers::FileHelper
10
+
8
11
  attr_accessor :context, :frame, :display, :file, :line, :prev_line
9
12
  attr_writer :interface
10
13
 
@@ -36,7 +39,6 @@ module Byebug
36
39
  @proceed = true
37
40
  end
38
41
 
39
- include FileFunctions
40
42
  #
41
43
  # Current (formatted) location
42
44
  #
@@ -87,11 +89,7 @@ module Byebug
87
89
 
88
90
  locals = context.frame_locals(pos) unless Setting[:callstyle] == 'short'
89
91
  my_args = args.map do |arg|
90
- case arg[0]
91
- when :block then prefix, default = '&', 'block'
92
- when :rest then prefix, default = '*', 'args'
93
- else prefix, default = '', nil
94
- end
92
+ prefix, default = prefix_and_default_from(arg[0])
95
93
 
96
94
  kls = if Setting[:callstyle] == 'short' || arg[1].nil? || locals.empty?
97
95
  ''
@@ -174,5 +172,16 @@ module Byebug
174
172
 
175
173
  File.join('...', components[-3..-1])
176
174
  end
175
+
176
+ def prefix_and_default_from(arg_type)
177
+ case arg_type
178
+ when :block
179
+ return ['&', 'block']
180
+ when :rest
181
+ return ['*', 'args']
182
+ else
183
+ return ['', nil]
184
+ end
185
+ end
177
186
  end
178
187
  end
@@ -0,0 +1,33 @@
1
+ module Byebug
2
+ #
3
+ # Holds an array of subcommands for a command
4
+ #
5
+ class SubcommandList
6
+ def initialize(commands, parent)
7
+ @commands = commands
8
+ @parent = parent
9
+ end
10
+
11
+ def find(name)
12
+ @commands.find { |cmd| cmd.match(name) }
13
+ end
14
+
15
+ def help(name)
16
+ subcmd = find(name)
17
+ return errmsg("Unknown subcommand '#{name}'") unless subcmd
18
+
19
+ subcmd.help
20
+ end
21
+
22
+ def to_s
23
+ width = @commands.map(&:to_name).max_by(&:size).size
24
+
25
+ formatted_cmds = @commands.map do |subcmd|
26
+ format("%s %-#{width}s -- %s\n",
27
+ @parent, subcmd.to_name, subcmd.short_description)
28
+ end
29
+
30
+ formatted_cmds.join
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,53 @@
1
+ require 'byebug/command'
2
+ require 'byebug/subcommand_list'
3
+
4
+ module Byebug
5
+ #
6
+ # Subcommand additions.
7
+ #
8
+ module Subcommands
9
+ #
10
+ # Summarized description of a subcommand
11
+ #
12
+ def short_description
13
+ fail(NotImplementedError, 'Your custom subcommand needs to define this')
14
+ end
15
+
16
+ #
17
+ # Delegates to subcommands or prints help if no subcommand specified.
18
+ #
19
+ def execute
20
+ return puts(help) unless @match[1]
21
+
22
+ subcmd = subcommands.find(@match[1])
23
+ return errmsg("Unknown subcommand '#{@match[1]}'\n") unless subcmd
24
+
25
+ subcmd.execute
26
+ end
27
+
28
+ #
29
+ # Default help text for a command with subcommands
30
+ #
31
+ def help
32
+ prettify <<-EOH
33
+ #{description}
34
+
35
+ List of "#{to_name}" subcommands:
36
+
37
+ --
38
+ #{subcommands}
39
+ EOH
40
+ end
41
+
42
+ #
43
+ # Command's subcommands.
44
+ #
45
+ def subcommands
46
+ subcmd_klasses = self.class.subcommands
47
+ return nil unless subcmd_klasses.any?
48
+
49
+ subcmd_list = subcmd_klasses.map { |cmd| cmd.new(@state) }
50
+ SubcommandList.new(subcmd_list, self.class.name)
51
+ end
52
+ end
53
+ end
@@ -1,3 +1,3 @@
1
1
  module Byebug
2
- VERSION = '4.0.5'
2
+ VERSION = '5.0.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: byebug
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.5
4
+ version: 5.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Rodriguez
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-04-02 00:00:00.000000000 Z
13
+ date: 2015-05-18 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: columnize
@@ -80,36 +80,72 @@ files:
80
80
  - lib/byebug/commands/condition.rb
81
81
  - lib/byebug/commands/continue.rb
82
82
  - lib/byebug/commands/delete.rb
83
+ - lib/byebug/commands/disable.rb
84
+ - lib/byebug/commands/disable/breakpoints.rb
85
+ - lib/byebug/commands/disable/display.rb
83
86
  - lib/byebug/commands/display.rb
87
+ - lib/byebug/commands/down.rb
84
88
  - lib/byebug/commands/edit.rb
85
- - lib/byebug/commands/enable_disable.rb
89
+ - lib/byebug/commands/enable.rb
90
+ - lib/byebug/commands/enable/breakpoints.rb
91
+ - lib/byebug/commands/enable/display.rb
86
92
  - lib/byebug/commands/eval.rb
87
93
  - lib/byebug/commands/finish.rb
88
94
  - lib/byebug/commands/frame.rb
89
95
  - lib/byebug/commands/help.rb
90
96
  - lib/byebug/commands/history.rb
91
97
  - lib/byebug/commands/info.rb
98
+ - lib/byebug/commands/info/args.rb
99
+ - lib/byebug/commands/info/breakpoints.rb
100
+ - lib/byebug/commands/info/catch.rb
101
+ - lib/byebug/commands/info/display.rb
102
+ - lib/byebug/commands/info/file.rb
103
+ - lib/byebug/commands/info/line.rb
104
+ - lib/byebug/commands/info/program.rb
92
105
  - lib/byebug/commands/interrupt.rb
93
106
  - lib/byebug/commands/irb.rb
94
107
  - lib/byebug/commands/kill.rb
95
108
  - lib/byebug/commands/list.rb
96
109
  - lib/byebug/commands/method.rb
110
+ - lib/byebug/commands/next.rb
111
+ - lib/byebug/commands/pp.rb
97
112
  - lib/byebug/commands/pry.rb
113
+ - lib/byebug/commands/ps.rb
114
+ - lib/byebug/commands/putl.rb
98
115
  - lib/byebug/commands/quit.rb
99
116
  - lib/byebug/commands/restart.rb
100
117
  - lib/byebug/commands/save.rb
101
118
  - lib/byebug/commands/set.rb
102
119
  - lib/byebug/commands/show.rb
103
120
  - lib/byebug/commands/source.rb
104
- - lib/byebug/commands/stepping.rb
121
+ - lib/byebug/commands/step.rb
105
122
  - lib/byebug/commands/thread.rb
123
+ - lib/byebug/commands/thread/current.rb
124
+ - lib/byebug/commands/thread/list.rb
125
+ - lib/byebug/commands/thread/resume.rb
126
+ - lib/byebug/commands/thread/stop.rb
127
+ - lib/byebug/commands/thread/switch.rb
106
128
  - lib/byebug/commands/tracevar.rb
107
129
  - lib/byebug/commands/undisplay.rb
108
130
  - lib/byebug/commands/untracevar.rb
131
+ - lib/byebug/commands/up.rb
109
132
  - lib/byebug/commands/var.rb
133
+ - lib/byebug/commands/var/all.rb
134
+ - lib/byebug/commands/var/const.rb
135
+ - lib/byebug/commands/var/global.rb
136
+ - lib/byebug/commands/var/instance.rb
137
+ - lib/byebug/commands/var/local.rb
138
+ - lib/byebug/commands/where.rb
110
139
  - lib/byebug/context.rb
111
140
  - lib/byebug/core.rb
112
- - lib/byebug/helper.rb
141
+ - lib/byebug/helpers/eval.rb
142
+ - lib/byebug/helpers/file.rb
143
+ - lib/byebug/helpers/frame.rb
144
+ - lib/byebug/helpers/parse.rb
145
+ - lib/byebug/helpers/string.rb
146
+ - lib/byebug/helpers/thread.rb
147
+ - lib/byebug/helpers/toggle.rb
148
+ - lib/byebug/helpers/var.rb
113
149
  - lib/byebug/history.rb
114
150
  - lib/byebug/interface.rb
115
151
  - lib/byebug/interfaces/local_interface.rb
@@ -138,12 +174,15 @@ files:
138
174
  - lib/byebug/settings/linetrace.rb
139
175
  - lib/byebug/settings/listsize.rb
140
176
  - lib/byebug/settings/post_mortem.rb
177
+ - lib/byebug/settings/savefile.rb
141
178
  - lib/byebug/settings/stack_on_error.rb
142
179
  - lib/byebug/settings/verbose.rb
143
180
  - lib/byebug/settings/width.rb
144
181
  - lib/byebug/state.rb
145
182
  - lib/byebug/states/control_state.rb
146
183
  - lib/byebug/states/regular_state.rb
184
+ - lib/byebug/subcommand_list.rb
185
+ - lib/byebug/subcommands.rb
147
186
  - lib/byebug/version.rb
148
187
  homepage: http://github.com/deivid-rodriguez/byebug
149
188
  licenses:
@@ -165,7 +204,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
165
204
  version: '0'
166
205
  requirements: []
167
206
  rubyforge_project:
168
- rubygems_version: 2.4.5
207
+ rubygems_version: 2.4.7
169
208
  signing_key:
170
209
  specification_version: 4
171
210
  summary: Ruby 2.0 fast debugger - base + CLI