The examples show how to debug
found in your
Binary MEX files built with the
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 Troubleshoot MEX Files.
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®. Refer to the "Creating C/C++ Language MEX Files" topic Debugging on Microsoft Windows Platforms for instructions on using this debugger.
The MATLAB supported Fortran compiler g95 has a
for building binary MEX files with debug information. Such files can
be used with gdb, the GNU® Debugger. This section describes using
In this example, the MATLAB command prompt
shown in front of MATLAB commands, and
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
linux> matlab -Dgdb
Start MATLAB without the Java® Virtual Machine
(JVM™) by using the
-nojvm startup flag:
<gdb> run -nojvm
In MATLAB, enable debugging with the
dbmex function and run your binary MEX
>> dbmex on >> y = timestwo(4)
You are ready to start debugging.
It is often convenient to set a breakpoint at
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 Linux command
The operating system responds with something like:
0000091c T mexfunction_
<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.