From 6ce2a87c23bbaacece7d32df276f64a0058e447d Mon Sep 17 00:00:00 2001 From: Milian Wolff Date: Tue, 26 Mar 2019 14:07:03 +0100 Subject: Forward declare all types required for compilation with `-trace` This patch fixes compilation with `-trace lttng` or `-trace etw`. We need to forward declare QEvent, QImageReader etc., otherwise the types will be unknown while compiling the trace points. In order to handle this generically, the tracegen utility is extended to support a 'prefix text' in the `*.tracepoints` input files. Any text within curly braces will be embedded as-is in the generated file. This can then be used to add forward declarations for the types we need, including potential namespaces and such. Change-Id: I5cb16763ce0fcb48ce3ea4577578d468ff3a4f4b Reviewed-by: Konstantin Tokarev --- src/tools/tracegen/etw.cpp | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'src/tools/tracegen/etw.cpp') diff --git a/src/tools/tracegen/etw.cpp b/src/tools/tracegen/etw.cpp index 8c065f93c9..e839137915 100644 --- a/src/tools/tracegen/etw.cpp +++ b/src/tools/tracegen/etw.cpp @@ -110,19 +110,21 @@ static QString createGuid(const QUuid &uuid) return guid; } -static void writePrologue(QTextStream &stream, const QString &fileName, const QString &providerName) +static void writePrologue(QTextStream &stream, const QString &fileName, const Provider &provider) { - QUuid uuid = QUuid::createUuidV5(QUuid(), providerName.toLocal8Bit()); + QUuid uuid = QUuid::createUuidV5(QUuid(), provider.name.toLocal8Bit()); - const QString provider = providerVar(providerName); + const QString providerV = providerVar(provider.name); const QString guard = includeGuard(fileName); const QString guid = createGuid(uuid); const QString guidString = uuid.toString(); stream << "#ifndef " << guard << "\n" << "#define " << guard << "\n" + << "\n" << "#include \n" - << "#include \n"; + << "#include \n" + << "\n"; /* TraceLogging API macros cannot deal with UTF8 * source files, so we work around it like this @@ -132,30 +134,33 @@ static void writePrologue(QTextStream &stream, const QString &fileName, const QS "#define _TlgPragmaUtf8Begin\n" "#define _TlgPragmaUtf8End\n"; + stream << "\n"; stream << qtHeaders(); - stream << "\n"; + if (!provider.prefixText.isEmpty()) + stream << provider.prefixText.join(QLatin1Char('\n')) << "\n\n"; + stream << "#ifdef TRACEPOINT_DEFINE\n" << "/* " << guidString << " */\n" - << "TRACELOGGING_DEFINE_PROVIDER(" << provider << ", \"" - << providerName <<"\", " << guid << ");\n\n"; + << "TRACELOGGING_DEFINE_PROVIDER(" << providerV << ", \"" + << provider.name <<"\", " << guid << ");\n\n"; stream << "static inline void registerProvider()\n" << "{\n" - << " TraceLoggingRegister(" << provider << ");\n" + << " TraceLoggingRegister(" << providerV << ");\n" << "}\n\n"; stream << "static inline void unregisterProvider()\n" << "{\n" - << " TraceLoggingUnregister(" << provider << ");\n" + << " TraceLoggingUnregister(" << providerV << ");\n" << "}\n"; stream << "Q_CONSTRUCTOR_FUNCTION(registerProvider)\n" << "Q_DESTRUCTOR_FUNCTION(unregisterProvider)\n\n"; stream << "#else\n" - << "TRACELOGGING_DECLARE_PROVIDER(" << provider << ");\n" + << "TRACELOGGING_DECLARE_PROVIDER(" << providerV << ");\n" << "#endif // TRACEPOINT_DEFINE\n\n"; } @@ -224,7 +229,7 @@ void writeEtw(QFile &file, const Provider &provider) const QString fileName = QFileInfo(file.fileName()).fileName(); - writePrologue(stream, fileName, provider.name); + writePrologue(stream, fileName, provider); writeTracepoints(stream, provider); writeEpilogue(stream, fileName); } -- cgit v1.2.3