From d2eaa03ba08e5672f11de5263b73fb3acd13b792 Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Thu, 14 May 2015 10:29:50 -0400 Subject: [PATCH] make from_glob a per-component field rather than per-pp The original need for from_glob in probe_point was to distinguish "specified" probe points from those that were still generic/globby. E.g. so that we know to make function suggestions for process("/usr/bin/ls").function("bad_func") but not yet for process("/usr/bin/l*").function("bad_func"). The issue however is that there is no distinction between which component is from a globby one. E.g. if we have process("/usr/bin/l*").library("libc").function("bad_func"), which becomes process("/usr/bin/ls").library("libc").function("bad_func"), we won't know while resolving the library whether from_glob is true because the process was globby or because the library was globby. Thus, the 'from_globbiness' is a property of the component, not the whole probe point. In this commit, we make from_glob instead a member of probe_point::component. We then add a from_globby_comp() function which can be used to determine if a specific component was derived from a globby one. --- elaborate.cxx | 9 +++------ staptree.cxx | 24 ++++++++++++++++-------- staptree.h | 5 +++-- tapset-mark.cxx | 3 ++- tapsets.cxx | 21 ++++++++++++--------- 5 files changed, 36 insertions(+), 26 deletions(-) diff --git a/elaborate.cxx b/elaborate.cxx index 81d04f57e..dc1350916 100644 --- a/elaborate.cxx +++ b/elaborate.cxx @@ -482,9 +482,9 @@ match_node::find_and_build (systemtap_session& s, // Synthesize "foo*bar" probe_point *simple_pp = new probe_point(*loc); - simple_pp->from_glob = true; probe_point::component *simple_comp = new probe_point::component(*comp); simple_comp->functor = prefix + "*" + suffix; + simple_comp->from_glob = true; simple_pp->components[pos] = simple_comp; try { @@ -507,9 +507,9 @@ match_node::find_and_build (systemtap_session& s, // Synthesize "foo*.**bar" // NB: any component arg should attach to the latter part only probe_point *expanded_pp = new probe_point(*loc); - expanded_pp->from_glob = true; probe_point::component *expanded_comp_pre = new probe_point::component(*comp); expanded_comp_pre->functor = prefix + "*"; + expanded_comp_pre->from_glob = true; expanded_comp_pre->arg = NULL; probe_point::component *expanded_comp_post = new probe_point::component(*comp); expanded_comp_post->functor = "**" + suffix; @@ -573,10 +573,10 @@ match_node::find_and_build (systemtap_session& s, // wildcard component, and substitute the non-wildcard // functor. probe_point *non_wildcard_pp = new probe_point(*loc); - non_wildcard_pp->from_glob = true; probe_point::component *non_wildcard_component = new probe_point::component(*loc->components[pos]); non_wildcard_component->functor = subkey.name; + non_wildcard_component->from_glob = true; non_wildcard_pp->components[pos] = non_wildcard_component; // NB: probe conditions are not attached at the wildcard @@ -880,9 +880,6 @@ alias_expansion_builder::build_with_suffix(systemtap_session & sess, for (unsigned i=0; ilocations.size(); i++) { probe_point *pp = new probe_point(*alias->locations[i]); - // if the original pp that gave rise to the alias we're building was from - // a globby probe, then inherit globbiness - pp->from_glob = location->from_glob; pp->components.insert(pp->components.end(), suffix.begin(), suffix.end()); pp->condition = add_condition (pp->condition, location->condition); n->locations.push_back(pp); diff --git a/staptree.cxx b/staptree.cxx index 045746aeb..9e72465a6 100644 --- a/staptree.cxx +++ b/staptree.cxx @@ -95,25 +95,32 @@ symboldecl::~symboldecl () probe_point::probe_point (std::vector const & comps): components(comps), optional (false), sufficient (false), - from_glob (false), well_formed (false), condition (0) + well_formed (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), - from_glob (pp.from_glob), well_formed (pp.well_formed), - condition (pp.condition) + well_formed (pp.well_formed), condition (pp.condition) { } probe_point::probe_point (): - optional (false), sufficient (false), from_glob (false), - well_formed (false), condition (0) + optional (false), sufficient (false), well_formed (false), condition (0) { } +bool +probe_point::from_globby_comp(const std::string& comp) +{ + vector::const_iterator it; + for (it = components.begin(); it != components.end(); it++) + if ((*it)->functor == comp) + return (*it)->from_glob; + return false; +} unsigned probe::last_probeidx = 0; @@ -142,13 +149,14 @@ probe::probe(probe* p, probe_point* l) probe_point::component::component (): - arg (0), tok(0) + arg (0), from_glob(false), tok(0) { } -probe_point::component::component (std::string const & f, literal * a): - functor(f), arg(a), tok(0) +probe_point::component::component (std::string const & f, + literal * a, bool from_glob): + functor(f), arg(a), from_glob(from_glob), tok(0) { } diff --git a/staptree.h b/staptree.h index 7412a62f7..ccdbb662f 100644 --- a/staptree.h +++ b/staptree.h @@ -796,14 +796,14 @@ struct probe_point { std::string functor; literal* arg; // optional + bool from_glob; component (); const token* tok; // points to component's functor - component(std::string const & f, literal * a = NULL); + component(std::string const & f, literal *a=NULL, bool from_glob=false); }; std::vector components; bool optional; bool sufficient; - bool from_glob; bool well_formed; // used in derived_probe::script_location() expression* condition; void print (std::ostream& o, bool print_extras=true) const; @@ -811,6 +811,7 @@ struct probe_point probe_point(const probe_point& pp); probe_point(std::vector const & comps); std::string str(bool print_extras=true) const; + bool from_globby_comp(const std::string& comp); }; std::ostream& operator << (std::ostream& o, const probe_point& k); diff --git a/tapset-mark.cxx b/tapset-mark.cxx index 98e1990e8..050d73045 100644 --- a/tapset-mark.cxx +++ b/tapset-mark.cxx @@ -725,7 +725,8 @@ mark_builder::build(systemtap_session & sess, } } - if (results_pre == finished_results.size() && !loc->from_glob) + if (results_pre == finished_results.size() + && !loc->from_globby_comp(TOK_MARK)) { string sugs = suggest_marks(sess, mark_str_val); if (!sugs.empty()) diff --git a/tapsets.cxx b/tapsets.cxx index c270392dd..8f92b762f 100644 --- a/tapsets.cxx +++ b/tapsets.cxx @@ -2552,7 +2552,6 @@ build_library_probe(dwflpp& dw, probe_point *base_loc) { probe_point* specific_loc = new probe_point(*base_loc); - specific_loc->from_glob = true; vector derived_comps; // Create new probe point for the matching library. This is what will be @@ -2566,7 +2565,8 @@ build_library_probe(dwflpp& dw, new literal_string(path_remove_sysroot(dw.sess, dw.module_name)))); else if ((*it)->functor == TOK_LIBRARY) derived_comps.push_back(new probe_point::component(TOK_LIBRARY, - new literal_string(path_remove_sysroot(dw.sess, library)))); + new literal_string(path_remove_sysroot(dw.sess, library)), + true /* from_glob */ )); else derived_comps.push_back(*it); probe_point* derived_loc = new probe_point(*specific_loc); @@ -7611,7 +7611,8 @@ resolve_library_by_path(base_query & q, dwflpp & dw = q.dw; string lib; - if (!location->from_glob && q.has_library && !visited_libraries.empty() + if (!location->from_globby_comp(TOK_LIBRARY) && q.has_library + && !visited_libraries.empty() && q.get_string_param(parameters, TOK_LIBRARY, lib)) { // The library didn't fit any DT_NEEDED libraries. As a last effort, @@ -7797,7 +7798,6 @@ dwarf_builder::build(systemtap_session & sess, // synthesize a new probe_point, with the glob-expanded string probe_point *pp = new probe_point (*location); - pp->from_glob = true; // PR13338: quote results to prevent recursion string eglobbed = escape_glob_chars (globbed); @@ -7807,8 +7807,10 @@ dwarf_builder::build(systemtap_session & sess, module_name.c_str(), eglobbed.c_str()) << endl; string eglobbed_tgt = path_remove_sysroot(sess, eglobbed); - probe_point::component* ppc = new probe_point::component (TOK_PROCESS, - new literal_string (eglobbed_tgt)); + probe_point::component* ppc + = new probe_point::component (TOK_PROCESS, + new literal_string (eglobbed_tgt), + true /* from_glob */ ); ppc->tok = location->components[0]->tok; // overwrite [0] slot, pattern matched above pp->components[0] = ppc; @@ -8028,7 +8030,8 @@ dwarf_builder::build(systemtap_session & sess, return; // Did we fail to find a mark? - if (results_pre == finished_results.size() && !location->from_glob) + if (results_pre == finished_results.size() + && !location->from_globby_comp(TOK_MARK)) { string provider; (void) get_param(filled_parameters, TOK_PROVIDER, provider); @@ -8128,7 +8131,7 @@ dwarf_builder::build(systemtap_session & sess, // required because modules_seen needs to accumulate across recursive // calls for process(glob)[.library(glob)] probes. string func; - if (results_pre == results_post && !location->from_glob + if (results_pre == results_post && !location->from_globby_comp(TOK_FUNCTION) && get_param(filled_parameters, TOK_FUNCTION, func) && !func.empty()) { @@ -8140,7 +8143,7 @@ dwarf_builder::build(systemtap_session & sess, sugs.find(',') == string::npos, sugs.c_str())); } - else if (results_pre == results_post && !location->from_glob + else if (results_pre == results_post && !location->from_globby_comp(TOK_PLT) && get_param(filled_parameters, TOK_PLT, func) && !func.empty()) { -- 2.43.5