This is the mail archive of the cygwin-patches mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: tracing malloc/free call


Hi Marco,

On Jan 16 15:23, Marco Atzeri wrote:
> On 1/15/2015 10:34 AM, Corinna Vinschen wrote:
> >Bottom line, you should be able to fetch the original return address by
> >printing the value at
> >
> >   *(void*)_my_tls->stackptr
> >
> >which points to the uppermost entry on the stack.
> 
> Hi Corinna,
> 
> in reality I found it is "*(_my_tls.stackptr-1)"

Oh, right!  Sorry about that.  I missed to take the behavior of xadd
into account.

> -  malloc_printf ("(%p), called by %p", p, __builtin_return_address (0));
> +  malloc_printf ("(%p), called by %p", p, *(_my_tls.stackptr-1));
> 
> Attached patch that allows tracking of original caller,
> for the 4 memory allocation calls.
> 
> Tested on 64 bit.
> 
>  $ grep 0x6000D6AA1 ncview.strace4
>    20 1605112 [main] ncview 4408 free: (0x6000D6AA1), called by 0x10040E744
> 
> 
>  $ addr2line.exe -a 0x10040E744 -e /usr/bin/ncview.exe
> 0x000000010040e744
> /usr/src/debug/ncview-2.1.4-2/src/file_netcdf.c:271

Thanks for the patch, but it won't work nicely either this way.  The
problem is that, in theory, the code has to differ between internal and
external callers.  Internal callers (that is, Cygwin functions itself)
don't hop into the function via _sigfe/_sigbe.  Thus the output for
internal callers of malloc/free is now wrong with your patch.

The solution for this problem would be a test which checks if the return
address is the _sigbe function and if so, returns *(_my_tls.stackptr-1),
otherwise __builtin_return_address(0).  However, the symbol _sigbe is
not exported since, so far, it was only used inside _sigfe.  This needs
a bit of tweaking.  I'll have a look.

Btw., when sending a patch, a matching ChangeLog entry would be quite
helpful :}


Thanks,
Corinna


-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

Attachment: pgpHmDa4NDg8_.pgp
Description: PGP signature


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]