public inbox for systemtap@sourceware.org
 help / color / mirror / Atom feed
* alternate static marker approach
@ 2009-04-28 14:54 Stan Cox
  0 siblings, 0 replies; only message in thread
From: Stan Cox @ 2009-04-28 14:54 UTC (permalink / raw)
  To: SystemTap List

We have been thinking about alternative static marker approaches.   
Perhaps the @cast support might provide an alternative to the clever, or 
baroque depending on one's perspective, macros used to set up the 
markers.   The dtrace .d input file types are self contained so if a .d 
file was converted to a .h file and made available in a place like 
/usr/share then it would be easy for @cast to make use of it.

 For the purpose of the example the dup syscall has been hijacked as a 
means of setting the probe.  So given this little example:
* tstsyscall.h *
// this would be created from package.d
struct astruct
{
  int a;
  int b;
};
* tstsyscall.c *
#define _GNU_SOURCE
#include <sys/syscall.h>
#include "tstsyscall.h"
int
main(int argc, char *argv[])
{
  int ret;
  int a1 = 1;
  int a2 = 2;
  int a3 = 3;
  int a4 = 4;
  struct astruct astruct = {5, 6};
  // STAP_PROBE(test,probe_one,a1,a2,a3,a4,&astruct) would map to:
  ret = syscall (__NR_dup, -12345, a1, a2, a3, a4, &astruct);
}

So a probe like:
stap -c ./tstsyscall.x -e 'probe process("tstsyscall.x").mark("test") {
printf("a2=%d a3=%d a4=%d a5=%d astruct.a=%d astruct.b=%d\n",
a1, a2, a3, a4, astruct.a, astruct.b)'

could map to something like:

stap -c ./tstsyscall.x -e '
probe syscall.dup {
arg2=int_arg(2);arg3=int_arg(3);arg4=int_arg(4);arg5=int_arg(5);
arg6a=@cast(ulong_arg(6),"astruct","</work/.../tstsyscall.h>")->a;
arg6b=@cast(ulong_arg(6),"astruct","</work/.../tstsyscall.h>")->b;
printf("a1=%d a2=%d a3=%d a4=%d astruct.a=%d astruct.b=%d\n",name, 
arg1,arg2,arg3,arg4,arg5,arg6a,arg6b)}'

which yields:

a1=1 a2=2 a3=3 a4=4 astruct.a=5 astruct.b=6

For example here is an excerpt from tclDTrace.d
typedef struct Tcl_Obj Tcl_Obj;
provider tcl {
 probe proc__entry(char* name, int objc, Tcl_Obj **objv);
 ...
}
struct Tcl_Obj {
    int refCount;
    char *bytes;
    int length;
    ...
}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2009-04-28 14:54 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-04-28 14:54 alternate static marker approach Stan Cox

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).