-
-
Notifications
You must be signed in to change notification settings - Fork 330
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9854ec0
commit e2039ed
Showing
5 changed files
with
179 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "../../command" | ||
require_relative "../../helpers/parse" | ||
|
||
module Byebug | ||
# | ||
# Reopens the +condition+ command to define the +expression+ subcommand | ||
# | ||
class ConditionCommand < Command | ||
# | ||
# Information about arguments of the current method/block | ||
# | ||
class ExpressionCommand < Command | ||
include Helpers::ParseHelper | ||
|
||
self.allow_in_post_mortem = true | ||
|
||
def self.regexp | ||
/ | ||
^\s* | ||
(?:expr(?:ession)?\s+)? | ||
(?: | ||
(?<number>\d+) # breakpoint number | ||
(?:\s+(?<expression>.*))? # conditional expression | ||
)? | ||
\s*$ | ||
/x | ||
end | ||
|
||
def self.description | ||
<<-DESCRIPTION | ||
cond[ition] [expr[ession]] <n> [<expr>] | ||
#{short_description} | ||
Set or unset the conditional expression of breakpoint number <n>. If a | ||
conditional expression is set, the breakpoint will not break unless the | ||
expression evaluates to true. If <expr> is omitted, the condition | ||
expression is removed. | ||
DESCRIPTION | ||
end | ||
|
||
def self.short_description | ||
"Set a conditional expression on a breakpoint" | ||
end | ||
|
||
def execute | ||
return puts(help) unless @match && @match[:number] | ||
|
||
breakpoints = Byebug.breakpoints.sort_by(&:id) | ||
return errmsg(pr("condition.errors.no_breakpoints")) if breakpoints.empty? | ||
|
||
pos, err = get_int(@match[:number], "Condition", 1) | ||
return errmsg(err) if err | ||
|
||
breakpoint = breakpoints.find { |b| b.id == pos } | ||
return errmsg(pr("break.errors.no_breakpoint")) unless breakpoint | ||
|
||
return errmsg(pr("break.errors.not_changed", expr: @match[:expression])) unless syntax_valid?(@match[:expression]) | ||
|
||
breakpoint.expr = @match[:expression] | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "../../command" | ||
require_relative "../../helpers/parse" | ||
|
||
module Byebug | ||
# | ||
# Reopens the +condition+ command to define the +expression+ subcommand | ||
# | ||
class ConditionCommand < Command | ||
# | ||
# Information about arguments of the current method/block | ||
# | ||
class HitCountCommand < Command | ||
include Helpers::ParseHelper | ||
|
||
self.allow_in_post_mortem = true | ||
|
||
def self.regexp | ||
/ | ||
^\s* | ||
hit(?:\s?count)? | ||
(?:\s+ | ||
(?<number>\d+) # breakpoint number | ||
(?:\s+ | ||
(?<operation>[\w><=%]+) # hit condition | ||
\s+(?<value>\d+) # value | ||
)? | ||
)? | ||
\s*$ | ||
/x | ||
end | ||
|
||
def self.description | ||
<<-DESCRIPTION | ||
cond[ition] hit[[ ]count] <n> [<op> <value>] | ||
#{short_description} | ||
Set or unset the hit condition of breakpoint number <n>. If a hit | ||
condition is set, the breakpoint will not break unless its hit count | ||
meets the hit condition. If <op> <value> is omitted, the condition | ||
expression is removed. <op> can be gt, ge, eq, mod, or the symbolic | ||
equivalent. | ||
DESCRIPTION | ||
end | ||
|
||
def self.short_description | ||
"Set a hit condition on a breakpoint" | ||
end | ||
|
||
def execute | ||
return puts(help) unless @match && @match[:number] | ||
|
||
breakpoints = Byebug.breakpoints.sort_by(&:id) | ||
return errmsg(pr("condition.errors.no_breakpoints")) if breakpoints.empty? | ||
|
||
pos, err = get_int(@match[:number], "Condition", 1) | ||
return errmsg(err) if err | ||
|
||
breakpoint = breakpoints.find { |b| b.id == pos } | ||
return errmsg(pr("break.errors.no_breakpoint")) unless breakpoint | ||
|
||
v = @match[:value].to_i | ||
case @match[:operation] | ||
when nil | ||
breakpoint.hit_condition = nil | ||
|
||
when 'gt', '>' | ||
breakpoint.hit_condition = :greater_or_equal | ||
breakpoint.hit_value = v + 1 | ||
when 'ge', '>=' | ||
breakpoint.hit_condition = :greater_or_equal | ||
breakpoint.hit_value = v | ||
when 'eq', '=', '==', '===' | ||
breakpoint.hit_condition = :equal | ||
breakpoint.hit_value = v | ||
when 'mod', '%' | ||
breakpoint.hit_condition = :modulo | ||
breakpoint.hit_value = v | ||
else | ||
return errmsg(pr("break.errors.hit_condition", cond: @match[:operation])) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters