qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [Qemu-block] [PATCH 2/2] trace: Forbid event format end


From: Philippe Mathieu-Daudé
Subject: Re: [Qemu-devel] [Qemu-block] [PATCH 2/2] trace: Forbid event format ending with newline character
Date: Fri, 13 Sep 2019 23:00:39 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0

On 9/13/19 10:01 PM, John Snow wrote:
> On 9/13/19 6:52 AM, Philippe Mathieu-Daudé wrote:
>> 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
>>
>> Signed-off-by: Philippe Mathieu-Daudé <address@hidden>
>> ---
>>  docs/devel/tracing.txt        | 2 ++
>>  scripts/tracetool/__init__.py | 3 +++
>>  2 files changed, 5 insertions(+)
>>
>> diff --git a/docs/devel/tracing.txt b/docs/devel/tracing.txt
>> index 76e492a489..8231bbf5d1 100644
>> --- a/docs/devel/tracing.txt
>> +++ b/docs/devel/tracing.txt
>> @@ -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:
>> diff --git a/scripts/tracetool/__init__.py b/scripts/tracetool/__init__.py
>> index 6fca674936..57df74e67c 100644
>> --- a/scripts/tracetool/__init__.py
>> +++ b/scripts/tracetool/__init__.py
>> @@ -277,6 +277,9 @@ class Event(object):
>>          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("\\n\""):
>> +            raise ValueError("Event format must not end with a newline "
> 
> It's barely worth mentioning, but you can use r"\n" for cases like this,
> if it makes it easier to read.

TIL Python r"" :)

This would be r"\n\"", right? We need to match the trailing '"'.
Same length, not sure which string is easier to review =)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]