Trying to debug embedding of Julia in a JUCE (VST) audio plugin

Hi! I’m trying to embed Julia into a VST plugin (using the JUCE framework) on windows.
JUCE provides several build targets, and the standalone target works fine (after some tweaks related to embedding Julia on windows). (I was able to generate some waveforms in real time using Julia - really nice!)

But when I try to use the actual VST3 plugin target, which creates a dll, I get a null pointer access somewhere inside libjulia-internal.dll when loading the plugin. I was able to debug this far:

  • The call to jl_init() succeeds.
  • Then I call jl_eval_string("IdDict()"), and somewhere inside that call I get the null pointer access.

Does anyone have any tips on how I can debug this? Is there a version of libjulia-internal.dll with debug symbols availble somewhere? Then I could at least figure out where the null pointer access occurs.

I should mention that in order to get the embedding to work, I had to go against Embedding Julia · The Julia Language and not link with libopenlibm.dll.a - otherwise I got an error that the entry point for acos could not be found when starting the program.

Any ideas?
/ Toivo

I should add that I’m using Julia 1.6.0 and Visual Studio 2017.

I think I figured it out.
My plugin was creating a thread to run Julia in. Apparently, the plugin got created, destroyed, and created again, so jl_init() got called once from one thread, then once from another, which I don’t think is supported. I’ll have to keep one global Julia thread for the whole lifetime of the plugin.

If someone else needs to debug into e g libjulia-internal-debug.dll using Visual Studio, here’s a few things that I found out that might be helpful:

Building Julia from source for windows (including the debug build) was pretty easy, but that in itself didn’t help me to get debug symbols for libjulia.dll / libjulia-internal.dll that I could use with Visual Studio, because the debug symbols are in DWARF format but Visual Studio wants pdb format.

But I found a tool called cv2pdb which actually worked pretty well. E g

cv2pdb.exe -C libjulia-internal-debug.dll

which creates libjulia-internal-debug.pdb and updates libjulia-internal-debug.dll. Then you put both files on your path. (This might also work on libjulia-internal.dll that comes in the official download, if it hasn’t been stripped.)

But the paths to the source files linked in the .pdb were wrong, maybe that’s why I could step into e g jl_init() initially. To make it work in Visual Studio, I had to

  • put a breakpoint at e g jl_init() and run to that point in the debugger,
  • go to the disassembly view and step into a few layers of calls,
    • then Visual Studio would ask me to locate the source file on disk that I had stepped into,
  • open the same source file with Visual Studio,

and then I could step through the code in libjulia-internal-debug.dll.