# Different behaviour during debugging and execution

**URL:** <https://discourse.julialang.org/t/different-behaviour-during-debugging-and-execution/32379>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [December 17, 2019, 12:31pm UTC](https://discourse.julialang.org/t/different-behaviour-during-debugging-and-execution/32379 "2019-12-17T12:31:23Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Volker](https://avatars.discourse-cdn.com/v4/letter/v/77aa72/32.png) [@Volker](https://discourse.julialang.org/u/Volker)\
**Post date:** [December 17, 2019, 12:31pm UTC](https://discourse.julialang.org/t/different-behaviour-during-debugging-and-execution/32379/1 "2019-12-17T12:31:23Z")

</div>

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?

```julia
using Plots
plotly()

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])]
            else
                push!(list_plots, scatter(list_data[1][:, i], list_data[1][:, j], xlabel=var_names[i], ylabel=var_names[j]))
            end
            for k in 2:length(list_data)
                scatter!(list_plots[end], list_data[k][:, i], list_data[k][:, j]);
            end
            println("($i,$j)")
        end
    end
    return list_plots
end

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

```

**Error Message during execution:**  
(1,2)  
ERROR: LoadError: UndefVarError: list\_plots not defined  
Stacktrace:  
[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  
julia\>

**Error Message during debugging:**  
julia\> Juno.@enter plot\_space([X1, X2, X3], var\_names)  
debug\> (1,2)  
(1,3)  
(2,3)  
ERROR: UndefVarError: list\_plots not defined  
Stacktrace:  
[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

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [December 17, 2019, 12:41pm UTC](https://discourse.julialang.org/t/different-behaviour-during-debugging-and-execution/32379/2 "2019-12-17T12:41:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Volker](https://avatars.discourse-cdn.com/v4/letter/v/77aa72/32.png) [@Volker](https://discourse.julialang.org/u/Volker)\
**Post date:** [December 17, 2019, 12:49pm UTC](https://discourse.julialang.org/t/different-behaviour-during-debugging-and-execution/32379/3 "2019-12-17T12:49:10Z")

</div>

Thanks. It solved the problem I had.

---

<div class="post-metadata">

**Author:** ![Kacper\_Kuryllo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kacper_kuryllo/32/11619_2.png) [@Kacper\_Kuryllo](https://discourse.julialang.org/u/Kacper_Kuryllo)\
**Post date:** [December 17, 2019, 1:36pm UTC](https://discourse.julialang.org/t/different-behaviour-during-debugging-and-execution/32379/4 "2019-12-17T13:36:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)\
**Post date:** [December 18, 2019, 5:09pm UTC](https://discourse.julialang.org/t/different-behaviour-during-debugging-and-execution/32379/5 "2019-12-18T17:09:35Z")

</div>

> [@Kacper\_Kuryllo](#):
>
> I’m curious how to fix this.

[https://github.com/JuliaDebug/JuliaInterpreter.jl/blob/5611e3c91785e3bf1ccad7f6fca20c501eb1ac38/src/interpret.jl#L424-L425](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.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [December 18, 2019, 5:20pm UTC](https://discourse.julialang.org/t/different-behaviour-during-debugging-and-execution/32379/6 "2019-12-18T17:20:05Z")

</div>

> [@tim.holy](#):
>
> [https://github.com/JuliaDebug/JuliaInterpreter.jl/blob/5611e3c91785e3bf1ccad7f6fca20c501eb1ac38/src/interpret.jl#L424-L425](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:

> <https://github.com/JuliaDebug/JuliaInterpreter.jl/blob/5611e3c91785e3bf1ccad7f6fca20c501eb1ac38/src/utils.jl#L548-L552>

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

> <https://github.com/JuliaDebug/Debugger.jl/blob/4e33178985922af7dcdb6175916c4e2e26acf0ca/src/repl.jl#L143-L151>
