Skip to content

Commit 5bb2ff1

Browse files
committed
support debugger method in subsession
supports `debugger do: "command"` in subsession.
1 parent e506161 commit 5bb2ff1

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

lib/debug/session.rb

+9-2
Original file line numberDiff line numberDiff line change
@@ -2492,10 +2492,17 @@ def debugger pre: nil, do: nil, up_level: 0
24922492
return if !defined?(::DEBUGGER__::SESSION) || !::DEBUGGER__::SESSION.active?
24932493

24942494
if pre || (do_expr = binding.local_variable_get(:do))
2495-
cmds = ['binding.break', pre, do_expr]
2495+
cmds = ['#debugger', pre, do_expr]
24962496
end
24972497

2498-
loc = caller_locations(up_level, 1).first; ::DEBUGGER__.add_line_breakpoint loc.path, loc.lineno + 1, oneshot: true, command: cmds
2498+
if ::DEBUGGER__::SESSION.in_subsession?
2499+
if cmds
2500+
commands = [*cmds[1], *cmds[2]].map{|c| c.split(';;').join("\n")}
2501+
::DEBUGGER__::SESSION.add_preset_commands cmds[0], commands, kick: false, continue: false
2502+
end
2503+
else
2504+
loc = caller_locations(up_level, 1).first; ::DEBUGGER__.add_line_breakpoint loc.path, loc.lineno + 1, oneshot: true, command: cmds
2505+
end
24992506
self
25002507
end
25012508

test/console/debugger_method_test.rb

+14
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,20 @@ def test_breakpoint_fires_correctly
3434
type 'kill!'
3535
end
3636
end
37+
38+
def test_debugger_method_in_subsession
39+
debug_code program do
40+
type 'c'
41+
assert_line_num 3
42+
type 'eval debugger do: "p 2 ** 32"'
43+
assert_line_text('4294967296')
44+
type 'eval debugger do: "p 2 ** 32;; n;; p 2 ** 33;;"'
45+
assert_line_num 4
46+
assert_line_text('4294967296')
47+
assert_line_text('8589934592')
48+
type 'c'
49+
end
50+
end
3751
end
3852

3953
class DebuggerMethodWithPreCommandTest < DebuggerMethodTest

0 commit comments

Comments
 (0)