public inbox for frysk-cvs@sourceware.org
help / color / mirror / Atom feed
* [SCM]  master: Use globs in ftrace
@ 2008-02-20 19:24 pmachata
  0 siblings, 0 replies; only message in thread
From: pmachata @ 2008-02-20 19:24 UTC (permalink / raw)
  To: frysk-cvs

The branch, master has been updated
       via  79c3336ab437f84fdcf207540d1cb68954ed2719 (commit)
      from  a698552443da8465f68ad185f7760ef1c9dcdf2a (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit 79c3336ab437f84fdcf207540d1cb68954ed2719
Author: Petr Machata <pmachata@redhat.com>
Date:   Wed Feb 20 20:24:11 2008 +0100

    Use globs in ftrace

-----------------------------------------------------------------------

Summary of changes:
 frysk-core/frysk/bindir/ChangeLog   |    5 ++
 frysk-core/frysk/bindir/ftrace.java |   90 +++++++++++++++++++++++++++++++++--
 2 files changed, 91 insertions(+), 4 deletions(-)

First 500 lines of diff:
diff --git a/frysk-core/frysk/bindir/ChangeLog b/frysk-core/frysk/bindir/ChangeLog
index ddf28e2..f60e599 100644
--- a/frysk-core/frysk/bindir/ChangeLog
+++ b/frysk-core/frysk/bindir/ChangeLog
@@ -1,3 +1,8 @@
+2008-02-20  Petr Machata  <pmachata@redhat.com>
+
+	* ftrace.java: Use globs instead of regular expressions.
+	(Glob): New class.
+
 2008-02-19  Andrew Cagney  <cagney@redhat.com>
 
 	* TestFstep.java: Update to match lib.dwfl.Elf.
diff --git a/frysk-core/frysk/bindir/ftrace.java b/frysk-core/frysk/bindir/ftrace.java
index a845b05..c9fcfec 100644
--- a/frysk-core/frysk/bindir/ftrace.java
+++ b/frysk-core/frysk/bindir/ftrace.java
@@ -73,6 +73,88 @@ import lib.dwfl.ElfSymbolVersion;
 import gnu.classpath.tools.getopt.Option;
 import gnu.classpath.tools.getopt.OptionException;
 
+class Glob
+{
+    private static int matchCharacterClass(String glob, int from)
+	throws PatternSyntaxException
+    {
+	int i = from + 2;
+	while (glob.charAt(++i) != ':' && i < glob.length())
+	    continue;
+	if (i >= glob.length() || glob.charAt(++i) != ']')
+	    throw new PatternSyntaxException
+		("Unmatched '['.", glob, from);
+	return i;
+    }
+
+    private static int matchBrack(String glob, int from)
+	throws PatternSyntaxException
+    {
+	// On first character, both [ and ] are legal.  But when [ is
+	// foolowed with :, it's character class.
+	int i = from + 1;
+	if (glob.charAt(i) == '[' && glob.charAt(i + 1) == ':')
+	    i = matchCharacterClass(glob, i) + 1;
+	else
+	    ++i; // skip any character, including [ or ]
+	boolean escape = false;
+	for (; i < glob.length(); ++i) {
+	    char c = glob.charAt(i);
+	    if (escape) {
+		++i;
+		escape = false;
+	    }
+	    else if (c == '[' && glob.charAt(i + 1) == ':')
+		i = matchCharacterClass(glob, i);
+	    else if (c == ']')
+		return i;
+	}
+	throw new PatternSyntaxException
+	    ("Unmatched '" + glob.charAt(from) + "'.", glob, from);
+    }
+
+    private static String toRegex(String glob) {
+	StringBuffer buf = new StringBuffer();
+	boolean escape = false;
+	for(int i = 0; i < glob.length(); ++i) {
+	    char c = glob.charAt(i);
+	    if (escape) {
+		if (c == '\\')
+		    buf.append("\\\\");
+		else if (c == '*')
+		    buf.append("\\*");
+		else if (c == '?')
+		    buf.append('?');
+		else
+		    buf.append('\\').append(c);
+		escape = false;
+	    }
+	    else {
+		if (c == '\\')
+		    escape = true;
+		else if (c == '[') {
+		    int j = matchBrack(glob, i);
+		    buf.append(glob.substring(i, j+1));
+		    i = j;
+		}
+		else if (c == '*')
+		    buf.append(".*");
+		else if (c == '?')
+		    buf.append('.');
+		else if (c == '.')
+		    buf.append("\\.");
+		else
+		    buf.append(c);
+	    }
+	}
+	return buf.toString();
+    }
+
+    public static Pattern compile(String glob) {
+	return Pattern.compile(toRegex(glob));
+    }
+}
+
 abstract class Rule
 {
     final public boolean addition;
@@ -141,9 +223,9 @@ class SymbolRule
     public SymbolRule(boolean addition, boolean stackTrace,
 		      String nameRe, String sonameRe, String versionRe) {
 	super (addition, stackTrace);
-	this.sonamePattern = Pattern.compile((sonameRe != null) ? sonameRe : ".*");
-	this.versionPattern = Pattern.compile((versionRe != null) ? versionRe : ".*");
-	this.namePattern = Pattern.compile((nameRe != null) ? nameRe : ".*");
+	this.sonamePattern = Glob.compile((sonameRe != null) ? sonameRe : "*");
+	this.versionPattern = Glob.compile((versionRe != null) ? versionRe : "*");
+	this.namePattern = Glob.compile((nameRe != null) ? nameRe : "*");
     }
 
     public String toString() {
@@ -232,7 +314,7 @@ class ByRegexpSyscallRule
     Pattern pattern;
     public ByRegexpSyscallRule(boolean addition, boolean stackTrace, String regexp) {
 	super (addition, stackTrace);
-	this.pattern = Pattern.compile(regexp);
+	this.pattern = Glob.compile(regexp);
     }
 
     public boolean matches(Object traceable) {


hooks/post-receive
--
frysk system monitor/debugger


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2008-02-20 19:24 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-20 19:24 [SCM] master: Use globs in ftrace pmachata

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).