This is the mail archive of the systemtap@sourceware.org mailing list for the systemtap project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Trapping malloc using systemtap


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]