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]

native typecasting in scripts


Hi all,

Today I committed support for typecasting in systemtap scripts with @cast(). You no longer have to resort to embedded-C to access members of arbitrary pointer types! It's also now possible to dereference pointers to usermode C/C++ types, which embedded-C can't handle.

I've included the manpage excerpt on typecasting below. I would appreciate any feedback and early test results while I work on proper testcases for this feature.

Thanks!

Josh



   TYPECASTING
       Once  a  pointer  has been saved into a script integer
       variable, the translator loses  the  type  information
       necessary  to access members from that pointer.  Using
       the @cast() operator tells the translator how to  read
       a pointer.
              @cast(p, "type_name"[, "module"])->member

       This  will  interpret p as a pointer to a struct/union
       named type_name and dereference the member value.  The
       optional module tells the translator where to look for
       information about that type.  If  the  module  is  not
       specified,  it will default either to the probe module
       for dwarf probes, or to "kernel" for functions and all
       other probes types.

       When  in  guru  mode,  the  translator will also allow
       scripts to assign new values to members of  typecasted
       pointers.

       Typecasting  is  also useful in the case of void* mem-
       bers whose type may be determinable at runtime.
              probe foo {
                if ($var->type == 1) {
                  value = @cast($var->data, "type1")->bar
                } else {
                  value = @cast($var->data, "type2")->baz
                }
                print(value)
              }


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