Examples for Debugger


I am a beginner Julia user (and programmer) and am trying to learn how to use the debugger 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 but am having difficulty. Are there more examples I could look at?

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

I am not sure.

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

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


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

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

using Debugger

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

@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?

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:


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> @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

using Revise

and then start debugging.

But I second the recommendation to use Juno’s debugger. Instructions are here.


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.


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 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]

@enter foo(20)

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

Did you read through this? Right now you can’t step through top-level code with the debugger, but that might change in the future.

1 Like

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

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.

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