summaryrefslogtreecommitdiffstats
path: root/src/tools/tracegen/helpers.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/tracegen/helpers.cpp')
-rw-r--r--src/tools/tracegen/helpers.cpp109
1 files changed, 66 insertions, 43 deletions
diff --git a/src/tools/tracegen/helpers.cpp b/src/tools/tracegen/helpers.cpp
index 8ffc088fed..0ea5848493 100644
--- a/src/tools/tracegen/helpers.cpp
+++ b/src/tools/tracegen/helpers.cpp
@@ -1,52 +1,33 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Rafael Roquetto <rafael.roquetto@kdab.com>
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the tools applications of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Rafael Roquetto <rafael.roquetto@kdab.com>
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "helpers.h"
#include <qdebug.h>
+using namespace Qt::StringLiterals;
+
+void writeCommonPrologue(QTextStream &stream)
+{
+ stream << R"CPP(
+#ifndef Q_TRACEPOINT
+#error "Q_TRACEPOINT not set for the module, Q_TRACE not enabled."
+#endif
+)CPP";
+}
+
+QString typeToTypeName(const QString &name)
+{
+ QString ret = name;
+ return ret.replace(QStringLiteral("::"), QStringLiteral("_"));
+}
+
QString includeGuard(const QString &filename)
{
QString guard = filename.toUpper();
for (int i = 0; i < guard.size(); ++i) {
if (!guard.at(i).isLetterOrNumber())
- guard[i] = QLatin1Char('_');
+ guard[i] = u'_';
}
return guard;
@@ -60,7 +41,7 @@ static QString joinArguments(const QList<Tracepoint::Argument> &args, T joinFunc
for (const Tracepoint::Argument &arg : args) {
if (!first)
- ret += QLatin1String(", ");
+ ret += ", "_L1;
ret += joinFunction(arg);
@@ -77,14 +58,56 @@ QString formatFunctionSignature(const QList<Tracepoint::Argument> &args)
});
}
-QString formatParameterList(const QList<Tracepoint::Argument> &args, ParamType type)
+QString formatParameterList(const Provider &provider, const QList<Tracepoint::Argument> &args, const QList<Tracepoint::Field> &fields, ParamType type)
{
if (type == LTTNG) {
QString ret;
- for (const Tracepoint::Argument &arg : args)
- ret += QLatin1String(", ") + arg.name;
+ for (int i = 0; i < args.size(); i++) {
+ const Tracepoint::Argument &arg = args[i];
+ const Tracepoint::Field &field = fields[i];
+ if (field.backendType == Tracepoint::Field::FlagType)
+ ret += ", trace_convert_"_L1 + typeToTypeName(arg.type) + "("_L1 + arg.name + ")"_L1;
+ else
+ ret += ", "_L1 + arg.name;
+ }
+ return ret;
+ }
+
+ auto findEnumeration = [](const QList<TraceEnum> &enums, const QString &name) {
+ for (const auto &e : enums) {
+ if (e.name == name)
+ return e;
+ }
+ return TraceEnum();
+ };
+
+ if (type == CTF) {
+ QString ret;
+ for (int i = 0; i < args.size(); i++) {
+ const Tracepoint::Argument &arg = args[i];
+ const Tracepoint::Field &field = fields[i];
+ if (arg.arrayLen > 1) {
+ ret += ", trace::toByteArrayFromArray("_L1 + arg.name + ", "_L1 + QString::number(arg.arrayLen) + ") "_L1;
+ } else if (field.backendType == Tracepoint::Field::EnumeratedType) {
+ const TraceEnum &e = findEnumeration(provider.enumerations, arg.type);
+ QString integerType;
+ if (e.valueSize == 8)
+ integerType = QStringLiteral("quint8");
+ else if (e.valueSize == 16)
+ integerType = QStringLiteral("quint16");
+ else
+ integerType = QStringLiteral("quint32");
+ ret += ", trace::toByteArrayFromEnum<"_L1 + integerType + ">("_L1 + arg.name + ")"_L1;
+ } else if (field.backendType == Tracepoint::Field::FlagType) {
+ ret += ", trace::toByteArrayFromFlags("_L1 + arg.name + ")"_L1;
+ } else if (field.backendType == Tracepoint::Field::String) {
+ ret += ", trace::toByteArrayFromCString("_L1 + arg.name + ")"_L1;
+ } else {
+ ret += ", "_L1 + arg.name;
+ }
+ }
return ret;
}