<html><body><p><font size="2" face="sans-serif">Hi guys,</font><br><br><font size="2" face="sans-serif">I am using liblttng-ust-libc-wrapper to detect memory leaks in my applications. </font><br><font size="2" face="sans-serif">In order to identify not only the thread where the unfreed allocations are done, but also the calling function, I extended the liblttng-ust-libc-wrapper to log the "return address" (__builtin_return_address(0)) in addition to the parameters of malloc(). It solves my problem and does not affect Trace Compass.</font><br><font size="2" face="sans-serif">Was this the right thing to do ? </font><br><font size="2" face="sans-serif">If it is, then I guess that it might interest other people too.</font><br><br><font size="2" face="sans-serif">diff -Nurd b/liblttng-ust-libc-wrapper/lttng-ust-malloc.c c/liblttng-ust-libc-wrapper/lttng-ust-malloc.c</font><br><font size="2" face="sans-serif">--- b/liblttng-ust-libc-wrapper/lttng-ust-malloc.c 2015-01-06 17:14:34.000000000 +0100</font><br><font size="2" face="sans-serif">+++ c/liblttng-ust-libc-wrapper/lttng-ust-malloc.c 2015-01-06 17:16:40.811145106 +0100</font><br><font size="2" face="sans-serif">@@ -260,7 +260,7 @@</font><br><font size="2" face="sans-serif"> }</font><br><font size="2" face="sans-serif"> retval = cur_alloc.malloc(size);</font><br><font size="2" face="sans-serif"> if (URCU_TLS(malloc_nesting) == 1) {</font><br><font size="2" face="sans-serif">- tracepoint(ust_libc, malloc, size, retval);</font><br><font size="2" face="sans-serif">+ tracepoint(ust_libc, malloc, size, retval, __builtin_return_address(0) );</font><br><font size="2" face="sans-serif"> }</font><br><font size="2" face="sans-serif"> URCU_TLS(malloc_nesting)--;</font><br><font size="2" face="sans-serif"> return retval;</font><br><font size="2" face="sans-serif">@@ -279,7 +279,7 @@</font><br><font size="2" face="sans-serif"> }</font><br><font size="2" face="sans-serif"> </font><br><font size="2" face="sans-serif"> if (URCU_TLS(malloc_nesting) == 1) {</font><br><font size="2" face="sans-serif">- tracepoint(ust_libc, free, ptr);</font><br><font size="2" face="sans-serif">+ tracepoint(ust_libc, free, ptr, __builtin_return_address(0) );</font><br><font size="2" face="sans-serif"> }</font><br><font size="2" face="sans-serif"> </font><br><font size="2" face="sans-serif"> if (cur_alloc.free == NULL) {</font><br><font size="2" face="sans-serif">@@ -308,7 +308,7 @@</font><br><font size="2" face="sans-serif"> }</font><br><font size="2" face="sans-serif"> retval = cur_alloc.calloc(nmemb, size);</font><br><font size="2" face="sans-serif"> if (URCU_TLS(malloc_nesting) == 1) {</font><br><font size="2" face="sans-serif">- tracepoint(ust_libc, calloc, nmemb, size, retval);</font><br><font size="2" face="sans-serif">+ tracepoint(ust_libc, calloc, nmemb, size, retval, __builtin_return_address(0) );</font><br><font size="2" face="sans-serif"> }</font><br><font size="2" face="sans-serif"> URCU_TLS(malloc_nesting)--;</font><br><font size="2" face="sans-serif"> return retval;</font><br><font size="2" face="sans-serif">@@ -360,7 +360,7 @@</font><br><font size="2" face="sans-serif"> retval = cur_alloc.realloc(ptr, size);</font><br><font size="2" face="sans-serif"> end:</font><br><font size="2" face="sans-serif"> if (URCU_TLS(malloc_nesting) == 1) {</font><br><font size="2" face="sans-serif">- tracepoint(ust_libc, realloc, ptr, size, retval);</font><br><font size="2" face="sans-serif">+ tracepoint(ust_libc, realloc, ptr, size, retval, __builtin_return_address(0) );</font><br><font size="2" face="sans-serif"> }</font><br><font size="2" face="sans-serif"> URCU_TLS(malloc_nesting)--;</font><br><font size="2" face="sans-serif"> return retval;</font><br><font size="2" face="sans-serif">@@ -380,7 +380,7 @@</font><br><font size="2" face="sans-serif"> }</font><br><font size="2" face="sans-serif"> retval = cur_alloc.memalign(alignment, size);</font><br><font size="2" face="sans-serif"> if (URCU_TLS(malloc_nesting) == 1) {</font><br><font size="2" face="sans-serif">- tracepoint(ust_libc, memalign, alignment, size, retval);</font><br><font size="2" face="sans-serif">+ tracepoint(ust_libc, memalign, alignment, size, retval, __builtin_return_address(0) );</font><br><font size="2" face="sans-serif"> }</font><br><font size="2" face="sans-serif"> URCU_TLS(malloc_nesting)--;</font><br><font size="2" face="sans-serif"> return retval;</font><br><font size="2" face="sans-serif">@@ -401,7 +401,7 @@</font><br><font size="2" face="sans-serif"> retval = cur_alloc.posix_memalign(memptr, alignment, size);</font><br><font size="2" face="sans-serif"> if (URCU_TLS(malloc_nesting) == 1) {</font><br><font size="2" face="sans-serif"> tracepoint(ust_libc, posix_memalign, *memptr, alignment, size,</font><br><font size="2" face="sans-serif">- retval);</font><br><font size="2" face="sans-serif">+ retval, __builtin_return_address(0) );</font><br><font size="2" face="sans-serif"> }</font><br><font size="2" face="sans-serif"> URCU_TLS(malloc_nesting)--;</font><br><font size="2" face="sans-serif"> return retval;</font><br><font size="2" face="sans-serif">diff -Nurd b/liblttng-ust-libc-wrapper/ust_libc.h c/liblttng-ust-libc-wrapper/ust_libc.h</font><br><font size="2" face="sans-serif">--- b/liblttng-ust-libc-wrapper/ust_libc.h 2015-01-06 17:14:34.000000000 +0100</font><br><font size="2" face="sans-serif">+++ c/liblttng-ust-libc-wrapper/ust_libc.h 2015-01-06 17:16:40.811145106 +0100</font><br><font size="2" face="sans-serif">@@ -33,54 +33,60 @@</font><br><font size="2" face="sans-serif"> #include <lttng/tracepoint.h></font><br><font size="2" face="sans-serif"> </font><br><font size="2" face="sans-serif"> TRACEPOINT_EVENT(ust_libc, malloc,</font><br><font size="2" face="sans-serif">- TP_ARGS(size_t, size, void *, ptr),</font><br><font size="2" face="sans-serif">+ TP_ARGS(size_t, size, void *, ptr, void *, ra),</font><br><font size="2" face="sans-serif"> TP_FIELDS(</font><br><font size="2" face="sans-serif"> ctf_integer(size_t, size, size)</font><br><font size="2" face="sans-serif"> ctf_integer_hex(void *, ptr, ptr)</font><br><font size="2" face="sans-serif">+ ctf_integer_hex(void *, ra, ra)</font><br><font size="2" face="sans-serif"> )</font><br><font size="2" face="sans-serif"> )</font><br><font size="2" face="sans-serif"> </font><br><font size="2" face="sans-serif"> TRACEPOINT_EVENT(ust_libc, free,</font><br><font size="2" face="sans-serif">- TP_ARGS(void *, ptr),</font><br><font size="2" face="sans-serif">+ TP_ARGS(void *, ptr, void *, ra),</font><br><font size="2" face="sans-serif"> TP_FIELDS(</font><br><font size="2" face="sans-serif"> ctf_integer_hex(void *, ptr, ptr)</font><br><font size="2" face="sans-serif">+ ctf_integer_hex(void *, ra, ra)</font><br><font size="2" face="sans-serif"> )</font><br><font size="2" face="sans-serif"> )</font><br><font size="2" face="sans-serif"> </font><br><font size="2" face="sans-serif"> TRACEPOINT_EVENT(ust_libc, calloc,</font><br><font size="2" face="sans-serif">- TP_ARGS(size_t, nmemb, size_t, size, void *, ptr),</font><br><font size="2" face="sans-serif">+ TP_ARGS(size_t, nmemb, size_t, size, void *, ptr, void *, ra),</font><br><font size="2" face="sans-serif"> TP_FIELDS(</font><br><font size="2" face="sans-serif"> ctf_integer(size_t, nmemb, nmemb)</font><br><font size="2" face="sans-serif"> ctf_integer(size_t, size, size)</font><br><font size="2" face="sans-serif"> ctf_integer_hex(void *, ptr, ptr)</font><br><font size="2" face="sans-serif">+ ctf_integer_hex(void *, ra, ra)</font><br><font size="2" face="sans-serif"> )</font><br><font size="2" face="sans-serif"> )</font><br><font size="2" face="sans-serif"> </font><br><font size="2" face="sans-serif"> TRACEPOINT_EVENT(ust_libc, realloc,</font><br><font size="2" face="sans-serif">- TP_ARGS(void *, in_ptr, size_t, size, void *, ptr),</font><br><font size="2" face="sans-serif">+ TP_ARGS(void *, in_ptr, size_t, size, void *, ptr, void *, ra),</font><br><font size="2" face="sans-serif"> TP_FIELDS(</font><br><font size="2" face="sans-serif"> ctf_integer_hex(void *, in_ptr, in_ptr)</font><br><font size="2" face="sans-serif"> ctf_integer(size_t, size, size)</font><br><font size="2" face="sans-serif"> ctf_integer_hex(void *, ptr, ptr)</font><br><font size="2" face="sans-serif">+ ctf_integer_hex(void *, ra, ra)</font><br><font size="2" face="sans-serif"> )</font><br><font size="2" face="sans-serif"> )</font><br><font size="2" face="sans-serif"> </font><br><font size="2" face="sans-serif"> TRACEPOINT_EVENT(ust_libc, memalign,</font><br><font size="2" face="sans-serif">- TP_ARGS(size_t, alignment, size_t, size, void *, ptr),</font><br><font size="2" face="sans-serif">+ TP_ARGS(size_t, alignment, size_t, size, void *, ptr, void *, ra),</font><br><font size="2" face="sans-serif"> TP_FIELDS(</font><br><font size="2" face="sans-serif"> ctf_integer(size_t, alignment, alignment)</font><br><font size="2" face="sans-serif"> ctf_integer(size_t, size, size)</font><br><font size="2" face="sans-serif"> ctf_integer_hex(void *, ptr, ptr)</font><br><font size="2" face="sans-serif">+ ctf_integer_hex(void *, ra, ra)</font><br><font size="2" face="sans-serif"> )</font><br><font size="2" face="sans-serif"> )</font><br><font size="2" face="sans-serif"> </font><br><font size="2" face="sans-serif"> TRACEPOINT_EVENT(ust_libc, posix_memalign,</font><br><font size="2" face="sans-serif">- TP_ARGS(void *, out_ptr, size_t, alignment, size_t, size, int, result),</font><br><font size="2" face="sans-serif">+ TP_ARGS(void *, out_ptr, size_t, alignment, size_t, size, int, result, void *, ra),</font><br><font size="2" face="sans-serif"> TP_FIELDS(</font><br><font size="2" face="sans-serif"> ctf_integer_hex(void *, out_ptr, out_ptr)</font><br><font size="2" face="sans-serif"> ctf_integer(size_t, alignment, alignment)</font><br><font size="2" face="sans-serif"> ctf_integer(size_t, size, size)</font><br><font size="2" face="sans-serif"> ctf_integer(int, result, result)</font><br><font size="2" face="sans-serif">+ ctf_integer_hex(void *, ra, ra)</font><br><font size="2" face="sans-serif"> )</font><br><font size="2" face="sans-serif"> )</font><br><font size="2" face="sans-serif"> </font><br><font size="2" face="sans-serif">Best regards,</font><table border="0" cellspacing="0" cellpadding="0"><tr valign="top"><td width="108" rowspan="2" valign="middle"><div align="center"><img src="cid:1__=4EBBF75FDFC078EC8f9e8a93df93@aweurope.be" width="107" height="98" align="bottom"></div></td><td width="788"><img width="1" height="1" src="cid:2__=4EBBF75FDFC078EC8f9e8a93df93@aweurope.be" border="0" alt=""></td></tr>
<tr valign="top"><td width="788" valign="middle"><ul style="padding-left: 0pt"><font size="3" color="#000080" face="Calibri"><b>Olivier Delbeke </b></font><font size="3" color="#000080" face="Calibri"><i>Senior Software Engineer</i></font><font size="3" color="#565051" face="Calibri"><br>Olivier.Delbeke@awtce.be / T. +32 2 389 25 53</font><hr width="100%" size="2" align="left" noshade style="color:#333399; "><font size="3" face="serif"> </font><font size="1" color="#000080" face="Calibri"><b>AWTC Europe S.A. </b></font><font size="1" color="#565051" face="Calibri">- Avenue de l’Industrie, 19 - 1420 Braine-l’Alleud - Belgium - www.aweurope.eu - www.aisin-aw.co.jp<br>VAT : BE 0474.474.114 - RPM Nivelles</font><font size="3" face="serif"> </font></ul></td></tr></table><br><font face="sans-serif">
This mail, and any attachments thereto, is intended only for use by the addressee(s) named herein and may contain legally privileged and/or confidential information. If you are not the intended recipient, please note that any review, dissemination, disclosure, alteration, printing, copying or transmission of this mail and/or any file transmitted with it, is strictly prohibited and may be unlawful. If you have received this mail by mistake, please immediately notify the sender as well as our mail administrator at postmaster@aweurope.be, and permanently destroy the original as well as any copy thereof.
</font>
</body></html>