This is the mail archive of the
systemtap@sourceware.org
mailing list for the systemtap project.
Re: Question regarding userspace tracing memcpy in glibc
- From: "Ariel Shaqed (Scolnicov)" <ariels at correlix dot com>
- To: systemtap at sources dot redhat dot com
- Cc: Holger Freyther <holger at freyther dot de>, "Frank Ch. Eigler" <fche at redhat dot com>
- Date: Thu, 9 Dec 2010 11:40:41 +0200
- Subject: Re: Question regarding userspace tracing memcpy in glibc
- References: <loom.20101126T174831-857@post.gmane.org> <y0mfwung32s.fsf@fche.csb>
On Fri, Nov 26, 2010 at 11:58 PM, Frank Ch. Eigler <fche@redhat.com> wrote:
>
> holger wrote:
>
>> [...]
>> I have an application that is spending some time copying structs with
>> memcpy. I wanted to use systemtap to figure out who is calling memcpy,
>> [...]
>> $ stap -e 'probe process("/lib/libc.so.6").function("memcpy") {printf();...}'
>> [...]
>> $ stap -e 'probe process("/lib/libc.so.6").function("__memcpy_ssse3")..
>> [...]
>
> Right. These are assembly language functions, with no dwarf data,
> just a symbol table entry. We ought to be able to attach to them
> anyway though, equivalently to ...
I believe the problem is much worse. Usually no functions are called
for memcpy (GCC implements them as intrinsics). E.g. info node
"(gcc)C Dialect Options" says (while explaining -fno-builtin, a switch
to turn off this behaviour):
GCC normally generates special code to handle certain built-in
functions more efficiently; for instance, calls to `alloca' may
become single instructions that adjust the stack directly, and
calls to `memcpy' may become inline copy loops. The resulting
code is often both smaller and faster, but since the function
calls no longer appear as such, you cannot set a breakpoint on
those calls, nor can you change the behavior of the functions by
linking with a different library.
Compiling some short test programs (on x86-64) with memcpy show a
variety of ways to implement memcpy, none of which involves calling a
function. Indeed, when the length of a short buffer is known at
compile time, GCC simply generates an unrolled loop of MOVQ
instructions!
[...]
HTH,
--
Ariel.