public inbox for frysk-cvs@sourceware.org
help / color / mirror / Atom feed
From: pmachata@sourceware.org
To: frysk-cvs@sourceware.org
Subject: [SCM]  master: FQIdentifier: *, ? and [ are enough to consider a string to be wildcard pattern
Date: Fri, 13 Jun 2008 15:06:00 -0000	[thread overview]
Message-ID: <20080613150617.32063.qmail@sourceware.org> (raw)

The branch, master has been updated
       via  a9c05fad829ce6b638eadeb1c93a44e71c4dd457 (commit)
       via  41d98c47346a1b34e739de3ec82ec942786e7c91 (commit)
       via  3fa8c38c3d39e1a5575b32141012fb2f9ddacd2d (commit)
      from  e7fe8b0edbf5bc538a3e7fbcd37997bc800d27a5 (commit)

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

- Log -----------------------------------------------------------------
commit a9c05fad829ce6b638eadeb1c93a44e71c4dd457
Author: Petr Machata <pmachata@redhat.com>
Date:   Fri Jun 13 16:47:55 2008 +0200

    FQIdentifier: *, ? and [ are enough to consider a string to be wildcard pattern
    
    * and rename containsGlobChar to isWildcardPattern while at it.

commit 41d98c47346a1b34e739de3ec82ec942786e7c91
Author: Petr Machata <pmachata@redhat.com>
Date:   Fri Jun 13 16:45:03 2008 +0200

    Glob: support ! as character set negation operator
    
    * That requires rewriting of the tool to use char[] instead of String,
      which is probably good also from the performance standpoint.
    * Since I'm doing pretty invasive change above, add a test.

commit 3fa8c38c3d39e1a5575b32141012fb2f9ddacd2d
Author: Petr Machata <pmachata@redhat.com>
Date:   Fri Jun 13 16:41:46 2008 +0200

    Update ftrace man page to match recent development

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

Summary of changes:
 frysk-core/frysk/bindir/ChangeLog        |    4 ++
 frysk-core/frysk/bindir/ftrace.xml-in    |   76 ++++++++++++++---------------
 frysk-core/frysk/expr/ChangeLog          |    7 +++
 frysk-core/frysk/expr/FQIdentParser.java |   16 ++-----
 frysk-core/frysk/expr/FQIdentifier.java  |    2 +-
 frysk-core/frysk/util/ChangeLog          |    5 ++
 frysk-core/frysk/util/Glob.java          |   40 +++++++++-------
 frysk-core/frysk/util/TestGlob.java      |   73 ++++++++++++++++++++++++++++
 8 files changed, 153 insertions(+), 70 deletions(-)
 create mode 100644 frysk-core/frysk/util/TestGlob.java

First 500 lines of diff:
diff --git a/frysk-core/frysk/bindir/ChangeLog b/frysk-core/frysk/bindir/ChangeLog
index 32b6db4..1097433 100644
--- a/frysk-core/frysk/bindir/ChangeLog
+++ b/frysk-core/frysk/bindir/ChangeLog
@@ -7,6 +7,10 @@
 	* TestFexe.java (testExeOfDeletedFile()): New; mark as unresolved
 	6621.
 
+2008-06-13  Petr Machata  <pmachata@redhat.com>
+
+	* ftrace.xml-in: Update.
+
 2008-06-10  Andrew Cagney  <cagney@redhat.com>
 
 	* TestFstack.java (testBackTraceWithFullPath): Specify "paths",
diff --git a/frysk-core/frysk/bindir/ftrace.xml-in b/frysk-core/frysk/bindir/ftrace.xml-in
index 525fef3..7e66e0e 100644
--- a/frysk-core/frysk/bindir/ftrace.xml-in
+++ b/frysk-core/frysk/bindir/ftrace.xml-in
@@ -246,56 +246,56 @@
     <title>SYMBOL RULE SYNTAX</title>
 
     <para>To decide which PLT slots or entry points should be traced,
-    following process takes place.  Initial working set is empty.
-    Rules, if present, are then enumerated from left to right, and set
-    is modified depending on the rules.  Rules are delimited by a
-    comma.  Syntax of each rule is following:</para>
+    following process takes place.  A set of symbols to trace
+    ("working set") is initially empty.  Rules, if present, are then
+    enumerated from left to right, and set is modified depending on
+    the rules.  Rules are delimited by a comma.  Syntax of each rule
+    is following:</para>
 
     <para>[-]<replaceable>pattern</replaceable>[/<replaceable>options</replaceable>]</para>
 
-    <para>Optional &quot;-&quot; at the beginning of the rule means
-    removal from the working set.  When the sign is omitted, the
-    default action is to add matching symbols to the working
-    set.</para>
+    <para>Without the optional &quot;-&quot; all symbols that match
+    the <replaceable>pattern</replaceable> are added to the working
+    set.  With &quot;-&quot;, matching symbols are removed.</para>
 
-    <para>If optional &quot;/&quot; is present at the end of the rule,
+    <para>If &quot;/&quot; is present at the end of the rule,
     following letters are interpreted as rule flags.  Currently only
     one flag is available, &quot;s&quot;.  When present, it means
     ftrace should show a stack trace when it hits a symbol that
     matches this rule.</para>
 
-    <para>When a &quot;-#&quot; rule is considered that has
-    &quot;s&quot; flag, then the call should still be traced, but
-    stack trace shouldn't be generated.</para>
+    <para>When a &quot;-&quot; rule has an &quot;/s&quot; flag, the
+    call should still be traced, but stack trace shouldn't be
+    generated.</para>
 
     <para><replaceable>pattern</replaceable> defines which symbols or
     PLT slots from which libraries should be added or removed from
-    working set.  Syntax of pattern is the following:</para>
-
-    <para><optional>#<replaceable>soname</replaceable>#</optional>
-    	  <optional><replaceable>filename.c</replaceable>#</optional>
-    	  <optional>(<replaceable>proc</replaceable>|<replaceable>line</replaceable>)#</optional>
-	  <optional>plt:</optional>symbol<optional>@<replaceable>version</replaceable></optional></para>
+    working set.  Syntax of pattern is as follows:</para>
 
+    <para><optional>#<replaceable>soname</replaceable>#</optional><!--
+       --><optional><replaceable>filename.c</replaceable>#</optional><!--
+       --><optional>(<replaceable>proc</replaceable>|<replaceable>line</replaceable>)#</optional><!--
+       --><optional>plt:</optional>symbol<optional>@<replaceable>version</replaceable></optional></para>
 
     <para><replaceable>soname</replaceable> component is matched
-    against a soname of a library in which we wish to track the call.
-    If the library has no associated soname or it is a main
-    executable, the match is done against the file name (without a
-    path).  Two special sonames are distinguished: "MAIN", which
-    always matches main executable; and "INTERP", which always matches
-    ELF interpreter (dynamic linker) of the main executable.  If the
-    component is missing, then the rule is applicable in all libraries
-    and in main executable.</para>
+    against a soname of a library in which we wish to trace the call.
+    If the library has no associated soname (such as is usual in case
+    of main executable), the match is done against the file name
+    (without a path).  Two special sonames are distinguished: "MAIN",
+    which always matches main executable; and "INTERP", which always
+    matches ELF interpreter (dynamic linker) of the main executable.
+    If the component is missing, then the rule is applicable in all
+    libraries and in main executable.</para>
 
     <para><replaceable>filename.c</replaceable> component is matched
-    against the name of a file where the symbol is defined.</para>
+    against the name of a file where the symbol is defined.  NOTE:
+    This is currently not implemented.</para>
 
     <para><replaceable>proc</replaceable> component is matched against
     the name of block surrounding the definition we wish to trace.  If
     the block doesn't have a name, you can instead refer to it with
     the <replaceable>line</replaceable> number that the block
-    surrounds.</para>
+    surrounds.  NOTE: This is currently not implemented.</para>
 
     <para><replaceable>symbol</replaceable> component is matched
     against the name of symbol under consideration.  If
@@ -306,11 +306,10 @@
     against version associated with symbol.  If the symbol has no
     associated version, it is considered to be an empty string.  (It
     is possible to request symbol without a version with the pattern
-    "foo@".)</para>
+    "foo@".) NOTE: This is currently not implemented.</para>
 
-    <para>NOTE: A lot of this is not yet implemented.  Currently all
-    the components are required to be plain strings, although in
-    future some form of globbing will be introduced.</para>
+    <para>All components are presented in glob syntax.  See glob(7)
+    manual page for more details.  See below for examples.</para>
   </refsect1>
 
   <refsect1>
@@ -364,8 +363,8 @@
     <para><replaceable>soname</replaceable> component is the same as
     in symbol tracing, i.e. it's matched against a soname of a library
     in which we wish to trace the address.  Same rules apply regarding
-    INTERP and MAIN meta-sonames.  Refer there for detailed
-    description.</para>
+    INTERP and MAIN meta-sonames.  Refer to the chapter "SYMBOL RULE
+    SYNTAX" for detailed description.</para>
 
     <para>Even though <replaceable>soname</replaceable> is optional,
     at least one soname has to be specified at the beginning of the
@@ -399,17 +398,16 @@
       <cmdsynopsis><command>ftrace -sys=&apos;*stat*,3&apos; ls</command></cmdsynopsis>
       <para>Various ways to tell ftrace that you want to stack trace on SIGUSR1:</para>
       <cmdsynopsis><command>ftrace -sig=USR1/s,usr1/s,SIGUSR1/s,sigusr1/s,10/s ~/sig</command></cmdsynopsis>
-      <para>Trace all library calls (NOTE globbing doesn't work yet):</para>
+      <para>Trace all library calls:</para>
       <cmdsynopsis><command>ftrace -sym=plt:* ls</command></cmdsynopsis>
       <para>Trace all library calls to functions that contain
-      substring "write" in their names (NOTE globbing doesn't work yet):</para>
+      substring "write" in their names:</para>
       <cmdsynopsis><command>ftrace -sym=plt:*write* ls</command></cmdsynopsis>
       <para>Trace memory functions done from libraries, i.e. not from
-      main executable (NOTE globbing doesn't work yet):</para>
+      main executable:</para>
       <cmdsynopsis><command>ftrace -sym=&apos;plt:*alloc,plt:free,-#MAIN#plt:*&apos; ls</command></cmdsynopsis>
       <para>Stack trace on everything, except for memory allocation
-      functions (which should still be traced) (NOTE globbing doesn't
-      work yet):</para>
+      functions (which should still be traced):</para>
       <cmdsynopsis><command>ftrace -sym=&apos;plt:*/s,-plt:*alloc/s,-plt:free/s&apos; ls</command></cmdsynopsis>
     </informalexample>
 
diff --git a/frysk-core/frysk/expr/ChangeLog b/frysk-core/frysk/expr/ChangeLog
index 0586e6d..2257a31 100644
--- a/frysk-core/frysk/expr/ChangeLog
+++ b/frysk-core/frysk/expr/ChangeLog
@@ -1,3 +1,10 @@
+2008-06-13  Petr Machata  <pmachata@redhat.com>
+
+	* FQIdentParser.java (containsGlobChar): Rename to
+	isWildcardPattern.  Only require *, ? or [ to consider
+	a string to be a wildcard pattern.
+	* FQIdentifier.java: Adapt to above.
+
 2008-06-12  Andrew Cagney  <cagney@redhat.com>
 
 	* ScratchSymTab.java: Throw UserException.
diff --git a/frysk-core/frysk/expr/FQIdentParser.java b/frysk-core/frysk/expr/FQIdentParser.java
index 86ed85a..de521f9 100644
--- a/frysk-core/frysk/expr/FQIdentParser.java
+++ b/frysk-core/frysk/expr/FQIdentParser.java
@@ -164,20 +164,12 @@ public class FQIdentParser {
 	    || c == '-';
     }
 
-    public static boolean containsGlobChar(String str) {
-	// If anyone finds this code stupid, and the duplication to
-	// the isGlobChar outrageous, I've chosen to do so for
-	// performance reasons.  Other tested variants include:
-	//  * iterate the string and call isGlobChar for each char
-	//  * call Matcher.find over str and regexp "[*?etc]"
-	//  * and a couple more
+    public static boolean isWildcardPattern(String str) {
+	// man 7 glob: """A string is a wildcard pattern if it
+	//  contains one of the characters "?", "*" or "["."""
 	return str.indexOf('*') != -1
 	    || str.indexOf('?') != -1
-	    || str.indexOf('[') != -1
-	    || str.indexOf(']') != -1
-	    || str.indexOf('^') != -1
-	    || str.indexOf(':') != -1
-	    || str.indexOf('-') != -1;
+	    || str.indexOf('[') != -1;
     }
 
     /**
diff --git a/frysk-core/frysk/expr/FQIdentifier.java b/frysk-core/frysk/expr/FQIdentifier.java
index 3b01028..e73fbbe 100644
--- a/frysk-core/frysk/expr/FQIdentifier.java
+++ b/frysk-core/frysk/expr/FQIdentifier.java
@@ -71,7 +71,7 @@ public class FQIdentifier {
     private FQIdentPattern getPatternFor(FQIdentToken tok, String str) {
 	if (str == null)
 	    return FQIdentPatternAll.instance;
-	else if (!tok.globs || !FQIdentParser.containsGlobChar(str))
+	else if (!tok.globs || !FQIdentParser.isWildcardPattern(str))
 	    return new FQIdentPatternExact(str);
 	else
 	    return new FQIdentPatternGlob(str);
diff --git a/frysk-core/frysk/util/ChangeLog b/frysk-core/frysk/util/ChangeLog
index 3c672ae..30aa6e4 100644
--- a/frysk-core/frysk/util/ChangeLog
+++ b/frysk-core/frysk/util/ChangeLog
@@ -1,3 +1,8 @@
+2008-06-13  Petr Machata  <pmachata@redhat.com>
+
+	* Glob.java: Support ! as character set negation operator.
+	* TestGlob.java: New class, suite of test cases for Glob compiler.
+
 2008-06-12  Andrew Cagney  <cagney@redhat.com>
 
 	* CommandlineParser.java: Catch UserException, not
diff --git a/frysk-core/frysk/util/Glob.java b/frysk-core/frysk/util/Glob.java
index 96c40c4..0bb0632 100644
--- a/frysk-core/frysk/util/Glob.java
+++ b/frysk-core/frysk/util/Glob.java
@@ -1,6 +1,6 @@
 // This file is part of the program FRYSK.
 //
-// Copyright 2005, 2006, 2007, 2008, Red Hat Inc.
+// Copyright 2007, 2008, Red Hat Inc.
 //
 // FRYSK is free software; you can redistribute it and/or modify it
 // under the terms of the GNU General Public License as published by
@@ -44,53 +44,57 @@ import java.util.regex.PatternSyntaxException;
 
 public class Glob {
 
-    private static int matchCharacterClass(String glob, int from)
+    private static int matchCharacterClass(char[] glob, int from)
 	throws PatternSyntaxException
     {
 	int i = from + 2;
-	while (glob.charAt(++i) != ':' && i < glob.length())
+	while (glob[++i] != ':' && i < glob.length)
 	    continue;
-	if (i >= glob.length() || glob.charAt(++i) != ']')
+	if (i >= glob.length || glob[++i] != ']')
 	    throw new PatternSyntaxException
-		("Unmatched '['.", glob, from);
+		("Unmatched '['.", new String(glob), from);
 	return i;
     }
 
-    private static int matchBrack(String glob, int from)
+    private static int matchBrack(char[] glob, int from)
 	throws PatternSyntaxException
     {
 	int i = from + 1;
 
-	if (glob.charAt(i) == '^') // Complement operator.
+	// Complement operator.
+	if (glob[i] == '^')
 	    ++i;
+	else if (glob[i] == '!')
+	    glob[i++] = '^';
 
 	// On first character, both [ and ] are legal.  But when [ is
 	// foolowed with :, it's character class.
-	if (glob.charAt(i) == '[' && glob.charAt(i + 1) == ':')
+	if (glob[i] == '[' && glob[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);
+	for (; i < glob.length; ++i) {
+	    char c = glob[i];
 	    if (escape) {
 		++i;
 		escape = false;
 	    }
-	    else if (c == '[' && glob.charAt(i + 1) == ':')
+	    else if (c == '[' && glob[i + 1] == ':')
 		i = matchCharacterClass(glob, i);
 	    else if (c == ']')
 		return i;
 	}
 	throw new PatternSyntaxException
-	    ("Unmatched '" + glob.charAt(from) + "'.", glob, from);
+	    ("Unmatched '" + glob[from] + "'.", new String(glob), from);
     }
 
-    private static String toRegex(String glob) {
+    // Package private so that TestGlob can access it.
+    static String toRegex(char[] glob) {
 	StringBuffer buf = new StringBuffer();
 	boolean escape = false;
-	for(int i = 0; i < glob.length(); ++i) {
-	    char c = glob.charAt(i);
+	for(int i = 0; i < glob.length; ++i) {
+	    char c = glob[i];
 	    if (escape) {
 		if (c == '\\')
 		    buf.append("\\\\");
@@ -107,7 +111,7 @@ public class Glob {
 		    escape = true;
 		else if (c == '[') {
 		    int j = matchBrack(glob, i);
-		    buf.append(glob.substring(i, j+1));
+		    buf.append(glob, i, j - i + 1);
 		    i = j;
 		}
 		else if (c == '*')
@@ -124,10 +128,10 @@ public class Glob {
     }
 
     public static Pattern compile(String glob) {
-	return Pattern.compile(toRegex(glob));
+	return Pattern.compile(toRegex(glob.toCharArray()));
     }
 
     public static Pattern compile(String glob, int flags) {
-	return Pattern.compile(toRegex(glob), flags);
+	return Pattern.compile(toRegex(glob.toCharArray()), flags);
     }
 }
diff --git a/frysk-core/frysk/util/TestGlob.java b/frysk-core/frysk/util/TestGlob.java
new file mode 100644
index 0000000..8efa4b8
--- /dev/null
+++ b/frysk-core/frysk/util/TestGlob.java
@@ -0,0 +1,73 @@
+// This file is part of the program FRYSK.
+//
+// Copyright 2008, Red Hat Inc.
+//
+// FRYSK is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// FRYSK is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+// 
+// You should have received a copy of the GNU General Public License
+// along with FRYSK; if not, write to the Free Software Foundation,
+// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+// 
+// In addition, as a special exception, Red Hat, Inc. gives You the
+// additional right to link the code of FRYSK with code not covered
+// under the GNU General Public License ("Non-GPL Code") and to
+// distribute linked combinations including the two, subject to the
+// limitations in this paragraph. Non-GPL Code permitted under this
+// exception must only link to the code of FRYSK through those well
+// defined interfaces identified in the file named EXCEPTION found in
+// the source code files (the "Approved Interfaces"). The files of
+// Non-GPL Code may instantiate templates or use macros or inline
+// functions from the Approved Interfaces without causing the
+// resulting work to be covered by the GNU General Public
+// License. Only Red Hat, Inc. may make changes or additions to the
+// list of Approved Interfaces. You must obey the GNU General Public
+// License in all respects for all of the FRYSK code and other code
+// used in conjunction with FRYSK except the Non-GPL Code covered by
+// this exception. If you modify this file, you may extend this
+// exception to your version of the file, but you are not obligated to
+// do so. If you do not wish to provide this exception without
+// modification, you must delete this exception statement from your
+// version and license this file solely under the GPL without
+// exception.
+
+package frysk.util;
+
+import frysk.junit.TestCase;
+
+public class TestGlob
+    extends TestCase {
+
+    private void translate(String glob, String expect) {
+	String pattern = Glob.toRegex(glob.toCharArray());
+	assertEquals(glob + " -> " + expect, pattern, expect);
+    }
+
+    public void testGlobs() {
+        translate("*", ".*");
+        translate("?", ".");
+        translate(".*", "\\..*");
+        translate("*.*", ".*\\..*");
+        translate("*a*", ".*a.*");
+        translate("[abc]", "[abc]");
+        translate("[^abc]", "[^abc]");
+        translate("[!abc]", "[^abc]");
+        translate("[]]", "[]]");
+        translate("[[]", "[[]");
+        translate("[^]]", "[^]]");
+        translate("[^a-z]", "[^a-z]");
+        translate("[abc\\]]", "[abc\\]]");
+        translate("[abc\\]def]", "[abc\\]def]");
+        translate("[[:space:]]", "[[:space:]]");
+        translate("[^[:space:]]", "[^[:space:]]");
+        translate("[![:space:]]", "[^[:space:]]");
+        translate("[^a-z]*", "[^a-z].*");
+        translate("[^a-z]bar*", "[^a-z]bar.*");
+    }
+}


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


                 reply	other threads:[~2008-06-13 15:06 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080613150617.32063.qmail@sourceware.org \
    --to=pmachata@sourceware.org \
    --cc=frysk-cvs@sourceware.org \
    --cc=frysk@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).