# Debugging in Julia for newbies

**URL:** <https://discourse.julialang.org/t/debugging-in-julia-for-newbies/24481>\
**Category:** New to Julia\
**Created:** [May 22, 2019, 3:16pm UTC](https://discourse.julialang.org/t/debugging-in-julia-for-newbies/24481 "2019-05-22T15:16:38Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![sbacelar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sbacelar/32/4359_2.png) [@sbacelar](https://discourse.julialang.org/u/sbacelar)\
**Post date:** [May 22, 2019, 3:16pm UTC](https://discourse.julialang.org/t/debugging-in-julia-for-newbies/24481/1 "2019-05-22T15:16:39Z")

</div>

Is there any tutorial about how to use a debugger in Julia for newbies (using Juno, VsCode, etc.)? Maybe something in video, similar to [Intro to Julia](https://www.youtube.com/watch?v=8h8rQyEpiZA&t).

---

<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:** [May 22, 2019, 8:57pm UTC](https://discourse.julialang.org/t/debugging-in-julia-for-newbies/24481/2 "2019-05-22T20:57:40Z")

</div>

[Debugging · Juno Documentation](http://docs.junolab.org/latest/man/debugging/) is pretty close to a tutorial. Be sure you actually try the examples you can see in the screenshots.

---

<div class="post-metadata">

**Author:** ![jlperla](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jlperla/32/34332_2.png) [@jlperla](https://discourse.julialang.org/u/jlperla)\
**Post date:** [May 22, 2019, 9:02pm UTC](https://discourse.julialang.org/t/debugging-in-julia-for-newbies/24481/3 "2019-05-22T21:02:21Z")

</div>

Is there any “idiot-proof” installation guide to support that tutorials? i.e. what exactly should I put in the `startup.jl`, do I have to `using` a particular package each time I want to debug, etc.

---

<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:** [May 22, 2019, 9:14pm UTC](https://discourse.julialang.org/t/debugging-in-julia-for-newbies/24481/4 "2019-05-22T21:14:20Z")

</div>

I’m not sure there’s anything you have to do—if it doesn’t work for you without some magical step, it would be great to spell it out (please submit PR [here](https://github.com/JunoLab/JunoDocs.jl/blob/master/docs/src/man/debugging.md)). Upon reflection, it’s possible/likely that you need to be `using Revise` or configure it [to run automatically](https://timholy.github.io/Revise.jl/dev/config/#Using-Revise-by-default-1). I always have it running so I may have not even considered that step. Try it and see! (and if something special is required, please submit that PR…)

---

<div class="post-metadata">

**Author:** ![jlperla](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jlperla/32/34332_2.png) [@jlperla](https://discourse.julialang.org/u/jlperla)\
**Post date:** [May 22, 2019, 9:22pm UTC](https://discourse.julialang.org/t/debugging-in-julia-for-newbies/24481/5 "2019-05-22T21:22:41Z")

</div>

OK, so as far as we know, installing and using Revise is the only thing necessary? No `using Debugger` in the startup or prior to trying to debug is needed?

---

<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:** [May 22, 2019, 10:54pm UTC](https://discourse.julialang.org/t/debugging-in-julia-for-newbies/24481/6 "2019-05-22T22:54:45Z")

</div>

`using Debugger` is definitely not necessary.

Whether Revise is needed, I’m not sure. Perhaps try working through the tutorial without it, and report back?

---

<div class="post-metadata">

**Author:** ![Balinus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/balinus/32/243_2.png) [@Balinus](https://discourse.julialang.org/u/Balinus)\
**Post date:** [May 23, 2019, 1:25am UTC](https://discourse.julialang.org/t/debugging-in-julia-for-newbies/24481/7 "2019-05-23T01:25:18Z")

</div>

I can confirm that the example works without Revise in `startup.jl`.

---

<div class="post-metadata">

**Author:** ![tk3369](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tk3369/32/2824_2.png) [@tk3369](https://discourse.julialang.org/u/tk3369)\
**Post date:** [May 23, 2019, 2:11am UTC](https://discourse.julialang.org/t/debugging-in-julia-for-newbies/24481/8 "2019-05-23T02:11:57Z")

</div>

Does vscode have the same level of debugging integration with Debugger as Juno yet? I know a few people who would really appreciate that.

---

<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:** [May 23, 2019, 6:12am UTC](https://discourse.julialang.org/t/debugging-in-julia-for-newbies/24481/9 "2019-05-23T06:12:24Z")

</div>

> [@tk3369](#):
>
> Does vscode have the same level of debugging integration with Debugger as Juno yet? I know a few people who would really appreciate that.

It does not.

---

<div class="post-metadata">

**Author:** ![StevenSiew](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevensiew/32/218393_2.png) [@StevenSiew](https://discourse.julialang.org/u/StevenSiew)\
**Post date:** [May 23, 2019, 7:35am UTC](https://discourse.julialang.org/t/debugging-in-julia-for-newbies/24481/10 "2019-05-23T07:35:54Z")

</div>

How to use debugger on Juno

Step 1. create file myjuliaprog.jl  
make sure there is a function called main() which runs your entire program. Just like the main() in the C language. For debugging purposes, make sure the initial call to main() is commented out otherwise the program will run when you includet it in step 3

Step 2. start REPL and type  
using Revise  
println(“the above is not necessary if you auto start Revise in your startup.jl”)

Step 3. on the REPL type  
includet(“myjuliaprog.jl")  
println(“Please note!!! There is a T at the end of the word include”)

Step 4. on Juno set your breakpoint clicking the mouse cursor on left of the linenumber. You can set as many breakpoints as you want

Step 5. on REPL type  
Juno.@enter main() or Juno.@run main()

---

<div class="post-metadata">

**Author:** ![sbacelar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sbacelar/32/4359_2.png) [@sbacelar](https://discourse.julialang.org/u/sbacelar)\
**Post date:** [May 23, 2019, 10:03am UTC](https://discourse.julialang.org/t/debugging-in-julia-for-newbies/24481/11 "2019-05-23T10:03:12Z")

</div>

I don’t understand the need of a main() function to debug `myjuliaprog.jl`.

---

<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:** [May 23, 2019, 10:10am UTC](https://discourse.julialang.org/t/debugging-in-julia-for-newbies/24481/12 "2019-05-23T10:10:07Z")

</div>

You can name it whatever you want. If it’s `foo()`, then the last step should be `Juno.@enter foo()` or `Juno.@run foo()`.

---

<div class="post-metadata">

**Author:** ![sbacelar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sbacelar/32/4359_2.png) [@sbacelar](https://discourse.julialang.org/u/sbacelar)\
**Post date:** [May 23, 2019, 10:22am UTC](https://discourse.julialang.org/t/debugging-in-julia-for-newbies/24481/13 "2019-05-23T10:22:13Z")

</div>

Normally I do `Juno.@enter foo(arg1, arg2)` to debug a function and then I use the command `Debug: next line`. How can I see the values that are assumed by the variables, for example inside a loop?

I understand that the objective of using `main()` is to debug not only a function but the entire program. Is that right?

---

<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:** [May 23, 2019, 10:42am UTC](https://discourse.julialang.org/t/debugging-in-julia-for-newbies/24481/14 "2019-05-23T10:42:55Z")

</div>

> How can I see the values that are assumed by the variables, for example inside a loop?

The tutorial covers that explicitly (twice 😄). Check both red annotations in the bottom section of the first image.

---

<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:** [May 23, 2019, 10:46am UTC](https://discourse.julialang.org/t/debugging-in-julia-for-newbies/24481/15 "2019-05-23T10:46:38Z")

</div>

> [@sbacelar](#):
>
> I understand that the objective of using `main()` is to debug not only a function but the entire program. Is that right?

`main` is just an example. In an interactive language the definition of “whole program” is a little tricky. Is `split("Hello world", isspace)` typed at the REPL a whole program or not? There was literally nothing special about instructing users to define `main`, it was just needed for consistency with the last step in @StevenSiew’s instructions.

---

<div class="post-metadata">

**Author:** ![sbacelar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sbacelar/32/4359_2.png) [@sbacelar](https://discourse.julialang.org/u/sbacelar)\
**Post date:** [May 23, 2019, 11:14am UTC](https://discourse.julialang.org/t/debugging-in-julia-for-newbies/24481/16 "2019-05-23T11:14:07Z")

</div>

I meant a (simple 🙂 ) jl file.

---

<div class="post-metadata">

**Author:** ![DIzer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dizer/32/3971_2.png) [@DIzer](https://discourse.julialang.org/u/DIzer)\
**Post date:** [May 26, 2019, 2:33pm UTC](https://discourse.julialang.org/t/debugging-in-julia-for-newbies/24481/17 "2019-05-26T14:33:11Z")

</div>

hmm I think that Juno should have much better integration with the debugger -the every beforementioned step can be done (and as the matter of fact should be done ) implicitly (by the IDE).

---

<div class="post-metadata">

**Author:** ![DIzer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dizer/32/3971_2.png) [@DIzer](https://discourse.julialang.org/u/DIzer)\
**Post date:** [May 26, 2019, 2:40pm UTC](https://discourse.julialang.org/t/debugging-in-julia-for-newbies/24481/18 "2019-05-26T14:40:00Z")

</div>

What is the trick? It is naturally for Juno (in debug mode) to wrap CURRENTLY executed script in a function definition and to proceed with debuggin / Is not it?

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [May 26, 2019, 3:41pm UTC](https://discourse.julialang.org/t/debugging-in-julia-for-newbies/24481/19 "2019-05-26T15:41:29Z")

</div>

The requirement for Revise will not be in the next version of Juno anymore, so you only need to make sure the code you want to debug is

- in a function, and
- prefix the evaluation with `Juno.@run` or `Juno.@enter`

We could indeed lift the second requirement with creating a new “REPL mode” which interprets your code by default, but I’m not sure if that is a good idea – imho it’s good to be explicit about what you want.  
The first requirement could be worked around as well, but, considering that you can evaluate a line of code with `Ctrl-Enter`, I’m not sure how worthwhile it would be to build a nice interface for that.

---

<div class="post-metadata">

**Author:** ![jlperla](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jlperla/32/34332_2.png) [@jlperla](https://discourse.julialang.org/u/jlperla)\
**Post date:** [May 26, 2019, 3:55pm UTC](https://discourse.julialang.org/t/debugging-in-julia-for-newbies/24481/20 "2019-05-26T15:55:36Z")

</div>

> [@pfitzseb](#):
>
> The requirement for Revise will not be in the next version of Juno

What is the ballpark timeline for that version? (e.g are we talking June or September)?

[Next page](https://discourse.julialang.org/t/debugging-in-julia-for-newbies/24481.md?page=2)
