[lttng-dev] Addition of the return address to liblttng-ust-libc-wrapper
Olivier Delbeke
Olivier.Delbeke at awtce.be
Tue Jan 13 10:50:38 EST 2015
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 at 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 at aweurope.be, and permanently destroy the original as well as any copy thereof.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lttng.org/pipermail/lttng-dev/attachments/20150113/529cb49d/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 1E482660.jpg
Type: image/jpeg
Size: 9458 bytes
Desc: not available
URL: <http://lists.lttng.org/pipermail/lttng-dev/attachments/20150113/529cb49d/attachment-0001.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ecblank.gif
Type: image/gif
Size: 45 bytes
Desc: not available
URL: <http://lists.lttng.org/pipermail/lttng-dev/attachments/20150113/529cb49d/attachment-0001.gif>
More information about the lttng-dev
mailing list