In Files

  • debug-1.4.0/lib/debug/breakpoint.rb

DEBUGGER__::WatchIVarBreakpoint

Public Class Methods

new(ivar, object, current, cond: nil, command: nil, path: nil) click to toggle source
 
               # File debug-1.4.0/lib/debug/breakpoint.rb, line 344
def initialize ivar, object, current, cond: nil, command: nil, path: nil
  @ivar = ivar.to_sym
  @object = object
  @key = [:watch, object.object_id, @ivar].freeze

  @current = current

  @cond = cond
  @command = command
  @path = path
  super()
end
            

Public Instance Methods

setup() click to toggle source
 
               # File debug-1.4.0/lib/debug/breakpoint.rb, line 375
def setup
  @tp = TracePoint.new(:line, :return, :b_return){|tp|
    next if tp.path.start_with? __dir__
    next if tp.path.start_with? '<internal:'

    watch_eval(tp)
  }
end
            
to_s() click to toggle source
 
               # File debug-1.4.0/lib/debug/breakpoint.rb, line 384
def to_s
  value_str =
    if defined?(@prev)
      "#{@prev} -> #{@current}"
    else
      "#{@current}"
    end
  "#{generate_label("Watch")} #{@object} #{@ivar} = #{value_str}"
end
            
watch_eval(tp) click to toggle source
 
               # File debug-1.4.0/lib/debug/breakpoint.rb, line 357
def watch_eval(tp)
  result = @object.instance_variable_get(@ivar)
  if result != @current
    begin
      @prev = @current
      @current = result

      if (@cond.nil? || @object.instance_eval(@cond)) && !skip_path?(tp.path)
        suspend
      end
    ensure
      remove_instance_variable(:@prev)
    end
  end
rescue Exception
  false
end