How can I debug an "include("file")'d script?

Hi there,

thanks for all of your great work. I love the fact that there is a debugger now and I’m trying to use it to debug a file that I would normally run via

$ julia "script.jl"

Lets assume the content of the file is just

println("foo")
@bp
println("bar) 

I understand that Debugger only works in the REPL, so I tried the following:

Option A

In REPL, do:

julia> using Debugger
julia> f() = include("script.jl")
julia> @run f()
foo
bar

When I @enter f(), I can see the breakpoint via bp: 1] script.jl:1. However, the breakpoint is not hit.

Option B

This is the closest I got to what I would like to achieve:

Change script.jl to

function f()
    println("foo"):
    @bp
    println("bar");
end 

and @run f() after include("script.jl") in REPL. This gives the desired behaviour:

foo                              
Hit breakpoint:  
In f() at /home/jakob/tmp/tmp.jl:2
 1  function f()
 2  println("foo"); 
●3  @bp
>4  println("bar");
 5  end

Option C

However, the breakpoints that I want to use are within files, that are include'd by other files. So the previous option breaks when I have the following files:
“script.jl”:

println("foo");
@bp
println("bar");

and “run.jl”:

function f()
    include("script.jl");
end

and then include("run.jl") in REPL and @run f(). Output:

foo
bar

When I @enter f() there are no breakpoints (which is expected, because “script.jl” is not included yet). So I bp add "script.jl":1, the breakpoint is registered correctly, but it’s still not hit:

julia> using Debugger
julia> include("run.jl")  
f (generic function with 1 method)
julia> @run f()
foo
bar                                                                                   
julia> @enter f()
In f() at /home/jakob/tmp/run.jl:2
 1  function f()
>2  include("tmp.jl")
 3  end

About to run: (Base.MainInclude.include)("tmp.jl")
1|debug> bp
1|debug> bp add "tmp.jl":1 
[ Info: added breakpoint at tmp.jl:1 
1] tmp.jl:1

1|debug> c
foo
bar

Is there a way I can just add @bp's in a larger structure of files, without having to wrap the code of interest in a function? Thank you so much.

Best, Jakob

Right now you need to wrap in a function.

Ok, thank you.

I actually managed to wrap it rather easily. Cheers