# Breakpoints fail in code called from compiled code?

**URL:** <https://discourse.julialang.org/t/breakpoints-fail-in-code-called-from-compiled-code/96328>\
**Category:** VS Code\
**Created:** [March 20, 2023, 5:07am UTC](https://discourse.julialang.org/t/breakpoints-fail-in-code-called-from-compiled-code/96328 "2023-03-20T05:07:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ross\_Boylan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ross_boylan/32/9210_2.png) [@Ross\_Boylan](https://discourse.julialang.org/u/Ross_Boylan)\
**Post date:** [March 20, 2023, 5:07am UTC](https://discourse.julialang.org/t/breakpoints-fail-in-code-called-from-compiled-code/96328/1 "2023-03-20T05:07:48Z")

</div>

Using VSCode and the following test code, with a breakpoint set where indicated:

```julia
function test5(x)
    a=10 #set breakpoint here
    return a+x
end

print(sum(test5(x) for x in [3, 5]))

```

When I run this with `F5` the code executes and prints 28, but it never stops.

My theory is that `sum` is compiled code and the breakpoints don’t fire in code called from compiled code.  
Can anyone confirm this explanation, or provide another one?  
Is there any good way around this, i.e., by doing something other than disabling the “compiled code” feature of the debugger, which would like make it too slow?

I formed the theory after many breakpoints failed to cause a break, and I noticed they fit this pattern. It’s really frustrating and weird to set breakpoints and discover that they don’t work.

There have been many other reports of breakpoints failing to work, in at least the following contexts:

- [used while running test suite](https://discourse.julialang.org/t/debugger-doesnt-stop-at-breakpoints-when-running-tests-but-does-during-normal-execution/93202)
- used outside of top level
- [used in an include file](https://discourse.julialang.org/t/vscode-debugger-not-hitting-breakpoint-in-include-file/46014)
- [used outside main thread](https://discourse.julialang.org/t/debugging-with-threads/93281)
- [used in a callback](https://discourse.julialang.org/t/vscode-breakpoint-not-working-in-callback/78830)

but I didn’t see this particular scenario mentioned, aside from someone suggesting compiled code might play a role in some of the difficulties.

Julia 1.8.5, VSCode julia extension 1.38.2.

---

<div class="post-metadata">

**Author:** ![oxinabox](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oxinabox/32/206603_2.png) [@oxinabox](https://discourse.julialang.org/u/oxinabox)\
**Post date:** [March 20, 2023, 7:25am UTC](https://discourse.julialang.org/t/breakpoints-fail-in-code-called-from-compiled-code/96328/2 "2023-03-20T07:25:01Z")

</div>

`sum` shouldn’t be being compiled.  
It is specifically excluded in the setting: `"julia.debuggerDefaultCompiled"`

---

<div class="post-metadata">

**Author:** ![Ross\_Boylan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ross_boylan/32/9210_2.png) [@Ross\_Boylan](https://discourse.julialang.org/u/Ross_Boylan)\
**Post date:** [March 20, 2023, 8:58am UTC](https://discourse.julialang.org/t/breakpoints-fail-in-code-called-from-compiled-code/96328/3 "2023-03-20T08:58:41Z")

</div>

Here are the results of some variations. Maybe it’s not the `sum` but the use of a `Generator`, but I’m not sure of what the key language difference is:

```julia
#print(sum(test5(x) for x in [3, 5])) no stop
#print(sum((test5(2), test5(10)))) stops
#print(sum((test5(x) for x in [3, 5]))) no stop
#print(sum([test5(x) for x in [4, 5]])) stops

```

I guess the exact context in which test5() is evaluated varies across these lines. AFAIK `julia` does not do lazy evaluation by default, so `f(g(x))` implies `g(x)` is evaluated _before_ calling `f`, and so whether `f` is “compiled” in the debugger sense wouldn’t matter.

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [March 20, 2023, 10:35am UTC](https://discourse.julialang.org/t/breakpoints-fail-in-code-called-from-compiled-code/96328/4 "2023-03-20T10:35:19Z")

</div>

This does happen due to the generator comprehension, yes. `sum` isn’t compiled, and neither is `test5`, but the internal machinery in between is.
