diff mbox series

[2/4] tracetool: add out_lineno and out_next_lineno to out()

Message ID 20200827142915.108730-3-stefanha@redhat.com
State New
Headers show
Series tracetool: show trace-events filename/lineno in fmt string errors | expand

Commit Message

Stefan Hajnoczi Aug. 27, 2020, 2:29 p.m. UTC
Make the output file line number and next line number available to
out().

A later patch will use this to improve error messages.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 scripts/tracetool/__init__.py | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

Comments

Peter Maydell Sept. 1, 2020, 12:49 p.m. UTC | #1
On Thu, 27 Aug 2020 at 15:29, Stefan Hajnoczi <stefanha@redhat.com> wrote:
>
> Make the output file line number and next line number available to
> out().
>
> A later patch will use this to improve error messages.
>
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM
diff mbox series

Patch

diff --git a/scripts/tracetool/__init__.py b/scripts/tracetool/__init__.py
index 98104fa50e..e4ee4d5e61 100644
--- a/scripts/tracetool/__init__.py
+++ b/scripts/tracetool/__init__.py
@@ -31,6 +31,7 @@  def error(*lines):
     sys.exit(1)
 
 
+out_lineno = 1
 out_filename = '<none>'
 out_fobj = sys.stdout
 
@@ -45,12 +46,19 @@  def out(*lines, **kwargs):
     You can use kwargs as a shorthand for mapping variables when formating all
     the strings in lines.
 
-    The 'out_filename' kwarg is automatically added with the output filename.
+    The 'out_lineno' kwarg is automatically added to reflect the current output
+    file line number. The 'out_next_lineno' kwarg is also automatically added
+    with the next output line number. The 'out_filename' kwarg is automatically
+    added with the output filename.
     """
+    global out_lineno
     output = []
     for l in lines:
+        kwargs['out_lineno'] = out_lineno
+        kwargs['out_next_lineno'] = out_lineno + 1
         kwargs['out_filename'] = out_filename
         output.append(l % kwargs)
+        out_lineno += 1
 
     out_fobj.writelines("\n".join(output) + "\n")