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: trace function argument


Hi Christian,

On Tue, 2009-06-16 at 11:47 +0200, Christian Kaiser wrote:
> Ananth N Mavinakayanahalli wrote:
> > On Tue, Jun 16, 2009 at 11:08:35AM +0200, Christian Kaiser wrote:
> >> Hi all,
> >>
> >> is it possible to get the value of a function argument of a probed 
> >> function?
> >>
> >> With dtrace for example, you can do something like:
> >> dtrace -n '::some_function:entry/arg0 != 0/{ printf("arg0 is not zero!"); 
> >> }'
> >>
> >> I have searched the "Beginners Guide", mailinglist, wiki, web, etc. but 
> >> could not find anything useful.
> > 
> > With SystemTap with debuginfo, you can refer to arguments by name.
> > 
> > probe kernel.function("do_fork")
> > {
> > 	if ($clone_flags == 0)
> > 		printf("clone_flags is zero!\n")
> > }
> > 
> > Further, to just list arguments, you can use $$parms:
> > 
> > stap -ve 'probe kernel.function("vfs_read") { printf("%s\n", $$parms) }'
> 
> Right, both suggestions are working for me. Thanks!
> 
> > With debuginfoless kernels, you can do pretty much what you cite with
> > DTrace above.
> 
> I am not sure if I understand you right. If I can do pretty much the 
> same, how is it working then? Let's take your example from above. How 
> can I print out 'clone_flags' with debuginfoless kernels?

Obviously without the information about the arguments and types
available through debuginfo it isn't as nice. But you can do 'debuginfo
less probes' with kprobe.function and then fetch the arguments by hand
with the various <TYPE>_arg(<argnr>) functions. You need to specify the
type yourself. e.g. for your example:

stap -e 'probe kprobe.function("do_fork") { printf("do_fork flags: %x\n", ulong_arg(1)) }'

There is an (internal) utility function, __fork_flags, you can use to
decode these for a bit nicer:

stap -e 'probe kprobe.function("do_fork") { printf("do_fork flags: %s\n", __fork_flags(ulong_arg(1))) }'

(Although I don't believe we support using the internal __functions, so don't depend on it.)

Cheers,

Mark


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