Skip to content
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

Add :sr debug command for stepping until return statement #558

Merged
merged 1 commit into from
Dec 29, 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
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