Julia VS code debugger gets stuck

I’m trying to debug my code in VSCode, but the debugger gets stuck and never reaches the breakpoint. My code uses several Julia packages (such as Distributions, Distances, JLD, BoltzmannMachines) and runs in a matter of seconds when not using the debugger. I’m using the latest version of vscode in MacOs Ventura (apple silicon), but experienced the same in windows. Would greatly appreciate any help.

How are you starting the debugger? Depending on how you do it, it will “Pause on entry.” If you hit the continue button in the floating debugger controls, it will execute the code until a break point.

If you add a print statement to the very first line of the function you’re debugging, do you get anything printed out? Just wondering if it’s executing anything at all.

If that isn’t the problem, could you figure out a minimum working example of code that freezes the debugger?

1 Like

How long did you wait? The debugger runs in interpreted mode which is pretty slow compared to normal execution. The debugger has a compiled mode you could try. Alternatively there is Infiltrator which is very handy or use the ref trick discussed here.

Edit: Just realized you said VSCode. In that case ignore my comment about Infiltrator. It does not play nice with VSCode.

1 Like

What problems are you experiencing using Infiltrator in VSCode. We are using it from time to time.

Infiltrator should work fine in VS Code, you just have to make sure not to use inline evaluation.

Hm - thanks for the tip. Maybe I was trying to do inline evaluation. I will experiment with it again and try to fix what I was doing before.

I use the Run and Debug button. It then shows the following on the terminal and then nothing happens:

  • Executing task: julia --color=yes --startup-file=no --history-file=no --project=/Users/user/.julia/environments/v1.8 /Users/mohammadchaposhloo/.vscode/extensions/julialang.language-julia-1.38.2/scripts/debugger/run_debugger.jl /var/folders/hz/6flzw5kn765922jhv7151yj00000gn/T/vsc-jl-dbg-5d1ec71c-1c0f-4d55-9e4f-3220881832f4 /var/folders/hz/6flzw5kn765922jhv7151yj00000gn/T/vsc-jl-cr-09fe7c9e-9e2f-4b45-8dd7-ee13d8122f8a

Connecting to debugger… Done!

In the floating debugger control only pause, restart and stop buttons are available. The other buttons are greyed out.

But I just realized that if I place the breakpoint at the beginning of some functions (not all), the debugger reaches the breaking point very fast.
And yes it does print out a print statement at the beginning of a function.

I waited once for 20 minutes but nothing happened. Thanks for suggesting Debugger and Infiltrator. I just wanted to make it clear that my problem is with vscode built-in debugger. I haven’t tried Debugger.jl or Infiltrator.jl yet but I definitely will give them a try. However, is there any “compiled mode” in vscode built-in debugger itself?

So since the debugger is working at first and somewhere it’s getting held up, I’d suggest putting a break point at the top of the entry point function and then stepping line by line until it freezes up to find the actual culprit. Then back up and “step into” that line and step through the next function until it freezes again. Eventually, you should be able to hone in on what specifically is causing the issue. Then you can post a more specific issue here!

It’s also entirely possible that this is “just” a performance issue with the debugger.

I think it is just a performance issue with the debugger, as when I reduced the number of loops before the breakpoint, the debugger eventually reached it.
I just wonder why the debugger gets so slow for a code that normally runs in seconds.

Yes, can confirm. Works fine in the integrated terminal running the Julia REPL. Thanks for the clarification!