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


On 1/15/2015 10:34 AM, Corinna Vinschen wrote:
Hi Marco,

On Jan 14 23:30, Marco Atzeri wrote:
Debugging a program I am trying to catch where this call is happening

17 1499678 [main] ncview 1484 free: (0x6000D7961), called by 0x180115A0B

unfortunately the 0x180115A0B address is not real caller address

No, the return address is the address of the _sigbe function defined in
the gendef script...

[cut]

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)"

-  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


Regards
Marco







Attachment: malloc_wrapper.patch
Description: Text document


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