Debugger.jl
Debugger.jl copied to clipboard
`n` skips assignments and branches
This behavior is surprising because it suddenly jumps to an unexpected place:
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[2]:1
1 function foo(x)
>2 println(x)
3 y = 0
4 if x
5 y = 1
6 end
About to run: (println)(true)
1|debug> n
true
In foo(x) at REPL[2]: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
This is due to https://github.com/JuliaDebug/JuliaInterpreter.jl/blob/8e7bac93fb03e98ff5bc89097995ada1518d0157/src/commands.jl#L184, which skips assignments and branches because they are neither function calls nor returns. Stopping only at function calls and returns may be a reasonable design choice, but it feels counterintuitive.
It should be possible to stop on assignments as well, you would just need to ignore the assignments to temporaries that also exist:
julia> function f()
x = 1
sin(x+x)
end
f (generic function with 1 method)
julia> ci = @code_lowered f()
CodeInfo(
1 ─ x = 1
│ %2 = x + x # <----------------- ignore
│ %3 = Main.sin(%2)
└── return %3
)
But these look quite different so that should be possible:
julia> ci.code[1] |> dump
Expr
head: Symbol =
args: Array{Any}((2,))
1: Core.SlotNumber
id: Int64 2
2: Int64 1
julia> ci.code[2] |> dump
Expr
head: Symbol call
args: Array{Any}((3,))
1: GlobalRef
mod: Module Main
name: Symbol +
2: Core.SlotNumber
id: Int64 2
3: Core.SlotNumber
id: Int64 2