byebug 9.0.5 → 11.1.3
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.
- checksums.yaml +5 -5
- data/CHANGELOG.md +399 -264
- data/CONTRIBUTING.md +12 -19
- data/GUIDE.md +40 -26
- data/LICENSE +18 -18
- data/README.md +103 -74
- data/exe/byebug +6 -0
- data/ext/byebug/breakpoint.c +2 -2
- data/ext/byebug/byebug.c +26 -31
- data/ext/byebug/byebug.h +44 -28
- data/ext/byebug/context.c +45 -32
- data/ext/byebug/extconf.rb +7 -5
- data/ext/byebug/locker.c +4 -4
- data/ext/byebug/threads.c +12 -12
- data/lib/byebug/attacher.rb +18 -4
- data/lib/byebug/breakpoint.rb +26 -6
- data/lib/byebug/command.rb +20 -14
- data/lib/byebug/command_list.rb +3 -1
- data/lib/byebug/commands/break.rb +36 -22
- data/lib/byebug/commands/catch.rb +16 -18
- data/lib/byebug/commands/condition.rb +11 -11
- data/lib/byebug/commands/continue.rb +32 -12
- data/lib/byebug/commands/debug.rb +7 -5
- data/lib/byebug/commands/delete.rb +13 -11
- data/lib/byebug/commands/disable/breakpoints.rb +7 -5
- data/lib/byebug/commands/disable/display.rb +7 -5
- data/lib/byebug/commands/disable.rb +8 -6
- data/lib/byebug/commands/display.rb +11 -9
- data/lib/byebug/commands/down.rb +10 -8
- data/lib/byebug/commands/edit.rb +11 -8
- data/lib/byebug/commands/enable/breakpoints.rb +7 -5
- data/lib/byebug/commands/enable/display.rb +7 -5
- data/lib/byebug/commands/enable.rb +8 -6
- data/lib/byebug/commands/finish.rb +9 -7
- data/lib/byebug/commands/frame.rb +11 -9
- data/lib/byebug/commands/help.rb +7 -5
- data/lib/byebug/commands/history.rb +7 -5
- data/lib/byebug/commands/info/breakpoints.rb +18 -14
- data/lib/byebug/commands/info/display.rb +16 -9
- data/lib/byebug/commands/info/file.rb +13 -14
- data/lib/byebug/commands/info/line.rb +5 -3
- data/lib/byebug/commands/info/program.rb +8 -6
- data/lib/byebug/commands/info.rb +11 -9
- data/lib/byebug/commands/interrupt.rb +8 -4
- data/lib/byebug/commands/irb.rb +13 -12
- data/lib/byebug/commands/kill.rb +11 -11
- data/lib/byebug/commands/list.rb +41 -46
- data/lib/byebug/commands/method.rb +10 -8
- data/lib/byebug/commands/next.rb +8 -6
- data/lib/byebug/commands/pry.rb +10 -10
- data/lib/byebug/commands/quit.rb +10 -8
- data/lib/byebug/commands/restart.rb +30 -11
- data/lib/byebug/commands/save.rb +10 -8
- data/lib/byebug/commands/set.rb +13 -11
- data/lib/byebug/commands/show.rb +7 -5
- data/lib/byebug/commands/skip.rb +85 -0
- data/lib/byebug/commands/source.rb +7 -7
- data/lib/byebug/commands/step.rb +8 -6
- data/lib/byebug/commands/thread/current.rb +6 -4
- data/lib/byebug/commands/thread/list.rb +7 -5
- data/lib/byebug/commands/thread/resume.rb +7 -7
- data/lib/byebug/commands/thread/stop.rb +6 -4
- data/lib/byebug/commands/thread/switch.rb +6 -4
- data/lib/byebug/commands/thread.rb +11 -9
- data/lib/byebug/commands/tracevar.rb +10 -11
- data/lib/byebug/commands/undisplay.rb +12 -11
- data/lib/byebug/commands/untracevar.rb +8 -6
- data/lib/byebug/commands/up.rb +10 -8
- data/lib/byebug/commands/var/all.rb +7 -5
- data/lib/byebug/commands/var/args.rb +6 -4
- data/lib/byebug/commands/var/const.rb +9 -9
- data/lib/byebug/commands/var/global.rb +5 -3
- data/lib/byebug/commands/var/instance.rb +6 -4
- data/lib/byebug/commands/var/local.rb +6 -4
- data/lib/byebug/commands/var.rb +12 -10
- data/lib/byebug/commands/where.rb +9 -7
- data/lib/byebug/commands.rb +40 -37
- data/lib/byebug/context.rb +7 -5
- data/lib/byebug/core.rb +26 -25
- data/lib/byebug/errors.rb +4 -2
- data/lib/byebug/frame.rb +19 -22
- data/lib/byebug/helpers/bin.rb +47 -0
- data/lib/byebug/helpers/eval.rb +15 -13
- data/lib/byebug/helpers/file.rb +6 -4
- data/lib/byebug/helpers/frame.rb +7 -5
- data/lib/byebug/helpers/parse.rb +5 -5
- data/lib/byebug/helpers/path.rb +9 -11
- data/lib/byebug/helpers/reflection.rb +2 -0
- data/lib/byebug/helpers/string.rb +11 -2
- data/lib/byebug/helpers/thread.rb +10 -8
- data/lib/byebug/helpers/toggle.rb +28 -27
- data/lib/byebug/helpers/var.rb +9 -7
- data/lib/byebug/history.rb +20 -11
- data/lib/byebug/interface.rb +13 -11
- data/lib/byebug/interfaces/local_interface.rb +25 -7
- data/lib/byebug/interfaces/remote_interface.rb +21 -9
- data/lib/byebug/interfaces/script_interface.rb +4 -1
- data/lib/byebug/interfaces/test_interface.rb +5 -3
- data/lib/byebug/option_setter.rb +14 -12
- data/lib/byebug/printers/base.rb +10 -10
- data/lib/byebug/printers/plain.rb +9 -8
- data/lib/byebug/printers/texts/base.yml +7 -3
- data/lib/byebug/printers/texts/plain.yml +1 -1
- data/lib/byebug/processors/command_processor.rb +11 -12
- data/lib/byebug/processors/control_processor.rb +4 -6
- data/lib/byebug/processors/post_mortem_processor.rb +4 -2
- data/lib/byebug/processors/script_processor.rb +7 -3
- data/lib/byebug/remote/client.rb +57 -0
- data/lib/byebug/remote/server.rb +47 -0
- data/lib/byebug/remote.rb +46 -66
- data/lib/byebug/runner.rb +43 -49
- data/lib/byebug/setting.rb +11 -5
- data/lib/byebug/settings/autoirb.rb +7 -5
- data/lib/byebug/settings/autolist.rb +7 -5
- data/lib/byebug/settings/autopry.rb +7 -5
- data/lib/byebug/settings/autosave.rb +4 -2
- data/lib/byebug/settings/basename.rb +4 -2
- data/lib/byebug/settings/callstyle.rb +4 -3
- data/lib/byebug/settings/fullpath.rb +4 -2
- data/lib/byebug/settings/histfile.rb +5 -3
- data/lib/byebug/settings/histsize.rb +4 -2
- data/lib/byebug/settings/linetrace.rb +6 -4
- data/lib/byebug/settings/listsize.rb +4 -2
- data/lib/byebug/settings/post_mortem.rb +6 -4
- data/lib/byebug/settings/savefile.rb +4 -2
- data/lib/byebug/settings/stack_on_error.rb +4 -2
- data/lib/byebug/settings/width.rb +3 -1
- data/lib/byebug/source_file_formatter.rb +71 -0
- data/lib/byebug/subcommands.rb +6 -4
- data/lib/byebug/version.rb +2 -1
- data/lib/byebug.rb +3 -1
- metadata +22 -20
- data/bin/byebug +0 -7
data/lib/byebug/frame.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
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.
|
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] ==
|
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
|
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) ?
|
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(
|
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
|
136
|
-
return
|
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 !=
|
159
|
+
return [] unless _self.to_s != "main"
|
163
160
|
|
164
|
-
|
161
|
+
_class.instance_method(_method).parameters
|
165
162
|
end
|
166
163
|
|
167
164
|
def ruby_args
|
168
|
-
meth_name = _binding.eval(
|
165
|
+
meth_name = _binding.eval("__method__")
|
169
166
|
return [] unless meth_name
|
170
167
|
|
171
|
-
meth_obj =
|
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] ==
|
175
|
+
Setting[:callstyle] == "short" || arg[1].nil? || locals.empty?
|
179
176
|
end
|
180
177
|
|
181
178
|
def prefix_and_default(arg_type)
|
182
|
-
return [
|
183
|
-
return [
|
179
|
+
return ["&", "block"] if arg_type == :block
|
180
|
+
return ["*", "args"] if arg_type == :rest
|
184
181
|
|
185
|
-
[
|
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
|
data/lib/byebug/helpers/eval.rb
CHANGED
@@ -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 /,
|
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(
|
65
|
-
msg = Setting[:stack_on_error] ? error_msg(
|
66
|
+
def msg(exception)
|
67
|
+
msg = Setting[:stack_on_error] ? error_msg(exception) : warning_msg(exception)
|
66
68
|
|
67
|
-
pr(
|
69
|
+
pr("eval.exception", text_message: msg)
|
68
70
|
end
|
69
71
|
|
70
|
-
def error_msg(
|
71
|
-
at =
|
72
|
+
def error_msg(exception)
|
73
|
+
at = exception.backtrace
|
72
74
|
|
73
|
-
locations = ["#{at.shift}: #{warning_msg(
|
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(
|
79
|
-
"#{
|
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
|
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
|
-
|
121
|
+
rescue StandardError
|
122
|
+
"*Error in evaluation*"
|
121
123
|
end
|
122
124
|
end
|
123
125
|
end
|
data/lib/byebug/helpers/file.rb
CHANGED
@@ -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([]) { |
|
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) { |
|
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(
|
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
|
-
[
|
59
|
+
["(irb)", "-e", "(byebug)", "(eval)"].include?(name)
|
58
60
|
end
|
59
61
|
end
|
60
62
|
end
|
data/lib/byebug/helpers/frame.rb
CHANGED
@@ -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(
|
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(
|
22
|
-
return frame_err(
|
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(
|
69
|
-
|
70
|
+
def index_from_start(index)
|
71
|
+
index >= 0 ? index : context.stack_size + index
|
70
72
|
end
|
71
73
|
end
|
72
74
|
end
|
data/lib/byebug/helpers/parse.rb
CHANGED
@@ -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
|
-
|
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(
|
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(
|
25
|
+
err = pr("parse.errors.int.too_high", cmd: cmd, str: str, max: max)
|
26
26
|
return nil, err
|
27
27
|
end
|
28
28
|
|
data/lib/byebug/helpers/path.rb
CHANGED
@@ -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 ||=
|
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(
|
14
|
+
@root_path ||= File.expand_path(File.join("..", "..", ".."), __dir__)
|
13
15
|
end
|
14
16
|
|
15
17
|
def lib_files
|
16
|
-
@lib_files ||=
|
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 ||=
|
22
|
+
@test_files ||= glob_for("test")
|
25
23
|
end
|
26
24
|
|
27
25
|
def gem_files
|
28
|
-
@gem_files ||= [bin_file] + lib_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
|
38
|
-
Dir.glob(File.
|
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
|
#
|
@@ -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
|
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(
|
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(
|
34
|
+
pr("thread.errors.no_thread")
|
33
35
|
elsif ctx == context
|
34
|
-
pr(
|
36
|
+
pr("thread.errors.current_thread")
|
35
37
|
elsif ctx.ignored?
|
36
|
-
pr(
|
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
|
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
|
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
|
-
|
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
|
-
|
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
|
-
|
32
|
-
enabled = (
|
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
|
-
|
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
|
-
|
33
|
+
raise err unless err.nil?
|
49
34
|
|
50
|
-
Byebug.displays[pos - 1][0] = (
|
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
|
data/lib/byebug/helpers/var.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
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,
|
18
|
+
puts prv(vars, "instance")
|
17
19
|
end
|
18
20
|
|
19
21
|
def var_global
|
20
22
|
globals = global_variables.reject do |v|
|
21
|
-
[
|
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 ||
|
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 ==
|
37
|
-
puts prv(locals.keys.sort.map { |k| [k, locals[k]] },
|
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]] },
|
50
|
+
puts prv(locals.keys.sort.map { |k| [k, locals[k]] }, "instance")
|
49
51
|
end
|
50
52
|
end
|
51
53
|
end
|
data/lib/byebug/history.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
begin
|
2
|
-
require
|
4
|
+
require "readline"
|
3
5
|
rescue LoadError
|
4
|
-
warn <<-
|
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
|
-
|
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],
|
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 =
|
86
|
+
commands = buffer.last(show_size)
|
78
87
|
|
79
88
|
last_ids(show_size).zip(commands).map do |l|
|
80
|
-
format(
|
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
|
94
|
+
# Array of ids of the last +number+ commands.
|
86
95
|
#
|
87
|
-
def last_ids(
|
88
|
-
(1 + size -
|
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
|
124
|
+
return true if /^\s*$/.match?(buf)
|
116
125
|
return false if Readline::HISTORY.empty?
|
117
126
|
|
118
|
-
|
127
|
+
buffer[Readline::HISTORY.length - 1] == buf
|
119
128
|
end
|
120
129
|
end
|
121
130
|
end
|