diff options
author | brolley <brolley> | 2008-02-13 16:43:08 +0000 |
---|---|---|
committer | brolley <brolley> | 2008-02-13 16:43:08 +0000 |
commit | 2c5a19c6ba969d8fa30070e7579c1597a0e1c194 (patch) | |
tree | 1b1de9e06811e80ccd5703cf8c03004e4edeeb35 /elaborate.cxx | |
parent | 4bab8964266929ec9356590db0d0fe51607c4b6b (diff) | |
download | systemtap-steved-2c5a19c6ba969d8fa30070e7579c1597a0e1c194.tar.gz systemtap-steved-2c5a19c6ba969d8fa30070e7579c1597a0e1c194.tar.xz systemtap-steved-2c5a19c6ba969d8fa30070e7579c1597a0e1c194.zip |
2008-02-13 Dave Brolley <brolley@redhat.com>
PR5609
* staptree.h (probe::collect_derivation_chain): Now takes vector<probe*>.
(probe::get_alias): New virtual method.
* elaborate.h (derived_probe::collect_derivation_chain): Now takes vector<probe*>.
* staptree.cxx (probe::collect_derivation_chain): Now takes vector<probe*>. Don't
cast 'this' to (derived_probe*).
* elaborate.cxx (derived_probe::collect_derivation_chain): Now takes vector<probe*>.
(alias_derived_probe::get_alias): New virtual method.
(alias_derived_probe::alias): New member.
(alias_expansion_builder::build): Call checkForRecursiveExpansion and emit a
diagnostic if recursion is detected. Pass alias to constructor of
alias_derived_probe.
(alias_expansion_builder::checkForRecursiveExpansion): New method.
* coveragedb.cxx: Pass vector<probe*> on all calls to collect_derivation_chain.
Diffstat (limited to 'elaborate.cxx')
-rw-r--r-- | elaborate.cxx | 41 |
1 files changed, 38 insertions, 3 deletions
diff --git a/elaborate.cxx b/elaborate.cxx index 445c7ff0..bc0d1489 100644 --- a/elaborate.cxx +++ b/elaborate.cxx @@ -112,7 +112,7 @@ derived_probe::printsig_nested (ostream& o) const void -derived_probe::collect_derivation_chain (std::vector<derived_probe*> &probes_list) +derived_probe::collect_derivation_chain (std::vector<probe*> &probes_list) { probes_list.push_back(this); base->collect_derivation_chain(probes_list); @@ -432,7 +432,8 @@ match_node::build_no_more (systemtap_session& s) struct alias_derived_probe: public derived_probe { - alias_derived_probe (probe* base, probe_point *l): derived_probe (base, l) {} + alias_derived_probe (probe* base, probe_point *l, const probe_alias *a): + derived_probe (base, l), alias(a) {} void upchuck () { throw semantic_error ("inappropriate", this->tok); } @@ -441,6 +442,11 @@ struct alias_derived_probe: public derived_probe // systemtap_session.probes void join_group (systemtap_session&) { upchuck (); } + + virtual const probe_alias *get_alias () const { return alias; } + +private: + const probe_alias *alias; // Used to check for recursion }; @@ -460,11 +466,20 @@ alias_expansion_builder std::map<std::string, literal *> const &, vector<derived_probe *> & finished_results) { + // Don't build the alias expansion if infinite recursion is detected. + if (checkForRecursiveExpansion (use)) { + stringstream msg; + msg << "Recursive loop in alias expansion of " << *location << " at " << location->tok->location; + // semantic_errors thrown here are ignored. + sess.print_error (semantic_error (msg.str())); + return; + } + // We're going to build a new probe and wrap it up in an // alias_expansion_probe so that the expansion loop recognizes it as // such and re-expands its expansion. - alias_derived_probe * n = new alias_derived_probe (use, location /* soon overwritten */); + alias_derived_probe * n = new alias_derived_probe (use, location /* soon overwritten */, this->alias); n->body = new block(); // The new probe gets the location list of the alias (with incoming condition joined) @@ -508,6 +523,26 @@ alias_expansion_builder derive_probes (sess, n, finished_results, location->optional); } + + bool checkForRecursiveExpansion (probe *use) + { + // Collect the derivation chain of this probe. + vector<probe*>derivations; + use->collect_derivation_chain (derivations); + + // Check all probe points in the alias expansion against the currently-being-expanded probe point + // of each of the probes in the derivation chain, looking for a match. This + // indicates infinite recursion. + // The first element of the derivation chain will be the derived_probe representing 'use', so + // start the search with the second element. + assert (derivations.size() > 0); + assert (derivations[0] == use); + for (unsigned d = 1; d < derivations.size(); ++d) { + if (use->get_alias() == derivations[d]->get_alias()) + return true; // recursion detected + } + return false; + } }; |