class DEBUGGER__::LineBreakpoint

Constants

NearestISeq

Attributes

command[R]
cond[R]
hook_call[R]
iseq[R]
line[R]
oneshot[R]
path[R]

Public Class Methods

copy(bp, root_iseq) click to toggle source
# File debug-1.9.1/lib/debug/breakpoint.rb, line 136
def self.copy bp, root_iseq
  nbp = LineBreakpoint.new bp.path, bp.line,
                           cond: bp.cond, oneshot: bp.oneshot, hook_call: bp.hook_call,
                           command: bp.command, skip_activate: true
  nbp.try_activate root_iseq
  nbp
end
new(path, line, cond: nil, oneshot: false, hook_call: true, command: nil, skip_activate: false, skip_src: false) click to toggle source
Calls superclass method DEBUGGER__::Breakpoint::new
# File debug-1.9.1/lib/debug/breakpoint.rb, line 144
def initialize path, line, cond: nil, oneshot: false, hook_call: true, command: nil, skip_activate: false, skip_src: false
  @line = line
  @oneshot = oneshot
  @hook_call = hook_call
  @skip_src = skip_src
  @pending = false

  @iseq = nil
  @type = nil

  @key = [path, @line].freeze

  super(cond, command, path)

  try_activate unless skip_activate
  @pending = !@iseq
end

Public Instance Methods

activate(iseq, event, line) click to toggle source
# File debug-1.9.1/lib/debug/breakpoint.rb, line 188
def activate iseq, event, line
  @iseq = iseq
  @type = event
  @line = line
  @path = iseq.absolute_path

  @key = [@path, @line].freeze
  SESSION.rehash_bps
  setup
  enable

  if @pending && !@oneshot
    DEBUGGER__.info "#{self} is activated."
  end

  @pending = false
end
activate_exact(iseq, events, line) click to toggle source
# File debug-1.9.1/lib/debug/breakpoint.rb, line 206
def activate_exact iseq, events, line
  case
  when events.include?(:RUBY_EVENT_CALL)
    # "def foo" line set bp on the beginning of method foo
    activate(iseq, :call, line)
  when events.include?(:RUBY_EVENT_LINE)
    activate(iseq, :line, line)
  when events.include?(:RUBY_EVENT_RETURN)
    activate(iseq, :return, line)
  when events.include?(:RUBY_EVENT_B_RETURN)
    activate(iseq, :b_return, line)
  when events.include?(:RUBY_EVENT_END)
    activate(iseq, :end, line)
  else
    # not activated
  end
end
duplicable?() click to toggle source
# File debug-1.9.1/lib/debug/breakpoint.rb, line 224
def duplicable?
  @oneshot
end
enable() click to toggle source
# File debug-1.9.1/lib/debug/breakpoint.rb, line 174
def enable
  return unless @iseq

  if @type == :line
    @tp.enable(target: @iseq, target_line: @line)
  else
    @tp.enable(target: @iseq)
  end

rescue ArgumentError
  puts @iseq.disasm # for debug
  raise
end
inspect() click to toggle source
# File debug-1.9.1/lib/debug/breakpoint.rb, line 293
def inspect
  "<#{self.class.name} #{self.to_s}>"
end
iterate_iseq(root_iseq) { |iseq| ... } click to toggle source
# File debug-1.9.1/lib/debug/breakpoint.rb, line 230
def iterate_iseq root_iseq
  if root_iseq
    is = [root_iseq]
    while iseq = is.pop
      yield iseq
      iseq.each_child do |child_iseq|
        is << child_iseq
      end
    end
  else
    ObjectSpace.each_iseq do |iseq|
      if DEBUGGER__.compare_path((iseq.absolute_path || iseq.path), self.path) &&
         iseq.first_lineno <= self.line &&
         iseq.type != :ensure # ensure iseq is copied (duplicated)
        yield iseq
      end
    end
  end
end
path_is?(path) click to toggle source
# File debug-1.9.1/lib/debug/breakpoint.rb, line 297
def path_is? path
  DEBUGGER__.compare_path(@path, path)
end
setup() click to toggle source
# File debug-1.9.1/lib/debug/breakpoint.rb, line 162
def setup
  return unless @type

  @tp = TracePoint.new(@type) do |tp|
    if @cond
      next unless safe_eval tp.binding, @cond
    end
    delete if @oneshot
    suspend
  end
end
to_s() click to toggle source
Calls superclass method DEBUGGER__::Breakpoint#to_s
# File debug-1.9.1/lib/debug/breakpoint.rb, line 283
def to_s
  oneshot = @oneshot ? " (oneshot)" : ""

  if @iseq
    "#{generate_label("Line")} #{@path}:#{@line} (#{@type})#{oneshot}" + super
  else
    "#{generate_label("Line (pending)")} #{@path}:#{@line}#{oneshot}" + super
  end
end
try_activate(root_iseq = nil) click to toggle source
# File debug-1.9.1/lib/debug/breakpoint.rb, line 250
def try_activate root_iseq = nil
  nearest = nil # NearestISeq
  iterate_iseq root_iseq do |iseq|
    iseq.traceable_lines_norec(line_events = {})
    lines = line_events.keys.sort

    if !lines.empty? && lines.last >= line
      nline = lines.bsearch{|l| line <= l}
      events = line_events[nline]

      next if events == [:RUBY_EVENT_B_CALL]

      if @hook_call &&
        events.include?(:RUBY_EVENT_CALL) &&
        self.line == iseq.first_lineno
        nline = iseq.first_lineno
      end

      if !nearest || ((line - nline).abs < (line - nearest.line).abs)
        nearest = NearestISeq.new(iseq, nline, events)
      elsif @hook_call &&
            nearest.line == iseq.first_line &&
            events.include?(:RUBY_EVENT_CALL)
        nearest = NearestISeq.new(iseq, nline, events)
      end
    end
  end

  if nearest
    activate_exact nearest.iseq, nearest.events, nearest.line
  end
end