Sha256: a2946546bfce080a30a00a5b68cfea9e141a3ec8281f7ec3e94c1fa3991a63e4

Contents?: true

Size: 1.44 KB

Versions: 12

Compression:

Stored size: 1.44 KB

Contents

# frozen_string_literal: true

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
      <<-DESCRIPTION
        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.
      DESCRIPTION
    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

12 entries across 12 versions & 5 rubygems

Version Path
mountapi-0.11.1 vendor/bundle/ruby/2.7.0/gems/byebug-10.0.2/lib/byebug/commands/condition.rb
metanorma-cli-1.3.4 gems/ruby/2.6.0/gems/byebug-10.0.2/lib/byebug/commands/condition.rb
metanorma-cli-1.3.3.1 gems/ruby/2.6.0/gems/byebug-10.0.2/lib/byebug/commands/condition.rb
dadapush_client-1.0.1 vendor/bundle/ruby/2.3.0/gems/byebug-10.0.2/lib/byebug/commands/condition.rb
jets-0.5.5 vendor/lambdagem/bundled/gems/ruby/2.5.0/gems/byebug-10.0.0/lib/byebug/commands/condition.rb
jets-0.5.4 vendor/lambdagem/bundled/gems/ruby/2.5.0/gems/byebug-10.0.0/lib/byebug/commands/condition.rb
jets-0.5.3 vendor/lambdagem/bundled/gems/ruby/2.5.0/gems/byebug-10.0.0/lib/byebug/commands/condition.rb
jets-0.5.2 vendor/lambdagem/bundled/gems/ruby/2.5.0/gems/byebug-10.0.0/lib/byebug/commands/condition.rb
jets-0.5.1 vendor/lambdagem/bundled/gems/ruby/2.5.0/gems/byebug-10.0.0/lib/byebug/commands/condition.rb
byebug-10.0.2 lib/byebug/commands/condition.rb
byebug-10.0.1 lib/byebug/commands/condition.rb
byebug-10.0.0 lib/byebug/commands/condition.rb