Simulink Debug brings up two Visual studio sessions

1 Ansicht (letzte 30 Tage)
Heng Zhou
Heng Zhou am 12 Sep. 2024
Kommentiert: Heng Zhou am 16 Sep. 2024
I ran into issues when trying to debug c caller code in simulink. environment: Matlab 2022a, Visual Studio Community 2019.
When Debug-> Add Breakpoint -> set breakpoint in custom code , two sessions of Visual Studio were brough up. The code I was debugging did not show in the module view in one of the sessions, so the breakpoint did not work. The other session has the module loaded , but looks like the thread was not attached to the actual simulation ( even though it showed as attached. )
Update: I tried uncheck Simulate custom code in a separate process. This time, Simulink brought up one session without the module loaded .
Anybody has a solution or suggestion ?

Antworten (1)

Kothuri
Kothuri am 13 Sep. 2024
I understand that you are facing an issue while trying to debug C caller code in Simulink.
You can try the below steps to resolve the issue
  • Ensure all necessary components for C/C++ development are installed in Visual Studio.
  • Make sure that Visual Studio is correctly set up as the compiler in MATLAB. You can do this by running mex -setup in MATLAB and selecting Visual Studio.
  • Attach Debugger Manually: If the automatic attachment is not working, you can manually attach the debugger to the MATLAB process: Open Visual Studio -> Go to Debug -> Attach to Process. -> Select the MATLAB process (matlab.exe) from the list and click Attach.
  • Once attached, open your C source file in Visual Studio and set breakpoints manually. Sometimes, breakpoints might not be hit if the code is optimized away or if the exact execution path doesn't include the breakpoint.
  • Ensure that the module containing your C code is loaded. You can check this in the Modules window in Visual Studio (Debug -> Windows -> Modules).
  • Enable verbose logging in Simulink to get more detailed information about the simulation and any issues that arise.
  • You can also use the Simulink debugger to step through your model and check if the custom code is being called correctly. In Simulink, go to Debug -> Simulink Debugger.
You can refer the below documentation link for more info:
Hope this helps!
  1 Kommentar
Heng Zhou
Heng Zhou am 16 Sep. 2024
Hello Kothuri,
Thanks for the response.
The problem was that Simulink brought up two sessions of VS , one with loaded modules, the other without. The one without was actually attached to Matlab.exe . Break point can be set in the one with module loaded, but it won't break .

Melden Sie sich an, um zu kommentieren.

Tags

Produkte


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by