- 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.
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 ?
0 个评论
回答(1 个)
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
You can refer the below documentation link for more info:
Hope this helps!
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Naming Conventions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!