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)
= 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;
}
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);
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
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;
}
// 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 ()