4

Julia's new Debugger.jl is great, but it's kind of a pain to get to the exact point in code that I want to get to sometimes.

Is there a way I can enter an interactive debug mode, similar to what Python has in pdb.set_trace() or ipdb.set_trace()? For example, I'd love to be able to insert a line of code where I want the debugger to start, like so:

function myfunc(a, b)
     # do stuff
     set_trace() # interactive debug mode will start here
     # do other stuff
end

p.s. I know that this is basically like setting a breakpoint in Juno, but 1) I can't always develop in Juno; and 2) I couldn't really get breakpoints to work well with Juno's debugger even after a lot of struggling. It might be my user error but I'm sure other Julia newbies will encounter the same problems and would love a solution like pdb.set_trace().

J. Blauvelt
  • 785
  • 3
  • 14

1 Answers1

5

The function you're looking for is wonderfully concise:

@bp

Just make sure you have loaded the Debugger package so that you can use it:

using Debugger

Note that it won't actually stop at the breakpoint if you run the outer-most function (e.g., myfunc) via normal methods. You need to run it in debug mode using @enter or @run. Here's a complete example:

using Debugger
function myfunc(a, b)
     c = a + b
     @bp # interactive debug mode will start here
     c += 1
end

@run myfunc(42, 5)

(Juno sometimes produces weird behavior when you run the @run ... line using CTRL+ENTER. It may be better to copy and paste that particular line directly into the REPL instead.)

@bp is actually a macro that's part of JuliaInterpreter.jl. That module has many other useful functions for debugging - see the JuliaInterpreter docs for more details.

J. Blauvelt
  • 785
  • 3
  • 14