Class: DEBUGGER__::WatchIVarBreakpoint

Inherits:
Breakpoint show all
Defined in:
lib/debug/breakpoint.rb

Instance Attribute Summary

Attributes inherited from Breakpoint

#key, #skip_src

Instance Method Summary collapse

Methods inherited from Breakpoint

#delete, #deleted?, #description, #disable, #duplicable?, #enable, #enabled?, #generate_label, #oneshot?, #safe_eval, #skip_path?, #suspend

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

Methods included from SkipPathHelper

#skip_config_skip_path?, #skip_internal_path?, #skip_location?, #skip_path?

Constructor Details

#initialize(ivar, object, current, cond: nil, command: nil, path: nil) ⇒ WatchIVarBreakpoint

Returns a new instance of WatchIVarBreakpoint.



382
383
384
385
386
387
388
389
390
# File 'lib/debug/breakpoint.rb', line 382

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

  super(cond, command, path)
end

Instance Method Details

#setupObject



410
411
412
413
414
# File 'lib/debug/breakpoint.rb', line 410

def setup
  @tp = TracePoint.new(:line, :return, :b_return){|tp|
    watch_eval(tp)
  }
end

#to_sObject



416
417
418
419
420
421
422
423
424
# File 'lib/debug/breakpoint.rb', line 416

def to_s
  value_str =
    if defined?(@prev)
      "#{@prev} -> #{@current}"
    else
      "#{@current}"
    end
  "#{generate_label("Watch")} #{@object} #{@ivar} = #{value_str}"
end

#watch_eval(tp) ⇒ Object



392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
# File 'lib/debug/breakpoint.rb', line 392

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