Skip to content

debugger in subsession #833

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

Merged
merged 2 commits into from
Nov 25, 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
11 changes: 9 additions & 2 deletions lib/debug/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand All @@ -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|
Expand Down Expand Up @@ -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|
Expand All @@ -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

Expand Down