ed-precompiled_debug 1.11.0-arm64-darwin

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,241 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DEBUGGER__
4
+ class Tracer
5
+ include SkipPathHelper
6
+ include Color
7
+
8
+ def colorize(str, color)
9
+ # don't colorize trace sent into a file
10
+ if @into
11
+ str
12
+ else
13
+ super
14
+ end
15
+ end
16
+
17
+ attr_reader :type, :key
18
+
19
+ def initialize ui, pattern: nil, into: nil
20
+ if /\ADEBUGGER__::(([A-Z][a-z]+?)[A-Z][a-z]+)/ =~ self.class.name
21
+ @name = $1
22
+ @type = $2.downcase
23
+ end
24
+
25
+ setup
26
+
27
+ if pattern
28
+ @pattern = Regexp.compile(pattern)
29
+ else
30
+ @pattern = nil
31
+ end
32
+
33
+ if @into = into
34
+ @output = File.open(into, 'w')
35
+ @output.puts "PID:#{Process.pid} #{self}"
36
+ else
37
+ @output = ui
38
+ end
39
+
40
+ @key = [@type, @pattern, @into].freeze
41
+
42
+ enable
43
+ end
44
+
45
+ def header depth
46
+ "DEBUGGER (trace/#{@type}) \#th:#{Thread.current.instance_variable_get(:@__thread_client_id)} \#depth:#{'%-2d'%depth}"
47
+ end
48
+
49
+ def enable
50
+ @tracer.enable
51
+ end
52
+
53
+ def disable
54
+ @tracer.disable
55
+ end
56
+
57
+ def enabled?
58
+ @tracer.enabled?
59
+ end
60
+
61
+ def description
62
+ nil
63
+ end
64
+
65
+ def to_s
66
+ s = "#{@name}#{description} (#{@tracer.enabled? ? 'enabled' : 'disabled'})"
67
+ s += " with pattern #{@pattern.inspect}" if @pattern
68
+ s += " into: #{@into}" if @into
69
+ s
70
+ end
71
+
72
+ def skip? tp
73
+ ThreadClient.current.management? || skip_path?(tp.path) || skip_with_pattern?(tp)
74
+ end
75
+
76
+ def skip_with_pattern?(tp)
77
+ @pattern && !tp.path.match?(@pattern)
78
+ end
79
+
80
+ def out tp, msg = nil, depth = caller.size - 1
81
+ location_str = colorize("#{FrameInfo.pretty_path(tp.path)}:#{tp.lineno}", [:GREEN])
82
+ buff = "#{header(depth)}#{msg} at #{location_str}"
83
+
84
+ if false # TODO: Ractor.main?
85
+ ThreadClient.current.on_trace self.object_id, buff
86
+ else
87
+ @output.puts buff
88
+ @output.flush
89
+ end
90
+ end
91
+
92
+ def minfo tp
93
+ return "block{}" if tp.event == :b_call
94
+
95
+ klass = tp.defined_class
96
+
97
+ if klass.singleton_class?
98
+ "#{tp.self}.#{tp.method_id}"
99
+ else
100
+ "#{klass}\##{tp.method_id}"
101
+ end
102
+ end
103
+ end
104
+
105
+ class LineTracer < Tracer
106
+ def setup
107
+ @tracer = TracePoint.new(:line){|tp|
108
+ next if skip?(tp)
109
+ # pp tp.object_id, caller(0)
110
+ out tp
111
+ }
112
+ end
113
+ end
114
+
115
+ class CallTracer < Tracer
116
+ def setup
117
+ @tracer = TracePoint.new(:a_call, :a_return){|tp|
118
+ next if skip?(tp)
119
+
120
+ depth = caller.size
121
+
122
+ call_identifier_str =
123
+ if tp.defined_class
124
+ minfo(tp)
125
+ else
126
+ "block"
127
+ end
128
+
129
+ call_identifier_str = colorize_blue(call_identifier_str)
130
+
131
+ case tp.event
132
+ when :call, :c_call, :b_call
133
+ depth += 1 if tp.event == :c_call
134
+ sp = ' ' * depth
135
+ out tp, ">#{sp}#{call_identifier_str}", depth
136
+ when :return, :c_return, :b_return
137
+ depth += 1 if tp.event == :c_return
138
+ sp = ' ' * depth
139
+ return_str = colorize_magenta(DEBUGGER__.safe_inspect(tp.return_value, short: true))
140
+ out tp, "<#{sp}#{call_identifier_str} #=> #{return_str}", depth
141
+ end
142
+ }
143
+ end
144
+
145
+ def skip_with_pattern?(tp)
146
+ super && !tp.method_id&.match?(@pattern)
147
+ end
148
+ end
149
+
150
+ class ExceptionTracer < Tracer
151
+ def setup
152
+ @tracer = TracePoint.new(:raise) do |tp|
153
+ next if skip?(tp)
154
+
155
+ exc = tp.raised_exception
156
+
157
+ out tp, " #{colorize_magenta(exc.inspect)}"
158
+ rescue Exception => e
159
+ p e
160
+ end
161
+ end
162
+
163
+ def skip_with_pattern?(tp)
164
+ super && !tp.raised_exception.inspect.match?(@pattern)
165
+ end
166
+ end
167
+
168
+ class ObjectTracer < Tracer
169
+ def initialize ui, obj_id, obj_inspect, **kw
170
+ @obj_id = obj_id
171
+ @obj_inspect = obj_inspect
172
+ super(ui, **kw)
173
+ @key = [@type, @obj_id, @pattern, @into].freeze
174
+ end
175
+
176
+ def description
177
+ " for #{@obj_inspect}"
178
+ end
179
+
180
+ def colorized_obj_inspect
181
+ colorize_magenta(@obj_inspect)
182
+ end
183
+
184
+ def setup
185
+ @tracer = TracePoint.new(:a_call){|tp|
186
+ next if skip?(tp)
187
+
188
+ if M_OBJECT_ID.bind_call(tp.self) == @obj_id
189
+ klass = tp.defined_class
190
+ method = tp.method_id
191
+ method_info =
192
+ if klass.singleton_class?
193
+ if tp.self.is_a?(Class)
194
+ ".#{method} (#{klass}.#{method})"
195
+ else
196
+ ".#{method}"
197
+ end
198
+ else
199
+ "##{method} (#{klass}##{method})"
200
+ end
201
+
202
+ out tp, " #{colorized_obj_inspect} receives #{colorize_blue(method_info)}"
203
+ elsif !tp.parameters.empty?
204
+ b = tp.binding
205
+ method_info = colorize_blue(minfo(tp))
206
+
207
+ tp.parameters.each{|type, name|
208
+ next unless name
209
+
210
+ colorized_name = colorize_cyan(name)
211
+
212
+ case type
213
+ when :req, :opt, :key, :keyreq
214
+ if b.local_variable_get(name).object_id == @obj_id
215
+ out tp, " #{colorized_obj_inspect} is used as a parameter #{colorized_name} of #{method_info}"
216
+ end
217
+ when :rest
218
+ next if name == :"*"
219
+
220
+ ary = b.local_variable_get(name)
221
+ ary.each{|e|
222
+ if e.object_id == @obj_id
223
+ out tp, " #{colorized_obj_inspect} is used as a parameter in #{colorized_name} of #{method_info}"
224
+ end
225
+ }
226
+ when :keyrest
227
+ next if name == :'**'
228
+ h = b.local_variable_get(name)
229
+ h.each{|k, e|
230
+ if e.object_id == @obj_id
231
+ out tp, " #{colorized_obj_inspect} is used as a parameter in #{colorized_name} of #{method_info}"
232
+ end
233
+ }
234
+ end
235
+ }
236
+ end
237
+ }
238
+ end
239
+ end
240
+ end
241
+
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DEBUGGER__
4
+ VERSION = "1.11.0"
5
+ end
data/lib/debug.rb ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ if ENV['RUBY_DEBUG_LAZY']
4
+ require_relative 'debug/prelude'
5
+ else
6
+ require_relative 'debug/session'
7
+ return unless defined?(DEBUGGER__)
8
+ DEBUGGER__::start no_sigint_hook: true, nonstop: true
9
+ end