Skip to content

Commit cdc38ca

Browse files
committed
Fix breakpoints' path option
It should distinguish if path is a string or a regexp and match them with the path in different ways.
1 parent 804ed8d commit cdc38ca

File tree

4 files changed

+39
-7
lines changed

4 files changed

+39
-7
lines changed

lib/debug/breakpoint.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,11 @@ def duplicable?
8282
end
8383

8484
def skip_path?(path)
85-
if @path
85+
case @path
86+
when Regexp
8687
!path.match?(@path)
88+
when String
89+
!path.include?(@path)
8790
else
8891
super
8992
end

lib/debug/session.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,14 +1271,20 @@ def parse_break arg
12711271
end
12721272
}
12731273
expr.default_proc = nil
1274-
expr.transform_values{|v| v.join(' ')}
1274+
expr = expr.transform_values{|v| v.join(' ')}
1275+
1276+
if (path = expr[:path]) && path =~ /\A\/(.*)\/\z/
1277+
expr[:path] = Regexp.compile($1)
1278+
end
1279+
1280+
expr
12751281
end
12761282

12771283
def repl_add_breakpoint arg
12781284
expr = parse_break arg.strip
12791285
cond = expr[:if]
12801286
cmd = ['break', expr[:pre], expr[:do]] if expr[:pre] || expr[:do]
1281-
path = Regexp.compile(expr[:path]) if expr[:path]
1287+
path = expr[:path]
12821288

12831289
case expr[:sig]
12841290
when /\A(\d+)\z/
@@ -1301,7 +1307,7 @@ def repl_add_catch_breakpoint arg
13011307
expr = parse_break arg.strip
13021308
cond = expr[:if]
13031309
cmd = ['catch', expr[:pre], expr[:do]] if expr[:pre] || expr[:do]
1304-
path = Regexp.compile(expr[:path]) if expr[:path]
1310+
path = expr[:path]
13051311

13061312
bp = CatchBreakpoint.new(expr[:sig], cond: cond, command: cmd, path: path)
13071313
add_bp bp

test/debug/break_test.rb

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,13 +224,34 @@ def program(extra_file_path)
224224
end
225225

226226
def test_break_only_stops_when_path_matches
227-
with_extra_tempfile do |extra_file|
227+
with_extra_tempfile("foopy") do |extra_file|
228+
# exact path match should work in both Regexp and String form
229+
debug_code(program(extra_file.path)) do
230+
type "break Foo#bar path: /#{extra_file.path}/"
231+
type 'c'
232+
assert_line_text(/#{extra_file.path}/)
233+
type 'c'
234+
end
235+
228236
debug_code(program(extra_file.path)) do
229237
type "break Foo#bar path: #{extra_file.path}"
230238
type 'c'
231239
assert_line_text(/#{extra_file.path}/)
232240
type 'c'
233241
end
242+
243+
# special characters should be treated differently in Regexp/String form
244+
debug_code(program(extra_file.path)) do
245+
type "break Foo#bar path: /.py/"
246+
type 'c'
247+
assert_line_text(/#{extra_file.path}/)
248+
type 'c'
249+
end
250+
251+
debug_code(program(extra_file.path)) do
252+
type "break Foo#bar path: .py"
253+
type 'c'
254+
end
234255
end
235256
end
236257

test/support/test_case.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ def remove_temp_file
2727
@temp_file = nil
2828
end
2929

30-
def with_extra_tempfile
31-
t = Tempfile.create([SecureRandom.hex(5), '.rb']).tap do |f|
30+
def with_extra_tempfile(*additional_words)
31+
name = SecureRandom.hex(5) + additional_words.join
32+
33+
t = Tempfile.create([name, '.rb']).tap do |f|
3234
f.write(extra_file)
3335
f.close
3436
end

0 commit comments

Comments
 (0)