Why does the Visual Studio debugger not stop at a breakpoint when used with Simulink ?

27 visualizaciones (últimos 30 días)
I am attempting to debug my custom code in Simulink with the Microsoft Visual Studio external debugger (2015, 2017, 2019, or 2022). After attaching Visual Studio to the MATLAB.exe process and setting breakpoints in the code I am debugging in VS, I receive the following warning message from Visual Studio:
The breakpoint will not currently be hit. No symbols have been loaded for this document
How can I resolve this issue and start debugging my custom code in Simulink with Visual Studio?

Respuesta aceptada

MathWorks Support Team
MathWorks Support Team el 19 de Ag. de 2023
Please note that the warning "The breakpoint will not currently be hit. No symbols have been loaded for this document" in Visual Studio can be ignored in most cases. It is expected that this warning is shown if you have not yet run the executable file. You should try to execute the MEX function (or run the Simulink model) anyway - in most cases, the breakpoint will still be hit despite the warning.
As a first step, ensure that Visual Studio debugging works with a simple C MEX file in MATLAB. Follow the instructions below:
However, if the Visual Studio debugger does indeed not stop at breakpoints, and the issue seems to be specific to using Simulink (but works with MATLAB), note that there are some quirks with attaching Visual Studio (2015, 2017, 2019, or 2022) as a debugger for external code in Simulink. Typically things need to be done in a certain sequence for it to work right as listed below.
See also the "Debugging C MEX S-Functions Using the Microsoft Visual C++ .NET Environment" example for details:
1. PDB files are required for Visual Studio to debug an S-function since they contain the symbols related to that source file. It should be ensured that the MEX files for the S-function are generated using the right compiler i.e., Visual Studio in this case. 
The compiler being used can be checked by entering the following command:
>> mex -setup C
2. Next, ensure you have disabled Simulation Target > Enable Custom Code Analysis in the configuration parameters of your Simulink model.
3. In MATLAB R2022a and earlier, make sure that the execution of the below command returns 1 (true):
>> Simulink.CustomCode.debugSymbols('on')
In MATLAB R2022b and newer, this option is always turned on.
4. Next, issue the following command at the MATLAB Command Window to delete any existing MEX files and cache(s):
>> clear mex
5. Attach the Visual Studio debugger to the MATLAB.exe process
6. Add a breakpoint to the source code in Visual Studio. At this stage, Visual Studio will still say the breakpoint will not be hit. This is expected.
7. Return to Simulink and update the model (Ctrl+D)
8. Now, the breakpoint will light up in Visual Studio and function as normal. Breakpoints you place will be hit as you simulate the model.

Más respuestas (0)

Categorías

Más información sobre Manual Performance Optimization en Help Center y File Exchange.

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by