Clear Filters
Clear Filters

How can one debug mex code called by fminsearch?

3 views (last 30 days)
Pierre
Pierre on 18 Sep 2023
Edited: Pierre on 21 Sep 2023
On Windows or MacOS, I've never been able to debug a mex file without disabling Java with the option -nojvm. Otherwise I always get segmentation violation errors or bad access exceptions from Java code (a dog's breakfast, clearly) that my debugger catches.
Up to now this worked for my needs, with the minor annoyance of having to shut off all graphical output.
Now I'm trying to debug a mex code called by fminsearch. This function can use an option 'Display' 'off' (or 'none"). You'd have thought that it would play nice with -nojvm but not at all, its still insists on calling some graphics even without any need, and matlab stops with:
Error in callAllOptimPlotFcns (line 64)
fig = figure('visible','off');
Unrecognized function or variable 'Error'.
What am I supposed to do now (apart from banging my head on a wall)?
Thanks for the help.
  1 Comment
Pierre
Pierre on 21 Sep 2023
Edited: Pierre on 21 Sep 2023
Actually this error was caused by a previous line specifying a value for 'PlotFcns'. If this is nonempty, even with 'Display' set to 'off' (or equivalently, 'none'), Matlab will make a call to Java graphics. If fminsearch options' 'PlotFcns' is [] (the default) and 'Display' is 'off', it is indeed possible to run fminsearch with -nojvm.
This leaves open the question how you can debug Matlab on MacOS with Java activated. At this hour I haven't found a way.

Sign in to comment.

Answers (1)

Steven Lord
Steven Lord on 18 Sep 2023
What happened after you handled the SIGSEGV and SIGBUS signals as described in the last section, "Debug MEX with JVM", on this documentation page? Were you able to debug your MEX-file on Mac with the JVM successfully after that?
  1 Comment
Pierre
Pierre on 18 Sep 2023
Edited: Pierre on 18 Sep 2023
Actually, on MacOS, my current platform, I can deal with SIGBUS and SIGSEGV. But that's not the end of it: EXC_BAD_ACCESS exceptions still mess up everything. LLDB gets indefinitely stuck on those.
I tried "settings set platform.plugin.darwin.ignored-exceptions EXC_BAD_ACCESS" in LLDB but, to my disappointment, it didn't change a thing: LLDB still can't get past such an exception in the Java 2D queue flusher.

Sign in to comment.

Categories

Find more on C Shared Library Integration in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!