]> sourceware.org Git - systemtap.git/commitdiff
move auto_path expansion to tapset resolution phase
authorFelix Lu <flu@redhat.com>
Thu, 11 Aug 2016 16:26:19 +0000 (12:26 -0400)
committerFelix Lu <flu@redhat.com>
Fri, 12 Aug 2016 15:07:19 +0000 (11:07 -0400)
* parse.cxx: parse_probe_points - Remove alias seen flag.
* staptree.h: struct probe_point - New auto_path flag.
* tapsets.cxx: dwarf_builder::build - Expand process component
  for /PATH/ directory.

parse.cxx
staptree.cxx
staptree.h
tapsets.cxx

index 1a5ba4cc21370eb98a18ea66a1eb0e01befaea80..d2f5893a8449e5986391494f2cc4e68c083d0915 100644 (file)
--- a/parse.cxx
+++ b/parse.cxx
@@ -179,9 +179,9 @@ private: // nonterminals
   void do_parse_functiondecl (vector<functiondecl*>&, const token*,
                               string const&, bool);
   embeddedcode* parse_embeddedcode ();
-  vector<probe_point*> parse_probe_points (bool alias_seen);
-  vector<probe_point*> parse_components (bool alias_seen);
-  vector<probe_point*> parse_component (bool alias_seen);
+  vector<probe_point*> parse_probe_points ();
+  vector<probe_point*> parse_components ();
+  vector<probe_point*> parse_component ();
   literal_string* consume_string_literals (const token*);
   literal_string* parse_literal_string ();
   literal* parse_literal ();
@@ -2030,11 +2030,10 @@ parser::parse_probe (vector<probe *> & probe_ret,
   vector<probe_point *> locations;
 
   int epilogue_alias = 0;
-  bool alias_seen = false;
 
   while (1)
     {
-      vector<probe_point*> pps = parse_probe_points(alias_seen);
+      vector<probe_point*> pps = parse_probe_points();
 
       const token* t = peek ();
       if (pps.size() == 1 && t
@@ -2043,7 +2042,6 @@ parser::parse_probe (vector<probe *> & probe_ret,
           if (pps[0]->optional || pps[0]->sufficient)
             throw PARSE_ERROR (_("probe point alias name cannot be optional nor sufficient"), pps[0]->components.front()->tok);
           aliases.push_back(pps[0]);
-          alias_seen = true;
           swallow ();
           continue;
         }
@@ -2054,7 +2052,6 @@ parser::parse_probe (vector<probe *> & probe_ret,
             throw PARSE_ERROR (_("probe point alias name cannot be optional nor sufficient"), pps[0]->components.front()->tok);
           aliases.push_back(pps[0]);
           epilogue_alias = 1;
-          alias_seen = true;
           swallow ();
           continue;
         }
@@ -2479,12 +2476,12 @@ parser::do_parse_functiondecl (vector<functiondecl*>& functions, const token* t,
 }
 
 vector<probe_point*>
-parser::parse_probe_points(bool alias_seen)
+parser::parse_probe_points()
 {
   vector<probe_point*> pps;
   while (1)
     {
-      vector<probe_point*> tail = parse_components(alias_seen);
+      vector<probe_point*> tail = parse_components();
       pps.insert(pps.end(), tail.begin(), tail.end());
 
       const token* t = peek();
@@ -2505,12 +2502,12 @@ parser::parse_probe_points(bool alias_seen)
 }
 
 vector<probe_point*>
-parser::parse_components(bool alias_seen)
+parser::parse_components()
 {
   vector<probe_point*> pps;
   while (1)
     {
-      vector<probe_point*> suffix = parse_component(alias_seen);
+      vector<probe_point*> suffix = parse_component();
 
       // Cartesian product of components
       if (pps.empty())
@@ -2528,11 +2525,14 @@ parser::parse_components(bool alias_seen)
                 {
                   probe_point* pp = new probe_point;
                   pp->components.insert(pp->components.end(),
-                                        pps[i]->components.begin(), pps[i]->components.end());
+                                        pps[i]->components.begin(),
+                                        pps[i]->components.end());
                   pp->components.insert(pp->components.end(),
-                                        suffix[j]->components.begin(), suffix[j]->components.end());
+                                        suffix[j]->components.begin(),
+                                        suffix[j]->components.end());
                   pp->optional = suffix[j]->optional;
                   pp->sufficient = suffix[j]->sufficient;
+                  pp->auto_path = suffix[j]->auto_path;
                   pp->condition = suffix[j]->condition;
                   product.push_back(pp);
                 }
@@ -2596,7 +2596,7 @@ parser::parse_components(bool alias_seen)
 }
 
 vector<probe_point*>
-parser::parse_component(bool alias_seen)
+parser::parse_component()
 {
   const token* t = next ();
   if (! (t->type == tok_identifier
@@ -2609,7 +2609,7 @@ parser::parse_component(bool alias_seen)
   if (t && t->type == tok_operator && t->content == "{")
     {
       swallow();
-      vector<probe_point*> pps = parse_probe_points(alias_seen);
+      vector<probe_point*> pps = parse_probe_points();
       t = peek();
       if (!(t && t->type == tok_operator && t->content == "}"))
         throw PARSE_ERROR (_("expected '}'"));
@@ -2658,6 +2658,7 @@ parser::parse_component(bool alias_seen)
       c->tok = t;
       vector<probe_point*> pps;
       probe_point* pp = new probe_point;
+      pp->auto_path = auto_path;
       pp->components.push_back(c);
       pps.push_back(pp);
       // NB we may add c->arg soon
@@ -2670,33 +2671,11 @@ parser::parse_component(bool alias_seen)
           swallow (); // consume "("
           c->arg = parse_literal ();
 
-          // prefix argument with file location from PATH directory
-          if (auto_path && c->functor == "process")
-            {
-              literal_string* ls = dynamic_cast<literal_string*>(c->arg);
-              if (ls && !ls->value.empty() && ls->value[0] != '/')
-                {
-                  string::size_type start = input_name.find("PATH/") + 4;
-                  string::size_type end = input_name.rfind("/");
-                  string path = input_name.substr(start, end-start+1) + ls->value.to_string();
-                  ls->value = path;
-                }
-            }
-
           t = next ();
           if (! (t->type == tok_operator && t->content == ")"))
             throw PARSE_ERROR (_("expected ')'"));
           swallow ();
         }
-      else if (alias_seen && auto_path && c->functor == "process")
-        {
-          // PATH expansion of process component without argument.
-          // The filename without the .stp extension is used.
-          string::size_type start = input_name.find("PATH/") + 4;
-          string::size_type end = input_name.rfind(".stp");
-          string path = input_name.substr(start, end - start);
-          c->arg = new literal_string(path);
-        }
 
       return pps;
     }
index 4b12e3b9ab03b712e1a9cbd2575d02863b2a086f..44bc1d8b0669c0ed60568745adb95ebb260644d8 100644 (file)
@@ -92,20 +92,21 @@ symboldecl::~symboldecl ()
 
 probe_point::probe_point (std::vector<component*> const & comps):
   components(comps), optional (false), sufficient (false),
-  well_formed (false), condition (0)
+  well_formed (false), auto_path (false), condition (0)
 {
 }
 
 // NB: shallow-copy of compoonents & condition!
 probe_point::probe_point (const probe_point& pp):
   components(pp.components), optional (pp.optional), sufficient (pp.sufficient),
-  well_formed (pp.well_formed), condition (pp.condition)
+  well_formed (pp.well_formed), auto_path (pp.auto_path), condition (pp.condition)
 {
 }
 
 
 probe_point::probe_point ():
-  optional (false), sufficient (false), well_formed (false), condition (0)
+  optional (false), sufficient (false), well_formed (false), auto_path (false),
+  condition (0)
 {
 }
 
index 1dfb43ebc0b4e708c9e47783f39ad138b15bc0d2..88a876b95bd775fd1dc0d54969691d773d3cc69c 100644 (file)
@@ -808,6 +808,7 @@ struct probe_point
   bool optional;
   bool sufficient;
   bool well_formed; // used in derived_probe::script_location()
+  bool auto_path;
   expression* condition;
   void print (std::ostream& o, bool print_extras=true) const;
   probe_point ();
index da5a5af5d6bd96bc18e9fb90bb160a4aaf48acc6..529f753217d53a612253324e86f37d959ca348ab 100644 (file)
@@ -7920,33 +7920,51 @@ dwarf_builder::build(systemtap_session & sess,
 
       if(has_null_param(filled_parameters, TOK_PROCESS))
         {
-          string file;
-          try
+          if (location->auto_path)
             {
-              file = sess.cmd_file();
-            }
-          catch (const semantic_error& e)
-            {
-              if(sess.target_pid)
-                throw SEMANTIC_ERROR(_("invalid -x pid for unspecified process"
-                                       " probe [man stapprobes]"), NULL, NULL, &e);
-              else
-                throw SEMANTIC_ERROR(_("invalid -c command for unspecified process"
-                                     " probe [man stapprobes]"), NULL, NULL, &e);
+              if (location->components[0]->functor == TOK_PROCESS &&
+                  location->components[0]->arg == 0)
+                {
+                  // PATH expansion of process component without argument.
+                  // The filename without the .stp extension is used.
+                  string full_path = location->components[0]->tok->location.file->name;
+                  string::size_type start = full_path.find("PATH/") + 4;
+                  string::size_type end = full_path.rfind(".stp");
+                  module_name = full_path.substr(start, end - start);
+                  location->components[0]->arg = new literal_string(module_name);
+                  filled_parameters[TOK_PROCESS] = new literal_string(module_name);
+                }
             }
-          if(file.empty())
-            throw SEMANTIC_ERROR(_("unspecified process probe is invalid without"
-                                   " a -c COMMAND or -x PID [man stapprobes]"));
-          module_name = sess.sysroot + file;
-          filled_parameters[TOK_PROCESS] = new literal_string(module_name);// this needs to be used in place of the blank map
-          // in the case of TOK_MARK we need to modify locations as well   // XXX why?
-          if(location->components[0]->functor==TOK_PROCESS &&
-             location->components[0]->arg == 0)
+          else
             {
-              if (sess.target_pid)
-                location->components[0]->arg = new literal_number(sess.target_pid);
-              else
-                location->components[0]->arg = new literal_string(module_name);
+              string file;
+              try
+                {
+                  file = sess.cmd_file();
+                }
+              catch (const semantic_error& e)
+                {
+                  if(sess.target_pid)
+                    throw SEMANTIC_ERROR(_("invalid -x pid for unspecified process"
+                                           " probe [man stapprobes]"), NULL, NULL, &e);
+                  else
+                    throw SEMANTIC_ERROR(_("invalid -c command for unspecified process"
+                                           " probe [man stapprobes]"), NULL, NULL, &e);
+                }
+              if(file.empty())
+                throw SEMANTIC_ERROR(_("unspecified process probe is invalid without"
+                                       " a -c COMMAND or -x PID [man stapprobes]"));
+              module_name = sess.sysroot + file;
+              filled_parameters[TOK_PROCESS] = new literal_string(module_name);// this needs to be used in place of the blank map
+              // in the case of TOK_MARK we need to modify locations as well   // XXX why?
+              if(location->components[0]->functor==TOK_PROCESS &&
+                 location->components[0]->arg == 0)
+                {
+                  if (sess.target_pid)
+                    location->components[0]->arg = new literal_number(sess.target_pid);
+                  else
+                    location->components[0]->arg = new literal_string(module_name);
+                }
             }
         }
 
@@ -7954,8 +7972,25 @@ dwarf_builder::build(systemtap_session & sess,
       // we get the module_name out.
       else if (get_param (parameters, TOK_PROCESS, module_name))
         {
-          module_name = (string)sess.sysroot + (string)module_name;
-          filled_parameters[TOK_PROCESS] = new literal_string(module_name);
+          if (location->auto_path)
+            {
+              if (!module_name.empty() && module_name[0] != '/')
+                {
+                  // prefix argument with file location from PATH directory
+                  string full_path = location->components[0]->tok->location.file->name;
+                  string::size_type start = full_path.find("PATH/") + 4;
+                  string::size_type end = full_path.rfind("/");
+                  string arg = module_name;
+                  module_name = full_path.substr(start, end-start+1) + arg;
+                  location->components[0]->arg = new literal_string(module_name);
+                  filled_parameters[TOK_PROCESS] = new literal_string(module_name);
+                }
+            }
+          else
+            {
+              module_name = (string)sess.sysroot + (string)module_name;
+              filled_parameters[TOK_PROCESS] = new literal_string(module_name);
+            }
         }
 
       else if (get_param (parameters, TOK_PROCESS, proc_pid))
This page took 0.049355 seconds and 5 git commands to generate.