Debugger.jl: Access object `%2`

I am trying to debug some code using Debug.jl:

In _pullback(ctx, f, args) at /home/gkraemer/.julia/packages/Zygote/YeCEW/src/compiler/interface2.jl:7
  1  1 ─       $(Expr(:meta, :inline))
  2  │   %2  = (ZygoteRules._pullback)(ctx, Zygote.unwrap, :(Main.sr), Main.sr)
> 3  │   %3  = (getindex)(%2, 1)
  4  │   %4  = (getindex)(%2, 2)
  5  │   %5  = (ZygoteRules._pullback)(ctx, loss, %3)
  6  │   %6  = (getindex)(%5, 1)
  7  │   %7  = (getindex)(%5, 2)
  8  │   %8  = (tuple)(%4, %7)
  9  │   %9  = (typeof(∂(#18)))(%8)
 10  │   %10 = (tuple)(%6, %9)
 11  └──       return %10

About to run: <(getindex)((VBagg.Bags{Float64}(VBagg.Bag{Float64}[VBagg.Bag{Float64}([0.9323391769092779 0.056934747...>
1|julia> %2
ERROR: syntax: "%" is not a unary operator

I want to know how %2 looks like, because the code will fail when executing line 4. In normal code I can just press ` and get an interactive Julia prompt to explore local variables. This doesn’t work in the present case. How can I take a look at %2?

I am not sure Debugger.jl is set up to support this. If you can create all the arguments to _pullback, you could manually create a frame with JuliaInterpreter.enter_frame and then issue debugcommands until you’ve passed statement 2. Then you can look up the value in frame.framedata.ssavlues.

For more info, see the docs.

Yeah, we should add syntax in Debugger.jl for querying SSAvalues. Any suggestions?

Debugger seems to get the string and then do its own parsing. Could we just check for a first non-whitespace character of %?

I thought it would be cool to include it in the standard julia evaluation mode (which uses the Julia parser) so you could do sin(a * %2 * 5) for example but that runs into % not being an infix operator. Hmm…

1 Like

var"%2"? That’s what I’d try to do (as a user) first.

2 Likes

Yeah, that is a good idea, I’ll try it out.

https://github.com/JuliaDebug/JuliaInterpreter.jl/pull/395 has a PR with the var syntax:

1|debug>
In sin(x) at special/trig.jl:30
  3  │          Core.NewvarNode(:(n))
  4  │          absx = (abs)(x)
  5  │    %5  = absx
  6  │    %6  = ($(Expr(:static_parameter, 1)))(π)
> 7  │    %7  = (/)(%6, 4)
  8  │    %8  = (<)(%5, %7)
  9  └───       goto #6 if not %8
 10  2 ── %10 = absx
 11  │    %11 = (eps)($(Expr(:static_parameter, 1)))

About to run: (/)(3.141592653589793, 4)
1|julia> var"%5", var"%6"
(2.0, 3.141592653589793)
6 Likes