Simulink Debug brings up two Visual studio sessions

1 次查看(过去 30 天)
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 ?

回答(1 个)

Kothuri
Kothuri 2024-9-13
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 个评论
Heng Zhou
Heng Zhou 2024-9-16
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 .

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Naming Conventions 的更多信息

标签

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by