From: James on
Hello,

I am trying to use the GNU mtrace library to debug a MEX file. Apparently it can be done (http://www.mathworks.com/support/solutions/en/data/1-18CLQ/index.html?solution=1-18CLQ).

I have managed to generate an mtrace output file that contains a long list of unfreed memory and never-alloc'd memory, looking something like this:

====
- 0x0b9bcbc0 Free 173 was never alloc'd 0x71c5df
- 0x0a2eefc0 Free 251 was never alloc'd 0x71c5df
- 0xa69b8ac8 Free 504 was never alloc'd 0x1d34eef

Memory not freed:
-----------------
Address Size Caller
0x09ee7b70 0x30 at 0x71c6cc
0x0a2c2010 0x30 at 0x71c6cc
0x0a47e638 0x14 at 0xc09106
0x0a47ed58 0x3c at 0x6ede44d
0xa6400018 0x7ff4 at 0xb5de6e5a
0xa6408010 0x7ff4 at 0xb5de6e5a
====

Normally the "Caller" field would look like this only if I used one argument to the mtrace command line utility. In the case above, I am using the required two arguments to mtrace, i.e. mtrace exec-name log-file. I've tried using the name of the mexglx file that generated the trace, the object file for that mex file, and of course the source code file, but none of them generate anything other than the memory addresses above. The mexglx file was compiled with the debug flag (-g), so the debug symbols are in there.

What executable name should I use to get mtrace to correctly translate the above Caller addresses into source code and line number data?

I am compiling with mtrace.h only imported in the mexFunction source. I didn't think I'd need to import it in the other source files.

Any ideas?

Thanks!
James
From: James on
I just tried importing mcheck.h into the other source files, but that didn't make a difference.

I forgot to mention: I'm using a mixed-language mex file composed of both C and Fortran (yeah I know, I don't like it either). I have no idea how mtrace handles that.