Breakpoint issues and best practices in VSCode

I have been advocating Julia to my colleagues to switch from MATLAB. One of the biggest roadblocks for us is the breakpoint debug feature in VSCode.

I personally have never gotten breakpoints to work. Below are the issues I have run into

  1. My code base is relatively big and the main script includes other files (both modules and scripts). Breakpoints in included files never stops
  2. I have GLMakie in my code, so speed things up I used the recommended settings with ALL_MODULES_EXCEPT_MAIN in the config file: Debugging · Julia in VS Code. None of the breakpoints in my own custom module functions work. I am guessing I need to explicit them put them interpretive mode with “-” prefix? I tried doing this for one module, and called a function at the main script level, the breakpoint I set in that function doesn’t work either.
  3. Adding breakpoints dynamically at the main script level also doesn’t work for me.

I feel maybe there is something very obvious I am missing. Any suggestions or recommendations on how folks usually get around these issues would be helpful. I am very close to convince a wider adoption of Julia in my circle if I can show people a MATLAB like debug flow using breakpoints. Thanks!

Hello, Kevjzheng.

In fact, there is something obvious and you are not missing at all. Debugging in Julia is some awful experience for a lot of people. So I’m really sorry if my response doesn’t give you a solution. I’m going to put here posts about debugging in julia so you can see that is a very hot topic and people coming from other languages that are used to debug are facing the same issue. In the first post you can find a discussion about some debugger Pkg

What is the standard way to debug Julia?

Debugger status and future plans?

I have had trouble with this myself. (See this Issue and this Discourse post. I don’t think either are really resolved unfortunately.)

One obvious thing I was missing initially is that you need to run the debugger on code that calls your functions not on the code which defines your functions. The breakpoints are set in the source code files, but the debugger is usually run from a separate file. You can either create a file for testing your functions yourself and click the GUI button for “Julia: Debug File in New Process” on that file, or you can use these macros to start debugging from the REPL e.g. @run f(x).

Typically now, I will try the @enter macro first, and if that is too slow, I will switch to using Infiltrator.jl. Infiltrator works faster and more reliably, albeit with fewer features.
.

2 Likes