Examples for Debugger

#1

Hello,

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?

#2

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

#3

I am not sure.

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

#4

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.

2 Likes
#5

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

#6

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

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

#8

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:

4 Likes
#9

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
includet("file_with_my_code.jl")

and then start debugging.

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

4 Likes
#10

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.

6 Likes