Attach debugger to running process

Hi all

Glancing at DebugAdapter.jl it seemed to me that you could debug a program “after the fact”, i.e. attach a debugger to it once it has started. Is that correct? Can DebugAdapter.jl do this? If so, can this functionality be used from the vscode plugin? I’m fine with running my code through a special function if need be.

Thanks,
Damian

Yes, check out the docs at

Nice! Does the REPL have to be launched from vscode? How does vscode know which REPL to connect to? By port number? Can I launch a REPL outside of vscode and then connect to it?

Thanks for your help!

No, not necessarily.

A socket path gets passed at startup.

Yes, use the Julia: Connect external REPL command for that. You’ll need to have a REPL available in the process you’re trying to connect to (though technically that requirement could be relaxed).

Is it an actual REPL I need to attach to? A Debugger.jl “session” (if such a thing exists) isn’t enough? I believe debugging in the REPL relies on Debugger.jl under the hood? I’m asking because I’m embedding Julia using jlrs and I don’t have a running REPL there, nor do I know of an official way to start one “after-the-fact”, programmatially, from inside Julia.

Thanks a lot!

something like py-spy for Julia would be quite cool. I have something vibe coded locally that provides similar features

Julia: Connect external REPL requires an actual REPL, yes. DebugAdapter.jl doesn’t, but it’s easiest to use from one and we don’t currently officially support attaching to random Julia processes.

Yes, but Debugger.jl and DebugAdapter.jl both are debugger frontends built on top of the JuliaInterpreter.jl infrastructure. The VS Code integration only works with the latter.

Thanks for your reply. My current workflow is

  1. Start a Julia REPL outside of vscode
  2. Connect external REPL (get the “external REPL connected” message)
  3. include my script there after having set a breakpoint in it in vscode

However, my breakpoint isn’t hit. Any idea what I’m doing wrong?

Thanks!

Check out the instructions at

and also this thread:

Hi

Thanks for getting back. Hmm, I know it’s a bit of a cop-out but a MWE is not trivial, our setup is quite complex… What I can say is that can start

  1. A REPL outside of vscode
  2. Successfully connect vscode to the REPL
  3. Kick off my code in the REPL
  4. Have Debugger.jl stop in the REPL at a manually inserted @bp in the code.

But what I fail to do is for vscode to stop at a breakpoint added in the editor. Note that the code on which I set the breakpoint in vscode is “dynamically” included, outside of the normal module definitions (does that make sense, not sure if I explained it well).

P.S.: I’ve set the Julia debug options and I can see that the breakpoints are set:

┌ Debug: Setting breakpoint at c:\Users\damian.birchler\src\private\julia4trnsys\julia4trnsys.rs\julia\types\ConstantEffectivenessHeatExchanger.jl:73 (condition nothing)

This file is included “dynamically” some time along the run of the program, so I wonder how the breakpoint is “matched”. Does each (interpreted) instructed know what file it came from?

Actually, the workflow is Julia REPL → Native module (jlrs/Rust) → calls back into Julia via C API → Julia code I want to debug. I guess the debugging infrastructure is just not made for something so convoluted?

Cheers,
Damian