Trapping malloc using systemtap

Frank Ch. Eigler fche@redhat.com
Wed Feb 23 12:32:00 GMT 2011


Hi -

deepak.venkatesh wrote:
> [...]
>        How can I probe the function call to malloc. Also how can I get
> return value of malloc in systemtap script considering the below piece
> of code.
> [...]
> The steps I followed:
>     $ gcc -g test.c                 #which generated a.out file
>     $ stap -e 'probe process("a.out").function("malloc")
> {print_ubacktrace()}' -c './a.out'

The problem here is that the malloc function is not *defined* in the
a.out process, only referenced from there.  At this time, we have no
syntax for probing the shared library PLT to trap references
(PR12215).  However, we can probe the definition site in the shared
library:

    probe process("/lib*/libc.so.*").function("malloc") {}

To grab the return value:

    probe process("/lib*/libc.so.*").function("malloc").return {
         do_something_with($return)
    }


> Also can you please tell me whether system tap supports static linking
> of shared libraries. If yes, please direct me to the corresponding page.

systemtap does not get involved in how you link your programs.  If you
link libc statically, your original process("a.out").function("malloc")
probe would probably work.

- FChE



More information about the Systemtap mailing list