From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27167 invoked by alias); 20 Feb 2008 19:24:26 -0000 Received: (qmail 27142 invoked by uid 9697); 20 Feb 2008 19:24:26 -0000 Date: Wed, 20 Feb 2008 19:24:00 -0000 Message-ID: <20080220192426.27127.qmail@sourceware.org> From: pmachata@sourceware.org To: frysk-cvs@sourceware.org Subject: [SCM] master: Use globs in ftrace X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Oldrev: a698552443da8465f68ad185f7760ef1c9dcdf2a X-Git-Newrev: 79c3336ab437f84fdcf207540d1cb68954ed2719 Mailing-List: contact frysk-cvs-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: frysk-cvs-owner@sourceware.org Reply-To: frysk@sourceware.org X-SW-Source: 2008-q1/txt/msg00234.txt.bz2 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 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 + + * ftrace.java: Use globs instead of regular expressions. + (Glob): New class. + 2008-02-19 Andrew Cagney * 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