# Examples for Debugger

**URL:** <https://discourse.julialang.org/t/examples-for-debugger/23648>\
**Category:** Juno\
**Created:** [April 29, 2019, 1:37pm UTC](https://discourse.julialang.org/t/examples-for-debugger/23648 "2019-04-29T13:37:24Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![HelgavonLichtenstein](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/helgavonlichtenstein/32/5005_2.png) [@HelgavonLichtenstein](https://discourse.julialang.org/u/HelgavonLichtenstein)\
**Post date:** [April 29, 2019, 1:37pm UTC](https://discourse.julialang.org/t/examples-for-debugger/23648/1 "2019-04-29T13:37:24Z")

</div>

Hello,

I am a beginner Julia user (and programmer) and am trying to learn how to use the [debugger](https://julialang.org/blog/2019/03/debuggers) in Atom. From the link, I understand that I need to install `Debugger`, `Rebugger`, `Revise`, `JuliaInterpreter`, `LoweredCodeUtils`, and `CodeTracking`.

I am trying to learn to use [Debugger](https://github.com/JuliaDebug/Debugger.jl) but am having difficulty. Are there more examples I could look at?

---

<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:** [April 29, 2019, 1:40pm UTC](https://discourse.julialang.org/t/examples-for-debugger/23648/2 "2019-04-29T13:40:57Z")

</div>

Do you mean the the text interface (Debugger.jl) or the graphical debugger interface in Juno?

---

<div class="post-metadata">

**Author:** ![HelgavonLichtenstein](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/helgavonlichtenstein/32/5005_2.png) [@HelgavonLichtenstein](https://discourse.julialang.org/u/HelgavonLichtenstein)\
**Post date:** [April 29, 2019, 1:52pm UTC](https://discourse.julialang.org/t/examples-for-debugger/23648/3 "2019-04-29T13:52:54Z")

</div>

I am not sure.

I mean the one where I type `@enter` in Atom and `1|debug>` shows up in the REPL.

---

<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:** [April 29, 2019, 1:53pm UTC](https://discourse.julialang.org/t/examples-for-debugger/23648/4 "2019-04-29T13:53:55Z")

</div>

Did you try the example at [https://github.com/JuliaDebug/Debugger.jl#usage](https://github.com/JuliaDebug/Debugger.jl#usage). It is hard to help since you are not really saying what the problem is.

---

<div class="post-metadata">

**Author:** ![HelgavonLichtenstein](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/helgavonlichtenstein/32/5005_2.png) [@HelgavonLichtenstein](https://discourse.julialang.org/u/HelgavonLichtenstein)\
**Post date:** [April 29, 2019, 1:58pm UTC](https://discourse.julialang.org/t/examples-for-debugger/23648/5 "2019-04-29T13:58:09Z")

</div>

I ran it but… I don’t understand it. Is there… a simpler example?

---

<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:** [April 29, 2019, 2:04pm UTC](https://discourse.julialang.org/t/examples-for-debugger/23648/6 "2019-04-29T14:04:05Z")

</div>

That is about as simple as it gets. What is it you don’t understand? What part is problematic?

---

<div class="post-metadata">

**Author:** ![HelgavonLichtenstein](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/helgavonlichtenstein/32/5005_2.png) [@HelgavonLichtenstein](https://discourse.julialang.org/u/HelgavonLichtenstein)\
**Post date:** [April 29, 2019, 2:20pm UTC](https://discourse.julialang.org/t/examples-for-debugger/23648/7 "2019-04-29T14:20:07Z")

</div>

```julia
using Debugger

function foo(n)
    x = n+1
    ((BigInt[1 1; 1 0])^x)[2,1]
end

@enter foo(20)

In foo(n) at [...]
>1 1 ─ x = (+)(n, 1)
 2 │ %2 = (tuple)(2, 2) # what do (2,2) refer to?
 3 │ %3 = (Base.typed_hvcat)(BigInt, %2, 1, 1, 1, 0) # what does %2 refer to?
 4 │ %4 = (^)(%3, x) # what does %3 refer to, and why does it separate ^ from x ?
 5 │ %5 = (getindex)(%4, 2, 1) # what does %4 refer to?

About to run: (+)(20, 1)

```

I also don’t understand how I can use this for debugging. Julia sometimes highlights the line of code it is unhappy with, and then I have to think about what could be defined or formulated incorrectly. Could you please provide an example of how I could use the debugger to fix something?

---

<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:** [April 29, 2019, 3:28pm UTC](https://discourse.julialang.org/t/examples-for-debugger/23648/8 "2019-04-29T15:28:02Z")

</div>

Short answer: The `%2` etc are temporary variables, and e.g. `(tuple)(2,2)` is a function call equivalent to `tuple(2,2)`.  
You might also want to try Juno’s debugger, which might make things a bit clearer in some cases:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/c/f/cf8b1b77f375160c32e63d2ef164a2f81cc417ac.png)

---

<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:** [April 29, 2019, 4:08pm UTC](https://discourse.julialang.org/t/examples-for-debugger/23648/9 "2019-04-29T16:08:54Z")

</div>

You’re seeing what’s called _lowered code_, which is what happens when Debugger can’t find the source of what you’re debugging. Not sure why this is happening, with Julia 1.1 I get this:

```julia
julia> @enter foo(3)
In foo(n) at /tmp/rundebug.jl:4
 3 function foo(n)
>4 x = n+1
 5 ((BigInt[1 1; 1 0])^x)[2,1]
 6 end

```

which I suspect is more what you were hoping to see.

Since I can’t replicate what you’re seeing, I don’t know exactly why it’s happening. One thought is that perhaps you might have more luck if you put your code in a file, save it, and then in the Julia session say

```julia
using Revise
includet("file_with_my_code.jl")

```

and then start debugging.

But I second the recommendation to use Juno’s debugger. Instructions are [here](http://docs.junolab.org/latest/man/debugging/).

---

<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:** [April 29, 2019, 5:42pm UTC](https://discourse.julialang.org/t/examples-for-debugger/23648/10 "2019-04-29T17:42:26Z")

</div>

> [@tim.holy](#):
>
> You’re seeing what’s called _lowered code_ , which is what happens when Debugger can’t find the source of what you’re debugging. Not sure why this is happening,

It happens because the file in Atom hasn’t been saved. Instead ctrl + enter was used to directly evaluate the method definition. So the source information points towards a file with no content (and then lowered code gets shown).

So yeah, save the file before `@enter`.

---

<div class="post-metadata">

**Author:** ![mackyo123](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mackyo123/32/8271_2.png) [@mackyo123](https://discourse.julialang.org/u/mackyo123)\
**Post date:** [June 15, 2019, 6:20pm UTC](https://discourse.julialang.org/t/examples-for-debugger/23648/11 "2019-06-15T18:20:02Z")

</div>

I’m with HelgavonLichtenstein. Is there a way to start the Debugger and then step through the code? And have the interpreter/debugger run the code step by step without having to put “using Debugger” and @enter in your program … in the announcement it says:

- Step into functions and manually walk through your code while inspecting its state
- Set breakpoints and trap errors, allowing you to discover what went wrong at the point of trouble
- Interactively update and replace existing code to rapidly fix bugs in place without restarting
- Use the full-featured IDE in [Juno](http://junolab.org/) to bundle all these features together in an easy to use graphical interface

does it do that? can you start at line 1 and step thru to the end, and step into functions and loops?  
If it does how? is there a line of code to start it?, Something in Juno?  
using Debugger

function foo(n)  
x = n+1  
((BigInt[1 1; 1 0])^x)[2,1]  
end

@enter foo(20)

if this is all there is. You have to put all of this stuff in your code?

---

<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:** [June 15, 2019, 6:42pm UTC](https://discourse.julialang.org/t/examples-for-debugger/23648/12 "2019-06-15T18:42:28Z")

</div>

Did you read through [this](http://docs.junolab.org/latest/man/debugging/)? Right now you can’t step through top-level code with the debugger, but that might change in the future.

---

<div class="post-metadata">

**Author:** ![mackyo123](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mackyo123/32/8271_2.png) [@mackyo123](https://discourse.julialang.org/u/mackyo123)\
**Post date:** [June 15, 2019, 7:25pm UTC](https://discourse.julialang.org/t/examples-for-debugger/23648/13 "2019-06-15T19:25:28Z")

</div>

I did. Oh well, it will get better. I’m just spoiled … thanks

---

<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:** [June 15, 2019, 7:33pm UTC](https://discourse.julialang.org/t/examples-for-debugger/23648/14 "2019-06-15T19:33:22Z")

</div>

You can just wrap your code in a function and use that, or just use Juno’s inline evaluation to step through your toplevel code though.

---

<div class="post-metadata">

**Author:** ![Paul\_Soderlind](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paul_soderlind/32/1753_2.png) [@Paul\_Soderlind](https://discourse.julialang.org/u/Paul_Soderlind)\
**Post date:** [June 15, 2019, 7:59pm UTC](https://discourse.julialang.org/t/examples-for-debugger/23648/15 "2019-06-15T19:59:37Z")

</div>

I am running the risk of repeating myself here, but…

(1) Juno has a very nice mechanism for stepping through a script (ctrl- or shift- enter)  
(2) doing @Juno.enter `functionName(x)` in the “Atom REPL” allows you to step through a function. Also very nice.

If it were possible to merge the two into one single way of stepping through a script&functions, then that would be most welcome.

/Paul Söderlind
