I am using the Parameters package v0.12.0 by @mauro3 in my numerical simulations. While using the Juno debugger in JuliaPro, I noticed that the debugger stops when reaching a call to Parameters’ @unpack
. Below is a MWE:
# MWE.jl
using Parameters
@with_kw struct A
a::Int = 6
end
function testA(varA::A)
@unpack a = varA
# a = varA.a
print(a, '\n')
end
Everything is working fine when running
julia> include("MWE.jl")
julia> testA(A())
julia> Juno.@enter testA(A())
up to the last line. This debugging statement opens @unpack
in debug mode (Parameters.jl, stopping at line 751: $kdblock
), which becomes annoying when debugging a big code with several such calls. Note that the same MWE where @unpack a = varA
is replaced by a = varA.a
behaves fine (but it’s less convenient).
Question: is there a way to avoid that the debugger stops at @unpack
?
I am using JuliaPro 1.4.1-1 (Julia 1.4.1, Atom 1.45.0, julia-client 0.12.4) on Windows 10, but observed the same behavior on previous versions too.
Edit: Similar behavior with the @unpack
macro from UnPack.jl, by writing using UnPack
and
# MWE.jl [...]
UnPack.@unpack a = varA
Edit: Also same behavior with a breakpoint located at print(a, '\n')
, and with the command
julia> Juno.@run testA(A())
That is odd. But I’m not using Juno, so I cannot easily help here. One thing you should try is whether this also happens when using @unpack
directly from UnPack.jl
.
2 Likes
The Juno debugger does step into the expanded macro, yes. This is by design.
I’d suggest setting breakpoints at wherever you want to actually stop and start stepping through the code from there (also need to use Juno.@run testA(A())
or the Debug: Run Block
command).
2 Likes
Thanks for support. The MWE
# MWE.jl
using Parameters
using UnPack
@with_kw struct A
a::Int = 6
end
function testA(varA::A)
UnPack.@unpack a = varA
# a = varA.a
print(a, '\n')
end
has the same behavior (Juno debugger steps into the macro @unpack
from UnPack.jl and stops at the same line). Might be a Juno feature.
Thanks for support. I tried Juno.@run testA(A())
with a breakpoint at the line print(a, '\n')
, but the behavior is the same. Juno debugger steps into Parameters.jl, and is stuck in that source file. Continuing debug session works, but then breakpoints in MWE.jl are ignored. (Everything is still working fine when @unpack a = varA
is replaced by a = varA.a
– which are supposed to behave in a similar way).
Ah, true. The problem is that the @unpack
macro expands to ~12 lines of code, so breakpoints on the next few lines actually stop you in @unpack
.
The best solution right now is probably to use JuliaInterpreter
s @bp
macro like
function testA(varA::A)
@unpack a = varA
@bp
println(a)
end
Juno.@run testA(A())
3 Likes
Yes, using @bp
allows to continue debugging after Juno’s debugger stepped into @unpack
. Thanks!
You can continue debugging even when you are in @unpack
by doing a few (or more) Step Expr
steps.