]> sourceware.org Git - systemtap.git/commitdiff
stapdyn: implement tapset target() and stp_pid()
authorJosh Stone <jistone@redhat.com>
Thu, 16 May 2013 19:23:27 +0000 (12:23 -0700)
committerJosh Stone <jistone@redhat.com>
Thu, 16 May 2013 19:23:27 +0000 (12:23 -0700)
Add fields for the target pid and stapdyn's own pid to the new
stp_session_attributes, and expose them in the tapset.

runtime/dyninst/session_attributes.c
runtime/dyninst/session_attributes.h
stapdyn/mutatee.h
stapdyn/mutator.cxx
tapset/dyninst/context.stp

index a51ef2a35b21a8a156f5e4b819324783059cc113..7a3101643374c602a08dcb5c452f729192119304 100644 (file)
 static struct _stp_session_attributes _stp_init_session_attributes = {
        .log_level = 0,
        .suppress_warnings = 0,
+       .stp_pid = 0,
+       .target = 0,
 };
 
 static void stp_session_attributes_init(void)
 {
-       stp_session_attributes()->log_level
-           = _stp_init_session_attributes.log_level;
-       stp_session_attributes()->suppress_warnings
-           = _stp_init_session_attributes.suppress_warnings;
+       *stp_session_attributes() = _stp_init_session_attributes;
 }
 
 static int stp_session_attribute_setter(const char *name, const char *value)
@@ -38,6 +37,16 @@ static int stp_session_attribute_setter(const char *name, const char *value)
                    = strtoul(value, NULL, 10);
                return 0;
        }
+       else if (strcmp(name, "@stp_pid") == 0) {
+               _stp_init_session_attributes.stp_pid
+                   = strtoul(value, NULL, 10);
+               return 0;
+       }
+       else if (strcmp(name, "@target") == 0) {
+               _stp_init_session_attributes.target
+                   = strtoul(value, NULL, 10);
+               return 0;
+       }
        return -EINVAL;
 }
 
index b96e2455cf74aaf2711914c49245a65ebe374289..bb46dd3dd871d3494985fcd9042f8e61fe35a857 100644 (file)
@@ -12,6 +12,8 @@
 struct _stp_session_attributes {
        unsigned long log_level;
        unsigned long suppress_warnings;
+       unsigned long stp_pid;
+       unsigned long target;
 };
 
 static void stp_session_attributes_init(void);
index 996ea4809de7c32949c47fc2b18f4ad7af2d0b45..b7abb88c75989512633905c5d4c7dad76071d6f8 100644 (file)
@@ -52,6 +52,8 @@ class mutatee {
     mutatee(BPatch_process* process);
     ~mutatee();
 
+    pid_t process_id() { return pid; }
+
     bool operator==(BPatch_process* other) { return process == other; }
 
     // Inject the stap module into the target process
index 682bb3c2b63f6e7731aaba5792547bdeef46944c..1b4adc9366aa546ab7c2d239f4880d3070eecf76 100644 (file)
@@ -346,6 +346,17 @@ mutator::init_session_attributes()
   if (rc != 0)
     stapwarn() << "couldn't set 'suppress_warnings' global" << endl;
 
+  rc = global_setter("@stp_pid", lex_cast(getpid()).c_str());
+  if (rc != 0)
+    stapwarn() << "couldn't set 'stp_pid' global" << endl;
+
+  if (target_mutatee)
+    {
+      rc = global_setter("@target", lex_cast(target_mutatee->process_id()).c_str());
+      if (rc != 0)
+        stapwarn() << "couldn't set 'target' global" << endl;
+    }
+
   return;
 }
 
index c9519f8f15f8dbb3af99deb7bffea7c1ba521a2f..b35b14a6cbbd355709b72a39a56c2b5a40befe4a 100644 (file)
@@ -95,11 +95,17 @@ function user_mode:long ()
 
 // TODO function is_return:long ()
 
-// TODO function target:long ()
+function target:long ()
+%{ /* pure */ /* unprivileged */
+       STAP_RETVALUE = stp_session_attributes()->target;
+%}
 
 // TODO function module_name:string ()
 
-// TODO function stp_pid:long ()
+function stp_pid:long ()
+%{ /* pure */ /* unprivileged */
+       STAP_RETVALUE = stp_session_attributes()->stp_pid;
+%}
 
 // TODO function remote_id:long ()
 
This page took 0.034242 seconds and 5 git commands to generate.