123456789_123456789_123456789_123456789_123456789_

Class: DEBUGGER__::DAP_TraceInspector::MultiTracer

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
Inherits: DEBUGGER__::Tracer
Defined in: lib/debug/dap_custom/traceInspector.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(ui, evts, trace_params, max_log_size: nil, **kw) ⇒ MultiTracer

[ GitHub ]

  
# 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 (rw)

[ GitHub ]

  
# File 'lib/debug/dap_custom/traceInspector.rb', line 19

attr_accessor :dropped_trace_cnt

#log (readonly)

[ GitHub ]

  
# File 'lib/debug/dap_custom/traceInspector.rb', line 20

attr_reader :log

Instance Method Details

#append(log)

[ GitHub ]

  
# 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)

[ GitHub ]

  
# 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)

[ GitHub ]

  
# 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)

[ GitHub ]

  
# 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)

[ GitHub ]

  
# 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

#setup

[ GitHub ]

  
# 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

[ GitHub ]

  
# File 'lib/debug/dap_custom/traceInspector.rb', line 94

def skip? tp
  super || !@evts.include?(tp.event)
end

#skip_with_pattern?(tp) ⇒ Boolean

[ GitHub ]

  
# File 'lib/debug/dap_custom/traceInspector.rb', line 98

def skip_with_pattern?(tp)
  super && !tp.method_id&.match?(@pattern)
end