Skip to content

Commit

Permalink
trace: Forbid event format ending with newline character
Browse files Browse the repository at this point in the history
Event format ending with newlines confuse the trace reports.
Forbid them.

Add a check to refuse new format added with trailing newline:

  $ make
  [...]
    GEN     hw/misc/trace.h
  Traceback (most recent call last):
    File "scripts/tracetool.py", line 152, in <module>
      main(sys.argv)
    File "scripts/tracetool.py", line 143, in main
      events.extend(tracetool.read_events(fh, arg))
    File "scripts/tracetool/__init__.py", line 367, in read_events
      event = Event.build(line)
    File "scripts/tracetool/__init__.py", line 281, in build
      raise ValueError("Event format can not end with a newline character")
  ValueError: Error at hw/misc/trace-events:121: Event format can not end with a newline character

Reviewed-by: John Snow <jsnow@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-id: 20190916095121.29506-3-philmd@redhat.com
Message-Id: <20190916095121.29506-3-philmd@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
  • Loading branch information
philmd authored and stefanhaRH committed Sep 18, 2019
1 parent 794dcb5 commit 9f7ad79
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/devel/tracing.txt
Expand Up @@ -112,6 +112,8 @@ Trace events should use types as follows:
Format strings should reflect the types defined in the trace event. Take
special care to use PRId64 and PRIu64 for int64_t and uint64_t types,
respectively. This ensures portability between 32- and 64-bit platforms.
Format strings must not end with a newline character. It is the responsibility
of backends to adapt line ending for proper logging.

Each event declaration will start with the event name, then its arguments,
finally a format string for pretty-printing. For example:
Expand Down
3 changes: 3 additions & 0 deletions scripts/tracetool/__init__.py
Expand Up @@ -277,6 +277,9 @@ def build(line_str):
if fmt.find("%m") != -1 or fmt_trans.find("%m") != -1:
raise ValueError("Event format '%m' is forbidden, pass the error "
"as an explicit trace argument")
if fmt.endswith(r'\n"'):
raise ValueError("Event format must not end with a newline "
"character")

if len(fmt_trans) > 0:
fmt = [fmt_trans, fmt]
Expand Down

0 comments on commit 9f7ad79

Please sign in to comment.