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 -

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


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