User`s manual

3 Creating Fortran MEX-Files
3-38
Debugging Fortran Language MEX-Files
On most platforms, it is now possible to debug MEX-files while they are
running within MATLAB. Complete source code debugging, including setting
breakpoints, examining variables, and stepping through the source code
line-by-line, is now available.
Note The section on “Troubleshooting” on page 1-32 provides additional
information on isolating problems with MEX-files.
To debug a MEX-file from within MATLAB, you must first compile the
MEX-file with the
-g option to mex.
mex -g filename.f
Debugging on UNIX
You must start MATLAB from within a debugger. To do this, specify the name
of the debugger you want to use with the
-D option when starting MATLAB.
For example, to use
dbx, the UNIX debugger, type
matlab -Ddbx
Once the debugger loads MATLAB into memory, you can start it by issuing a
run command. Now, from within MATLAB, enable MEX-file debugging by
typing
dbmex on
at the MATLAB prompt. Then run the MEX-file you want to debug as you
would ordinarily (either directly or by means of some other function or script).
Before executing the MEX-file, you will be returned to the debugger.
You may need to tell the debugger where the MEX-file was loaded or the name
of the MEX-file, in which case MATLAB will display the appropriate command
for you to use. At this point, you are ready to start debugging. You can list the
source code for your MEX-file and set break points in it. It is often convenient
to set one at
mexFunction so that you stop at the beginning of the gateway
routine.