tracing malloc/free call

Corinna Vinschen
Fri Jan 16 15:44:00 GMT 2015

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 :}


Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <>

More information about the Cygwin-patches mailing list