diff --git a/lib/debug/session.rb b/lib/debug/session.rb index b83479390..3fbb696a9 100644 --- a/lib/debug/session.rb +++ b/lib/debug/session.rb @@ -2492,10 +2492,17 @@ def debugger pre: nil, do: nil, up_level: 0 return if !defined?(::DEBUGGER__::SESSION) || !::DEBUGGER__::SESSION.active? if pre || (do_expr = binding.local_variable_get(:do)) - cmds = ['binding.break', pre, do_expr] + cmds = ['#debugger', pre, do_expr] end - loc = caller_locations(up_level, 1).first; ::DEBUGGER__.add_line_breakpoint loc.path, loc.lineno + 1, oneshot: true, command: cmds + if ::DEBUGGER__::SESSION.in_subsession? + if cmds + commands = [*cmds[1], *cmds[2]].map{|c| c.split(';;').join("\n")} + ::DEBUGGER__::SESSION.add_preset_commands cmds[0], commands, kick: false, continue: false + end + else + loc = caller_locations(up_level, 1).first; ::DEBUGGER__.add_line_breakpoint loc.path, loc.lineno + 1, oneshot: true, command: cmds + end self end diff --git a/test/console/debug_statement_test.rb b/test/console/debugger_method_test.rb similarity index 69% rename from test/console/debug_statement_test.rb rename to test/console/debugger_method_test.rb index 54fe466f3..8cc32198f 100644 --- a/test/console/debug_statement_test.rb +++ b/test/console/debugger_method_test.rb @@ -3,23 +3,23 @@ require_relative '../support/console_test_case' module DEBUGGER__ - class DebugStatementTest < ConsoleTestCase - STATEMENT_PLACE_HOLDER = "__BREAK_STATEMENT__" - SUPPORTED_DEBUG_STATEMENTS = %w(binding.break binding.b debugger).freeze + class DebuggerMethodTest < ConsoleTestCase + METHOD_PLACE_HOLDER = "__BREAK_METHOD__" + SUPPORTED_DEBUG_METHODS = %w(debugger binding.break binding.b).freeze def debug_code(program) - SUPPORTED_DEBUG_STATEMENTS.each do |statement| - super(program.gsub(STATEMENT_PLACE_HOLDER, statement)) + SUPPORTED_DEBUG_METHODS.each do |mid| + super(program.gsub(METHOD_PLACE_HOLDER, mid)) end end end - class BasicTest < DebugStatementTest + class DebuggerMethodBasicTest < DebuggerMethodTest def program <<~RUBY 1| class Foo 2| def bar - 3| #{STATEMENT_PLACE_HOLDER} + 3| #{METHOD_PLACE_HOLDER} 4| end 5| end 6| @@ -34,19 +34,33 @@ def test_breakpoint_fires_correctly type 'kill!' end end + + def test_debugger_method_in_subsession + debug_code program do + type 'c' + assert_line_num 3 + type 'eval debugger do: "p 2 ** 32"' + assert_line_text('4294967296') + type 'eval debugger do: "p 2 ** 32;; n;; p 2 ** 33;;"' + assert_line_num 4 + assert_line_text('4294967296') + assert_line_text('8589934592') + type 'c' + end + end end - class DebugStatementWithPreCommandTest < DebugStatementTest + class DebuggerMethodWithPreCommandTest < DebuggerMethodTest def program <<~RUBY 1| class Foo 2| def bar - 3| #{STATEMENT_PLACE_HOLDER}(pre: "p 'aaaaa'") + 3| #{METHOD_PLACE_HOLDER}(pre: "p 'aaaaa'") 4| baz 5| end 6| 7| def baz - 8| #{STATEMENT_PLACE_HOLDER} + 8| #{METHOD_PLACE_HOLDER} 9| end 10| end 11| @@ -77,17 +91,17 @@ def test_debugger_doesnt_complain_about_duplicated_breakpoint end end - class DebugStatementWithDoCommandTest < DebugStatementTest + class DebuggerMethodWithDoCommandTest < DebuggerMethodTest def program <<~RUBY 1| class Foo 2| def bar - 3| #{STATEMENT_PLACE_HOLDER}(do: "p 'aaaaa'") + 3| #{METHOD_PLACE_HOLDER}(do: "p 'aaaaa'") 4| baz 5| end 6| 7| def baz - 8| #{STATEMENT_PLACE_HOLDER} + 8| #{METHOD_PLACE_HOLDER} 9| end 10| end 11| @@ -113,18 +127,18 @@ def test_debugger_doesnt_complain_about_duplicated_breakpoint end end - class ThreadManagementTest < DebugStatementTest + class ThreadManagementTest < DebuggerMethodTest def program <<~RUBY 1| Thread.new do - 2| #{STATEMENT_PLACE_HOLDER}(do: "p 'foo' + 'bar'") + 2| #{METHOD_PLACE_HOLDER}(do: "p 'foo' + 'bar'") 3| end.join 4| 5| Thread.new do - 6| #{STATEMENT_PLACE_HOLDER}(do: "p 'bar' + 'baz'") + 6| #{METHOD_PLACE_HOLDER}(do: "p 'bar' + 'baz'") 7| end.join 8| - 9| #{STATEMENT_PLACE_HOLDER} + 9| #{METHOD_PLACE_HOLDER} RUBY end