Skip to content

Commit 3387cae

Browse files
KristofferCtimholy
authored andcommitted
step out of wrapper calls (#197)
1 parent 634c36e commit 3387cae

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/commands.jl

+10-1
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ function changed_line!(expr, line, fls)
162162
end
163163
end
164164

165+
# Sentinel to see if the call was a wrapper call
166+
struct Wrapper end
167+
165168
"""
166169
pc = next_line!(recurse, frame, istoplevel=false)
167170
pc = next_line!(frame, istoplevel=false)
@@ -236,7 +239,7 @@ function maybe_step_through_wrapper!(@nospecialize(recurse), frame::Frame)
236239
last = stmts[end-1]
237240
isexpr(last, :(=)) && (last = last.args[2])
238241
is_kw = isa(scope, Method) && startswith(String(Base.unwrap_unionall(Base.unwrap_unionall(scope.sig).parameters[1]).name.name), "#kw")
239-
if is_kw || isexpr(last, :call) && any(x->x==Core.SlotNumber(1), last.args)
242+
if is_kw || isexpr(last, :call) && any(isequal(Core.SlotNumber(1)), last.args)
240243
# If the last expr calls #self# or passes it to an implementation method,
241244
# this is a wrapper function that we might want to step through
242245
while frame.pc != length(stmts)-1
@@ -245,6 +248,7 @@ function maybe_step_through_wrapper!(@nospecialize(recurse), frame::Frame)
245248
end
246249
ret = evaluate_call!(dummy_breakpoint, frame, last)
247250
@assert isa(ret, BreakpointRef)
251+
frame.framedata.ssavalues[frame.pc] = Wrapper()
248252
return maybe_step_through_wrapper!(recurse, callee(frame))
249253
end
250254
return frame
@@ -339,8 +343,13 @@ function maybe_reset_frame!(@nospecialize(recurse), frame::Frame, @nospecialize(
339343
frame = caller(frame)
340344
frame === nothing && return nothing
341345
frame.callee = nothing
346+
ssavals = frame.framedata.ssavalues
347+
is_wrapper = isassigned(ssavals, frame.pc) && ssavals[frame.pc] === Wrapper()
342348
maybe_assign!(frame, val)
343349
frame.pc += 1
350+
if is_wrapper
351+
return maybe_reset_frame!(recurse, frame, finish!(recurse, frame), rootistoplevel)
352+
end
344353
pc = maybe_next_call!(recurse, frame, rootistoplevel && frame.caller===nothing)
345354
return maybe_reset_frame!(recurse, frame, pc, rootistoplevel)
346355
end

test/debug.jl

+6-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ struct B{T} end
154154
frame = JuliaInterpreter.enter_call(f, 2; b = 4)
155155
fr = JuliaInterpreter.maybe_step_through_wrapper!(frame)
156156
fr, pc = debug_command(fr, :nc)
157-
fr, pc = debug_command(fr, :nc)
157+
debug_command(fr, :nc)
158158
@test get_return(frame) == 6
159159
end
160160

@@ -397,5 +397,10 @@ struct B{T} end
397397
frame, pc = debug_command(frame, :n)
398398
# Check that we are at the kw call to g
399399
@test Core.kwfunc(g) == JuliaInterpreter.@lookup frame JuliaInterpreter.pc_expr(frame).args[1]
400+
# Step into the inner g
401+
frame, pc = debug_command(frame, :s)
402+
# Finish the frame and make sure we step out of the wrapper
403+
frame, pc = debug_command(frame, :finish)
404+
@test frame.framecode.scope == @which f(2, 3)
400405
end
401406
# end

0 commit comments

Comments
 (0)