byebug 5.0.0 → 6.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +26 -1
- data/CONTRIBUTING.md +35 -13
- data/GUIDE.md +256 -198
- data/README.md +5 -11
- data/ext/byebug/byebug.c +5 -43
- data/ext/byebug/byebug.h +6 -1
- data/ext/byebug/context.c +4 -5
- data/lib/byebug/command.rb +64 -64
- data/lib/byebug/command_list.rb +32 -0
- data/lib/byebug/commands.rb +37 -0
- data/lib/byebug/commands/break.rb +45 -37
- data/lib/byebug/commands/catch.rb +52 -28
- data/lib/byebug/commands/condition.rb +19 -13
- data/lib/byebug/commands/continue.rb +15 -11
- data/lib/byebug/commands/delete.rb +18 -12
- data/lib/byebug/commands/disable.rb +9 -10
- data/lib/byebug/commands/disable/breakpoints.rb +13 -11
- data/lib/byebug/commands/disable/display.rb +13 -11
- data/lib/byebug/commands/display.rb +32 -24
- data/lib/byebug/commands/down.rb +18 -14
- data/lib/byebug/commands/edit.rb +42 -26
- data/lib/byebug/commands/enable.rb +9 -3
- data/lib/byebug/commands/enable/breakpoints.rb +13 -11
- data/lib/byebug/commands/enable/display.rb +13 -11
- data/lib/byebug/commands/finish.rb +23 -14
- data/lib/byebug/commands/frame.rb +21 -18
- data/lib/byebug/commands/help.rb +39 -16
- data/lib/byebug/commands/history.rb +16 -10
- data/lib/byebug/commands/info.rb +8 -5
- data/lib/byebug/commands/info/breakpoints.rb +16 -14
- data/lib/byebug/commands/info/display.rb +18 -18
- data/lib/byebug/commands/info/file.rb +22 -22
- data/lib/byebug/commands/info/line.rb +13 -11
- data/lib/byebug/commands/info/program.rb +13 -17
- data/lib/byebug/commands/interrupt.rb +13 -11
- data/lib/byebug/commands/irb.rb +16 -10
- data/lib/byebug/commands/kill.rb +19 -13
- data/lib/byebug/commands/list.rb +35 -24
- data/lib/byebug/commands/method.rb +25 -15
- data/lib/byebug/commands/next.rb +15 -13
- data/lib/byebug/commands/pry.rb +18 -11
- data/lib/byebug/commands/ps.rb +21 -23
- data/lib/byebug/commands/quit.rb +17 -11
- data/lib/byebug/commands/restart.rb +28 -24
- data/lib/byebug/commands/save.rb +23 -15
- data/lib/byebug/commands/set.rb +26 -19
- data/lib/byebug/commands/show.rb +20 -14
- data/lib/byebug/commands/source.rb +15 -14
- data/lib/byebug/commands/step.rb +15 -13
- data/lib/byebug/commands/thread.rb +8 -4
- data/lib/byebug/commands/thread/current.rb +11 -11
- data/lib/byebug/commands/thread/list.rb +14 -14
- data/lib/byebug/commands/thread/resume.rb +14 -14
- data/lib/byebug/commands/thread/stop.rb +14 -14
- data/lib/byebug/commands/thread/switch.rb +15 -14
- data/lib/byebug/commands/tracevar.rb +20 -16
- data/lib/byebug/commands/undisplay.rb +22 -18
- data/lib/byebug/commands/untracevar.rb +13 -11
- data/lib/byebug/commands/up.rb +18 -14
- data/lib/byebug/commands/var.rb +10 -3
- data/lib/byebug/commands/var/all.rb +15 -13
- data/lib/byebug/commands/var/args.rb +37 -0
- data/lib/byebug/commands/var/const.rb +25 -14
- data/lib/byebug/commands/var/global.rb +13 -11
- data/lib/byebug/commands/var/instance.rb +13 -11
- data/lib/byebug/commands/var/local.rb +13 -11
- data/lib/byebug/commands/where.rb +15 -11
- data/lib/byebug/context.rb +71 -73
- data/lib/byebug/core.rb +45 -26
- data/lib/byebug/errors.rb +27 -0
- data/lib/byebug/frame.rb +181 -0
- data/lib/byebug/helpers/eval.rb +67 -26
- data/lib/byebug/helpers/file.rb +18 -3
- data/lib/byebug/helpers/frame.rb +36 -39
- data/lib/byebug/helpers/parse.rb +15 -13
- data/lib/byebug/helpers/path.rb +21 -0
- data/lib/byebug/helpers/reflection.rb +17 -0
- data/lib/byebug/helpers/thread.rb +20 -14
- data/lib/byebug/helpers/toggle.rb +10 -5
- data/lib/byebug/helpers/var.rb +36 -15
- data/lib/byebug/interface.rb +27 -9
- data/lib/byebug/option_setter.rb +93 -0
- data/lib/byebug/printers/base.rb +3 -0
- data/lib/byebug/printers/plain.rb +4 -14
- data/lib/byebug/printers/texts/base.yml +2 -7
- data/lib/byebug/processors/command_processor.rb +101 -102
- data/lib/byebug/processors/control_processor.rb +20 -0
- data/lib/byebug/processors/post_mortem_processor.rb +16 -0
- data/lib/byebug/processors/script_processor.rb +49 -0
- data/lib/byebug/remote.rb +13 -7
- data/lib/byebug/runner.rb +39 -65
- data/lib/byebug/setting.rb +4 -1
- data/lib/byebug/settings/post_mortem.rb +0 -16
- data/lib/byebug/settings/savefile.rb +1 -4
- data/lib/byebug/subcommands.rb +27 -29
- data/lib/byebug/version.rb +4 -1
- metadata +14 -29
- data/lib/byebug/commands/eval.rb +0 -43
- data/lib/byebug/commands/info/args.rb +0 -39
- data/lib/byebug/commands/info/catch.rb +0 -39
- data/lib/byebug/commands/pp.rb +0 -41
- data/lib/byebug/commands/putl.rb +0 -43
- data/lib/byebug/processor.rb +0 -43
- data/lib/byebug/processors/control_command_processor.rb +0 -48
- data/lib/byebug/settings/verbose.rb +0 -20
- data/lib/byebug/state.rb +0 -12
- data/lib/byebug/states/control_state.rb +0 -26
- data/lib/byebug/states/regular_state.rb +0 -187
- data/lib/byebug/subcommand_list.rb +0 -33
@@ -8,28 +8,30 @@ module Byebug
|
|
8
8
|
#
|
9
9
|
# Shows local variables in current scope
|
10
10
|
#
|
11
|
-
class
|
11
|
+
class LocalCommand < Command
|
12
12
|
include Helpers::VarHelper
|
13
13
|
|
14
|
-
|
15
|
-
/^\s* l(?:ocal)? \s*$/x
|
16
|
-
end
|
17
|
-
|
18
|
-
def execute
|
19
|
-
var_local
|
20
|
-
end
|
14
|
+
self.allow_in_post_mortem = true
|
21
15
|
|
22
|
-
def
|
23
|
-
|
16
|
+
def self.regexp
|
17
|
+
/^\s* l(?:ocal)? \s*$/x
|
24
18
|
end
|
25
19
|
|
26
|
-
def description
|
20
|
+
def self.description
|
27
21
|
<<-EOD
|
28
22
|
v[ar] l[ocal]
|
29
23
|
|
30
24
|
#{short_description}
|
31
25
|
EOD
|
32
26
|
end
|
27
|
+
|
28
|
+
def self.short_description
|
29
|
+
'Shows local variables in current scope.'
|
30
|
+
end
|
31
|
+
|
32
|
+
def execute
|
33
|
+
var_local
|
34
|
+
end
|
33
35
|
end
|
34
36
|
end
|
35
37
|
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
1
|
require 'pathname'
|
4
2
|
require 'byebug/command'
|
5
3
|
require 'byebug/helpers/frame'
|
@@ -11,19 +9,17 @@ module Byebug
|
|
11
9
|
class WhereCommand < Command
|
12
10
|
include Helpers::FrameHelper
|
13
11
|
|
14
|
-
|
15
|
-
/^\s* (?:w(?:here)?|bt|backtrace) \s*$/x
|
16
|
-
end
|
12
|
+
self.allow_in_post_mortem = true
|
17
13
|
|
18
|
-
def
|
19
|
-
|
14
|
+
def self.regexp
|
15
|
+
/^\s* (?:w(?:here)?|bt|backtrace) \s*$/x
|
20
16
|
end
|
21
17
|
|
22
|
-
def description
|
18
|
+
def self.description
|
23
19
|
<<-EOD
|
24
20
|
w[here]|bt|backtrace
|
25
21
|
|
26
|
-
|
22
|
+
#{short_description}
|
27
23
|
|
28
24
|
Print the entire stack frame. Each frame is numbered; the most recent
|
29
25
|
frame is 0. A frame number can be referred to in the "frame" command.
|
@@ -34,11 +30,19 @@ module Byebug
|
|
34
30
|
EOD
|
35
31
|
end
|
36
32
|
|
33
|
+
def self.short_description
|
34
|
+
'Displays the backtrace'
|
35
|
+
end
|
36
|
+
|
37
|
+
def execute
|
38
|
+
print_backtrace
|
39
|
+
end
|
40
|
+
|
37
41
|
private
|
38
42
|
|
39
43
|
def print_backtrace
|
40
|
-
bt = prc('frame.line', (0
|
41
|
-
|
44
|
+
bt = prc('frame.line', (0...context.stack_size)) do |_, index|
|
45
|
+
Frame.new(context, index).to_hash
|
42
46
|
end
|
43
47
|
|
44
48
|
print(bt)
|
data/lib/byebug/context.rb
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
require 'byebug/frame'
|
2
|
+
require 'byebug/helpers/path'
|
3
|
+
require 'byebug/helpers/file'
|
4
|
+
require 'byebug/processors/command_processor'
|
5
|
+
|
1
6
|
module Byebug
|
2
7
|
#
|
3
8
|
# Mantains context information for the debugger and it's the main
|
@@ -5,19 +10,32 @@ module Byebug
|
|
5
10
|
# at_breakpoint, at_catchpoint, at_tracing, at_line and at_return callbacks
|
6
11
|
#
|
7
12
|
class Context
|
8
|
-
|
9
|
-
# List of files byebug will ignore while debugging
|
10
|
-
#
|
11
|
-
def self.ignored_files
|
12
|
-
Byebug.mode == :standalone ? lib_files + [bin_file] : lib_files
|
13
|
-
end
|
13
|
+
include Helpers::FileHelper
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
class << self
|
16
|
+
include Helpers::PathHelper
|
17
|
+
|
18
|
+
attr_writer :ignored_files
|
18
19
|
|
19
|
-
|
20
|
-
|
20
|
+
#
|
21
|
+
# List of files byebug will ignore while debugging
|
22
|
+
#
|
23
|
+
def ignored_files
|
24
|
+
@ignored_files ||=
|
25
|
+
Byebug.mode == :standalone ? lib_files + [bin_file] : lib_files
|
26
|
+
end
|
27
|
+
|
28
|
+
attr_writer :interface
|
29
|
+
|
30
|
+
def interface
|
31
|
+
@interface ||= LocalInterface.new
|
32
|
+
end
|
33
|
+
|
34
|
+
attr_writer :processor
|
35
|
+
|
36
|
+
def processor
|
37
|
+
@processor ||= CommandProcessor
|
38
|
+
end
|
21
39
|
end
|
22
40
|
|
23
41
|
#
|
@@ -29,6 +47,32 @@ module Byebug
|
|
29
47
|
self.class.ignored_files.include?(path)
|
30
48
|
end
|
31
49
|
|
50
|
+
def frame
|
51
|
+
@frame ||= Frame.new(self, 0)
|
52
|
+
end
|
53
|
+
|
54
|
+
def frame=(pos)
|
55
|
+
@frame = Frame.new(self, pos)
|
56
|
+
end
|
57
|
+
|
58
|
+
def file
|
59
|
+
frame.file
|
60
|
+
end
|
61
|
+
|
62
|
+
def line
|
63
|
+
frame.line
|
64
|
+
end
|
65
|
+
|
66
|
+
def location
|
67
|
+
"#{normalize(file)}:#{line}"
|
68
|
+
end
|
69
|
+
|
70
|
+
def full_location
|
71
|
+
return location if virtual_file?(file)
|
72
|
+
|
73
|
+
"#{location} #{get_line(file, line)}"
|
74
|
+
end
|
75
|
+
|
32
76
|
#
|
33
77
|
# Context's stack size
|
34
78
|
#
|
@@ -44,83 +88,37 @@ module Byebug
|
|
44
88
|
step_into 1
|
45
89
|
end
|
46
90
|
|
47
|
-
|
48
|
-
|
49
|
-
#
|
50
|
-
# @param frame_no Frame index in the backtrace. Defaults to 0.
|
51
|
-
#
|
52
|
-
# TODO: Use brand new local_variable_{get,set,defined?} for rubies >= 2.1
|
53
|
-
#
|
54
|
-
def frame_locals(frame_no = 0)
|
55
|
-
bind = frame_binding(frame_no)
|
56
|
-
return [] unless bind
|
57
|
-
|
58
|
-
bind.eval('local_variables.inject({}){|h, v| h[v] = eval(v.to_s); h}')
|
91
|
+
def at_breakpoint(breakpoint)
|
92
|
+
new_processor.at_breakpoint(breakpoint)
|
59
93
|
end
|
60
94
|
|
61
|
-
|
62
|
-
|
63
|
-
#
|
64
|
-
# @param frame_no Frame index in the backtrace. Defaults to 0.
|
65
|
-
#
|
66
|
-
def frame_args(frame_no = 0)
|
67
|
-
bind = frame_binding(frame_no)
|
68
|
-
return c_frame_args(frame_no) unless bind
|
69
|
-
|
70
|
-
ruby_frame_args(bind)
|
95
|
+
def at_catchpoint(exception)
|
96
|
+
new_processor.at_catchpoint(exception)
|
71
97
|
end
|
72
98
|
|
73
|
-
def
|
74
|
-
|
75
|
-
end
|
99
|
+
def at_tracing(file, _line)
|
100
|
+
return if ignored_file?(file)
|
76
101
|
|
77
|
-
|
78
|
-
handler.at_breakpoint(self, brkpnt)
|
102
|
+
new_processor.at_tracing
|
79
103
|
end
|
80
104
|
|
81
|
-
def
|
82
|
-
|
83
|
-
|
105
|
+
def at_line(file, _l)
|
106
|
+
self.frame = 0
|
107
|
+
return if ignored_file?(file)
|
84
108
|
|
85
|
-
|
86
|
-
handler.at_tracing(self, file, line) unless ignored_file?(file)
|
109
|
+
new_processor.at_line
|
87
110
|
end
|
88
111
|
|
89
|
-
def
|
90
|
-
|
91
|
-
end
|
112
|
+
def at_return(file, _line)
|
113
|
+
return if ignored_file?(file)
|
92
114
|
|
93
|
-
|
94
|
-
handler.at_return(self, file, line) unless ignored_file?(file)
|
115
|
+
new_processor.at_return
|
95
116
|
end
|
96
117
|
|
97
118
|
private
|
98
119
|
|
99
|
-
|
100
|
-
|
101
|
-
#
|
102
|
-
# @param frame_no Frame index in the backtrace.
|
103
|
-
#
|
104
|
-
def c_frame_args(frame_no)
|
105
|
-
myself = frame_self(frame_no)
|
106
|
-
return [] unless myself.to_s != 'main'
|
107
|
-
|
108
|
-
myself.method(frame_method(frame_no)).parameters
|
109
|
-
end
|
110
|
-
|
111
|
-
#
|
112
|
-
# Gets method arguments for a ruby-frame.
|
113
|
-
#
|
114
|
-
# @param bind Binding for the ruby-frame.
|
115
|
-
#
|
116
|
-
def ruby_frame_args(bind)
|
117
|
-
return [] unless bind.eval('__method__')
|
118
|
-
|
119
|
-
bind.eval('method(__method__).parameters')
|
120
|
-
rescue NameError => e
|
121
|
-
Byebug.errmsg \
|
122
|
-
"Exception #{e.class} (#{e.message}) while retreving frame params"
|
123
|
-
[]
|
120
|
+
def new_processor
|
121
|
+
@processor ||= self.class.processor.new(self)
|
124
122
|
end
|
125
123
|
end
|
126
124
|
end
|
data/lib/byebug/core.rb
CHANGED
@@ -1,34 +1,33 @@
|
|
1
|
+
require 'byebug/helpers/reflection'
|
1
2
|
require 'byebug/byebug'
|
2
|
-
require 'byebug/version'
|
3
3
|
require 'byebug/context'
|
4
4
|
require 'byebug/breakpoint'
|
5
5
|
require 'byebug/interface'
|
6
|
-
require 'byebug/
|
6
|
+
require 'byebug/processors/script_processor'
|
7
|
+
require 'byebug/processors/post_mortem_processor'
|
8
|
+
require 'byebug/commands'
|
7
9
|
require 'byebug/remote'
|
8
10
|
require 'byebug/printers/plain'
|
9
11
|
|
12
|
+
#
|
13
|
+
# Main debugger's container module. Everything is defined under this module
|
14
|
+
#
|
10
15
|
module Byebug
|
16
|
+
include Helpers::ReflectionHelper
|
17
|
+
|
11
18
|
extend self
|
12
19
|
|
13
20
|
#
|
14
21
|
# Configuration file used for startup commands. Default value is .byebugrc
|
15
22
|
#
|
16
|
-
|
17
|
-
|
18
|
-
#
|
19
|
-
# Main debugger's processor
|
20
|
-
#
|
21
|
-
attr_accessor :handler
|
22
|
-
self.handler = CommandProcessor.new
|
23
|
-
|
24
|
-
extend Forwardable
|
25
|
-
def_delegators :handler, :errmsg, :puts
|
23
|
+
attr_accessor :init_file
|
24
|
+
self.init_file = '.byebugrc'
|
26
25
|
|
27
26
|
#
|
28
|
-
#
|
27
|
+
# Debugger's display expressions
|
29
28
|
#
|
30
|
-
attr_accessor :
|
31
|
-
self.
|
29
|
+
attr_accessor :displays
|
30
|
+
self.displays = []
|
32
31
|
|
33
32
|
#
|
34
33
|
# Running mode of the debugger. Can be either:
|
@@ -48,39 +47,59 @@ module Byebug
|
|
48
47
|
# are debugging, in the directory where you invoke byebug.
|
49
48
|
#
|
50
49
|
def run_init_script
|
51
|
-
home_rc = File.expand_path(File.join(ENV['HOME'].to_s,
|
50
|
+
home_rc = File.expand_path(File.join(ENV['HOME'].to_s, init_file))
|
52
51
|
run_script(home_rc) if File.exist?(home_rc)
|
53
52
|
|
54
|
-
cwd_rc = File.expand_path(File.join('.',
|
53
|
+
cwd_rc = File.expand_path(File.join('.', init_file))
|
55
54
|
run_script(cwd_rc) if File.exist?(cwd_rc) && cwd_rc != home_rc
|
56
55
|
end
|
57
56
|
|
57
|
+
def self.load_settings
|
58
|
+
Dir.glob(File.expand_path('../settings/*.rb', __FILE__)).each do |file|
|
59
|
+
require file
|
60
|
+
end
|
61
|
+
|
62
|
+
constants.grep(/[a-z]Setting/).map do |name|
|
63
|
+
setting = const_get(name).new
|
64
|
+
Byebug::Setting.settings[setting.to_sym] = setting
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
58
68
|
#
|
59
|
-
#
|
60
|
-
#
|
69
|
+
# Saves information about the unhandled exception and gives a byebug
|
70
|
+
# prompt back to the user before program termination.
|
61
71
|
#
|
62
|
-
def
|
63
|
-
|
72
|
+
def self.handle_post_mortem
|
73
|
+
return unless raised_exception
|
74
|
+
|
75
|
+
context = raised_exception.__bb_context
|
64
76
|
|
65
|
-
|
77
|
+
PostMortemProcessor.new(context).at_line
|
66
78
|
end
|
67
79
|
|
80
|
+
at_exit { Byebug.handle_post_mortem if Byebug.post_mortem? }
|
81
|
+
|
68
82
|
private
|
69
83
|
|
70
84
|
#
|
71
85
|
# Runs a script file
|
72
86
|
#
|
73
87
|
def run_script(file, verbose = false)
|
74
|
-
|
75
|
-
|
76
|
-
|
88
|
+
old_interface = Context.interface
|
89
|
+
Context.interface = ScriptInterface.new(file, verbose)
|
90
|
+
|
91
|
+
ScriptProcessor.new(nil).process_commands
|
92
|
+
ensure
|
93
|
+
Context.interface = old_interface
|
77
94
|
end
|
78
95
|
end
|
79
96
|
|
97
|
+
Byebug.load_settings
|
98
|
+
|
80
99
|
#
|
81
100
|
# Extends the extension class to be able to pass information about the
|
82
101
|
# debugging environment from the c-extension to the user.
|
83
102
|
#
|
84
103
|
class Exception
|
85
|
-
attr_reader :
|
104
|
+
attr_reader :__bb_context
|
86
105
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Byebug
|
2
|
+
#
|
3
|
+
# Custom exception exception to signal "command not found" errors
|
4
|
+
#
|
5
|
+
class CommandNotFound < NoMethodError
|
6
|
+
def initialize(input, parent = nil)
|
7
|
+
@input = input
|
8
|
+
@parent = parent
|
9
|
+
|
10
|
+
super("Unknown command '#{name}'. Try '#{help}'")
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def name
|
16
|
+
build_cmd(@parent, @input)
|
17
|
+
end
|
18
|
+
|
19
|
+
def help
|
20
|
+
build_cmd('help', @parent)
|
21
|
+
end
|
22
|
+
|
23
|
+
def build_cmd(*args)
|
24
|
+
args.compact.join(' ')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/byebug/frame.rb
ADDED
@@ -0,0 +1,181 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'byebug/helpers/file'
|
4
|
+
|
5
|
+
module Byebug
|
6
|
+
#
|
7
|
+
# Represents a frame in the stack trace
|
8
|
+
#
|
9
|
+
class Frame
|
10
|
+
include Helpers::FileHelper
|
11
|
+
|
12
|
+
attr_reader :pos
|
13
|
+
|
14
|
+
def initialize(context, pos)
|
15
|
+
@context = context
|
16
|
+
@pos = pos
|
17
|
+
end
|
18
|
+
|
19
|
+
def file
|
20
|
+
@context.frame_file(pos)
|
21
|
+
end
|
22
|
+
|
23
|
+
def line
|
24
|
+
@context.frame_line(pos)
|
25
|
+
end
|
26
|
+
|
27
|
+
def _self
|
28
|
+
@context.frame_self(pos)
|
29
|
+
end
|
30
|
+
|
31
|
+
def _binding
|
32
|
+
@context.frame_binding(pos)
|
33
|
+
end
|
34
|
+
|
35
|
+
def _class
|
36
|
+
@context.frame_class(pos)
|
37
|
+
end
|
38
|
+
|
39
|
+
def _method
|
40
|
+
@context.frame_method(pos)
|
41
|
+
end
|
42
|
+
|
43
|
+
def current?
|
44
|
+
@context.frame.pos == pos
|
45
|
+
end
|
46
|
+
|
47
|
+
#
|
48
|
+
# Gets local variables for the frame.
|
49
|
+
#
|
50
|
+
# TODO: Use brand new local_variable_{get,set,defined?} for rubies >= 2.1
|
51
|
+
#
|
52
|
+
def locals
|
53
|
+
return [] unless _binding
|
54
|
+
|
55
|
+
_binding.eval('local_variables.inject({}){|h, v| h[v] = eval(v.to_s); h}')
|
56
|
+
end
|
57
|
+
|
58
|
+
#
|
59
|
+
# Gets current method arguments for the frame.
|
60
|
+
#
|
61
|
+
def args
|
62
|
+
return c_args unless _binding
|
63
|
+
|
64
|
+
ruby_args
|
65
|
+
end
|
66
|
+
|
67
|
+
#
|
68
|
+
# Returns the current class in the frame or an empty string if the current
|
69
|
+
# +callstyle+ setting is 'short'
|
70
|
+
#
|
71
|
+
def deco_class
|
72
|
+
Setting[:callstyle] == 'short' || _class.to_s.empty? ? '' : "#{_class}."
|
73
|
+
end
|
74
|
+
|
75
|
+
def deco_block
|
76
|
+
_method[/(?:block(?: \(\d+ levels\))?|rescue) in /] || ''
|
77
|
+
end
|
78
|
+
|
79
|
+
def deco_method
|
80
|
+
_method[/((?:block(?: \(\d+ levels\))?|rescue) in )?(.*)/]
|
81
|
+
end
|
82
|
+
|
83
|
+
#
|
84
|
+
# Builds a string containing all available args in the frame number, in a
|
85
|
+
# verbose or non verbose way according to the value of the +callstyle+
|
86
|
+
# setting
|
87
|
+
#
|
88
|
+
def deco_args
|
89
|
+
return '' if args.empty?
|
90
|
+
|
91
|
+
my_args = args.map do |arg|
|
92
|
+
prefix, default = prefix_and_default(arg[0])
|
93
|
+
|
94
|
+
kls = use_short_style?(arg) ? '' : "##{locals[arg[1]].class}"
|
95
|
+
|
96
|
+
"#{prefix}#{arg[1] || default}#{kls}"
|
97
|
+
end
|
98
|
+
|
99
|
+
"(#{my_args.join(', ')})"
|
100
|
+
end
|
101
|
+
|
102
|
+
#
|
103
|
+
# Builds a formatted string containing information about current method call
|
104
|
+
#
|
105
|
+
def deco_call
|
106
|
+
deco_block + deco_class + deco_method + deco_args
|
107
|
+
end
|
108
|
+
|
109
|
+
#
|
110
|
+
# Formatted filename in frame
|
111
|
+
#
|
112
|
+
def deco_file
|
113
|
+
Setting[:fullpath] ? File.expand_path(file) : shortpath(file)
|
114
|
+
end
|
115
|
+
|
116
|
+
#
|
117
|
+
# Properly formatted frame number of frame
|
118
|
+
#
|
119
|
+
def deco_pos
|
120
|
+
format('%-2d', pos)
|
121
|
+
end
|
122
|
+
|
123
|
+
#
|
124
|
+
# Formatted mark for the frame.
|
125
|
+
#
|
126
|
+
# --> marks the current frame
|
127
|
+
# ͱ-- marks c-frames
|
128
|
+
# marks regular frames
|
129
|
+
#
|
130
|
+
def mark
|
131
|
+
return '-->' if current?
|
132
|
+
return ' ͱ--' if c_frame?
|
133
|
+
|
134
|
+
' '
|
135
|
+
end
|
136
|
+
|
137
|
+
#
|
138
|
+
# Checks whether the frame is a c-frame
|
139
|
+
#
|
140
|
+
def c_frame?
|
141
|
+
_binding.nil?
|
142
|
+
end
|
143
|
+
|
144
|
+
def to_hash
|
145
|
+
{
|
146
|
+
mark: mark,
|
147
|
+
pos: deco_pos,
|
148
|
+
call: deco_call,
|
149
|
+
file: deco_file,
|
150
|
+
line: line,
|
151
|
+
full_path: File.expand_path(deco_file)
|
152
|
+
}
|
153
|
+
end
|
154
|
+
|
155
|
+
private
|
156
|
+
|
157
|
+
def c_args
|
158
|
+
return [] unless _self.to_s != 'main'
|
159
|
+
|
160
|
+
_self.method(_method).parameters
|
161
|
+
end
|
162
|
+
|
163
|
+
def ruby_args
|
164
|
+
return [] unless _binding.eval('__method__')
|
165
|
+
return [] unless _binding.eval('method(__method__)')
|
166
|
+
|
167
|
+
_binding.eval('method(__method__).parameters')
|
168
|
+
end
|
169
|
+
|
170
|
+
def use_short_style?(arg)
|
171
|
+
Setting[:callstyle] == 'short' || arg[1].nil? || locals.empty?
|
172
|
+
end
|
173
|
+
|
174
|
+
def prefix_and_default(arg_type)
|
175
|
+
return ['&', 'block'] if arg_type == :block
|
176
|
+
return ['*', 'args'] if arg_type == :rest
|
177
|
+
|
178
|
+
['', nil]
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|