Class: DEBUGGER__::DAP_TraceInspector::MultiTracer
- Inherits:
-
Tracer
show all
- Defined in:
- lib/debug/dap_custom/traceInspector.rb
Instance Attribute Summary collapse
Attributes inherited from Tracer
#key, #type
Instance Method Summary
collapse
Methods inherited from Tracer
#colorize, #description, #disable, #enable, #enabled?, #header, #minfo, #out, #to_s
Methods included from Color
#color_pp, #colored_inspect, #colorize, #colorize_blue, #colorize_code, #colorize_cyan, #colorize_dim, #colorize_magenta, #irb_colorize, #with_inspection_error_guard
#skip_config_skip_path?, #skip_internal_path?, #skip_location?, #skip_path?
Constructor Details
#initialize(ui, evts, trace_params, max_log_size: nil, **kw) ⇒ MultiTracer
Returns a new instance of MultiTracer.
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/debug/dap_custom/traceInspector.rb', line 4
def initialize ui, evts, trace_params, max_log_size: nil, **kw
@evts = evts
@log = []
@trace_params = trace_params
if max_log_size
@max_log_size = max_log_size
else
@max_log_size = 50000
end
@dropped_trace_cnt = 0
super(ui, **kw)
@type = 'multi'
@name = 'TraceInspector'
end
|
Instance Attribute Details
#dropped_trace_cnt ⇒ Object
Returns the value of attribute dropped_trace_cnt.
19
20
21
|
# File 'lib/debug/dap_custom/traceInspector.rb', line 19
def dropped_trace_cnt
@dropped_trace_cnt
end
|
Returns the value of attribute log.
20
21
22
|
# File 'lib/debug/dap_custom/traceInspector.rb', line 20
def log
@log
end
|
Instance Method Details
#append(log) ⇒ Object
60
61
62
63
64
65
66
|
# File 'lib/debug/dap_custom/traceInspector.rb', line 60
def append log
if @log.size >= @max_log_size
@dropped_trace_cnt += 1
@log.shift
end
@log << log
end
|
#call_identifier_str(tp) ⇒ Object
52
53
54
55
56
57
58
|
# File 'lib/debug/dap_custom/traceInspector.rb', line 52
def call_identifier_str tp
if tp.defined_class
minfo(tp)
else
"block"
end
end
|
#call_trace_log(tp, return_str: nil, params: nil) ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/debug/dap_custom/traceInspector.rb', line 68
def call_trace_log tp, return_str: nil, params: nil
log = {
depth: DEBUGGER__.frame_depth,
name: call_identifier_str(tp),
threadId: Thread.current.instance_variable_get(:@__thread_client_id),
location: {
path: tp.path,
line: tp.lineno
}
}
log[:returnValue] = return_str if return_str
log[:parameters] = params if params && params.size > 0
log
end
|
#line_trace_log(tp) ⇒ Object
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/debug/dap_custom/traceInspector.rb', line 83
def line_trace_log tp
{
depth: DEBUGGER__.frame_depth,
threadId: Thread.current.instance_variable_get(:@__thread_client_id),
location: {
path: tp.path,
line: tp.lineno
}
}
end
|
#parameters_info(tp) ⇒ Object
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/debug/dap_custom/traceInspector.rb', line 41
def parameters_info tp
b = tp.binding
tp.parameters.map{|_type, name|
begin
{ name: name, value: DEBUGGER__.safe_inspect(b.local_variable_get(name), short: true, max_length: 4096) }
rescue NameError, TypeError
nil
end
}.compact
end
|
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/debug/dap_custom/traceInspector.rb', line 22
def setup
@tracer = TracePoint.new(*@evts){|tp|
next if skip?(tp)
case tp.event
when :call, :c_call, :b_call
if @trace_params
params = parameters_info tp
end
append(call_trace_log(tp, params: params))
when :return, :c_return, :b_return
return_str = DEBUGGER__.safe_inspect(tp.return_value, short: true, max_length: 4096)
append(call_trace_log(tp, return_str: return_str))
when :line
append(line_trace_log(tp))
end
}
end
|
#skip?(tp) ⇒ Boolean
94
95
96
|
# File 'lib/debug/dap_custom/traceInspector.rb', line 94
def skip? tp
super || !@evts.include?(tp.event)
end
|
#skip_with_pattern?(tp) ⇒ Boolean
98
99
100
|
# File 'lib/debug/dap_custom/traceInspector.rb', line 98
def skip_with_pattern?(tp)
super && !tp.method_id&.match?(@pattern)
end
|