123456789_123456789_123456789_123456789_123456789_

Class: DEBUGGER__::MethodBreakpoint

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Breakpoint
Instance Chain:
Inherits: DEBUGGER__::Breakpoint
Defined in: lib/debug/breakpoint.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Breakpoint - Inherited

Color - Included

#color_pp

See additional method definition at line 50.

#colored_inspect,
#colorize

See additional method definition at line 36.

#colorize_blue,
#colorize_code

See additional method definition at line 79.

#colorize_cyan, #colorize_dim, #colorize_magenta,
#irb_colorize

See additional method definition at line 27.

#with_inspection_error_guard

SkipPathHelper - Included

Constructor Details

.new(b, klass_name, op, method_name, cond: nil, command: nil, path: nil) ⇒ MethodBreakpoint

[ GitHub ]

  
# File 'lib/debug/breakpoint.rb', line 426

def initialize b, klass_name, op, method_name, cond: nil, command: nil, path: nil
  @sig_klass_name = klass_name
  @sig_op = op
  @sig_method_name = method_name
  @klass_eval_binding = b
  @override_method = false

  @klass = nil
  @method = nil
  @cond_class = nil
  @key = "#{klass_name}#{op}#{method_name}".freeze

  super(cond, command, path, do_enable: false)
end

Instance Attribute Details

#klass (readonly)

[ GitHub ]

  
# File 'lib/debug/breakpoint.rb', line 424

attr_reader :sig_method_name, :method, :klass

#method (readonly)

[ GitHub ]

  
# File 'lib/debug/breakpoint.rb', line 424

attr_reader :sig_method_name, :method, :klass

#sig_method_name (readonly)

[ GitHub ]

  
# File 'lib/debug/breakpoint.rb', line 424

attr_reader :sig_method_name, :method, :klass

Instance Method Details

#enable

[ GitHub ]

  
# File 'lib/debug/breakpoint.rb', line 471

def enable
  try_enable
end

#eval_class_name

[ GitHub ]

  
# File 'lib/debug/breakpoint.rb', line 453

def eval_class_name
  return @klass if @klass
  @klass = @klass_eval_binding.eval(@sig_klass_name)
  @klass_eval_binding = nil
  @klass
end

#override(klass)

See additional method definition at line 476.

[ GitHub ]

  
# File 'lib/debug/breakpoint.rb', line 485

def override klass
  sig_method_name = @sig_method_name
  klass.prepend Module.new{
    define_method(sig_method_name) do |*args, &block|
      super(*args, &block)
    end
  }
end

#search_method

[ GitHub ]

  
# File 'lib/debug/breakpoint.rb', line 460

def search_method
  case @sig_op
  when '.'
    @method = @klass.method(@sig_method_name)
  when '#'
    @method = @klass.instance_method(@sig_method_name)
  else
    raise "Unknown op: #{@sig_op}"
  end
end

#setup

[ GitHub ]

  
# File 'lib/debug/breakpoint.rb', line 441

def setup
  @tp = TracePoint.new(:call){|tp|
    next if !safe_eval(tp.binding, @cond) if @cond
    next if @cond_class && !tp.self.kind_of?(@cond_class)

    caller_location = caller_locations(2, 1).first.to_s
    next if skip_path?(caller_location)

    suspend
  }
end

#sig

[ GitHub ]

  
# File 'lib/debug/breakpoint.rb', line 539

def sig
  @key
end

#to_s

[ GitHub ]

  
# File 'lib/debug/breakpoint.rb', line 543

def to_s
  if @method
    loc = @method.source_location || []
    "#{generate_label("Method")} #{sig} at #{loc.join(':')}"
  else
    "#{generate_label("Method (pending)")} #{sig}"
  end + super
end

#try_enable(added: false)

[ GitHub ]

  
# File 'lib/debug/breakpoint.rb', line 495

def try_enable added: false
  eval_class_name
  search_method

  begin
    retried = false

    @tp.enable(target: @method)
    DEBUGGER__.warn "#{self} is activated." if added

    if @sig_op == '#'
      @cond_class = @klass if @method.owner != @klass
    else # '.'
      begin
        @cond_class = @klass.singleton_class if @method.owner != @klass.singleton_class
      rescue TypeError
      end
    end

  rescue ArgumentError
    raise if retried
    retried = true

    # maybe C method
    case @sig_op
    when '.'
      begin
        override @klass.singleton_class
      rescue TypeError
        override @klass.class
      end
    when '#'
      override @klass
    end

    # re-collect the method object after the above patch
    search_method
    @override_method = true if @method
    retry
  end
rescue Exception
  raise unless added
end