Skip to content

Commit

Permalink
only unlink frames if exception will not be thrown to top level (#214)
Browse files Browse the repository at this point in the history
* only unlink frames if exception will not be thrown to top level

* Update src/interpret.jl

Co-Authored-By: KristofferC <kristoffer.carlsson@chalmers.se>

* put less in try
  • Loading branch information
KristofferC committed Mar 27, 2019
1 parent d6186c6 commit 841423c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/interpret.jl
Original file line number Diff line number Diff line change
Expand Up @@ -555,16 +555,18 @@ behaviors:
"""
function handle_err(@nospecialize(recurse), frame, err)
data = frame.framedata
err_will_be_thrown_to_top_level = isempty(data.exception_frames) && !data.caller_will_catch_err
if break_on_error[]
# See if the current frame or a frame in the stack will catch this exception,
# otherwise this exception would have been thrown to the user and we should
# return a breakpoint
if isempty(data.exception_frames) && !data.caller_will_catch_err
if err_will_be_thrown_to_top_level
return BreakpointRef(frame.framecode, frame.pc, err)
end
end
if isempty(data.exception_frames)
if frame.caller !== nothing
is_root_frame = frame.caller === nothing
if !is_root_frame && !err_will_be_thrown_to_top_level
frame.caller.callee = nothing
recycle(frame)
end
Expand Down
19 changes: 18 additions & 1 deletion test/debug.jl
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ struct B{T} end
g_inner() = error()
fr = JuliaInterpreter.enter_call(f_outer)
@test_throws ErrorException debug_command(fr, :finish)
@test stacklength(fr) == 1
@test stacklength(fr) == 3

# Break on error
try
Expand Down Expand Up @@ -424,4 +424,21 @@ struct B{T} end
frame, pc = debug_command(frame, :si)
@test frame.pc == 1
end


@testset "preservation of stack when throwing to toplevel" begin
f() = "αβ"[2]
frame1 = JuliaInterpreter.enter_call(f);
err = try debug_command(frame1, :c)
catch err
err
end
try
break_on(:error)
frame2, pc = @interpret f()
@test leaf(frame2).framecode.scope === leaf(frame1).framecode.scope
finally
break_off(:error)
end
end
# end

0 comments on commit 841423c

Please sign in to comment.