- Specify the debug tool using the
xmcImportFunctionSettings
command. In the MATLAB command prompt, type the following:>> xmcImportFunctionSettings('build','debug','compiler','Visual Studio');
Press Enter.
This command picks the installed Visual Studio in your machine for debugging.
- Observe the version and location of Visual Studio from the MATLAB console.
- Type the following in the MATLAB console to get more information on this
command and also to set different version of Visual
studio.
>>help xmcImportFunctionSettings
- Invoke Visual Studio from your install directory to start debugging
C/C++
code.
- In the Visual Studio startup page, open the
C/C++
file that you want to debug.Click on RGB2HSV_wrap.h and click Open.
and browse to the location where the Color Detection example design resides. Select the file
- Observe that RGB2HSV_wrap.h opens in the Visual Studio as
shown in the following figure.
- Now set the break point in the RGB2HSV_wrap.h.
To set the break point, click on the grey color space at line number. A red dot appears there, as shown in the following figure. This indicates that the break point has been set at the corresponding line.
- Next, attach the MATLAB process to the debugger by clicking
the Attach icon in the tool bar as shown in the following
figure.
- In the Attach to Process dialog box, which is opened, search for the process
MATLAB.exe
.
When attaching Visual Studio to the MATLAB process, you must make sure to set the Attach to field to choose Native Code from the drop down menu as highlighted above.
Click on Attach button. Your MATLAB process is attached to the debugger.
- Now, go back to the Simulink model and start simulating the
color_detection design.
- The simulation process may take some time to initialize. Once this is done,
switch back to the Visual Studio GUI to start debugging.
If any Exception is thrown by Visual Studio, simply uncheck Break when this exception type is thrown in the Exception settings and click Continue.
- You can now see the simulation hitting the break point in Visual
Studio.
- To debug, you can use the Step Over
icon in the tool bar.
Important:Click the Step Into icon to execute the next line of the code. If the line involves a call to an operation, it steps into the operation’s implementation and breaks the execution on the first action of that implementation.
Clicking the Step Over icon does not step into the line’s implementation details, but steps to the next line of code after the call.
- Observe the values of variables at each corresponding step, as you progress with
debugging.
- You can change the breakpoint to a different line, by removing the initial break
point, and setting a new one for example at Line 22 and clicking the
Continue button from tool bar.
Now you can observe the break point hitting Line 22.
- Now, remove all the break points and click the Continue
button. You can see the model running.Note: As the design is running in debug mode, the simulation may progress slowly.Note: You can always set a break point as long, as the design is simulating.
- Once you are done with debugging, you can the click Stop Debugging button in the tool bar.
- To come out of debugging mode in MATLAB, type the following command in the MATLAB console and press Enter.
>> xmcImportFunctionSettings('build','release');
Now, you can run the imported
C/C++
code in release mode.