Skip to contentSkip to conversation

trace: tighten up trace-events regex to fix bad parse

PATCH Superseded Stefan Hajnoczi 3 participants 4 messages Sep 22, 2014 – Sep 23, 2014

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 trace: tighten up trace-events regex to fix bad parse

Use \w for properties and trace event names since they are both drawn from [a-zA-Z0-9_] character sets.

The .* for matching properties was too aggressive and caused the following failure with foo(int rc) "(this is a test)":

Traceback (most recent call last):
File "scripts/tracetool.py", line 139, in <module>
main(sys.argv)
File "scripts/tracetool.py", line 134, in main
binary=binary, probe_prefix=probe_prefix)
File "scripts/tracetool/__init__.py", line 334, in generate
events = _read_events(fevents)
File "scripts/tracetool/__init__.py", line 262, in _read_events
res.append(Event.build(line))
File "scripts/tracetool/__init__.py", line 225, in build
return Event(name, props, fmt, args, arg_fmts)
File "scripts/tracetool/__init__.py", line 185, in __init__
% ", ".join(unknown_props))
ValueError: Unknown properties: foo(int, rc)

---
 scripts/tracetool/__init__.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
scripts/tracetool/__init__.py +2 -2
index 36c789d..474f11b 100644
@@ -140,8 +140,8 @@ class Event(object):
         The format strings for each argument.
     """
 
-    _CRE = re.compile("((?P<props>.*)\s+)?"
-                      "(?P<name>[^(\s]+)"
+    _CRE = re.compile("((?P<props>\w*)\s+)?"
+                      "(?P<name>\w+)"
                       "\((?P<args>[^)]*)\)"
                       "\s*"
                       "(?:(?:(?P<fmt_trans>\".+),)?\s*(?P<fmt>\".+))?"
Signature · 1 line
1.9.3
#1 lore raw
Quoted 33 lines · Stefan Hajnoczi

Use \w for properties and trace event names since they are both drawn from [a-zA-Z0-9_] character sets.

The .* for matching properties was too aggressive and caused the following failure with foo(int rc) "(this is a test)":

Traceback (most recent call last):
File "scripts/tracetool.py", line 139, in <module>
main(sys.argv)
File "scripts/tracetool.py", line 134, in main
binary=binary, probe_prefix=probe_prefix)
File "scripts/tracetool/__init__.py", line 334, in generate
events = _read_events(fevents)
File "scripts/tracetool/__init__.py", line 262, in _read_events
res.append(Event.build(line))
File "scripts/tracetool/__init__.py", line 225, in build
return Event(name, props, fmt, args, arg_fmts)
File "scripts/tracetool/__init__.py", line 185, in __init__
% ", ".join(unknown_props))
ValueError: Unknown properties: foo(int, rc)

---
 scripts/tracetool/__init__.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
scripts/tracetool/__init__.py +0 -0
index 36c789d..474f11b 100644

scripts/tracetool/__init__.py class Event(object): · line 147

Quoted 10 lines
scripts/tracetool/__init__.py +2 -2
@@ -140,8 +140,8 @@ class Event(object):
         The format strings for each argument.
     """
 
-    _CRE = re.compile("((?P<props>.*)\s+)?"
-                      "(?P<name>[^(\s]+)"
+    _CRE = re.compile("((?P<props>\w*)\s+)?"
+                      "(?P<name>\w+)"
                       "\((?P<args>[^)]*)\)"
                       "\s*"
                       "(?:(?:(?P<fmt_trans>\".+),)?\s*(?P<fmt>\".+))?"

The previous implementation allowed multiple properties. Maybe this should be instead (which still allows multiple properties):

    "((?P<props>[\w\s]+)\s+)?"
    "(?P<name>\w+)\s*"
    ...

Thanks,
Lluis

Signature · 4 lines
 "And it's much the same thing with knowledge, for whenever you learn
 something new, the whole world becomes that much richer."
 -- The Princess of Pure Reason, as told by Norton Juster in The Phantom
 Tollbooth
#2 lore raw

Dear all,

Many thanks for the fix. I am currently travelling but I will test it early next week with vfio PCI & platform case. Also following Alex advises, I will move [RFC] vfio: migration to trace points into a PATCH.

Best Regards

Eric

Quoted 57 lines · Lluís Vilanova
Quoted 33 lines · Stefan Hajnoczi

Use \w for properties and trace event names since they are both drawn from [a-zA-Z0-9_] character sets.

The .* for matching properties was too aggressive and caused the following failure with foo(int rc) "(this is a test)":

Traceback (most recent call last):
File "scripts/tracetool.py", line 139, in <module>
main(sys.argv)
File "scripts/tracetool.py", line 134, in main
binary=binary, probe_prefix=probe_prefix)
File "scripts/tracetool/__init__.py", line 334, in generate
events = _read_events(fevents)
File "scripts/tracetool/__init__.py", line 262, in _read_events
res.append(Event.build(line))
File "scripts/tracetool/__init__.py", line 225, in build
return Event(name, props, fmt, args, arg_fmts)
File "scripts/tracetool/__init__.py", line 185, in __init__
% ", ".join(unknown_props))
ValueError: Unknown properties: foo(int, rc)

---
 scripts/tracetool/__init__.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
scripts/tracetool/__init__.py +0 -0
index 36c789d..474f11b 100644

scripts/tracetool/__init__.py class Event(object): · line 147

Quoted 10 lines
scripts/tracetool/__init__.py +2 -2
@@ -140,8 +140,8 @@ class Event(object):
         The format strings for each argument.
     """
 
-    _CRE = re.compile("((?P<props>.*)\s+)?"
-                      "(?P<name>[^(\s]+)"
+    _CRE = re.compile("((?P<props>\w*)\s+)?"
+                      "(?P<name>\w+)"
                       "\((?P<args>[^)]*)\)"
                       "\s*"
                       "(?:(?:(?P<fmt_trans>\".+),)?\s*(?P<fmt>\".+))?"

The previous implementation allowed multiple properties. Maybe this should be instead (which still allows multiple properties):

    "((?P<props>[\w\s]+)\s+)?"
    "(?P<name>\w+)\s*"
    ...

Thanks,
Lluis

#3 lore raw
In reply to Lluís Vilanova
Quoted 46 lines · Lluís Vilanova
Quoted 33 lines · Stefan Hajnoczi

Use \w for properties and trace event names since they are both drawn from [a-zA-Z0-9_] character sets.

The .* for matching properties was too aggressive and caused the following failure with foo(int rc) "(this is a test)":

Traceback (most recent call last):
File "scripts/tracetool.py", line 139, in <module>
main(sys.argv)
File "scripts/tracetool.py", line 134, in main
binary=binary, probe_prefix=probe_prefix)
File "scripts/tracetool/__init__.py", line 334, in generate
events = _read_events(fevents)
File "scripts/tracetool/__init__.py", line 262, in _read_events
res.append(Event.build(line))
File "scripts/tracetool/__init__.py", line 225, in build
return Event(name, props, fmt, args, arg_fmts)
File "scripts/tracetool/__init__.py", line 185, in __init__
% ", ".join(unknown_props))
ValueError: Unknown properties: foo(int, rc)

---
 scripts/tracetool/__init__.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
scripts/tracetool/__init__.py +0 -0
index 36c789d..474f11b 100644

scripts/tracetool/__init__.py class Event(object): · line 147

Quoted 10 lines
scripts/tracetool/__init__.py +2 -2
@@ -140,8 +140,8 @@ class Event(object):
         The format strings for each argument.
     """
 
-    _CRE = re.compile("((?P<props>.*)\s+)?"
-                      "(?P<name>[^(\s]+)"
+    _CRE = re.compile("((?P<props>\w*)\s+)?"
+                      "(?P<name>\w+)"
                       "\((?P<args>[^)]*)\)"
                       "\s*"
                       "(?:(?:(?P<fmt_trans>\".+),)?\s*(?P<fmt>\".+))?"
Quoted 6 lines

The previous implementation allowed multiple properties. Maybe this should be instead (which still allows multiple properties):

    "((?P<props>[\w\s]+)\s+)?"
    "(?P<name>\w+)\s*"
    ...

Ooops, good point!

I will send v2.

Stefan