Sha256: 3c9b5282c07d5edbdf0fa9051666dc6f4ad0e8fe18d6ec7ad52d971ab28e4ab6

Contents?: true

Size: 1.39 KB

Versions: 26

Compression:

Stored size: 1.39 KB

Contents

require 'byebug/command'
require 'byebug/helpers/parse'

module Byebug
  #
  # Implements conditions on breakpoints.
  #
  # Adds the ability to stop on breakpoints only under certain conditions.
  #
  class ConditionCommand < Command
    include Helpers::ParseHelper

    self.allow_in_post_mortem = true

    def self.regexp
      /^\s* cond(?:ition)? (?:\s+(\d+)(?:\s+(.*))?)? \s*$/x
    end

    def self.description
      <<-EOD
        cond[ition] <n>[ expr]

        #{short_description}

        Specify breakpoint number <n> to break only if <expr> is true. <n> is
        an integer and <expr> is an expression to be evaluated whenever
        breakpoint <n> is reached. If no expression is specified, the condition
        is removed.
      EOD
    end

    def self.short_description
      'Sets conditions on breakpoints'
    end

    def execute
      return puts(help) unless @match[1]

      breakpoints = Byebug.breakpoints.sort_by(&:id)
      return errmsg(pr('condition.errors.no_breakpoints')) if breakpoints.empty?

      pos, err = get_int(@match[1], 'Condition', 1)
      return errmsg(err) if err

      breakpoint = breakpoints.find { |b| b.id == pos }
      return errmsg(pr('break.errors.no_breakpoint')) unless breakpoint

      unless syntax_valid?(@match[2])
        return errmsg(pr('break.errors.not_changed', expr: @match[2]))
      end

      breakpoint.expr = @match[2]
    end
  end
end

Version data entries

26 entries across 25 versions & 3 rubygems

Version Path
dirwatch-0.0.2 vendor/bundle/ruby/2.3.0/gems/byebug-9.1.0/lib/byebug/commands/condition.rb
tdiary-5.0.6 vendor/bundle/gems/byebug-9.1.0/lib/byebug/commands/condition.rb
byebug-9.1.0 lib/byebug/commands/condition.rb
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/byebug-9.0.6/lib/byebug/commands/condition.rb
tdiary-5.0.5 vendor/bundle/gems/byebug-9.0.6/lib/byebug/commands/condition.rb
tdiary-5.0.4 vendor/bundle/gems/byebug-9.0.6/lib/byebug/commands/condition.rb
byebug-9.0.6 lib/byebug/commands/condition.rb
byebug-9.0.5 lib/byebug/commands/condition.rb
byebug-9.0.4 lib/byebug/commands/condition.rb
byebug-9.0.3 lib/byebug/commands/condition.rb
byebug-9.0.2 lib/byebug/commands/condition.rb
byebug-9.0.1 lib/byebug/commands/condition.rb
byebug-9.0.0 lib/byebug/commands/condition.rb
byebug-8.2.5 lib/byebug/commands/condition.rb
byebug-8.2.4 lib/byebug/commands/condition.rb
byebug-8.2.3 lib/byebug/commands/condition.rb
byebug-8.2.2 lib/byebug/commands/condition.rb
byebug-8.2.1 lib/byebug/commands/condition.rb
byebug-8.2.0 lib/byebug/commands/condition.rb
byebug-8.1.0 lib/byebug/commands/condition.rb