Skip to content

Commit b48b839

Browse files
authored
Add :sr debug command for stepping until return statement (#558)
1 parent 8fd92c2 commit b48b839

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/commands.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ Perform one "debugger" command. The keyword arguments are not used for all debug
422422
- `:n`: advance to the next line
423423
- `:s`: step into the next call
424424
- `:sl` step into the last call on the current line (e.g. steps into `f` if the line is `f(g(h(x)))`).
425+
- `:sr` step until the current function will return
425426
- `:until`: advance the frame to line `line` if given, otherwise advance to the line after the current line
426427
- `:c`: continue execution until termination or reaching a breakpoint
427428
- `:finish`: finish the current frame and return to the parent
@@ -463,6 +464,10 @@ function debug_command(@nospecialize(recurse), frame::Frame, cmd::Symbol, rootis
463464
end
464465
return debug_command(recurse, frame, :s, rootistoplevel; line)
465466
end
467+
if cmd === :sr
468+
maybe_next_until!(frame -> is_return(pc_expr(frame)), recurse, frame, istoplevel)
469+
return frame, frame.pc
470+
end
466471
enter_generated = false
467472
if cmd === :sg
468473
enter_generated = true

test/debug.jl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,3 +558,25 @@ end
558558
frame, pc = JuliaInterpreter.debug_command(frame, :sl)
559559
@test JuliaInterpreter.scopeof(frame).name === :h
560560
end
561+
562+
@testset "step until return" begin
563+
function f(x)
564+
if x == 1
565+
return 2
566+
end
567+
return 3
568+
end
569+
frame = JuliaInterpreter.enter_call(f, 1)
570+
frame, _ = JuliaInterpreter.debug_command(frame, :sr)
571+
@test JuliaInterpreter.get_return(frame) == f(1)
572+
frame = JuliaInterpreter.enter_call(f, 4)
573+
frame, _ = JuliaInterpreter.debug_command(frame, :sr)
574+
@test JuliaInterpreter.get_return(frame) == f(4)
575+
function g()
576+
y = f(1) + f(2)
577+
return y
578+
end
579+
frame = JuliaInterpreter.enter_call(g)
580+
frame, _ = JuliaInterpreter.debug_command(frame, :sr)
581+
@test JuliaInterpreter.get_return(frame) == g()
582+
end

0 commit comments

Comments
 (0)