Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -567,8 +567,10 @@ The `<...>` notation means the argument.
* break and run `<command>` before stopping.
* `b[reak] ... do: <command>`
* break and run `<command>`, and continue.
* `b[reak] ... path: <path_regexp>`
* break if the triggering event's path matches <path_regexp>.
* `b[reak] ... path: </path_regexp/>`
* break if the triggering event's path matches </path_regexp/>.
* `b[reak] ... path: <path_string>`
* break if the triggering event's path matches <path_string>.
* `b[reak] if: <expr>`
* break if: `<expr>` is true at any lines.
* Note that this feature is super slow.
Expand All @@ -580,8 +582,10 @@ The `<...>` notation means the argument.
* runs `<command>` before stopping.
* `catch ... do: <command>`
* stops and run `<command>`, and continue.
* `catch ... path: <path_regexp>`
* stops if the exception is raised from a path that matches <path_regexp>.
* `catch ... path: </path_regexp/>`
* stops if the exception is raised from a path that matches </path_regexp/>.
* `catch ... path: <path_string>`
* stops if the exception is raised from a path that matches <path_string>.
* `watch @ivar`
* Stop the execution when the result of current scope's `@ivar` is changed.
* Note that this feature is super slow.
Expand All @@ -591,8 +595,10 @@ The `<...>` notation means the argument.
* runs `<command>` before stopping.
* `watch ... do: <command>`
* stops and run `<command>`, and continue.
* `watch ... path: <path_regexp>`
* stops if the triggering event's path matches <path_regexp>.
* `watch ... path: </path_regexp/>`
* stops if the triggering event's path matches </path_regexp/>.
* `watch ... path: <path_string>`
* stops if the triggering event's path matches <path_string>.
* `del[ete]`
* delete all breakpoints.
* `del[ete] <bpnum>`
Expand Down
5 changes: 4 additions & 1 deletion lib/debug/breakpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,11 @@ def duplicable?
end

def skip_path?(path)
if @path
case @path
when Regexp
!path.match?(@path)
when String
!path.include?(@path)
else
super
end
Expand Down
30 changes: 21 additions & 9 deletions lib/debug/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -509,8 +509,10 @@ def process_command line
# * break and run `<command>` before stopping.
# * `b[reak] ... do: <command>`
# * break and run `<command>`, and continue.
# * `b[reak] ... path: <path_regexp>`
# * break if the triggering event's path matches <path_regexp>.
# * `b[reak] ... path: </path_regexp/>`
# * break if the triggering event's path matches </path_regexp/>.
# * `b[reak] ... path: <path_string>`
# * break if the triggering event's path matches <path_string>.
# * `b[reak] if: <expr>`
# * break if: `<expr>` is true at any lines.
# * Note that this feature is super slow.
Expand Down Expand Up @@ -565,8 +567,10 @@ def process_command line
# * runs `<command>` before stopping.
# * `catch ... do: <command>`
# * stops and run `<command>`, and continue.
# * `catch ... path: <path_regexp>`
# * stops if the exception is raised from a path that matches <path_regexp>.
# * `catch ... path: </path_regexp/>`
# * stops if the exception is raised from a path that matches </path_regexp/>.
# * `catch ... path: <path_string>`
# * stops if the exception is raised from a path that matches <path_string>.
when 'catch'
check_postmortem

Expand All @@ -587,8 +591,10 @@ def process_command line
# * runs `<command>` before stopping.
# * `watch ... do: <command>`
# * stops and run `<command>`, and continue.
# * `watch ... path: <path_regexp>`
# * stops if the triggering event's path matches <path_regexp>.
# * `watch ... path: </path_regexp/>`
# * stops if the triggering event's path matches </path_regexp/>.
# * `watch ... path: <path_string>`
# * stops if the triggering event's path matches <path_string>.
when 'wat', 'watch'
check_postmortem

Expand Down Expand Up @@ -1271,14 +1277,20 @@ def parse_break arg
end
}
expr.default_proc = nil
expr.transform_values{|v| v.join(' ')}
expr = expr.transform_values{|v| v.join(' ')}

if (path = expr[:path]) && path =~ /\A\/(.*)\/\z/
expr[:path] = Regexp.compile($1)
end

expr
end

def repl_add_breakpoint arg
expr = parse_break arg.strip
cond = expr[:if]
cmd = ['break', expr[:pre], expr[:do]] if expr[:pre] || expr[:do]
path = Regexp.compile(expr[:path]) if expr[:path]
path = expr[:path]

case expr[:sig]
when /\A(\d+)\z/
Expand All @@ -1301,7 +1313,7 @@ def repl_add_catch_breakpoint arg
expr = parse_break arg.strip
cond = expr[:if]
cmd = ['catch', expr[:pre], expr[:do]] if expr[:pre] || expr[:do]
path = Regexp.compile(expr[:path]) if expr[:path]
path = expr[:path]

bp = CatchBreakpoint.new(expr[:sig], cond: cond, command: cmd, path: path)
add_bp bp
Expand Down
23 changes: 22 additions & 1 deletion test/debug/break_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,34 @@ def program(extra_file_path)
end

def test_break_only_stops_when_path_matches
with_extra_tempfile do |extra_file|
with_extra_tempfile("foopy") do |extra_file|
# exact path match should work in both Regexp and String form
debug_code(program(extra_file.path)) do
type "break Foo#bar path: /#{extra_file.path}/"
type 'c'
assert_line_text(/#{extra_file.path}/)
type 'c'
end

debug_code(program(extra_file.path)) do
type "break Foo#bar path: #{extra_file.path}"
type 'c'
assert_line_text(/#{extra_file.path}/)
type 'c'
end

# special characters should be treated differently in Regexp/String form
debug_code(program(extra_file.path)) do
type "break Foo#bar path: /.py/"
type 'c'
assert_line_text(/#{extra_file.path}/)
type 'c'
end

debug_code(program(extra_file.path)) do
type "break Foo#bar path: .py"
type 'c'
end
end
end

Expand Down
6 changes: 4 additions & 2 deletions test/support/test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ def remove_temp_file
@temp_file = nil
end

def with_extra_tempfile
t = Tempfile.create([SecureRandom.hex(5), '.rb']).tap do |f|
def with_extra_tempfile(*additional_words)
name = SecureRandom.hex(5) + additional_words.join

t = Tempfile.create([name, '.rb']).tap do |f|
f.write(extra_file)
f.close
end
Expand Down