The examples show how to debug
timestwo.F, found in your
Binary MEX files built with the
-g option do not execute
on other computers because they rely on files that are not distributed with
MATLAB® software. For more information on isolating problems with MEX
files, see Troubleshooting on C MEX File Applications.
For MEX files compiled with any version of the Intel® Visual Fortran compiler, you can use the debugging tools found in your version of Microsoft® Visual Studio®.
The MATLAB supported Fortran compiler g95 has a
option for building binary MEX files with debug information. Such files can
be used with gdb, the GNU® Debugger. This section describes using gdb.
In this example, the MATLAB command prompt
>> is shown in
front of MATLAB commands, and
linux> represents a
Linux® prompt; your system might show a different prompt. The
debugger prompt is
To compile the source MEX file, type:
linux> mex -g timestwo.F
At the Linux prompt, start the gdb debugger using the
linux> matlab -Dgdb
Start MATLAB without the Java® Virtual Machine (JVM™) by using the
<gdb> run -nojvm
In MATLAB, enable debugging with the
function and run your binary MEX file:
>> dbmex on >> y = timestwo(4)
You are ready to start debugging.
It is often convenient to set a breakpoint at
mexFunction so you stop at the
beginning of the gateway routine.
The compiler might alter the function name. For
example, it might append an underscore. To determine
how this symbol appears in a given MEX file, use the
timestwo.mexa64| grep -i mexfunction
The operating system responds with something like:
0000091c T mexfunction_
mexFunction in the
breakpoint statement. Be sure to use the correct
<gdb> break mexfunction_ <gdb> continue
Once you hit one of your breakpoints, you can make full use of any commands the debugger provides to examine variables, display memory, or inspect registers.
To proceed from a breakpoint, type
After stopping at the last breakpoint, type:
timestwo finishes and MATLAB displays:
y = 8
From the MATLAB prompt you can return control to the debugger by typing:
>> dbmex stop
Or, if you are finished running MATLAB, type:
When you are finished with the debugger, type:
You return to the Linux prompt.
Refer to the documentation provided with your debugger for more information on its use.