public inbox for systemtap@sourceware.org
 help / color / mirror / Atom feed
* Re: Trapping malloc using systemtap
       [not found] <81939A763626854B8ECA106278B28F3402D06ADC@BLR-SJP-MBX02.wipro.com>
@ 2011-02-23 12:32 ` Frank Ch. Eigler
       [not found]   ` <81939A763626854B8ECA106278B28F3402D06D59@BLR-SJP-MBX02.wipro.com>
  0 siblings, 1 reply; 2+ messages in thread
From: Frank Ch. Eigler @ 2011-02-23 12:32 UTC (permalink / raw)
  To: deepak.venkatesh; +Cc: systemtap, giribalaji.ragavan

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

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

* Re: Trapping malloc using systemtap
       [not found]   ` <81939A763626854B8ECA106278B28F3402D06D59@BLR-SJP-MBX02.wipro.com>
@ 2011-02-23 14:21     ` Frank Ch. Eigler
  0 siblings, 0 replies; 2+ messages in thread
From: Frank Ch. Eigler @ 2011-02-23 14:21 UTC (permalink / raw)
  To: deepak.venkatesh; +Cc: systemtap

Hi -

On Wed, Feb 23, 2011 at 07:43:14PM +0530, deepak.venkatesh@wipro.com wrote:
> [...]

Thanks for your good questions!


> 	1. Consider the below scrip just as an example,
> 	 	probe process("a.out").function("myrealloc"){}
> 	Function myrealloc takes 2 parameters. How can I get individual
> parameters sent to this function?
> 	Prototype of myrealloc:
> 		void * myrealloc(void *p, int size);

See the CONTEXT VARIABLES section in the stapprobes (3stap) man page.

probe process("a.out").function("myrealloc") {
   # for example:
   printf ("reallocing %d (%p)\n", $size, $p)
}

or, to see the return value too:

probe process("a.out").function("myrealloc").return {
   printf ("realloc %d (%p) -> %p\n", @entry($size), @entry($p), $return);
}


> 	2. Consider the below piece of code,
> 		void fun()
> 		{
> 			int a,b,c;
> 			for(a=0;....)
> 			for(b=0;....)
> 				c=random();
> 		}
> 
> 		How can I access the variables a, b and c at the same
> time in the systemtap script?

As for setting a breakpoint in gdb, you'd want a statement probe at a
line where the relevant variables are in scope.  Say, a hypothetical
line 23, perhaps after the "c=random()" part:

       probe process("a.out").statement("*@file.c:23") { println($$vars) }

You can trace execution of my_fn statement-by-statement like this:

       probe process("a.out").statement("my_fn@*:*") {
             println(pp(), " ", $$vars) 
       }


> -----Original Message-----
> [...]

(Please trim your replies.)

- FChE

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

end of thread, other threads:[~2011-02-23 14:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <81939A763626854B8ECA106278B28F3402D06ADC@BLR-SJP-MBX02.wipro.com>
2011-02-23 12:32 ` Trapping malloc using systemtap Frank Ch. Eigler
     [not found]   ` <81939A763626854B8ECA106278B28F3402D06D59@BLR-SJP-MBX02.wipro.com>
2011-02-23 14:21     ` Frank Ch. Eigler

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).