Skip to content

Commit 8747603

Browse files
st0012ko1
authored andcommitted
Add command support to CheckBreakpoint
1 parent b7a2cf1 commit 8747603

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

lib/debug/breakpoint.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,9 @@ def description
317317
end
318318

319319
class CheckBreakpoint < Breakpoint
320-
def initialize expr, path
320+
def initialize expr, path, command
321321
@expr = expr.freeze
322+
@command = command
322323
@key = [:check, @expr].freeze
323324
@path = path
324325

@@ -338,7 +339,10 @@ def setup
338339
end
339340

340341
def to_s
341-
"#{generate_label("Check")} #{@expr}"
342+
s = "#{generate_label("Check")} #{@expr}"
343+
s << " pre: #{@command[1]}" if defined?(@command) && @command && @command[1]
344+
s << " do: #{@command[2]}" if defined?(@command) && @command && @command[2]
345+
s
342346
end
343347
end
344348

lib/debug/session.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,7 +1324,7 @@ def repl_add_breakpoint arg
13241324
@tc << [:breakpoint, :method, $1, $2, $3, cond, cmd, path]
13251325
return :noretry
13261326
when nil
1327-
add_check_breakpoint cond, path
1327+
add_check_breakpoint cond, path, cmd
13281328
else
13291329
@ui.puts "Unknown breakpoint format: #{arg}"
13301330
@ui.puts
@@ -1356,8 +1356,8 @@ def add_catch_breakpoint pat
13561356
add_bp bp
13571357
end
13581358

1359-
def add_check_breakpoint expr, path
1360-
bp = CheckBreakpoint.new(expr, path)
1359+
def add_check_breakpoint expr, path, command
1360+
bp = CheckBreakpoint.new(expr, path, command)
13611361
add_bp bp
13621362
end
13631363

test/debug/break_test.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,17 @@ def test_break_command_executes_do_option_and_continues_with_method_bp
460460
type 'c'
461461
end
462462
end
463+
464+
def test_break_command_executes_do_option_and_continues_with_check_bp
465+
debug_code(program) do
466+
type 'break if: s.is_a?(String) do: p "foobar"'
467+
assert_line_text(/BP - Check s\.is_a\?\(String\) do: p "foobar"/)
468+
type 'break 9'
469+
type 'c'
470+
assert_line_text(/foobar/)
471+
type 'c'
472+
end
473+
end
463474
end
464475

465476
#

0 commit comments

Comments
 (0)