From 76fb722224d35f6326342f85f34f5b50ed260294 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Thu, 16 May 2013 12:23:27 -0700 Subject: [PATCH] stapdyn: implement tapset target() and stp_pid() 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 | 17 +++++++++++++---- runtime/dyninst/session_attributes.h | 2 ++ stapdyn/mutatee.h | 2 ++ stapdyn/mutator.cxx | 11 +++++++++++ tapset/dyninst/context.stp | 10 ++++++++-- 5 files changed, 36 insertions(+), 6 deletions(-) diff --git a/runtime/dyninst/session_attributes.c b/runtime/dyninst/session_attributes.c index a51ef2a35..7a3101643 100644 --- a/runtime/dyninst/session_attributes.c +++ b/runtime/dyninst/session_attributes.c @@ -14,14 +14,13 @@ 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; } diff --git a/runtime/dyninst/session_attributes.h b/runtime/dyninst/session_attributes.h index b96e2455c..bb46dd3dd 100644 --- a/runtime/dyninst/session_attributes.h +++ b/runtime/dyninst/session_attributes.h @@ -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); diff --git a/stapdyn/mutatee.h b/stapdyn/mutatee.h index 996ea4809..b7abb88c7 100644 --- a/stapdyn/mutatee.h +++ b/stapdyn/mutatee.h @@ -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 diff --git a/stapdyn/mutator.cxx b/stapdyn/mutator.cxx index 682bb3c2b..1b4adc936 100644 --- a/stapdyn/mutator.cxx +++ b/stapdyn/mutator.cxx @@ -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; } diff --git a/tapset/dyninst/context.stp b/tapset/dyninst/context.stp index c9519f8f1..b35b14a6c 100644 --- a/tapset/dyninst/context.stp +++ b/tapset/dyninst/context.stp @@ -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 () -- 2.43.5