Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to debug mex code with Eclipse?

I am trying to write some mex code but it is painful to debug it on the console with gbd. Is it possible to use Eclipse or the GUI of Matlab? If these are not feasible methods, what is the best way of writing mex code that provides good debug capabilities?

like image 393
erogol Avatar asked Jan 23 '13 01:01

erogol


People also ask

How do I debug a script in Eclipse?

A Java program can be debugged simply by right clicking on the Java editor class file from Package explorer. Select Debug As → Java Application or use the shortcut Alt + Shift + D, J instead.

How do I debug a breakpoint in Eclipse?

To put breakpoints in your code, double click in the left margin on the line you want execution to stop on. You may alternatively put your cursor in this line and then press Shift + Ctrl + B . To control execution use the Step Into, Step Over and Step Return buttons. They have the shortcuts F5 , F6 and F7 respectively.


3 Answers

Debugging C/C++ MEX files in gdb is already comprehensively covered in the official documentation, so my suggestion is to try and integrate gdb with Eclipse CDT.

There's plenty of information out there about how to do it properly, so I'm not going to repeat everything here. The best tutorial I know is IBM's two-part guide, "Interfacing with the CDT debugger":

  1. Part 1: Understand the C/C++ debugger interface - covers the high-level basics.
  2. Part 2: Accessing gdb with the Eclipse CDT and MI - explains how to make Eclipse work with gdb.

I think part 2 is what you really need. Basically, you have to install a plug-in and configure it in Eclipse.

There are also quite a few related questions about this even here on StackOverflow:

  1. How do I use GDB in Eclipse for C/C++ Debugging?
  2. How to install GDB debugger to Eclipse CDT
  3. Debugging with Eclipse CDT and GDB
  4. How can I enter commands to a gdb prompt while debugging with Eclipse CDT?

I haven't tried it out yet, so I hope this works.

like image 184
Eitan T Avatar answered Oct 09 '22 09:10

Eitan T


On Windows platform:
The best way (to my experience) to debug a mex code is to use Visual studio. Here's a link on how to do it.

Other platforms (Linux/Mac):
I'm afraid I haven't find any good way to do so apart from gdb (which is not fun at all).

Update (2018):

Recently, Mathworks released a blog post describing how to use Visual Studio Code to debug mex code.
I haven't tried it myself, but it seems like a nice cross-platform solution for debugging mex files.

like image 36
Shai Avatar answered Oct 09 '22 07:10

Shai


Here is my solution which works in Ubuntu 12.04, Matlab R2012b, and Eclipse IDE for C/C++ Developers Kepler Release.

  1. In Eclipse open "Debug Configurations" from the run tab. Then make a new "C/C++ Application".
  2. In the "Main"-tab write the correct path to the matlab executable in the "C/C++ Application" (mine is "/usr/local/MATLAB/R2012b/bin/glnxa64/MATLAB" NOTE: not MATLABPATH/bin/matlab). Main tab
  3. In the "Arguments"-tab add "-nojvm" as program arguments. Arguments
  4. In the "Environment"-tab add variable "MATLAB_DEBUG" with value "gdb" Environment
  5. Press "Apply" and "Debug"
  6. A "Matlab console" will open in the "Console" view.
  7. Write "dbmex on" in this console. This enables debugging.
  8. Run the mex file! (Matlab will stop at loading of each new mex file)
  9. Have fun debugging! :-)
like image 7
Torstein I. Bø Avatar answered Oct 09 '22 07:10

Torstein I. Bø