Sha256: 8635b177c4fa5a5155ca0c63879fea9e00084c8d39a0901cad50e56a26d9a7c7

Contents?: true

Size: 1.2 KB

Versions: 22

Compression:

Stored size: 1.2 KB

Contents

module Debugger

  class ConditionCommand < Command # :nodoc:

    def regexp
      /^\s* cond(?:ition)? (?:\s+(\d+)\s*(.*))?$/ix
    end
    
    def execute
      if not @match[1]
        errmsg "\"condition\" must be followed a breakpoint number and expression\n"
      else
        breakpoints = Debugger.breakpoints.sort_by{|b| b.id }
        largest = breakpoints.inject(0) do |tally, b|
          tally = b.id if b.id > tally
        end
        if 0 == largest
          print "No breakpoints have been set.\n"
          return
        end
        pos = get_int(@match[1], "Condition", 1, largest)
        return unless pos
        breakpoints.each do |b|
          if b.id == pos 
            b.expr = @match[2].empty? ? nil : @match[2]
            break
          end
        end

      end
    end
    
    class << self
      def help_command
        'condition'
      end

      def help(cmd)
        %{
          Condition breakpoint-number expression
Specify breakpoint number N to break only if COND is true.
N is an integer and COND is an expression to be evaluated whenever 
breakpoint N is reached. If the empty string is used, the condition is removed.
        }
      end
    end
  end

end # module Debugger

Version data entries

22 entries across 22 versions & 3 rubygems

Version Path
debugger2-1.0.0.beta2 lib/ruby-debug/commands/condition.rb
debugger2-1.0.0.beta1 lib/ruby-debug/commands/condition.rb
needy_debugger-1.4.0 lib/ruby-debug/commands/condition.rb
debugger-1.4.0 lib/ruby-debug/commands/condition.rb
debugger-1.3.3 lib/ruby-debug/commands/condition.rb
debugger-1.3.2 lib/ruby-debug/commands/condition.rb
debugger-1.3.1 lib/ruby-debug/commands/condition.rb
debugger-1.3.0 lib/ruby-debug/commands/condition.rb
debugger-1.2.4 lib/ruby-debug/commands/condition.rb
debugger-1.2.3 lib/ruby-debug/commands/condition.rb
debugger-1.2.2 lib/ruby-debug/commands/condition.rb
debugger-1.2.1 lib/ruby-debug/commands/condition.rb
debugger-1.2.0 lib/ruby-debug/commands/condition.rb
debugger-1.1.4 lib/ruby-debug/commands/condition.rb
debugger-1.1.3 lib/ruby-debug/commands/condition.rb
debugger-1.1.2 lib/ruby-debug/commands/condition.rb
debugger-1.1.1 lib/ruby-debug/commands/condition.rb
debugger-1.1.0 lib/ruby-debug/commands/condition.rb
debugger-1.0.1 lib/ruby-debug/commands/condition.rb
debugger-1.0.0 cli/ruby-debug/commands/condition.rb