Skip to content

Commit 9c5fd8f

Browse files
authored
fixes for stack inversion in Debugger.jl, also remove some unused functions (#86)
* fixes for stack inversion in Debugger.jl, also remove some unused functions * remove moved macro definition
1 parent 0a2428e commit 9c5fd8f

File tree

2 files changed

+3
-44
lines changed

2 files changed

+3
-44
lines changed

src/JuliaInterpreter.jl

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ using UUIDs
1111
using Random.DSFMT
1212
using InteractiveUtils
1313

14-
export @enter, @make_stack, @interpret, Compiled, JuliaStackFrame,
14+
export @interpret, Compiled, JuliaStackFrame,
1515
Breakpoints, breakpoint, @breakpoint, breakpoints, enable, disable, remove
1616

1717
module CompiledCalls
@@ -995,28 +995,6 @@ function enter_call(@nospecialize(finfo), @nospecialize(args...); kwargs...)
995995
return nothing
996996
end
997997

998-
function maybe_step_through_wrapper!(stack)
999-
length(stack[1].code.code.code) < 2 && return stack
1000-
last = stack[1].code.code.code[end-1]
1001-
isexpr(last, :(=)) && (last = last.args[2])
1002-
stack1 = stack[1]
1003-
is_kw = stack1.code.scope isa Method && startswith(String(Base.unwrap_unionall(Base.unwrap_unionall(stack1.code.scope.sig).parameters[1]).name.name), "#kw")
1004-
if is_kw || isexpr(last, :call) && any(x->x==SlotNumber(1), last.args)
1005-
# If the last expr calls #self# or passes it to an implementation method,
1006-
# this is a wrapper function that we might want to step through
1007-
frame = stack1
1008-
pc = frame.pc[]
1009-
while pc != JuliaProgramCounter(length(frame.code.code.code)-1)
1010-
pc = next_call!(Compiled(), frame, pc)
1011-
end
1012-
stack[1] = JuliaStackFrame(JuliaFrameCode(frame.code; wrapper=true), frame, pc)
1013-
newcall = Expr(:call, map(x->@lookup(frame, x), last.args)...)
1014-
pushfirst!(stack, enter_call_expr(newcall))
1015-
return maybe_step_through_wrapper!(stack)
1016-
end
1017-
stack
1018-
end
1019-
1020998
lower(mod, arg) = false ? expand(arg) : Meta.lower(mod, arg)
1021999

10221000
# This is a version of gen_call_with_extracted_types, except that is passes back the call expression
@@ -1069,25 +1047,6 @@ function extract_args(__module__, ex0)
10691047
* "break it down to simpler parts if possible")
10701048
end
10711049

1072-
function _make_stack(mod, arg)
1073-
args = try
1074-
extract_args(mod, arg)
1075-
catch e
1076-
return :(throw($e))
1077-
end
1078-
quote
1079-
theargs = $(esc(args))
1080-
stack = [JuliaInterpreter.enter_call_expr(Expr(:call,theargs...))]
1081-
JuliaInterpreter.maybe_step_through_wrapper!(stack)
1082-
stack[1] = JuliaInterpreter.JuliaStackFrame(stack[1], JuliaInterpreter.maybe_next_call!(Compiled(), stack[1]))
1083-
stack
1084-
end
1085-
end
1086-
1087-
macro make_stack(arg)
1088-
_make_stack(__module__, arg)
1089-
end
1090-
10911050
"""
10921051
@interpret f(args; kwargs...)
10931052

src/interpret.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -721,13 +721,13 @@ function next_line!(stack, frame, dbstack = nothing)
721721
# With splatting it can happen that we do something like ssa = tuple(#self#), _apply(ssa), which
722722
# confuses the logic here, just step into the first call that's not a builtin
723723
while true
724-
dbstack[1] = JuliaStackFrame(JuliaFrameCode(frame.code; wrapper = true), frame, pc)
724+
dbstack[end] = JuliaStackFrame(JuliaFrameCode(frame.code; wrapper = true), frame, pc)
725725
call_expr = pc_expr(frame, pc)
726726
isexpr(call_expr, :(=)) && (call_expr = call_expr.args[2])
727727
call_expr = Expr(:call, map(x->@lookup(frame, x), call_expr.args)...)
728728
new_frame = enter_call_expr(call_expr)
729729
if new_frame !== nothing
730-
pushfirst!(dbstack, new_frame)
730+
push!(dbstack, new_frame)
731731
frame = new_frame
732732
pc = frame.pc[]
733733
break

0 commit comments

Comments
 (0)