All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] trace: fix group name generation
@ 2016-10-14 21:26 Greg Kurz
  2016-10-14 21:31 ` Eric Blake
  0 siblings, 1 reply; 16+ messages in thread
From: Greg Kurz @ 2016-10-14 21:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: Stefan Hajnoczi

Since commit "80dd5c4918ab trace: introduce a formal group name for trace
events", tracetool generates C variable names and macro definitions out
of the path to the trace-events-all file.

The current code takes care of turning '/' and '-' characters into
underscores so that the resulting names are valid C tokens. This is
enough because these are the only illegal characters that appear in
a relative path within the QEMU source tree.

Things are different for out of tree builds where the path may contain
arbitrary character combinations, causing tracetool to generate invalid
names.

This may cause a variety of build breaks like below:

trace/generated-tracers.h:4:15: warning: ISO C99 requires whitespace after the macro name
 #define TRACE_.BUILD_GENERATED_TRACERS_H

or

trace/generated-tracers.c:17497:13: error: variable or field ‘trace_’ declared void
 static void trace_=build_register_events(void)

or

trace/generated-tracers.c: In function ‘trace_2build_register_event’:
trace/generated-tracers.c:17499:32: error: invalid suffix "build_trace_events" on integer constant
     trace_event_register_group(2build_trace_events);

This patch ensures that only letters [A-Za-z], digits [0-9] and underscores
are kept. All other characters are turned into underscores. Also, since the
first character of C symbol names cannot be a digit, an underscore is
prepended to the group name.

Signed-off-by: Greg Kurz <groug@kaod.org>
---
 scripts/tracetool.py |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/tracetool.py b/scripts/tracetool.py
index 629b2593c846..b81b834db924 100755
--- a/scripts/tracetool.py
+++ b/scripts/tracetool.py
@@ -70,7 +70,7 @@ def make_group_name(filename):
 
     if dirname == "":
         return "common"
-    return re.sub(r"/|-", "_", dirname)
+    return "_" + re.sub(r"[^\w]", "_", dirname)
 
 def main(args):
     global _SCRIPT

^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2016-11-17 10:05 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-14 21:26 [Qemu-devel] [PATCH] trace: fix group name generation Greg Kurz
2016-10-14 21:31 ` Eric Blake
2016-10-14 22:06   ` Greg Kurz
2016-10-15 12:03     ` Peter Maydell
2016-10-16  9:20       ` Greg Kurz
2016-10-18 15:16   ` Daniel P. Berrange
2016-10-18 15:31     ` Daniel P. Berrange
2016-10-18 15:52       ` Greg Kurz
2016-10-20 14:25         ` Stefan Hajnoczi
2016-11-17  8:07           ` Fam Zheng
2016-11-17  9:10             ` Greg Kurz
2016-11-17  9:34               ` Fam Zheng
2016-11-17  9:48                 ` Greg Kurz
2016-11-17 10:00                   ` Fam Zheng
2016-11-17 10:05                   ` Stefan Hajnoczi
2016-10-18 15:36     ` Greg Kurz

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.