This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
[Bug libc/12831] New: mtrace location not usefull for C++
- From: "yair.lenga at citi dot com" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sources dot redhat dot com
- Date: Wed, 1 Jun 2011 08:28:07 +0000
- Subject: [Bug libc/12831] New: mtrace location not usefull for C++
- Auto-submitted: auto-generated
http://sourceware.org/bugzilla/show_bug.cgi?id=12831
Summary: mtrace location not usefull for C++
Product: glibc
Version: unspecified
Status: NEW
Severity: normal
Priority: P2
Component: libc
AssignedTo: drepper.fsp@gmail.com
ReportedBy: yair.lenga@citi.com
Summary:
The address reported by mtrace for C++ program is the location of the new
operators, and not the name of the calling program.
Long Description:
I've been working with mtrace output for the last few days to resolve a complex
memory management bug in C++ program. While the mtrace output provides
essential information, the address field is provided with each line is useless,
as it points to the new operators inside the c++ runtime library.
The correct/better behavior is to retrieve the address of the calling program
for the c++ new operators (using backtrace-like function), and using it in the
trace output file. This could be done whenever the address resolve to
"/usr/lib/libstdc++.so.6:(_Znwj+0x27)[0x258bb7]" address.
More general solution will allow specifying allowing user-defined env var to
control list of ".so", which should be ignored.
Even better solution will include addresses from multiple frames of the
backtrace, which will make it easier to capture the calling stack of the code
during the memory allocation.
In theory, all of those can be done using the malloc hooks. However,
implementing the hooks is very hard for most users. Implementing the proposed
solution in glibc will make the mtrace function significantly more valuable for
c++ developers.
Example:
consider the following C++ memory leaking program (complete source below). The
output is:
Memory not freed:
-----------------
Address Size Caller
0x084d9378 0x186a0 at prog.cc:11
0x084f1a20 0x2710 at prog.cc:12
0xb755a008 0xf4240 at 0x258bb7
0xb764f008 0xf4240 at 0x258bb7
The location of the malloc/calloc calls is resolved to line number. However,
all the "new" calls do not show the correct line number.
Complete example:
g++ -g prog.cc
export MALLOC_TRACE=trace.txt
./a.out
cat trace.txt
mtrace a.out trace.txt
Program: prog.cc
#include <mcheck.h>
#include <stdlib.h>
class T1 { char c[10000] ; } ;
int f(void)
{
mtrace() ;
static T1 *x = new T1[100] ;
static T1 *u = new T1[100] ;
static T1 *y = (T1 *)calloc(10, sizeof(T1)) ;
static T1 *z = (T1 *)malloc(sizeof(T1)) ;
}
int main(void)
{
f();
}
--
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.