Clear Filters
Clear Filters

How to debug MEX-files in Eclipse (Mars) compiled with MinGW64 and the -g flag in MATLAB R2017b and newer

32 views (last 30 days)

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 12 Nov 2018
Edited: MathWorks Support Team on 12 Nov 2018
NOTE: These instructions are valid for debugging with MinGW 5.3 and have been tested with Eclipse CDT (Mars)*.*
1. Start Eclipse and choose a new workspace.
You can download Eclipse from the Eclipse website at the following link:
2. Ensure that MinGW 5.3’s bin directory is on the Windows path.
3. Then in Eclipse select the following options.
"File" > "New" > "C Project" (or "C++ Project" for C++)
Select a name for the project and click finish.
4. Create a new text file by choosing
"File" > "New" > "Other..." and then "General" > "Untitled Text File"
Enter the following in the text file
handle SIGSEGV nostop
Then save the file as "gdbinit" in your project folder as shown in the figure.
5. Add the C/C++ source code of your MEX-file into the project by selecting
"File" > "New" > "Other..." and then "General" > "File"
Choose
"Advanced >>" > "Link to file in the file system"
and specify the full path to the MEX source file so that the source files stay in their original locations.
e.g.
C:\Program Files\MATLAB\R2017b\extern\examples\mex\yprime.c
6. Then go to
"Run" > "Debug Configurations..."
Select "C/C++ Attach to Application" and press the "New" button.
In this Window, at the bottom , click on "Select other..." and choose the “Legacy attach to process launcher”.
7. Specify the application with the full path to the MATLAB executable.
e.g.
C:\Program Files\MATLAB\R2017b\bin\matlab.exe
8. In the Debugger tab configure the settings as shown in the screenshot below and click "Debug".
9. Select MATLAB.exe from the list.
10. The debugger will suspend MATLAB. Use "Resume" button to continue running MATLAB.
11. Open the C/C++ code in Eclipse and place a breakpoint.
12. Run the MEX-file in MATLAB.
13. When the breakpoint is hit execution will be paused, and in the debugger you can, for example, step through the code and inspect variables.

More Answers (0)

Tags

No tags entered yet.

Products


Release

R2017b

Community Treasure Hunt

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

Start Hunting!