runger_byebug 11.2.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.
- checksums.yaml +7 -0
- data/CHANGELOG.md +954 -0
- data/CONTRIBUTING.md +58 -0
- data/GUIDE.md +1806 -0
- data/LICENSE +23 -0
- data/README.md +199 -0
- data/exe/byebug +6 -0
- data/ext/byebug/breakpoint.c +521 -0
- data/ext/byebug/byebug.c +900 -0
- data/ext/byebug/byebug.h +145 -0
- data/ext/byebug/context.c +687 -0
- data/ext/byebug/extconf.rb +12 -0
- data/ext/byebug/locker.c +96 -0
- data/ext/byebug/threads.c +241 -0
- data/lib/byebug/attacher.rb +48 -0
- data/lib/byebug/breakpoint.rb +94 -0
- data/lib/byebug/command.rb +111 -0
- data/lib/byebug/command_list.rb +34 -0
- data/lib/byebug/commands/break.rb +114 -0
- data/lib/byebug/commands/catch.rb +78 -0
- data/lib/byebug/commands/condition.rb +55 -0
- data/lib/byebug/commands/continue.rb +68 -0
- data/lib/byebug/commands/debug.rb +38 -0
- data/lib/byebug/commands/delete.rb +55 -0
- data/lib/byebug/commands/disable/breakpoints.rb +42 -0
- data/lib/byebug/commands/disable/display.rb +43 -0
- data/lib/byebug/commands/disable.rb +33 -0
- data/lib/byebug/commands/display.rb +66 -0
- data/lib/byebug/commands/down.rb +45 -0
- data/lib/byebug/commands/edit.rb +69 -0
- data/lib/byebug/commands/enable/breakpoints.rb +42 -0
- data/lib/byebug/commands/enable/display.rb +43 -0
- data/lib/byebug/commands/enable.rb +33 -0
- data/lib/byebug/commands/finish.rb +57 -0
- data/lib/byebug/commands/frame.rb +57 -0
- data/lib/byebug/commands/help.rb +64 -0
- data/lib/byebug/commands/history.rb +39 -0
- data/lib/byebug/commands/info/breakpoints.rb +65 -0
- data/lib/byebug/commands/info/display.rb +49 -0
- data/lib/byebug/commands/info/file.rb +80 -0
- data/lib/byebug/commands/info/line.rb +35 -0
- data/lib/byebug/commands/info/program.rb +49 -0
- data/lib/byebug/commands/info.rb +37 -0
- data/lib/byebug/commands/interrupt.rb +34 -0
- data/lib/byebug/commands/irb.rb +50 -0
- data/lib/byebug/commands/kill.rb +45 -0
- data/lib/byebug/commands/list.rb +159 -0
- data/lib/byebug/commands/method.rb +53 -0
- data/lib/byebug/commands/next.rb +40 -0
- data/lib/byebug/commands/pry.rb +41 -0
- data/lib/byebug/commands/quit.rb +42 -0
- data/lib/byebug/commands/restart.rb +64 -0
- data/lib/byebug/commands/save.rb +72 -0
- data/lib/byebug/commands/set.rb +79 -0
- data/lib/byebug/commands/show.rb +45 -0
- data/lib/byebug/commands/skip.rb +85 -0
- data/lib/byebug/commands/source.rb +40 -0
- data/lib/byebug/commands/step.rb +40 -0
- data/lib/byebug/commands/thread/current.rb +37 -0
- data/lib/byebug/commands/thread/list.rb +43 -0
- data/lib/byebug/commands/thread/resume.rb +45 -0
- data/lib/byebug/commands/thread/stop.rb +43 -0
- data/lib/byebug/commands/thread/switch.rb +46 -0
- data/lib/byebug/commands/thread.rb +34 -0
- data/lib/byebug/commands/tracevar.rb +54 -0
- data/lib/byebug/commands/undisplay.rb +51 -0
- data/lib/byebug/commands/untracevar.rb +36 -0
- data/lib/byebug/commands/up.rb +45 -0
- data/lib/byebug/commands/var/all.rb +41 -0
- data/lib/byebug/commands/var/args.rb +39 -0
- data/lib/byebug/commands/var/const.rb +49 -0
- data/lib/byebug/commands/var/global.rb +37 -0
- data/lib/byebug/commands/var/instance.rb +39 -0
- data/lib/byebug/commands/var/local.rb +39 -0
- data/lib/byebug/commands/var.rb +37 -0
- data/lib/byebug/commands/where.rb +64 -0
- data/lib/byebug/commands.rb +40 -0
- data/lib/byebug/context.rb +157 -0
- data/lib/byebug/core.rb +115 -0
- data/lib/byebug/errors.rb +29 -0
- data/lib/byebug/frame.rb +185 -0
- data/lib/byebug/helpers/bin.rb +47 -0
- data/lib/byebug/helpers/eval.rb +134 -0
- data/lib/byebug/helpers/file.rb +63 -0
- data/lib/byebug/helpers/frame.rb +75 -0
- data/lib/byebug/helpers/parse.rb +80 -0
- data/lib/byebug/helpers/path.rb +40 -0
- data/lib/byebug/helpers/reflection.rb +19 -0
- data/lib/byebug/helpers/string.rb +33 -0
- data/lib/byebug/helpers/thread.rb +67 -0
- data/lib/byebug/helpers/toggle.rb +62 -0
- data/lib/byebug/helpers/var.rb +70 -0
- data/lib/byebug/history.rb +130 -0
- data/lib/byebug/interface.rb +146 -0
- data/lib/byebug/interfaces/local_interface.rb +63 -0
- data/lib/byebug/interfaces/remote_interface.rb +50 -0
- data/lib/byebug/interfaces/script_interface.rb +33 -0
- data/lib/byebug/interfaces/test_interface.rb +67 -0
- data/lib/byebug/option_setter.rb +95 -0
- data/lib/byebug/printers/base.rb +68 -0
- data/lib/byebug/printers/plain.rb +44 -0
- data/lib/byebug/printers/texts/base.yml +115 -0
- data/lib/byebug/printers/texts/plain.yml +33 -0
- data/lib/byebug/processors/command_processor.rb +173 -0
- data/lib/byebug/processors/control_processor.rb +24 -0
- data/lib/byebug/processors/post_mortem_processor.rb +18 -0
- data/lib/byebug/processors/script_processor.rb +49 -0
- data/lib/byebug/remote/client.rb +57 -0
- data/lib/byebug/remote/server.rb +47 -0
- data/lib/byebug/remote.rb +85 -0
- data/lib/byebug/runner.rb +198 -0
- data/lib/byebug/setting.rb +79 -0
- data/lib/byebug/settings/autoirb.rb +29 -0
- data/lib/byebug/settings/autolist.rb +29 -0
- data/lib/byebug/settings/autopry.rb +29 -0
- data/lib/byebug/settings/autosave.rb +17 -0
- data/lib/byebug/settings/basename.rb +16 -0
- data/lib/byebug/settings/callstyle.rb +20 -0
- data/lib/byebug/settings/fullpath.rb +16 -0
- data/lib/byebug/settings/histfile.rb +20 -0
- data/lib/byebug/settings/histsize.rb +20 -0
- data/lib/byebug/settings/linetrace.rb +22 -0
- data/lib/byebug/settings/listsize.rb +21 -0
- data/lib/byebug/settings/post_mortem.rb +27 -0
- data/lib/byebug/settings/savefile.rb +20 -0
- data/lib/byebug/settings/stack_on_error.rb +15 -0
- data/lib/byebug/settings/width.rb +20 -0
- data/lib/byebug/source_file_formatter.rb +71 -0
- data/lib/byebug/subcommands.rb +54 -0
- data/lib/byebug/version.rb +8 -0
- data/lib/byebug.rb +3 -0
- metadata +194 -0
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "pathname"
|
4
|
+
require_relative "../command"
|
5
|
+
require_relative "../helpers/frame"
|
6
|
+
require_relative "../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
|
+
self.allow_in_post_mortem = true
|
17
|
+
|
18
|
+
def self.regexp
|
19
|
+
/^\s* up (?:\s+(\S+))? \s*$/x
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.description
|
23
|
+
<<-DESCRIPTION
|
24
|
+
up[ count]
|
25
|
+
|
26
|
+
#{short_description}
|
27
|
+
|
28
|
+
Use the "bt" command to find out where you want to go.
|
29
|
+
DESCRIPTION
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.short_description
|
33
|
+
"Moves to a higher frame in the stack trace"
|
34
|
+
end
|
35
|
+
|
36
|
+
def execute
|
37
|
+
pos, err = parse_steps(@match[1], "Up")
|
38
|
+
return errmsg(err) unless pos
|
39
|
+
|
40
|
+
jump_frames(pos)
|
41
|
+
|
42
|
+
ListCommand.new(processor).execute if Setting[:autolist]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../../helpers/var"
|
4
|
+
|
5
|
+
module Byebug
|
6
|
+
#
|
7
|
+
# Reopens the +var+ command to define the +all+ subcommand
|
8
|
+
#
|
9
|
+
class VarCommand < Command
|
10
|
+
#
|
11
|
+
# Shows global, instance and local variables
|
12
|
+
#
|
13
|
+
class AllCommand < Command
|
14
|
+
include Helpers::VarHelper
|
15
|
+
|
16
|
+
self.allow_in_post_mortem = true
|
17
|
+
|
18
|
+
def self.regexp
|
19
|
+
/^\s* a(?:ll)? \s*$/x
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.description
|
23
|
+
<<-DESCRIPTION
|
24
|
+
v[ar] a[ll]
|
25
|
+
|
26
|
+
#{short_description}
|
27
|
+
DESCRIPTION
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.short_description
|
31
|
+
"Shows local, global and instance variables of self."
|
32
|
+
end
|
33
|
+
|
34
|
+
def execute
|
35
|
+
var_global
|
36
|
+
var_instance("self")
|
37
|
+
var_local
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../../helpers/var"
|
4
|
+
|
5
|
+
module Byebug
|
6
|
+
#
|
7
|
+
# Reopens the +var+ command to define the +args+ subcommand
|
8
|
+
#
|
9
|
+
class VarCommand < Command
|
10
|
+
#
|
11
|
+
# Information about arguments of the current method/block
|
12
|
+
#
|
13
|
+
class ArgsCommand < Command
|
14
|
+
include Helpers::VarHelper
|
15
|
+
|
16
|
+
self.allow_in_post_mortem = true
|
17
|
+
|
18
|
+
def self.regexp
|
19
|
+
/^\s* a(?:rgs)? \s*$/x
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.description
|
23
|
+
<<-DESCRIPTION
|
24
|
+
v[ar] a[args]
|
25
|
+
|
26
|
+
#{short_description}
|
27
|
+
DESCRIPTION
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.short_description
|
31
|
+
"Information about arguments of the current scope."
|
32
|
+
end
|
33
|
+
|
34
|
+
def execute
|
35
|
+
var_args
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../../helpers/eval"
|
4
|
+
|
5
|
+
module Byebug
|
6
|
+
#
|
7
|
+
# Reopens the +var+ command to define the +const+ subcommand
|
8
|
+
#
|
9
|
+
class VarCommand < Command
|
10
|
+
#
|
11
|
+
# Shows constants
|
12
|
+
#
|
13
|
+
class ConstCommand < Command
|
14
|
+
include Helpers::EvalHelper
|
15
|
+
|
16
|
+
self.allow_in_post_mortem = true
|
17
|
+
|
18
|
+
def self.regexp
|
19
|
+
/^\s* c(?:onst)? (?:\s+ (.+))? \s*$/x
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.description
|
23
|
+
<<-DESCRIPTION
|
24
|
+
v[ar] c[onstant]
|
25
|
+
|
26
|
+
#{short_description}
|
27
|
+
DESCRIPTION
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.short_description
|
31
|
+
"Shows constants of an object."
|
32
|
+
end
|
33
|
+
|
34
|
+
def execute
|
35
|
+
obj = warning_eval(str_obj)
|
36
|
+
return errmsg(pr("variable.errors.not_module", object: str_obj)) unless obj.is_a?(Module)
|
37
|
+
|
38
|
+
constants = warning_eval("#{str_obj}.constants")
|
39
|
+
puts prv(constants.sort.map { |c| [c, obj.const_get(c)] }, "constant")
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def str_obj
|
45
|
+
@str_obj ||= @match[1] || "self.class"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Byebug
|
4
|
+
#
|
5
|
+
# Reopens the +var+ command to define the +global+ subcommand
|
6
|
+
#
|
7
|
+
class VarCommand < Command
|
8
|
+
#
|
9
|
+
# Shows global variables
|
10
|
+
#
|
11
|
+
class GlobalCommand < Command
|
12
|
+
include Helpers::VarHelper
|
13
|
+
|
14
|
+
self.allow_in_post_mortem = true
|
15
|
+
|
16
|
+
def self.regexp
|
17
|
+
/^\s* g(?:lobal)? \s*$/x
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.description
|
21
|
+
<<-DESCRIPTION
|
22
|
+
v[ar] g[lobal]
|
23
|
+
|
24
|
+
#{short_description}
|
25
|
+
DESCRIPTION
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.short_description
|
29
|
+
"Shows global variables."
|
30
|
+
end
|
31
|
+
|
32
|
+
def execute
|
33
|
+
var_global
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../../helpers/var"
|
4
|
+
|
5
|
+
module Byebug
|
6
|
+
#
|
7
|
+
# Reopens the +var+ command to define the +instance+ subcommand
|
8
|
+
#
|
9
|
+
class VarCommand < Command
|
10
|
+
#
|
11
|
+
# Shows instance variables
|
12
|
+
#
|
13
|
+
class InstanceCommand < Command
|
14
|
+
include Helpers::VarHelper
|
15
|
+
|
16
|
+
self.allow_in_post_mortem = true
|
17
|
+
|
18
|
+
def self.regexp
|
19
|
+
/^\s* i(?:nstance)? (?:\s+ (.+))? \s*$/x
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.description
|
23
|
+
<<-DESCRIPTION
|
24
|
+
v[ar] i[nstance][ <object>]
|
25
|
+
|
26
|
+
#{short_description}
|
27
|
+
DESCRIPTION
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.short_description
|
31
|
+
"Shows instance variables of self or a specific object."
|
32
|
+
end
|
33
|
+
|
34
|
+
def execute
|
35
|
+
var_instance(@match[1])
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../../helpers/var"
|
4
|
+
|
5
|
+
module Byebug
|
6
|
+
#
|
7
|
+
# Reopens the +var+ command to define the +local+ subcommand
|
8
|
+
#
|
9
|
+
class VarCommand < Command
|
10
|
+
#
|
11
|
+
# Shows local variables in current scope
|
12
|
+
#
|
13
|
+
class LocalCommand < Command
|
14
|
+
include Helpers::VarHelper
|
15
|
+
|
16
|
+
self.allow_in_post_mortem = true
|
17
|
+
|
18
|
+
def self.regexp
|
19
|
+
/^\s* l(?:ocal)? \s*$/x
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.description
|
23
|
+
<<-DESCRIPTION
|
24
|
+
v[ar] l[ocal]
|
25
|
+
|
26
|
+
#{short_description}
|
27
|
+
DESCRIPTION
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.short_description
|
31
|
+
"Shows local variables in current scope."
|
32
|
+
end
|
33
|
+
|
34
|
+
def execute
|
35
|
+
var_local
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../subcommands"
|
4
|
+
|
5
|
+
require_relative "var/all"
|
6
|
+
require_relative "var/args"
|
7
|
+
require_relative "var/const"
|
8
|
+
require_relative "var/instance"
|
9
|
+
require_relative "var/local"
|
10
|
+
require_relative "var/global"
|
11
|
+
|
12
|
+
module Byebug
|
13
|
+
#
|
14
|
+
# Shows variables and its values
|
15
|
+
#
|
16
|
+
class VarCommand < Command
|
17
|
+
include Subcommands
|
18
|
+
|
19
|
+
self.allow_in_post_mortem = true
|
20
|
+
|
21
|
+
def self.regexp
|
22
|
+
/^\s* v(?:ar)? (?:\s+ (.+))? \s*$/x
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.description
|
26
|
+
<<-DESCRIPTION
|
27
|
+
[v]ar <subcommand>
|
28
|
+
|
29
|
+
#{short_description}
|
30
|
+
DESCRIPTION
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.short_description
|
34
|
+
"Shows variables and its values"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "pathname"
|
4
|
+
require_relative "../command"
|
5
|
+
require_relative "../helpers/frame"
|
6
|
+
|
7
|
+
module Byebug
|
8
|
+
#
|
9
|
+
# Show current backtrace.
|
10
|
+
#
|
11
|
+
class WhereCommand < Command
|
12
|
+
include Helpers::FrameHelper
|
13
|
+
|
14
|
+
self.allow_in_post_mortem = true
|
15
|
+
|
16
|
+
def self.regexp
|
17
|
+
/^\s* (?:w(?:here)?|bt|backtrace) (?:\s+(\S+))? \s*$/x
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.description
|
21
|
+
<<-DESCRIPTION
|
22
|
+
w[here]|bt|backtrace[ maximum-frame]
|
23
|
+
|
24
|
+
#{short_description}
|
25
|
+
|
26
|
+
Print the entire stack frame. Each frame is numbered; the most recent
|
27
|
+
frame is 0. A frame number can be referred to in the "frame" command.
|
28
|
+
"up" and "down" add or subtract respectively to frame numbers shown.
|
29
|
+
The position of the current frame is marked with -->. C-frames hang
|
30
|
+
from their most immediate Ruby frame to indicate that they are not
|
31
|
+
navigable.
|
32
|
+
|
33
|
+
Without an argument, the command prints all the frames. With an argument,
|
34
|
+
the command prints the nth first frames, where n is the largest between
|
35
|
+
the argument or the maximum stack frame.
|
36
|
+
DESCRIPTION
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.short_description
|
40
|
+
"Displays the backtrace"
|
41
|
+
end
|
42
|
+
|
43
|
+
def execute
|
44
|
+
print_backtrace
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def print_backtrace
|
50
|
+
max_frame =
|
51
|
+
if @match[1] && @match[1].to_i <= context.stack_size
|
52
|
+
@match[1].to_i
|
53
|
+
else
|
54
|
+
context.stack_size
|
55
|
+
end
|
56
|
+
|
57
|
+
bt = prc("frame.line", (0...max_frame)) do |_, index|
|
58
|
+
Frame.new(context, index).to_hash
|
59
|
+
end
|
60
|
+
|
61
|
+
print(bt)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "commands/break"
|
4
|
+
require_relative "commands/catch"
|
5
|
+
require_relative "commands/condition"
|
6
|
+
require_relative "commands/continue"
|
7
|
+
require_relative "commands/debug"
|
8
|
+
require_relative "commands/delete"
|
9
|
+
require_relative "commands/disable"
|
10
|
+
require_relative "commands/display"
|
11
|
+
require_relative "commands/down"
|
12
|
+
require_relative "commands/edit"
|
13
|
+
require_relative "commands/enable"
|
14
|
+
require_relative "commands/finish"
|
15
|
+
require_relative "commands/frame"
|
16
|
+
require_relative "commands/help"
|
17
|
+
require_relative "commands/history"
|
18
|
+
require_relative "commands/info"
|
19
|
+
require_relative "commands/interrupt"
|
20
|
+
require_relative "commands/irb"
|
21
|
+
require_relative "commands/kill"
|
22
|
+
require_relative "commands/list"
|
23
|
+
require_relative "commands/method"
|
24
|
+
require_relative "commands/next"
|
25
|
+
require_relative "commands/pry"
|
26
|
+
require_relative "commands/quit"
|
27
|
+
require_relative "commands/restart"
|
28
|
+
require_relative "commands/save"
|
29
|
+
require_relative "commands/set"
|
30
|
+
require_relative "commands/show"
|
31
|
+
require_relative "commands/skip"
|
32
|
+
require_relative "commands/source"
|
33
|
+
require_relative "commands/step"
|
34
|
+
require_relative "commands/thread"
|
35
|
+
require_relative "commands/tracevar"
|
36
|
+
require_relative "commands/undisplay"
|
37
|
+
require_relative "commands/untracevar"
|
38
|
+
require_relative "commands/up"
|
39
|
+
require_relative "commands/var"
|
40
|
+
require_relative "commands/where"
|
@@ -0,0 +1,157 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "frame"
|
4
|
+
require_relative "helpers/path"
|
5
|
+
require_relative "helpers/file"
|
6
|
+
require_relative "processors/command_processor"
|
7
|
+
|
8
|
+
module Byebug
|
9
|
+
#
|
10
|
+
# Mantains context information for the debugger and it's the main
|
11
|
+
# communication point between the library and the C-extension through the
|
12
|
+
# at_breakpoint, at_catchpoint, at_tracing, at_line and at_return callbacks
|
13
|
+
#
|
14
|
+
class Context
|
15
|
+
include Helpers::FileHelper
|
16
|
+
|
17
|
+
class << self
|
18
|
+
include Helpers::PathHelper
|
19
|
+
|
20
|
+
attr_writer :ignored_files
|
21
|
+
|
22
|
+
#
|
23
|
+
# List of files byebug will ignore while debugging
|
24
|
+
#
|
25
|
+
def ignored_files
|
26
|
+
@ignored_files ||=
|
27
|
+
Byebug.mode == :standalone ? lib_files + [bin_file] : lib_files
|
28
|
+
end
|
29
|
+
|
30
|
+
attr_writer :interface
|
31
|
+
|
32
|
+
def interface
|
33
|
+
@interface ||= LocalInterface.new
|
34
|
+
end
|
35
|
+
|
36
|
+
attr_writer :processor
|
37
|
+
|
38
|
+
def processor
|
39
|
+
@processor ||= CommandProcessor
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
#
|
44
|
+
# Reader for the current frame
|
45
|
+
#
|
46
|
+
def frame
|
47
|
+
@frame ||= Frame.new(self, 0)
|
48
|
+
end
|
49
|
+
|
50
|
+
#
|
51
|
+
# Writer for the current frame
|
52
|
+
#
|
53
|
+
def frame=(pos)
|
54
|
+
@frame = Frame.new(self, pos)
|
55
|
+
end
|
56
|
+
|
57
|
+
extend Forwardable
|
58
|
+
def_delegators :frame, :file, :line
|
59
|
+
|
60
|
+
#
|
61
|
+
# Current file & line information
|
62
|
+
#
|
63
|
+
def location
|
64
|
+
"#{normalize(file)}:#{line}"
|
65
|
+
end
|
66
|
+
|
67
|
+
#
|
68
|
+
# Current file, line and source code information
|
69
|
+
#
|
70
|
+
def full_location
|
71
|
+
return location if virtual_file?(file)
|
72
|
+
|
73
|
+
"#{location} #{get_line(file, line)}"
|
74
|
+
end
|
75
|
+
|
76
|
+
#
|
77
|
+
# Context's stack size
|
78
|
+
#
|
79
|
+
def stack_size
|
80
|
+
return 0 unless backtrace
|
81
|
+
|
82
|
+
backtrace.drop_while { |l| ignored_file?(l.first.path) }
|
83
|
+
.take_while { |l| !ignored_file?(l.first.path) }
|
84
|
+
.size
|
85
|
+
end
|
86
|
+
|
87
|
+
def interrupt
|
88
|
+
step_into 1
|
89
|
+
end
|
90
|
+
|
91
|
+
#
|
92
|
+
# Line handler
|
93
|
+
#
|
94
|
+
def at_line
|
95
|
+
self.frame = 0
|
96
|
+
return if ignored_file?(file)
|
97
|
+
|
98
|
+
processor.at_line
|
99
|
+
end
|
100
|
+
|
101
|
+
#
|
102
|
+
# Tracing handler
|
103
|
+
#
|
104
|
+
def at_tracing
|
105
|
+
return if ignored_file?(file)
|
106
|
+
|
107
|
+
processor.at_tracing
|
108
|
+
end
|
109
|
+
|
110
|
+
#
|
111
|
+
# Breakpoint handler
|
112
|
+
#
|
113
|
+
def at_breakpoint(breakpoint)
|
114
|
+
processor.at_breakpoint(breakpoint)
|
115
|
+
end
|
116
|
+
|
117
|
+
#
|
118
|
+
# Catchpoint handler
|
119
|
+
#
|
120
|
+
def at_catchpoint(exception)
|
121
|
+
processor.at_catchpoint(exception)
|
122
|
+
end
|
123
|
+
|
124
|
+
#
|
125
|
+
# Return handler
|
126
|
+
#
|
127
|
+
def at_return(return_value)
|
128
|
+
return if ignored_file?(file)
|
129
|
+
|
130
|
+
processor.at_return(return_value)
|
131
|
+
end
|
132
|
+
|
133
|
+
#
|
134
|
+
# End of class definition handler
|
135
|
+
#
|
136
|
+
def at_end
|
137
|
+
return if ignored_file?(file)
|
138
|
+
|
139
|
+
processor.at_end
|
140
|
+
end
|
141
|
+
|
142
|
+
private
|
143
|
+
|
144
|
+
def processor
|
145
|
+
@processor ||= self.class.processor.new(self, self.class.interface)
|
146
|
+
end
|
147
|
+
|
148
|
+
#
|
149
|
+
# Tells whether a file is ignored by the debugger.
|
150
|
+
#
|
151
|
+
# @param path [String] filename to be checked.
|
152
|
+
#
|
153
|
+
def ignored_file?(path)
|
154
|
+
self.class.ignored_files.include?(path)
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
data/lib/byebug/core.rb
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "helpers/reflection"
|
4
|
+
require "byebug/byebug"
|
5
|
+
require_relative "context"
|
6
|
+
require_relative "breakpoint"
|
7
|
+
require_relative "interface"
|
8
|
+
require_relative "processors/script_processor"
|
9
|
+
require_relative "processors/post_mortem_processor"
|
10
|
+
require_relative "commands"
|
11
|
+
require_relative "remote"
|
12
|
+
require_relative "printers/plain"
|
13
|
+
|
14
|
+
#
|
15
|
+
# Main debugger's container module. Everything is defined under this module
|
16
|
+
#
|
17
|
+
module Byebug
|
18
|
+
include Helpers::ReflectionHelper
|
19
|
+
|
20
|
+
extend self
|
21
|
+
|
22
|
+
#
|
23
|
+
# Configuration file used for startup commands. Default value is .byebugrc
|
24
|
+
#
|
25
|
+
attr_accessor :init_file
|
26
|
+
self.init_file = ".byebugrc"
|
27
|
+
|
28
|
+
#
|
29
|
+
# Debugger's display expressions
|
30
|
+
#
|
31
|
+
attr_accessor :displays
|
32
|
+
self.displays = []
|
33
|
+
|
34
|
+
#
|
35
|
+
# Running mode of the debugger. Can be either:
|
36
|
+
#
|
37
|
+
# * :attached => Attached to a running program through the `byebug` method.
|
38
|
+
# * :standalone => Started through `byebug` script.
|
39
|
+
# * :off => Ignoring any `byebug` method calls.
|
40
|
+
#
|
41
|
+
attr_accessor :mode
|
42
|
+
|
43
|
+
#
|
44
|
+
# Runs normal byebug initialization scripts.
|
45
|
+
#
|
46
|
+
# Reads and executes the commands from init file (if any) in the current
|
47
|
+
# working directory. This is only done if the current directory is different
|
48
|
+
# from your home directory. Thus, you can have more than one init file, one
|
49
|
+
# generic in your home directory, and another, specific to the program you
|
50
|
+
# are debugging, in the directory where you invoke byebug.
|
51
|
+
#
|
52
|
+
def run_init_script
|
53
|
+
rc_dirs.each do |dir|
|
54
|
+
rc_file = File.expand_path(File.join(dir, init_file))
|
55
|
+
next unless File.exist?(rc_file)
|
56
|
+
|
57
|
+
run_rc_file(rc_file)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.load_settings
|
62
|
+
Dir.glob(File.join(__dir__, "settings", "*.rb")).each do |file|
|
63
|
+
require file
|
64
|
+
end
|
65
|
+
|
66
|
+
constants.grep(/[a-z]Setting/).map do |name|
|
67
|
+
setting = const_get(name).new
|
68
|
+
Byebug::Setting.settings[setting.to_sym] = setting
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
#
|
73
|
+
# Saves information about the unhandled exception and gives a byebug
|
74
|
+
# prompt back to the user before program termination.
|
75
|
+
#
|
76
|
+
def self.handle_post_mortem
|
77
|
+
return unless raised_exception
|
78
|
+
|
79
|
+
context = raised_exception.__bb_context
|
80
|
+
|
81
|
+
PostMortemProcessor.new(context).at_line
|
82
|
+
end
|
83
|
+
|
84
|
+
at_exit { Byebug.handle_post_mortem if Byebug.post_mortem? }
|
85
|
+
|
86
|
+
private
|
87
|
+
|
88
|
+
#
|
89
|
+
# Runs a initialization script file
|
90
|
+
#
|
91
|
+
def run_rc_file(rc_file)
|
92
|
+
interface = ScriptInterface.new(rc_file)
|
93
|
+
|
94
|
+
ScriptProcessor.new(nil, interface).process_commands
|
95
|
+
end
|
96
|
+
|
97
|
+
#
|
98
|
+
# List of folders to load rc files from
|
99
|
+
#
|
100
|
+
# @note Files will be loaded in the order specified here.
|
101
|
+
#
|
102
|
+
def rc_dirs
|
103
|
+
[ENV["HOME"], Dir.pwd].compact.uniq
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
Byebug.load_settings
|
108
|
+
|
109
|
+
#
|
110
|
+
# Extends the extension class to be able to pass information about the
|
111
|
+
# debugging environment from the c-extension to the user.
|
112
|
+
#
|
113
|
+
class Exception
|
114
|
+
attr_reader :__bb_context
|
115
|
+
end
|