Debugging a project which has mex files associated with it

Hi All, I have a project which I need to run. It has a few (10s) .m files and a few (5ish) mex files. I am in ubuntu. I have to debug the code. I can seem to run .m debugging and 1 mex file at a time debugging using matlab and gdb respectively. But I can't get to run both of them together. I have spend considerable amount of time on this and been using terminal and emacs and matlab. I have tried everything that was told online but most of the things were either only for mex files or only for .m files. how on earth do i get a project to debug ???
~neeraj

Answers (2)

Could you explain more about what you mean by "can't get to run both of them together"? I have debugged MATLAB files and C-MEX files together - the MATLAB breakpoints are to be set in the MATLAB Editor and the MEX breakpoints in the gdb. I would also recommend that you start MATLAB with the -nodesktop option when attaching with gdb - I have found that this is faster because all the additional libraries required to render the desktop need not be loaded.
Also, could you try running gdb from the shell (instead of from emacs) to see if that makes a difference? I understand that it's harder to set C breakpoints, but this setup has worked well for me in the past.
PS: Please remember to compile your MEX function with the -g (debug) option.
@KAUSTUBHA
I have tried gdb from shell and from emacs both. With shell i constantly get an error SIGUSR1 and the matlab (without jvm) crashes . This can happen with things as stupid as trying to load an image.
The step I follow are :
1)<linux> : matlab -Dgdb 2)<gdb> : run -nojvm 3)>> (load image) 4)>> (load some more variables) 5)>> run a program (.m) . with some breakpoints set.
So, when you mean i can set the breakpionts in mex files from gdb you mean i have to set the breakpoints before i start running the jvm ? If I do that i get the same error of SIGUSR1 ALL THE TIME and the system crashes. Other thing that happens is gdb can't even find the function loaded in its memory. I can't run that mex file because it requires variables which are set in .m files. I have no idea what that SIGUSR1 means and not even mathworks technical support has been able to pin down this problem.
Did you face something similar ?
~neeraj (...on the verge of loosing my faith in emacs and gdb)

1 Comment

Neeraj: It shouldn't matter whether you set the MEX breakpoint before starting MATLAB or after. Could you explain what you mean by "before i start running the jvm"? How do you start the JVM? I have found that running MATLAB with the -nojvm option is most reliable, because apparently JVM uses some signals like SIGSEGV during normal operation. A comment on this page suggests that you run "handle SIGSEGV pass noprint nostop" in gdb to avoid running into issues with SIGSEGV. I wonder if running "handle SIGUSR1 nostop" in gdb before "run -nojvm" might fix that?

Sign in to comment.

Categories

Products

Asked:

on 27 Jun 2012

Community Treasure Hunt

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

Start Hunting!