JuliaInterpreter.jl
JuliaInterpreter.jl copied to clipboard
make next command less skipping
This PR makes the next command less skipping. The motivation is described here: https://github.com/JuliaDebug/Debugger.jl/issues/291.
~~My approach is to add a keyword argument (sameline
) to the maybe_next_call!
function so that it tires to find a call or a return statement without stepping forward to the next lines. If it fails, it stops at the current program counter.~~
With this patch (and a minor modification to Debugger.jl), assignments and branches are no longer skipped and now it works like debuggers of other languages (such as Python's ipdb):
julia> function foo(x)
#println(x)
y = 0
if x
y = 1
end
return y
end
foo (generic function with 1 method)
julia> @enter foo(true)
In foo(x) at REPL[1]:1
1 function foo(x)
2 #println(x)
>3 y = 0
4 if x
5 y = 1
6 end
7 return y
8 end
About to run: 0
1|debug> n
In foo(x) at REPL[1]:1
1 function foo(x)
2 #println(x)
3 y = 0
>4 if x
5 y = 1
6 end
7 return y
8 end
About to run: goto %4 if not _J2
1|debug>
In foo(x) at REPL[1]:1
1 function foo(x)
2 #println(x)
3 y = 0
4 if x
>5 y = 1
6 end
7 return y
8 end
About to run: 1
1|debug>
In foo(x) at REPL[1]:1
3 y = 0
4 if x
5 y = 1
6 end
>7 return y
8 end
About to run: return 1
1|debug>
1
About to run: goto %4 if not _J2
I don't think it is good to stop at these internal looking statements.
Although that seems to be more of a printing issue? Stopping at branch conditions makes sense to me.
How to print assignments and branch conditions is a separated problem, and it should be fixed in Debugger.jl.
NOTE: I found the current impl is completely broken. So, there is no need to check the patch at the moment.
I've changed the design: next_line!
continues to step forward until it finds a statement which is one of:
- function calls
- assignments (both local and global)
- returns
- goto nodes (both conditional and unconditional)
Here, "assignment" excludes assignments to compiler-generated variables. I'm not perfectly sure how it can be achieved, but it now checks if slotnames
corresponding to the variable is Symbol("")
or not. Any better ideas are welcomed.