byebug 4.0.5 → 5.0.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 (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
@@ -21,18 +21,12 @@ module Byebug
21
21
  end
22
22
  end
23
23
 
24
- class << self
25
- def names
26
- %w(untracevar)
27
- end
28
-
29
- def description
30
- prettify <<-EOD
31
- untr[acevar] <variable>
24
+ def description
25
+ <<-EOD
26
+ untr[acevar] <variable>
32
27
 
33
- Stop tracing global variable <variable>.
34
- EOD
35
- end
28
+ Stop tracing global variable <variable>.
29
+ EOD
36
30
  end
37
31
  end
38
32
  end
@@ -0,0 +1,39 @@
1
+ # encoding: utf-8
2
+
3
+ require 'pathname'
4
+ require 'byebug/command'
5
+ require 'byebug/helpers/frame'
6
+ require 'byebug/helpers/parse'
7
+
8
+ module Byebug
9
+ #
10
+ # Move the current frame up in the backtrace.
11
+ #
12
+ class UpCommand < Command
13
+ include Helpers::FrameHelper
14
+ include Helpers::ParseHelper
15
+
16
+ def regexp
17
+ /^\s* u(?:p)? (?:\s+(\S+))? \s*$/x
18
+ end
19
+
20
+ def execute
21
+ pos, err = parse_steps(@match[1], 'Up')
22
+ return errmsg(err) unless pos
23
+
24
+ adjust_frame(pos, false)
25
+
26
+ ListCommand.new(@state).execute if Setting[:autolist]
27
+ end
28
+
29
+ def description
30
+ <<-EOD
31
+ up[ count]
32
+
33
+ Move to a higher frame in the stack trace.
34
+
35
+ Use the "bt" command to find out where you want to go.
36
+ EOD
37
+ end
38
+ end
39
+ end
@@ -1,107 +1,28 @@
1
- require 'byebug/command'
1
+ require 'byebug/subcommands'
2
2
 
3
- module Byebug
4
- #
5
- # Utilities for the var command.
6
- #
7
- module VarFunctions
8
- def var_list(ary, b = get_binding)
9
- vars = ary.sort.map do |v|
10
- s = begin
11
- b.eval(v.to_s).inspect
12
- rescue
13
- begin
14
- b.eval(v.to_s).to_s
15
- rescue
16
- '*Error in evaluation*'
17
- end
18
- end
19
- [v, s]
20
- end
21
- puts prv(vars)
22
- end
23
-
24
- def var_global(_str = nil)
25
- globals = global_variables.reject do |v|
26
- [:$IGNORECASE, :$=, :$KCODE, :$-K, :$binding].include?(v)
27
- end
28
-
29
- var_list(globals)
30
- end
31
-
32
- def var_instance(str)
33
- obj = bb_warning_eval(str || 'self')
34
- var_list(obj.instance_variables, obj.instance_eval { binding })
35
- end
36
-
37
- def var_constant(str)
38
- str ||= 'self.class'
39
- obj = bb_warning_eval(str)
40
- is_mod = obj.is_a?(Module)
41
- return errmsg(pr('variable.errors.not_module', object: str)) unless is_mod
42
-
43
- constants = bb_eval("#{str}.constants")
44
- puts prv(constants.sort.map { |c| [c, obj.const_get(c)] })
45
- end
46
-
47
- def var_local(_str = nil)
48
- _self = @state.context.frame_self(@state.frame)
49
- locals = @state.context.frame_locals
50
- puts prv(locals.keys.sort.map { |k| [k, locals[k]] })
51
- end
52
-
53
- def var_all(_str = nil)
54
- var_global
55
- var_instance('self')
56
- var_local
57
- end
58
- end
3
+ require 'byebug/commands/var/all'
4
+ require 'byebug/commands/var/const'
5
+ require 'byebug/commands/var/instance'
6
+ require 'byebug/commands/var/local'
7
+ require 'byebug/commands/var/global'
59
8
 
9
+ module Byebug
60
10
  #
61
- # Show variables and its values.
11
+ # Shows variables and its values
62
12
  #
63
13
  class VarCommand < Command
64
- include VarFunctions
65
-
66
- Subcommands = [
67
- ['constant', 2, 'Show constants of an object'],
68
- ['global', 1, 'Show global variables'],
69
- ['instance', 1, 'Show instance variables of self or a specific object'],
70
- ['local', 1, 'Show local variables in current scope'],
71
- ['all', 1, 'Shows local, global and instance variables of self']
72
- ].map do |name, min, help|
73
- Subcmd.new(name, min, help)
74
- end
14
+ include Subcommands
75
15
 
76
16
  def regexp
77
- /^\s* v(?:ar)? (?: \s+(\S+) (?:\s(\S+))? )? \s*$/x
78
- end
79
-
80
- def execute
81
- return puts(self.class.help) unless @match[1]
82
-
83
- subcmd = Command.find(Subcommands, @match[1])
84
- return errmsg("Unknown var command #{@match[1]}\n") unless subcmd
85
-
86
- if @state.context
87
- send("var_#{subcmd.name}", @match[2])
88
- else
89
- errmsg "'var #{subcmd.name}' not available without a context.\n"
90
- end
17
+ /^\s* v(?:ar)? (?:\s+ (.+))? \s*$/x
91
18
  end
92
19
 
93
- class << self
94
- def names
95
- %w(var)
96
- end
97
-
98
- def description
99
- prettify <<-EOD
100
- [v]ar
20
+ def description
21
+ <<-EOD
22
+ [v]ar <subcommand>
101
23
 
102
- Show variables and its values.
103
- EOD
104
- end
24
+ Shows variables and its values.
25
+ EOD
105
26
  end
106
27
  end
107
28
  end
@@ -0,0 +1,37 @@
1
+ require 'byebug/helpers/var'
2
+
3
+ module Byebug
4
+ #
5
+ # Reopens the +var+ command to define the +all+ subcommand
6
+ #
7
+ class VarCommand < Command
8
+ #
9
+ # Shows global, instance and local variables
10
+ #
11
+ class AllSubcommand < Command
12
+ include Helpers::VarHelper
13
+
14
+ def regexp
15
+ /^\s* a(?:ll)? \s*$/x
16
+ end
17
+
18
+ def execute
19
+ var_global
20
+ var_instance('self')
21
+ var_local
22
+ end
23
+
24
+ def short_description
25
+ 'Shows local, global and instance variables of self.'
26
+ end
27
+
28
+ def description
29
+ <<-EOD
30
+ v[ar] a[ll]
31
+
32
+ #{short_description}
33
+ EOD
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,38 @@
1
+ module Byebug
2
+ #
3
+ # Reopens the +var+ command to define the +const+ subcommand
4
+ #
5
+ class VarCommand < Command
6
+ #
7
+ # Shows constants
8
+ #
9
+ class ConstSubcommand < Command
10
+ def regexp
11
+ /^\s* c(?:onst)? (?:\s+ (.+))? \s*$/x
12
+ end
13
+
14
+ def execute
15
+ str_obj = @match[1] || 'self.class'
16
+ obj = bb_warning_eval(str_obj)
17
+ unless obj.is_a?(Module)
18
+ return errmsg(pr('variable.errors.not_module', object: str_obj))
19
+ end
20
+
21
+ constants = bb_eval("#{str_obj}.constants")
22
+ puts prv(constants.sort.map { |c| [c, obj.const_get(c)] }, 'constant')
23
+ end
24
+
25
+ def short_description
26
+ 'Shows constants of an object.'
27
+ end
28
+
29
+ def description
30
+ <<-EOD
31
+ v[ar] c[onstant]
32
+
33
+ #{short_description}
34
+ EOD
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,33 @@
1
+ module Byebug
2
+ #
3
+ # Reopens the +var+ command to define the +global+ subcommand
4
+ #
5
+ class VarCommand < Command
6
+ #
7
+ # Shows global variables
8
+ #
9
+ class GlobalSubcommand < Command
10
+ include Helpers::VarHelper
11
+
12
+ def regexp
13
+ /^\s* g(?:lobal)? \s*$/x
14
+ end
15
+
16
+ def execute
17
+ var_global
18
+ end
19
+
20
+ def short_description
21
+ 'Shows global variables.'
22
+ end
23
+
24
+ def description
25
+ <<-EOD
26
+ v[ar] g[lobal]
27
+
28
+ #{short_description}
29
+ EOD
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,35 @@
1
+ require 'byebug/helpers/var'
2
+
3
+ module Byebug
4
+ #
5
+ # Reopens the +var+ command to define the +instance+ subcommand
6
+ #
7
+ class VarCommand < Command
8
+ #
9
+ # Shows instance variables
10
+ #
11
+ class InstanceSubcommand < Command
12
+ include Helpers::VarHelper
13
+
14
+ def regexp
15
+ /^\s* i(?:nstance)? (?:\s+ (.+))? \s*$/x
16
+ end
17
+
18
+ def execute
19
+ var_instance(@match[1])
20
+ end
21
+
22
+ def short_description
23
+ 'Shows instance variables of self or a specific object.'
24
+ end
25
+
26
+ def description
27
+ <<-EOD
28
+ v[ar] i[nstance][ <object>]
29
+
30
+ #{short_description}
31
+ EOD
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,35 @@
1
+ require 'byebug/helpers/var'
2
+
3
+ module Byebug
4
+ #
5
+ # Reopens the +var+ command to define the +local+ subcommand
6
+ #
7
+ class VarCommand < Command
8
+ #
9
+ # Shows local variables in current scope
10
+ #
11
+ class LocalSubcommand < Command
12
+ include Helpers::VarHelper
13
+
14
+ def regexp
15
+ /^\s* l(?:ocal)? \s*$/x
16
+ end
17
+
18
+ def execute
19
+ var_local
20
+ end
21
+
22
+ def short_description
23
+ 'Shows local variables in current scope.'
24
+ end
25
+
26
+ def description
27
+ <<-EOD
28
+ v[ar] l[ocal]
29
+
30
+ #{short_description}
31
+ EOD
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,47 @@
1
+ # encoding: utf-8
2
+
3
+ require 'pathname'
4
+ require 'byebug/command'
5
+ require 'byebug/helpers/frame'
6
+
7
+ module Byebug
8
+ #
9
+ # Show current backtrace.
10
+ #
11
+ class WhereCommand < Command
12
+ include Helpers::FrameHelper
13
+
14
+ def regexp
15
+ /^\s* (?:w(?:here)?|bt|backtrace) \s*$/x
16
+ end
17
+
18
+ def execute
19
+ print_backtrace
20
+ end
21
+
22
+ def description
23
+ <<-EOD
24
+ w[here]|bt|backtrace
25
+
26
+ Display stack frames.
27
+
28
+ Print the entire stack frame. Each frame is numbered; the most recent
29
+ frame is 0. A frame number can be referred to in the "frame" command.
30
+ "up" and "down" add or subtract respectively to frame numbers shown.
31
+ The position of the current frame is marked with -->. C-frames hang
32
+ from their most immediate Ruby frame to indicate that they are not
33
+ navigable.
34
+ EOD
35
+ end
36
+
37
+ private
38
+
39
+ def print_backtrace
40
+ bt = prc('frame.line', (0...@state.context.stack_size)) do |_, index|
41
+ get_pr_arguments(index)
42
+ end
43
+
44
+ print(bt)
45
+ end
46
+ end
47
+ end
@@ -55,6 +55,16 @@ module Byebug
55
55
  run_script(cwd_rc) if File.exist?(cwd_rc) && cwd_rc != home_rc
56
56
  end
57
57
 
58
+ #
59
+ # A Byebug command is a class defined right under the Byebug module and
60
+ # named <something>Command
61
+ #
62
+ def commands
63
+ const_list = constants.map { |const| const_get(const, false) }
64
+
65
+ const_list.select { |c| c.is_a?(Class) && c.name =~ /[a-z]Command$/ }
66
+ end
67
+
58
68
  private
59
69
 
60
70
  #
@@ -0,0 +1,47 @@
1
+ module Byebug
2
+ module Helpers
3
+ #
4
+ # Utilities used by the eval command
5
+ #
6
+ module EvalHelper
7
+ #
8
+ # Run block temporarily ignoring all TracePoint events.
9
+ #
10
+ # Used to evaluate stuff within Byebug's prompt. Otherwise, any code
11
+ # creating new threads won't be properly evaluated because new threads
12
+ # will get blocked by byebug's main thread.
13
+ #
14
+ def allowing_other_threads
15
+ Byebug.unlock
16
+ res = yield
17
+ Byebug.lock
18
+ res
19
+ end
20
+
21
+ #
22
+ # Get current binding and yield it to the given block
23
+ #
24
+ def run_with_binding
25
+ binding = get_binding
26
+ yield binding
27
+ end
28
+
29
+ #
30
+ # Evaluate +expression+ using +binding+
31
+ #
32
+ # @param binding [Binding] Context where to evaluate the expression
33
+ # @param expression [String] Expression to evaluation
34
+ # @param stack_on_error [Boolean] Whether to show a stack trace on error.
35
+ #
36
+ def eval_with_setting(binding, expression, stack_on_error)
37
+ allowing_other_threads do
38
+ if stack_on_error
39
+ bb_eval(expression, binding)
40
+ else
41
+ bb_warning_eval(expression, binding)
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end