Skip to content

Commit

Permalink
Add :sr debug command for stepping until return statement
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre committed Dec 21, 2022
1 parent 8e02ddb commit 5f91d47
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/commands.jl
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ Perform one "debugger" command. The keyword arguments are not used for all debug
- `:n`: advance to the next line
- `:s`: step into the next call
- `:sl` step into the last call on the current line (e.g. steps into `f` if the line is `f(g(h(x)))`).
- `:sr` step until the current function will return
- `:until`: advance the frame to line `line` if given, otherwise advance to the line after the current line
- `:c`: continue execution until termination or reaching a breakpoint
- `:finish`: finish the current frame and return to the parent
Expand Down Expand Up @@ -463,6 +464,10 @@ function debug_command(@nospecialize(recurse), frame::Frame, cmd::Symbol, rootis
end
return debug_command(recurse, frame, :s, rootistoplevel; line)
end
if cmd === :sr
maybe_next_until!(frame -> is_return(pc_expr(frame)), recurse, frame, istoplevel)
return frame, frame.pc
end
enter_generated = false
if cmd === :sg
enter_generated = true
Expand Down
22 changes: 22 additions & 0 deletions test/debug.jl
Original file line number Diff line number Diff line change
Expand Up @@ -558,3 +558,25 @@ end
frame, pc = JuliaInterpreter.debug_command(frame, :sl)
@test JuliaInterpreter.scopeof(frame).name === :h
end

@testset "step until return" begin
function f(x)
if x == 1
return 2
end
return 3
end
frame = JuliaInterpreter.enter_call(f, 1)
frame, _ = JuliaInterpreter.debug_command(frame, :sr)
@test JuliaInterpreter.get_return(frame) == f(1)
frame = JuliaInterpreter.enter_call(f, 4)
frame, _ = JuliaInterpreter.debug_command(frame, :sr)
@test JuliaInterpreter.get_return(frame) == f(4)
function g()
y = f(1) + f(2)
return y
end
frame = JuliaInterpreter.enter_call(g)
frame, _ = JuliaInterpreter.debug_command(frame, :sr)
@test JuliaInterpreter.get_return(frame) == g()
end

0 comments on commit 5f91d47

Please sign in to comment.