ed-precompiled_debug 1.11.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.
@@ -0,0 +1,150 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'color'
4
+
5
+ module DEBUGGER__
6
+ class SourceRepository
7
+ include Color
8
+
9
+ def file_src iseq
10
+ if (path = (iseq.absolute_path || iseq.path)) && File.exist?(path)
11
+ File.readlines(path, chomp: true)
12
+ end
13
+ end
14
+
15
+ def get iseq
16
+ return unless iseq
17
+
18
+ if CONFIG[:show_evaledsrc]
19
+ orig_src(iseq) || file_src(iseq)
20
+ else
21
+ file_src(iseq) || orig_src(iseq)
22
+ end
23
+ end
24
+
25
+ if defined?(RubyVM.keep_script_lines)
26
+ # Ruby 3.1 and later
27
+ RubyVM.keep_script_lines = true
28
+ require 'objspace'
29
+
30
+ def initialize
31
+ # cache
32
+ @cmap = ObjectSpace::WeakMap.new
33
+ @loaded_file_map = {} # path => nil
34
+ end
35
+
36
+ def add iseq, src
37
+ # only manage loaded file names
38
+ if (path = (iseq.absolute_path || iseq.path)) && File.exist?(path)
39
+ if @loaded_file_map.has_key? path
40
+ return path, true # reloaded
41
+ else
42
+ @loaded_file_map[path] = path
43
+ return path, false
44
+ end
45
+ end
46
+ end
47
+
48
+ def orig_src iseq
49
+ lines = iseq.script_lines&.map(&:chomp)
50
+ line = iseq.first_line
51
+ if line > 1
52
+ [*([''] * (line - 1)), *lines]
53
+ else
54
+ lines
55
+ end
56
+ end
57
+
58
+ def get_colored iseq
59
+ if lines = @cmap[iseq]
60
+ lines
61
+ else
62
+ if src_lines = get(iseq)
63
+ @cmap[iseq] = colorize_code(src_lines.join("\n")).lines
64
+ else
65
+ nil
66
+ end
67
+ end
68
+ end
69
+ else
70
+ # ruby 3.0 or earlier
71
+ SrcInfo = Struct.new(:src, :colored)
72
+
73
+ def initialize
74
+ @files = {} # filename => SrcInfo
75
+ end
76
+
77
+ def add iseq, src
78
+ path = (iseq.absolute_path || iseq.path)
79
+
80
+ if path && File.exist?(path)
81
+ reloaded = @files.has_key? path
82
+
83
+ if src
84
+ add_iseq iseq, src
85
+ return path, reloaded
86
+ else
87
+ add_path path
88
+ return path, reloaded
89
+ end
90
+ else
91
+ add_iseq iseq, src
92
+ nil
93
+ end
94
+ end
95
+
96
+ private def all_iseq iseq, rs = []
97
+ rs << iseq
98
+ iseq.each_child{|ci|
99
+ all_iseq(ci, rs)
100
+ }
101
+ rs
102
+ end
103
+
104
+ private def add_iseq iseq, src
105
+ line = iseq.first_line
106
+ if line > 1
107
+ src = ("\n" * (line - 1)) + src
108
+ end
109
+
110
+ si = SrcInfo.new(src.each_line.map{|l| l.chomp})
111
+ all_iseq(iseq).each{|e|
112
+ e.instance_variable_set(:@debugger_si, si)
113
+ e.freeze
114
+ }
115
+ end
116
+
117
+ private def add_path path
118
+ src_lines = File.readlines(path, chomp: true)
119
+ @files[path] = SrcInfo.new(src_lines)
120
+ rescue SystemCallError
121
+ end
122
+
123
+ private def get_si iseq
124
+ return unless iseq
125
+
126
+ if iseq.instance_variable_defined?(:@debugger_si)
127
+ iseq.instance_variable_get(:@debugger_si)
128
+ elsif @files.has_key?(path = (iseq.absolute_path || iseq.path))
129
+ @files[path]
130
+ elsif path
131
+ add_path(path)
132
+ end
133
+ end
134
+
135
+ def orig_src iseq
136
+ if si = get_si(iseq)
137
+ si.src
138
+ end
139
+ end
140
+
141
+ def get_colored iseq
142
+ if si = get_si(iseq)
143
+ si.colored || begin
144
+ si.colored = colorize_code(si.src.join("\n")).lines
145
+ end
146
+ end
147
+ end
148
+ end
149
+ end
150
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'session'
4
+ return unless defined?(DEBUGGER__)
5
+ DEBUGGER__.start no_sigint_hook: false