simpletrace: correctly detect pointers to strings
PATCH 1/1 simpletrace: correctly detect pointers to strings
The visit_type_str tracepoint takes a char**, and the simpletrace backend incorrectly treats that as a string. The resulting compiler warning breaks --enable-trace-backend=simple builds (including the mingw docker target). Fix it by rejecting pointers to pointers to char; rewrite the detection as a regular expression for simplicity.
--- scripts/tracetool/backend/simple.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
scripts/tracetool/backend/simple.py +3 -5
@@ -14,17 +14,15 @@ __email__ = "[email protected]" from tracetool import out +import re PUBLIC = True +STRTYPE_RE = re.compile(r'\s*(?:const )?char\s*\*(?!\s*\*)') def is_string(arg): - strtype = ('const char*', 'char*', 'const char *', 'char *') - if arg.lstrip().startswith(strtype): - return True - else: - return False + return not (STRTYPE_RE.match(arg) is None) def generate_h_begin(events, group):
Signature · 1 line
1.8.3.1
Quoted 40 lines · Paolo Bonzini
The
visit_type_strtracepoint takes a char**, and the simpletrace backend incorrectly treats that as a string. The resulting compiler warning breaks --enable-trace-backend=simple builds (including the mingw docker target). Fix it by rejecting pointers to pointers to char; rewrite the detection as a regular expression for simplicity.Signed-off-by Paolo Bonzini <[email protected]>--- scripts/tracetool/backend/simple.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)scripts/tracetool/backend/simple.py +3
-5@@ -14,17 +14,15 @@ __email__ = "[email protected]" from tracetool import out +import re PUBLIC = True +STRTYPE_RE = re.compile(r'\s*(?:const )?char\s*\*(?!\s*\*)') def is_string(arg): - strtype = ('const char*', 'char*', 'const char *', 'char *') - if arg.lstrip().startswith(strtype): - return True - else: - return False + return not (STRTYPE_RE.match(arg) is None) def generate_h_begin(events, group):Signature · 1 line
1.8.3.1
There is already:
commit db4df20de86c6e8ecd6c9f042c029ffb9f9cddac
Author: Fam Zheng <[email protected]> Date: Wed Oct 26 11:50:06 2016 +0800
trace: Fix 'char **' compilation error in simple backend
Currently, the generated function body will do "strlen(arg)" but the argument could be 'char **' or 'char * const *'. Avoid that by excluding such cases in is_string check.
Reported by patchew's "make docker-test-mingw@fedora".
Message-id: [email protected]
Quoted 54 lines · Fam Zheng
Quoted 40 lines · Paolo Bonzini
The
visit_type_strtracepoint takes a char**, and the simpletrace backend incorrectly treats that as a string. The resulting compiler warning breaks --enable-trace-backend=simple builds (including the mingw docker target). Fix it by rejecting pointers to pointers to char; rewrite the detection as a regular expression for simplicity.Signed-off-by Paolo Bonzini <[email protected]>--- scripts/tracetool/backend/simple.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)scripts/tracetool/backend/simple.py +3
-5@@ -14,17 +14,15 @@ __email__ = "[email protected]" from tracetool import out +import re PUBLIC = True +STRTYPE_RE = re.compile(r'\s*(?:const )?char\s*\*(?!\s*\*)') def is_string(arg): - strtype = ('const char*', 'char*', 'const char *', 'char *') - if arg.lstrip().startswith(strtype): - return True - else: - return False + return not (STRTYPE_RE.match(arg) is None) def generate_h_begin(events, group):Signature · 1 line
1.8.3.1There is already:
commit
db4df20de86c6e8ecd6c9f042c029ffb9f9cddacAuthor: Fam Zheng <[email protected]> Date: Wed Oct 26 11:50:06 2016 +0800trace: Fix 'char **' compilation error in simple backend
Currently, the generated function body will do "strlen(arg)" but the argument could be 'char **' or 'char * const *'. Avoid that by excluding such cases in
is_stringcheck.
Quoted 7 lines
Reported by patchew's "make docker-test-mingw@fedora".
Suggested-by Eric Blake <[email protected]>Signed-off-by Fam Zheng <[email protected]>Reviewed-by Eric Blake <[email protected]>Message-id: [email protected]
Signed-off-by Peter Maydell <[email protected]>
Right, I'm going to skip Paolo's patch and have double-checked that --enable-trace-backend=simple compiles cleanly.
Stefan