# How to proper debug Julia?

**URL:** <https://discourse.julialang.org/t/how-to-proper-debug-julia/31234>\
**Category:** General Usage\
**Tags:** question\
**Created:** [November 18, 2019, 7:58pm UTC](https://discourse.julialang.org/t/how-to-proper-debug-julia/31234 "2019-11-18T19:58:08Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![adrpo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adrpo/32/11384_2.png) [@adrpo](https://discourse.julialang.org/u/adrpo)\
**Post date:** [November 18, 2019, 7:58pm UTC](https://discourse.julialang.org/t/how-to-proper-debug-julia/31234/1 "2019-11-18T19:58:08Z")

</div>

Hi all,

I have some code that works fine in Atom/Juno debugger but when I run it directly in Julia it goes in some sort of cycle and spins forever. Any ideas on how to debug such a thing? I have tried to attach to the julia process with gdb and look at the stack but that does’t help me too much. See one of the traces below, maybe somebody has some idea what’s going on.  
I also have looked a the thread stack using Process Explorer and it seems to be doing some sort of type checking.

The code was translated automatically from a type safe language and then hand changed a bit to make it work, so it basically has type definitions for everything. Also, large structures are send around to most of the functions. As far as I can tell it seems to be some sort of type conversion going on but I don’t quite know where it comes from using the debugger tools available. As I said, it works fine in Juno so I can’t debug using that.

You can find two of the gdb traces here (I could not paste them here as it complained about post size):

> **[(gdb) Attaching to program \`E:\\bin\\julia\\bin\\julia.exe', process 16180\[New Thr...](https://pastebin.com/9LXnUTAP)**
>
> Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.

> **[(gdb) Attaching to program \`E:\\bin\\julia\\bin\\julia.exe', process 16180\[New Thr...](https://pastebin.com/MLEGSpFs)**
>
> Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.

Cheers,  
Adrian Pop/

---

<div class="post-metadata">

**Author:** ![pixel27](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pixel27/32/8902_2.png) [@pixel27](https://discourse.julialang.org/u/pixel27)\
**Post date:** [November 20, 2019, 2:05pm UTC](https://discourse.julialang.org/t/how-to-proper-debug-julia/31234/2 "2019-11-20T14:05:03Z")

</div>

When I can’t reproduce things in the debugger I usually fall back on logging. If you know the area that appears to be hanging add lots of logging there and reproduce.

---

<div class="post-metadata">

**Author:** ![adrpo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adrpo/32/11384_2.png) [@adrpo](https://discourse.julialang.org/u/adrpo)\
**Post date:** [November 20, 2019, 2:41pm UTC](https://discourse.julialang.org/t/how-to-proper-debug-julia/31234/3 "2019-11-20T14:41:01Z")

</div>

The problem is that not even printouts are shown. When I call the main function it just hangs in there.

---

<div class="post-metadata">

**Author:** ![pixel27](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pixel27/32/8902_2.png) [@pixel27](https://discourse.julialang.org/u/pixel27)\
**Post date:** [November 20, 2019, 7:45pm UTC](https://discourse.julialang.org/t/how-to-proper-debug-julia/31234/4 "2019-11-20T19:45:45Z")

</div>

I wonder if it’s a compile issue…if you call:

```julia
   precompile(main, (arg types))

```

Updated for your main function along with the argument types…does that return?

---

<div class="post-metadata">

**Author:** ![adrpo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adrpo/32/11384_2.png) [@adrpo](https://discourse.julialang.org/u/adrpo)\
**Post date:** [November 21, 2019, 3:39pm UTC](https://discourse.julialang.org/t/how-to-proper-debug-julia/31234/5 "2019-11-21T15:39:09Z")

</div>

That seems to be the issue, is stuck at the call:

```julia
julia> methods(Main.OMCompiler.run)
# 1 method for generic function "run":
[1] run() in Main.OMCompiler at C:\home\adrpo33\dev\julia\OMCompiler.jl\src\Main\all.jl:62

julia> precompile(Main.OMCompiler.run, ())

```

Any idea how to debug this one?  
It just sits like that for hours and just gathers memory, I killed it at 5GB last time.

I do:

> include(“src/Main/all.jl”)  
> and that precompiles for about 15 minutes and then I call that.

You can see the code here:

> **[GitHub - JKRT/OLD\_OMFrontend.jl: A Julia based Modelica Compiler. Stay tuned...](https://github.com/JKRT/OLD_OMFrontend.jl)**
>
> A Julia based Modelica Compiler. Stay tuned people! (Experimental) - GitHub - JKRT/OLD\_OMFrontend.jl: A Julia based Modelica Compiler. Stay tuned people! (Experimental)

Truth is that we have a lot of recursive module imports, maybe that’s the issue.

---

<div class="post-metadata">

**Author:** ![tshort](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tshort/32/43_2.png) [@tshort](https://discourse.julialang.org/u/tshort)\
**Post date:** [November 21, 2019, 4:30pm UTC](https://discourse.julialang.org/t/how-to-proper-debug-julia/31234/6 "2019-11-21T16:30:55Z")

</div>

That is a lot of nested Modules–the Modelica background is obvious 🤪.

I tried installing it by dev’ing lots of packages, but I got stuck when it couldn’t find the Global package.

---

<div class="post-metadata">

**Author:** ![adrpo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adrpo/32/11384_2.png) [@adrpo](https://discourse.julialang.org/u/adrpo)\
**Post date:** [November 21, 2019, 7:31pm UTC](https://discourse.julialang.org/t/how-to-proper-debug-julia/31234/7 "2019-11-21T19:31:27Z")

</div>

Global.jl is inside OMCompiler/src/Frontend/Global.jl  
I only dev:  
[https://github.com/OpenModelica/MetaModelica.jl](https://github.com/OpenModelica/MetaModelica.jl)  
[https://github.com/OpenModelica/ImmutableList.jl](https://github.com/OpenModelica/ImmutableList.jl)  
[https://github.com/JKRT/ListUtil.jl](https://github.com/JKRT/ListUtil.jl)  
[https://github.com/adrpo/OpenModelicaParser.jl](https://github.com/adrpo/OpenModelicaParser.jl) (the parser only has the dlls for Windows, we could do Linux as well if needed)  
And then just include the stuff in OMCompiler.jl.

We are working on fixing some of the recursive imports, hopefully this will be better soon.
