Mtrace / addr2line not resolving address to file + line numb

I am attempting to use mtrace to do some memory leak detection but am unable to get it to resolve addresses to file names with line numbers. I have been working at this for at least 2 days now and am out of ideas. I hope someone at this forum may be able to offer some assistance.

I have created a very simple c++ file to test with:

[code]linuxcom-04> cat

using namespace std;

int main(int argc, char argv[])
cout ‘angle angle’ “hello world” ‘angle angle’ endl
str = new char[20];

I have set the environment variable:

linuxcom-04> echo $MALLOC_TRACE leak.out

And compiled with debugging:

linuxcom-04> g++ -g linuxcom-04> ls a.out

Ran the program once and got the mtrace output file

[code]linuxcom-04> ./a.out
hello world

linuxcom-04> ls
a.out leak.out

Ran mtrace with the executable name and the log file

[code]linuxcom-04> mtrace a.out leak.out

Memory not freed:

Address Size Caller
0x0949a378 0x14 at 0x92b86e

and only got the address of the caller. I believe mtrace uses addr2line so I figured I would attempt using that directly, but it was no help:

linuxcom-04> addr2line -e a.out 0x92b86e ??:0

linuxcom-04> addr2line --version
GNU addr2line 20060715

linuxcom-04> mtrace --version
mtrace (GNU libc) 2.3.2

I have tried on both ppc and i386-linux systems with different executables. I have updated binutils. I’ve done a mess of other little things trying to find out what the problem could possibly be.

I really hope someone here will be able to offer some assistance and end my suffering.

Thank you for your time,
-Jesse Harvey

Hi Jesse,

we are all very happy with valgrind from Did you ever consider using that instead?

Cheers, Axel.

Hey Axel, thanks for the quick reply.

We have considered and even attempted using Valgrind but the majority of our code is PPC and running on an e500 processor so in order to get coverage with that we would need to stop out all e500 code…which would be quite a big task.

I would appreciate it if anyone had any other advice. Thanks again for your help Axel!

Hi Jesse,

OK, that’s too bad for you :slight_smile: Now, try to add the line void* str2 = malloc(42); and re-build and re-run a.out. You’ll now see two lines in leak.out, something like @ /usr/lib/[0x1a9abe] + 0x915f378 0x14 @ ./a.out:(__gxx_personality_v0+0x225)[0x80488c5] + 0x915f390 0x2aAnd that explains why addr2line didn’t manage to tell you the func name: it’s not in a.out, because mtrace traces the C memory allocation, i.e. malloc and not new. new uses malloc, but only in libstdc++. Even if you’re able to convince addr2line to print the func name in libstdc++ it will only tell you that it happens in “new” or one of its work horses in libstdc++.

Summary: mtrace is not very helpful for C++ code. You might want to look for other tools. You can check ROOT’s memprobe facility, or Wim’s Hephaestus, e.g. at … stus/html/
No idea which one will work on your platform…

Cheers, Axel.

Thanks for the reply, I don’t know how I didn’t notice that in the first place…I guess I was too excited that I almost found a solution to our problem. I really appreciate the time you took to help me out. I will look into the other options you suggested and hopefully something will work for us.

Thanks again!
-Jesse Harvey