From 5069b561894206b65a16c3b8cfebd6b3e76c61d6 Mon Sep 17 00:00:00 2001 From: Stefan Hajnoczi Date: Wed, 10 Jan 2018 20:25:51 +0000 Subject: tracetool: prefix parse errors with line numbers Include the file line number in the message that is printed when trace-events parse errors are raised. [Use enumerate(fobj, 1) to avoid having to increment a 0-based index later, as suggested by Eric Blake. --Stefan] Suggested-by: Dr. David Alan Gilbert Signed-off-by: Stefan Hajnoczi Reviewed-by: Eric Blake Message-id: 20180110202553.31889-2-stefanha@redhat.com Signed-off-by: Stefan Hajnoczi --- scripts/tracetool/__init__.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/scripts/tracetool/__init__.py b/scripts/tracetool/__init__.py index 0670ec1..a744e26 100644 --- a/scripts/tracetool/__init__.py +++ b/scripts/tracetool/__init__.py @@ -300,13 +300,18 @@ def read_events(fobj): """ events = [] - for line in fobj: + for lineno, line in enumerate(fobj, 1): if not line.strip(): continue if line.lstrip().startswith('#'): continue - event = Event.build(line) + try: + event = Event.build(line) + except ValueError as e: + arg0 = 'Error on line %d: %s' % (lineno, e.args[0]) + e.args = (arg0,) + e.args[1:] + raise # transform TCG-enabled events if "tcg" not in event.properties: -- cgit v1.1 From 6e497fa1b12bbb28388f9c19e15a36d68f826f4a Mon Sep 17 00:00:00 2001 From: Stefan Hajnoczi Date: Wed, 10 Jan 2018 20:25:52 +0000 Subject: tracetool: clarify that "formats" means "format strings" The terminology used by tracetool is not consistent with C sprintf or docs/devel/tracing.txt. The word "formats" is sometimes used to mean "format strings". This patch clarifies comments and error messages that contain this word. Note that the error message lines are longer than 80 characters but I have not wrapped them to aid grepping. Signed-off-by: Stefan Hajnoczi Reviewed-by: Eric Blake Message-id: 20180110202553.31889-3-stefanha@redhat.com Signed-off-by: Stefan Hajnoczi --- scripts/tracetool/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/tracetool/__init__.py b/scripts/tracetool/__init__.py index a744e26..e3685bd 100644 --- a/scripts/tracetool/__init__.py +++ b/scripts/tracetool/__init__.py @@ -173,7 +173,7 @@ class Event(object): props : list of str Property names. fmt : str, list of str - Event printing format (or formats). + Event printing format string(s). args : Arguments Event arguments. orig : Event or None @@ -237,9 +237,9 @@ class Event(object): if "tcg-exec" in props: raise ValueError("Invalid property 'tcg-exec'") if "tcg" not in props and not isinstance(fmt, str): - raise ValueError("Only events with 'tcg' property can have two formats") + raise ValueError("Only events with 'tcg' property can have two format strings") if "tcg" in props and isinstance(fmt, str): - raise ValueError("Events with 'tcg' property must have two formats") + raise ValueError("Events with 'tcg' property must have two format strings") event = Event(name, props, fmt, args) @@ -263,7 +263,7 @@ class Event(object): _FMT = re.compile("(%[\d\.]*\w+|%.*PRI\S+)") def formats(self): - """List of argument print formats.""" + """List conversion specifiers in the argument print format string.""" assert not isinstance(self.fmt, list) return self._FMT.findall(self.fmt) -- cgit v1.1 From 24f4d3d3aeabf83445839099d6d66cbb3089c37a Mon Sep 17 00:00:00 2001 From: Stefan Hajnoczi Date: Wed, 10 Jan 2018 20:25:53 +0000 Subject: tracetool: report error on foo() instead of foo(void) C functions with no arguments must be declared foo(void) instead of foo(). The tracetool argument list parser has never accepted an empty argument list. This patch adds a clear error message for this error case. Signed-off-by: Stefan Hajnoczi Reviewed-by: Eric Blake Message-id: 20180110202553.31889-4-stefanha@redhat.com Signed-off-by: Stefan Hajnoczi --- scripts/tracetool/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/tracetool/__init__.py b/scripts/tracetool/__init__.py index e3685bd..1a9733d 100644 --- a/scripts/tracetool/__init__.py +++ b/scripts/tracetool/__init__.py @@ -75,6 +75,8 @@ class Arguments: res = [] for arg in arg_str.split(","): arg = arg.strip() + if not arg: + raise ValueError("Empty argument (did you forget to use 'void'?)") if arg == 'void': continue -- cgit v1.1