Patchwork [1.1,2/2] tracetool: allow parenthesis in trace-events format strings

login
register
mail settings
Submitter Stefan Hajnoczi
Date May 22, 2012, 4:03 p.m.
Message ID <1337702582-26368-3-git-send-email-stefanha@linux.vnet.ibm.com>
Download mbox | patch
Permalink /patch/160678/
State New
Headers show

Comments

Stefan Hajnoczi - May 22, 2012, 4:03 p.m.
The regular expression used to parse ./trace-events fails on the
following input:

  test_paren(int n) "(%d)"

The problem is that the regular expression uses greedy matching and '"'
becomes the name of the event while 'test_paren(int n) ' becomes the
properties of the event.

Prevent greedy matching from going too far by explicitly saying the name
cannot have a '"'.  This forces the regular expression engine to
backtrack to the desired match.

Reported-by: Bob Breuer <breuerr@mc.net>
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
---
 scripts/tracetool/__init__.py |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Lluís Vilanova - May 22, 2012, 6:06 p.m.
Stefan Hajnoczi writes:

> The regular expression used to parse ./trace-events fails on the
> following input:

>   test_paren(int n) "(%d)"

> The problem is that the regular expression uses greedy matching and '"'
> becomes the name of the event while 'test_paren(int n) ' becomes the
> properties of the event.

> Prevent greedy matching from going too far by explicitly saying the name
> cannot have a '"'.  This forces the regular expression engine to
> backtrack to the desired match.

> Reported-by: Bob Breuer <breuerr@mc.net>
> Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>

Reviewed-by: Lluís Vilanova <vilanova@ac.upc.edu>


> ---
>  scripts/tracetool/__init__.py |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

> diff --git a/scripts/tracetool/__init__.py b/scripts/tracetool/__init__.py
> index 175df08..148f553 100644
> --- a/scripts/tracetool/__init__.py
> +++ b/scripts/tracetool/__init__.py
> @@ -120,7 +120,7 @@ class Event(object):
>          The event arguments.
>      """
 
> -    _CRE = re.compile("((?P<props>.*)\s+)?(?P<name>[^(\s]+)\((?P<args>[^)]*)\)\s*(?P<fmt>\".*)?")
> +    _CRE = re.compile("((?P<props>.*)\s+)?(?P<name>[^\"(\s]+)\((?P<args>[^)]*)\)\s*(?P<fmt>\".*)?")
 
>      _VALID_PROPS = set(["disable"])
 
> -- 
> 1.7.10

Patch

diff --git a/scripts/tracetool/__init__.py b/scripts/tracetool/__init__.py
index 175df08..148f553 100644
--- a/scripts/tracetool/__init__.py
+++ b/scripts/tracetool/__init__.py
@@ -120,7 +120,7 @@  class Event(object):
         The event arguments.
     """
 
-    _CRE = re.compile("((?P<props>.*)\s+)?(?P<name>[^(\s]+)\((?P<args>[^)]*)\)\s*(?P<fmt>\".*)?")
+    _CRE = re.compile("((?P<props>.*)\s+)?(?P<name>[^\"(\s]+)\((?P<args>[^)]*)\)\s*(?P<fmt>\".*)?")
 
     _VALID_PROPS = set(["disable"])