This is the mail archive of the
systemtap@sourceware.org
mailing list for the systemtap project.
Re: Trapping malloc using systemtap
- From: "Frank Ch. Eigler" <fche at redhat dot com>
- To: deepak dot venkatesh at wipro dot com
- Cc: systemtap at sourceware dot org
- Date: Wed, 23 Feb 2011 09:20:59 -0500
- Subject: Re: Trapping malloc using systemtap
- References: <81939A763626854B8ECA106278B28F3402D06ADC@BLR-SJP-MBX02.wipro.com> <20110223123240.GJ1091@redhat.com> <81939A763626854B8ECA106278B28F3402D06D59@BLR-SJP-MBX02.wipro.com>
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