From d5d3a90bff8cd485a40176ff9a51f6a9eae597c2 Mon Sep 17 00:00:00 2001 From: Lukas Berk Date: Wed, 20 Mar 2013 19:31:49 -0400 Subject: [PATCH] Allow java("fully qualified class") style syntax *session.cxx: add class string member variable *session.h: add member variable *tapset-method.cxx: add class specification functionality --- session.cxx | 9 ++++++--- session.h | 4 +++- tapset-method.cxx | 48 +++++++++++++++++++++++++++++++++++++---------- 3 files changed, 47 insertions(+), 14 deletions(-) diff --git a/session.cxx b/session.cxx index 1242644bc..9cccbc792 100644 --- a/session.cxx +++ b/session.cxx @@ -162,7 +162,7 @@ systemtap_session::systemtap_session (): update_release_sysroot = false; suppress_time_limits = false; java_pid = 0; - + java_proc_class = ""; #ifdef HAVE_HELPER bminstall_path = ""; bmsubmit_path = ""; @@ -342,9 +342,11 @@ systemtap_session::systemtap_session (const systemtap_session& other, update_release_sysroot = other.update_release_sysroot; sysenv = other.sysenv; suppress_time_limits = other.suppress_time_limits; - java_pid = other.java_pid; + #ifdef HAVE_HELPER + java_pid = other.java_pid; + java_proc_class = other.java_proc_class; bminstall_path = other.bminstall_path; bmsubmit_path = other.bmsubmit_path; byteman_script_path = other.byteman_script_path; @@ -386,7 +388,8 @@ systemtap_session::systemtap_session (const systemtap_session& other, systemtap_session::~systemtap_session () { #ifdef HAVE_HELPER - if(java_pid != 0) + + if(java_pid != 0 || !java_proc_class.empty()) java_detach(); #endif //HAVE_HELPER remove_tmp_dir(); diff --git a/session.h b/session.h index a5a2fb57c..a7b8494e3 100644 --- a/session.h +++ b/session.h @@ -200,8 +200,10 @@ public: int download_dbinfo; bool suppress_handler_errors; bool suppress_time_limits; - int java_pid; + void java_detach(); + int java_pid; + std::string java_proc_class; std::string bminstall_path; std::string bmsubmit_path; std::string byteman_script_path; diff --git a/tapset-method.cxx b/tapset-method.cxx index 2de2ce764..fd6e98029 100644 --- a/tapset-method.cxx +++ b/tapset-method.cxx @@ -33,7 +33,7 @@ static const string TOK_CLASS ("class"); static const string TOK_METHOD ("method"); static const string TOK_PROCESS ("process"); static const string TOK_MARK ("mark"); -static const string TOK_JAVA("java"); +static const string TOK_JAVA ("java"); struct java_builder: public derived_probe_builder { @@ -57,6 +57,10 @@ public: bool get_number_param (literal_map_t const & params, string const & k, int & v); + bool get_param (std::map const & params, + const std::string& key, + std::string& value); + }; bool @@ -69,6 +73,20 @@ java_builder::get_number_param (literal_map_t const & params, return present; } +bool +java_builder::get_param (std::map const & params, + const std::string& key, + std::string& value) +{ + map::const_iterator i = params.find (key); + if (i == params.end()) + return false; + literal_string * ls = dynamic_cast(i->second); + if (!ls) + return false; + value = ls->value; + return true; +} void java_builder::build (systemtap_session & sess, @@ -93,6 +111,8 @@ java_builder::build (systemtap_session & sess, string class_str_val; // fully qualified class string bool has_class_str = get_param (parameters, TOK_CLASS, class_str_val); bool has_pid_int = get_number_param (parameters, TOK_JAVA, sess.java_pid); + bool has_pid_str = get_param (parameters, TOK_JAVA, sess.java_proc_class); + //need to count the number of parameters, exit if more than 10 int method_params_counter = 1; int method_params_count = count (method_str_val.begin (), method_str_val.end (), ','); @@ -169,14 +189,14 @@ java_builder::build (systemtap_session & sess, * continue regular compilation and action with redefined probe */ - if (! (has_pid_int)) + if (! (has_pid_int || has_pid_str) ) exit (1); //XXX proper exit with warning message - //this could be done using itoa string arg = static_cast ( & (ostringstream () - << sess.java_pid) )->str (); - + << sess.java_pid) )->str (); + const char* java_pid_str = arg.c_str (); + sess.bminstall_path = (find_executable ("bminstall.sh")); if (sess.verbose > 3) @@ -185,7 +205,11 @@ java_builder::build (systemtap_session & sess, vector bminstall_cmd; bminstall_cmd.push_back(sess.bminstall_path); - bminstall_cmd.push_back(java_pid_str); + if(!has_pid_str) + bminstall_cmd.push_back(java_pid_str); + else + bminstall_cmd.push_back(sess.java_proc_class); + (void) stap_system(sess.verbose, bminstall_cmd); vector bmsubmit_cmd; @@ -225,10 +249,14 @@ register_tapset_java (systemtap_session& s) { match_node* root = s.pattern_root; derived_probe_builder *builder = new java_builder (); - - root = root->bind_num (TOK_JAVA) - ->bind_str (TOK_CLASS)->bind_str (TOK_METHOD); - root->bind (builder); + + root->bind_str (TOK_JAVA) + ->bind_str (TOK_CLASS)->bind_str (TOK_METHOD) + ->bind(builder); + + root->bind_num (TOK_JAVA) + ->bind_str (TOK_CLASS)->bind_str (TOK_METHOD) + ->bind(builder); } -- 2.43.5