summaryrefslogtreecommitdiffstats
path: root/elaborate.cxx
diff options
context:
space:
mode:
authordsmith <dsmith>2006-05-24 18:37:50 +0000
committerdsmith <dsmith>2006-05-24 18:37:50 +0000
commita477f3f17daab73993ce765900e95cddc3463586 (patch)
tree7f8184c086e4d831255f86ecc1b3cc095f01259d /elaborate.cxx
parent357134252c66425e159c9eff011e35a70faf3e11 (diff)
downloadsystemtap-steved-a477f3f17daab73993ce765900e95cddc3463586.tar.gz
systemtap-steved-a477f3f17daab73993ce765900e95cddc3463586.tar.xz
systemtap-steved-a477f3f17daab73993ce765900e95cddc3463586.zip
2006-05-24 David Smith <dsmith@redhat.com>
* elaborate.cxx (isglob): New function. (match_key::globmatch): New function. (match_node::find_and_build): Uses isglob() and match_key::globmatch() to provide support for wildcards such as "kernel.syscall.*read*" (Bugzilla #1928). * elaborate.h (match_key::globmatch): Added function declaration. * parse.cxx (parser::parse_probe_point): Collects one or more tokens into a single probe-point functor string. * testsuite/parseko/twentytwo.stp: New file. * testsuite/parseok/sixteen.stp: New file.
Diffstat (limited to 'elaborate.cxx')
-rw-r--r--elaborate.cxx48
1 files changed, 36 insertions, 12 deletions
diff --git a/elaborate.cxx b/elaborate.cxx
index bdeb14f5..82e767e5 100644
--- a/elaborate.cxx
+++ b/elaborate.cxx
@@ -13,6 +13,7 @@
extern "C" {
#include <sys/utsname.h>
+#include <fnmatch.h>
}
#include <algorithm>
@@ -165,6 +166,23 @@ match_key::operator<(match_key const & other) const
&& parameter_type < other.parameter_type));
}
+static bool
+isglob(string const & str)
+{
+ return(str.find('*') != str.npos);
+}
+
+bool
+match_key::globmatch(match_key const & other) const
+{
+ const char *other_str = other.name.c_str();
+ const char *name_str = name.c_str();
+
+ return ((fnmatch(name_str, other_str, FNM_NOESCAPE) == 0)
+ && have_parameter == other.have_parameter
+ && parameter_type == other.parameter_type);
+}
+
// ------------------------------------------------------------------------
// Members of match_node
// ------------------------------------------------------------------------
@@ -242,27 +260,33 @@ match_node::find_and_build (systemtap_session& s,
b->build (s, p, loc, param_map, results);
}
- else if (loc->components[pos]->functor == "*") // wildcard?
+ else if (isglob(loc->components[pos]->functor)) // wildcard?
{
+ match_key match (* loc->components[pos]);
+
// Call find_and_build for each possible match. Ignore errors -
// unless we don't find any match.
unsigned int num_results = results.size();
for (sub_map_iterator_t i = sub.begin(); i != sub.end(); i++)
{
+ const match_key& subkey = i->first;
match_node* subnode = i->second;
- // recurse
- try
- {
- subnode->find_and_build (s, p, loc, pos+1, results);
- }
- catch (const semantic_error& e)
+
+ if (match.globmatch(subkey))
{
- // Ignore semantic_errors while expanding wildcards. If
- // we get done and nothing was expanded, the code
- // following the loop will complain.
+ // recurse
+ try
+ {
+ subnode->find_and_build (s, p, loc, pos+1, results);
+ }
+ catch (const semantic_error& e)
+ {
+ // Ignore semantic_errors while expanding wildcards.
+ // If we get done and nothing was expanded, the code
+ // following the loop will complain.
+ }
}
- }
-
+ }
if (num_results == results.size())
{
// We didn't find any wildcard matches (since the size of