Different behaviour during debugging and execution

Somehow I get a different behaviour of the following code, but I don´t know why. As you can see from the REPL output during debugging the for-loop was executed successfully, but during execution not.

Does somebody have clue why the code lead to an error and why I get different behaviour during execution and debugging?

using Plots

var_names = ["var1", "var2", "var3"]

# initialize regression matrices for training, validation and test
X1 =  rand(20, 3)
X2 =  rand(15, 3)
X3 = rand(10, 3)

function plot_space(list_data, var_names)
    num_dim = size(list_data[1], 2)
    num_plots = num_dim*(num_dim-1)/2

    for i in 1:num_dim
        for j in (i+1):num_dim
            if i==1 && j==2
                list_plots = [scatter(list_data[1][:, i], list_data[1][:, j], xlabel=var_names[i], ylabel=var_names[j])]
                push!(list_plots, scatter(list_data[1][:, i], list_data[1][:, j], xlabel=var_names[i], ylabel=var_names[j]))
            for k in 2:length(list_data)
                scatter!(list_plots[end], list_data[k][:, i], list_data[k][:, j]);
    return list_plots

list_plots = plot_space([X1, X2, X3], var_names)

Error Message during execution:
ERROR: LoadError: UndefVarError: list_plots not defined
[1] plot_space(::Array{Array{Float64,2},1}, ::Array{String,1}) at C:\Users\Volker\Julia_Files\space_analysis_test_example.jl:22
[2] top-level scope at none:0
in expression starting at C:\Users\Volker\Julia_Files\space_analysis_test_example.jl:33

Error Message during debugging:
julia> Juno.@enter plot_space([X1, X2, X3], var_names)
debug> (1,2)
ERROR: UndefVarError: list_plots not defined
[1] lookup_var at C:\Users\Volker.julia\packages\JuliaInterpreter\VHjfX\src\interpret.jl:9 [inlined]
[2] get_return(::JuliaInterpreter.Frame) at C:\Users\Volker.julia\packages\JuliaInterpreter\VHjfX\src\interpret.jl:64
[3] maybe_reset_frame!(::Any, ::JuliaInterpreter.Frame, ::Any, ::Bool) at C:\Users\Volker.julia\packages\JuliaInterpreter\VHjfX\src\commands.jl:327
[4] #debug_command#57(::Nothing, ::Function, ::Any, ::JuliaInterpreter.Frame, ::Symbol, ::Bool) at C:\Users\Volker.julia\packages\JuliaInterpreter\VHjfX\src\commands.jl:404
[5] debug_command(::Any, ::JuliaInterpreter.Frame, ::Symbol, ::Bool) at C:\Users\Volker.julia\packages\JuliaInterpreter\VHjfX\src\commands.jl:386
[6] (::getfield(Atom.JunoDebugger, Symbol("##51#53")){Bool})() at C:\Users\Volker.julia\packages\Atom\Wouyw\src\debugger\stepper.jl:144
[7] evalscope(::getfield(Atom.JunoDebugger, Symbol("##51#53")){Bool}) at C:\Users\Volker.julia\packages\Atom\Wouyw\src\debugger\stepper.jl:387
[8] startdebugging(::JuliaInterpreter.Frame, ::Bool) at C:\Users\Volker.julia\packages\Atom\Wouyw\src\debugger\stepper.jl:103
[9] top-level scope at C:\Users\Volker.julia\packages\Atom\Wouyw\src\debugger\stepper.jl:52

Not sure about the difference in debugging, but I think you should define list_plots before you enter the for loop.

1 Like

Thanks. It solved the problem I had.

I have the same issue when I use the Juno debugger. The stack trace it provides me appears to be for the interpreter and not the code being debugged. I’m curious how to fix this.

https://github.com/JuliaDebug/JuliaInterpreter.jl/blob/5611e3c91785e3bf1ccad7f6fca20c501eb1ac38/src/interpret.jl#L424-L425 should be a good start. The key would be to somehow populate a “real” stacktrace with the interpreter’s stacktrace.

I don’t think that is needed, JuliaInterpreter already has the tools to show a stacktrace for a frame:

All that should be needed is for Juno to hook into that in the same way Debugger.jl does:

1 Like