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

**URL:** <https://discourse.julialang.org/t/how-can-i-debug-an-include-file-d-script/25143>\
**Category:** Tooling\
**Tags:** debug\
**Created:** [June 11, 2019, 12:07pm UTC](https://discourse.julialang.org/t/how-can-i-debug-an-include-file-d-script/25143 "2019-06-11T12:07:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![j4ksch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/j4ksch/32/14878_2.png) [@j4ksch](https://discourse.julialang.org/u/j4ksch)\
**Post date:** [June 11, 2019, 12:07pm UTC](https://discourse.julialang.org/t/how-can-i-debug-an-include-file-d-script/25143/1 "2019-06-11T12:07:10Z")

</div>

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-auto
$ julia "script.jl"

```

Lets assume the content of the file is just

```julia-auto
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-auto
julia> using Debugger
julia> f() = include("script.jl")
julia> @run f()

```

```julia-auto
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

```julia-auto
function f()
    println("foo"):
    @bp
    println("bar");
end 

```

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

```julia-auto
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”:

```julia-auto
println("foo");
@bp
println("bar");

```

and “run.jl”:

```julia-auto
function f()
    include("script.jl");
end

```

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

```julia-auto
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-auto
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

---

<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:** [June 11, 2019, 12:51pm UTC](https://discourse.julialang.org/t/how-can-i-debug-an-include-file-d-script/25143/2 "2019-06-11T12:51:00Z")

</div>

> [@j4ksch](#):
>
> 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?

Right now you need to wrap in a function.

---

<div class="post-metadata">

**Author:** ![j4ksch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/j4ksch/32/14878_2.png) [@j4ksch](https://discourse.julialang.org/u/j4ksch)\
**Post date:** [June 12, 2019, 8:18am UTC](https://discourse.julialang.org/t/how-can-i-debug-an-include-file-d-script/25143/3 "2019-06-12T08:18:57Z")

</div>

Ok, thank you.

I actually managed to wrap it rather easily. Cheers

---

<div class="post-metadata">

**Author:** ![Neo\_li](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/neo_li/32/35467_2.png) [@Neo\_li](https://discourse.julialang.org/u/Neo_li)\
**Post date:** [June 8, 2022, 3:18pm UTC](https://discourse.julialang.org/t/how-can-i-debug-an-include-file-d-script/25143/4 "2022-06-08T15:18:04Z")

</div>

Any update now?  
It is very straightforward for python users since they have been used to `import pdb; pdb.set_trace()`
