All of lore.kernel.org
 help / color / mirror / Atom feed
* Addition of the return address to liblttng-ust-libc-wrapper
@ 2015-01-13 15:50 Olivier Delbeke
  0 siblings, 0 replies; 10+ messages in thread
From: Olivier Delbeke @ 2015-01-13 15:50 UTC (permalink / raw)
  To: lttng-dev


[-- Attachment #1.1.1: Type: text/plain, Size: 6863 bytes --]


Hi guys,

I am using liblttng-ust-libc-wrapper to detect memory leaks in my
applications.
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.
Was this the right thing to do ?
If it is, then I guess that it might interest other people too.

diff -Nurd b/liblttng-ust-libc-wrapper/lttng-ust-malloc.c
c/liblttng-ust-libc-wrapper/lttng-ust-malloc.c
--- b/liblttng-ust-libc-wrapper/lttng-ust-malloc.c    2015-01-06
17:14:34.000000000 +0100
+++ c/liblttng-ust-libc-wrapper/lttng-ust-malloc.c    2015-01-06
17:16:40.811145106 +0100
@@ -260,7 +260,7 @@
      }
      retval = cur_alloc.malloc(size);
      if (URCU_TLS(malloc_nesting) == 1) {
-           tracepoint(ust_libc, malloc, size, retval);
+           tracepoint(ust_libc, malloc, size, retval,
__builtin_return_address(0) );
      }
      URCU_TLS(malloc_nesting)--;
      return retval;
@@ -279,7 +279,7 @@
      }

      if (URCU_TLS(malloc_nesting) == 1) {
-           tracepoint(ust_libc, free, ptr);
+           tracepoint(ust_libc, free, ptr, __builtin_return_address(0) );
      }

      if (cur_alloc.free == NULL) {
@@ -308,7 +308,7 @@
      }
      retval = cur_alloc.calloc(nmemb, size);
      if (URCU_TLS(malloc_nesting) == 1) {
-           tracepoint(ust_libc, calloc, nmemb, size, retval);
+           tracepoint(ust_libc, calloc, nmemb, size, retval,
__builtin_return_address(0) );
      }
      URCU_TLS(malloc_nesting)--;
      return retval;
@@ -360,7 +360,7 @@
      retval = cur_alloc.realloc(ptr, size);
 end:
      if (URCU_TLS(malloc_nesting) == 1) {
-           tracepoint(ust_libc, realloc, ptr, size, retval);
+           tracepoint(ust_libc, realloc, ptr, size, retval,
__builtin_return_address(0) );
      }
      URCU_TLS(malloc_nesting)--;
      return retval;
@@ -380,7 +380,7 @@
      }
      retval = cur_alloc.memalign(alignment, size);
      if (URCU_TLS(malloc_nesting) == 1) {
-           tracepoint(ust_libc, memalign, alignment, size, retval);
+           tracepoint(ust_libc, memalign, alignment, size, retval,
__builtin_return_address(0) );
      }
      URCU_TLS(malloc_nesting)--;
      return retval;
@@ -401,7 +401,7 @@
      retval = cur_alloc.posix_memalign(memptr, alignment, size);
      if (URCU_TLS(malloc_nesting) == 1) {
            tracepoint(ust_libc, posix_memalign, *memptr, alignment, size,
-                 retval);
+                 retval, __builtin_return_address(0) );
      }
      URCU_TLS(malloc_nesting)--;
      return retval;
diff -Nurd b/liblttng-ust-libc-wrapper/ust_libc.h
c/liblttng-ust-libc-wrapper/ust_libc.h
--- b/liblttng-ust-libc-wrapper/ust_libc.h      2015-01-06
17:14:34.000000000 +0100
+++ c/liblttng-ust-libc-wrapper/ust_libc.h      2015-01-06
17:16:40.811145106 +0100
@@ -33,54 +33,60 @@
 #include <lttng/tracepoint.h>

 TRACEPOINT_EVENT(ust_libc, malloc,
-     TP_ARGS(size_t, size, void *, ptr),
+     TP_ARGS(size_t, size, void *, ptr, void *, ra),
      TP_FIELDS(
            ctf_integer(size_t, size, size)
            ctf_integer_hex(void *, ptr, ptr)
+           ctf_integer_hex(void *, ra, ra)
      )
 )

 TRACEPOINT_EVENT(ust_libc, free,
-     TP_ARGS(void *, ptr),
+     TP_ARGS(void *, ptr, void *, ra),
      TP_FIELDS(
            ctf_integer_hex(void *, ptr, ptr)
+           ctf_integer_hex(void *, ra, ra)
      )
 )

 TRACEPOINT_EVENT(ust_libc, calloc,
-     TP_ARGS(size_t, nmemb, size_t, size, void *, ptr),
+     TP_ARGS(size_t, nmemb, size_t, size, void *, ptr, void *, ra),
      TP_FIELDS(
            ctf_integer(size_t, nmemb, nmemb)
            ctf_integer(size_t, size, size)
            ctf_integer_hex(void *, ptr, ptr)
+           ctf_integer_hex(void *, ra, ra)
      )
 )

 TRACEPOINT_EVENT(ust_libc, realloc,
-     TP_ARGS(void *, in_ptr, size_t, size, void *, ptr),
+     TP_ARGS(void *, in_ptr, size_t, size, void *, ptr, void *, ra),
      TP_FIELDS(
            ctf_integer_hex(void *, in_ptr, in_ptr)
            ctf_integer(size_t, size, size)
            ctf_integer_hex(void *, ptr, ptr)
+           ctf_integer_hex(void *, ra, ra)
      )
 )

 TRACEPOINT_EVENT(ust_libc, memalign,
-     TP_ARGS(size_t, alignment, size_t, size, void *, ptr),
+     TP_ARGS(size_t, alignment, size_t, size, void *, ptr, void *, ra),
      TP_FIELDS(
            ctf_integer(size_t, alignment, alignment)
            ctf_integer(size_t, size, size)
            ctf_integer_hex(void *, ptr, ptr)
+           ctf_integer_hex(void *, ra, ra)
      )
 )

 TRACEPOINT_EVENT(ust_libc, posix_memalign,
-     TP_ARGS(void *, out_ptr, size_t, alignment, size_t, size, int,
result),
+     TP_ARGS(void *, out_ptr, size_t, alignment, size_t, size, int,
result, void *, ra),
      TP_FIELDS(
            ctf_integer_hex(void *, out_ptr, out_ptr)
            ctf_integer(size_t, alignment, alignment)
            ctf_integer(size_t, size, size)
            ctf_integer(int, result, result)
+           ctf_integer_hex(void *, ra, ra)
      )
 )

Best regards,
                                                                                                                  
                                                                                                                  
                                                                                                                  
               Olivier Delbeke Senior Software Engineer                                                           
               Olivier.Delbeke@awtce.be / T. +32 2 389 25 53 AWTC Europe S.A. - Avenue de l’Industrie, 19 - 1420  
               Braine-l’Alleud - Belgium - www.aweurope.eu - www.aisin-aw.co.jp                                   
               VAT : BE 0474.474.114 - RPM Nivelles                                                               
                                                                                                                  
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.  

[-- Attachment #1.1.2: Type: text/html, Size: 13538 bytes --]

[-- Attachment #1.2: 1E482660.jpg --]
[-- Type: image/jpeg, Size: 9458 bytes --]

[-- Attachment #1.3: ecblank.gif --]
[-- Type: image/gif, Size: 45 bytes --]

[-- Attachment #2: Type: text/plain, Size: 155 bytes --]

_______________________________________________
lttng-dev mailing list
lttng-dev@lists.lttng.org
http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2015-01-19 19:29 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <OF7097A1B1.090ABAC2-ONC1257DCC.0053FE7C-C1257DCC.00570880@LocalDomain>
2015-01-16 20:13 ` Addition of the return address to liblttng-ust-libc-wrapper Mathieu Desnoyers
     [not found] ` <1127206322.43789.1421439222351.JavaMail.zimbra@efficios.com>
2015-01-16 20:32   ` Simon Marchi
     [not found]   ` <CAFXXi0nzOHHPx+h5vUs-pCe1-zT0T=6jNq6L+EJN6z0Nh-_NMA@mail.gmail.com>
2015-01-16 20:37     ` Mathieu Desnoyers
2015-01-16 20:41 ` Mathieu Desnoyers
     [not found] ` <54250547.44000.1421440866572.JavaMail.zimbra@efficios.com>
2015-01-16 20:57   ` Olivier Delbeke
     [not found]   ` <OF208CF361.F3A478C1-ONC1257DD2.00266C5D-C1257DD2.0026BC70@LocalDomain>
2015-01-19 16:48     ` Addition of the return address toliblttng-ust-libc-wrapper Mathieu Desnoyers
     [not found]     ` <1097959140.8621.1421686124960.JavaMail.zimbra@efficios.com>
2015-01-19 17:19       ` Olivier Delbeke
     [not found]       ` <CAO6pHzgetc1HSYvmOzh5u7oMt5LANv1Ttb=qxTdqchspXaGhdg@mail.gmail.com>
2015-01-19 19:15         ` Mathieu Desnoyers
     [not found]         ` <1680663293.9819.1421694937650.JavaMail.zimbra@efficios.com>
2015-01-19 19:28           ` Olivier Delbeke
2015-01-13 15:50 Addition of the return address to liblttng-ust-libc-wrapper Olivier Delbeke

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.