Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support command on CheckBreakpoint #495

Merged
merged 4 commits into from
Mar 20, 2022
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
45 changes: 18 additions & 27 deletions lib/debug/breakpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ class Breakpoint

attr_reader :key

def initialize do_enable = true
def initialize cond, command, path, do_enable: true
@deleted = false

@cond = cond
@command = command
@path = path

setup
enable if do_enable
end
Expand Down Expand Up @@ -111,7 +115,7 @@ def initialize iseq, events, oneshot: false
@oneshot = oneshot
@key = [:iseq, @iseq.path, @iseq.first_lineno].freeze

super()
super(nil, nil, nil)
end

def setup
Expand All @@ -130,20 +134,17 @@ class LineBreakpoint < Breakpoint
attr_reader :path, :line, :iseq

def initialize path, line, cond: nil, oneshot: false, hook_call: true, command: nil
@path = path
@line = line
@cond = cond
@oneshot = oneshot
@hook_call = hook_call
@command = command
@pending = false

@iseq = nil
@type = nil

@key = [@path, @line].freeze
@key = [path, @line].freeze

super()
super(cond, command, path)

try_activate
@pending = !@iseq
Expand Down Expand Up @@ -280,11 +281,7 @@ def initialize pat, cond: nil, command: nil, path: nil
@key = [:catch, @pat].freeze
@last_exc = nil

@cond = cond
@command = command
@path = path

super()
super(cond, command, path)
end

def setup
Expand Down Expand Up @@ -317,27 +314,27 @@ def description
end

class CheckBreakpoint < Breakpoint
def initialize expr, path
@expr = expr.freeze
@key = [:check, @expr].freeze
@path = path
def initialize cond:, command: nil, path: nil
@key = [:check, cond].freeze

super()
super(cond, command, path)
end

def setup
@tp = TracePoint.new(:line){|tp|
next if ThreadClient.current.management?
next if skip_path?(tp.path)

if safe_eval tp.binding, @expr
if safe_eval tp.binding, @cond
suspend
end
}
end

def to_s
"#{generate_label("Check")} #{@expr}"
s = "#{generate_label("Check")}"
s += super
s
end
end

Expand All @@ -349,10 +346,7 @@ def initialize ivar, object, current, cond: nil, command: nil, path: nil

@current = current

@cond = cond
@command = command
@path = path
super()
super(cond, command, path)
end

def watch_eval(tp)
Expand Down Expand Up @@ -403,13 +397,10 @@ def initialize b, klass_name, op, method_name, cond: nil, command: nil, path: ni

@klass = nil
@method = nil
@cond = cond
@cond_class = nil
@command = command
@path = path
@key = "#{klass_name}#{op}#{method_name}".freeze

super(false)
super(cond, command, path, do_enable: false)
end

def setup
Expand Down
6 changes: 3 additions & 3 deletions lib/debug/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1327,7 +1327,7 @@ def repl_add_breakpoint arg
@tc << [:breakpoint, :method, $1, $2, $3, cond, cmd, path]
return :noretry
when nil
add_check_breakpoint cond, path
add_check_breakpoint cond, path, cmd
else
@ui.puts "Unknown breakpoint format: #{arg}"
@ui.puts
Expand Down Expand Up @@ -1359,8 +1359,8 @@ def add_catch_breakpoint pat
add_bp bp
end

def add_check_breakpoint expr, path
bp = CheckBreakpoint.new(expr, path)
def add_check_breakpoint cond, path, command
bp = CheckBreakpoint.new(cond: cond, path: path, command: command)
add_bp bp
end

Expand Down
13 changes: 12 additions & 1 deletion test/debug/break_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,17 @@ def test_break_command_executes_do_option_and_continues_with_method_bp
type 'c'
end
end

def test_break_command_executes_do_option_and_continues_with_check_bp
debug_code(program) do
type 'break if: s.is_a?(String) do: p "foobar"'
assert_line_text(/BP - Check if: s\.is_a\?\(String\) do: p "foobar"/)
type 'break 9'
type 'c'
assert_line_text(/foobar/)
type 'c'
end
end
end

#
Expand Down Expand Up @@ -643,7 +654,7 @@ def program
def test_conditional_breakpoint_stops_if_condition_is_true
debug_code program do
type 'break if: a == 4'
assert_line_text(/#0 BP - Check a == 4/)
assert_line_text(/#0 BP - Check if: a == 4/)
type 'c'
assert_line_num 4
type 'c'
Expand Down