diff options
author | Milian Wolff <milian.wolff@kdab.com> | 2022-12-03 15:56:48 +0100 |
---|---|---|
committer | Milian Wolff <milian.wolff@kdab.com> | 2022-12-08 19:42:05 +0000 |
commit | 813e5fa8cad97eb1af227bf8bdcd60d7cd8bffa1 (patch) | |
tree | 92dea66959eaa3f4e345cce924ba3cd390d11721 | |
parent | a4b06facbdeb370c4fcf721eca266fca19e4fe59 (diff) |
Fix compile with -DQT_NO_CAST_FROM_ASCII -DQT_NO_CAST_TO_ASCII
Change-Id: If53db019f7855128fa705b1f9bc344b4d78dcdc8
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | app/demangler.cpp | 7 | ||||
-rw-r--r-- | app/perfregisterinfo.cpp | 6 | ||||
-rw-r--r-- | app/perfsymboltable.cpp | 33 | ||||
-rw-r--r-- | app/perfsymboltable.h | 3 | ||||
-rw-r--r-- | tests/auto/perfdata/tst_perfdata.cpp | 75 |
6 files changed, 64 insertions, 62 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index c7f3ad6..73b1e71 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,6 +26,6 @@ include(CheckSymbolExists) set(CMAKE_REQUIRED_LIBRARIES elfutils::dw elfutils::elf) check_symbol_exists(dwfl_get_debuginfod_client "libdwfl.h" HAVE_DWFL_GET_DEBUGINFOD_CLIENT) -add_definitions(-DQT_USE_QSTRINGBUILDER) +add_definitions(-DQT_NO_CAST_FROM_ASCII -DQT_NO_CAST_TO_ASCII -DQT_USE_QSTRINGBUILDER) add_subdirectory(app) add_subdirectory(tests) diff --git a/app/demangler.cpp b/app/demangler.cpp index 2d82344..6078448 100644 --- a/app/demangler.cpp +++ b/app/demangler.cpp @@ -64,14 +64,13 @@ void Demangler::loadDemangleLib(const QString &name, const char* function, const { QLibrary lib(name); if (!lib.load()) { - qDebug() << QStringLiteral("failed to load %1 library").arg(name) - << lib.errorString(); + qDebug("failed to load library %ls: %ls", qUtf16Printable(name), qUtf16Printable(lib.errorString())); return; } const auto rawSymbol = lib.resolve(function); if (!rawSymbol) { - qDebug() << QStringLiteral("failed to resolve %1 function in library").arg(function) - << lib.fileName() << lib.errorString(); + qDebug("failed to resolve %s function in library %ls: %ls", function, qUtf16Printable(lib.fileName()), + qUtf16Printable(lib.errorString())); return; } diff --git a/app/perfregisterinfo.cpp b/app/perfregisterinfo.cpp index bf196ab..ae9630c 100644 --- a/app/perfregisterinfo.cpp +++ b/app/perfregisterinfo.cpp @@ -151,10 +151,8 @@ PerfRegisterInfo::Architecture PerfRegisterInfo::archByName(const QByteArray &na if (name.startsWith("sparc")) return ARCH_SPARC; - static const auto iX86pattern = QRegularExpression(QStringLiteral("^i[3-7]86$")); - if (name.startsWith("x86") - || iX86pattern.match(name).hasMatch() - || name == "amd64") + if (name.startsWith("x86") || name == "i386" || name == "i486" || name == "i586" || name == "i686" || name == "i786" + || name == "amd64") return ARCH_X86; if (name.startsWith("mips")) diff --git a/app/perfsymboltable.cpp b/app/perfsymboltable.cpp index 203c0c4..c3bcc0a 100644 --- a/app/perfsymboltable.cpp +++ b/app/perfsymboltable.cpp @@ -115,14 +115,12 @@ static QStringList splitPath(const QString &path) return path.split(QDir::listSeparator(), Qt::SkipEmptyParts); } -QFileInfo PerfSymbolTable::findFile(const char *path, const QString &fileName, - const QByteArray &buildId) const +QFileInfo PerfSymbolTable::findFile(const QString& path, const QString& fileName, const QByteArray& buildId) const { QFileInfo fullPath; // first try to find the debug information via build id, if available if (!buildId.isEmpty()) { - const QString buildIdPath = QString::fromUtf8(path) + QDir::separator() - + QString::fromUtf8(buildId.toHex()); + const QString buildIdPath = path + QDir::separator() + QString::fromUtf8(buildId.toHex()); foreach (const QString &extraPath, splitPath(m_unwind->debugPath())) { fullPath.setFile(extraPath); if (findBuildIdPath(fullPath, buildIdPath)) @@ -145,25 +143,23 @@ QFileInfo PerfSymbolTable::findFile(const char *path, const QString &fileName, } // last fall-back, try the system root - fullPath.setFile(m_unwind->systemRoot() + QString::fromUtf8(path)); + fullPath.setFile(m_unwind->systemRoot() + path); return fullPath; } void PerfSymbolTable::registerElf(const PerfRecordMmap &mmap, const QByteArray &buildId) { - QString filePath(mmap.filename()); + const auto filePath = QString::fromUtf8(mmap.filename()); // special regions, such as [heap], [vdso], [stack], [kernel.kallsyms]_text ... as well as //anon - const bool isSpecialRegion = (filePath.startsWith('[') && filePath.contains(']')) - || filePath.startsWith(QLatin1String("/dev/")) - || filePath.startsWith(QLatin1String("/memfd:")) - || filePath.startsWith(QLatin1String("/SYSV")) - || filePath == QLatin1String("//anon"); + const bool isSpecialRegion = (filePath.startsWith(QLatin1Char('[')) && filePath.contains(QLatin1Char(']'))) + || filePath.startsWith(QLatin1String("/dev/")) || filePath.startsWith(QLatin1String("/memfd:")) + || filePath.startsWith(QLatin1String("/SYSV")) || filePath == QLatin1String("//anon"); const auto fileName = isSpecialRegion ? QString() : QFileInfo(filePath).fileName(); QFileInfo fullPath; if (isSpecialRegion) { // don not set fullPath, these regions don't represent a real file } else if (mmap.pid() != PerfUnwind::s_kernelPid) { - fullPath = findFile(mmap.filename(), fileName, buildId); + fullPath = findFile(filePath, fileName, buildId); if (!fullPath.isFile()) { m_unwind->sendError(PerfUnwind::MissingElfFile, @@ -423,8 +419,9 @@ int PerfSymbolTable::findDebugInfo(Dwfl_Module *module, const char *moduleName, // fall-back, mostly for situations where we loaded a file via it's build-id. // search all known paths for the debug link in that case - const auto debugLinkString = QFile(debugLink).fileName(); - auto debugLinkFile = findFile(debugLink, debugLinkString); + const auto debugLinkPath = QString::fromUtf8(debugLink); + const auto debugLinkString = QFile(debugLinkPath).fileName(); + auto debugLinkFile = findFile(debugLinkPath, debugLinkString); if (!debugLinkFile.isFile()) { // fall-back to original file path with debug link file name const auto &elf = m_elfs.findElf(base); @@ -433,9 +430,9 @@ int PerfSymbolTable::findDebugInfo(Dwfl_Module *module, const char *moduleName, } /// FIXME: find a proper solution to this - if (!debugLinkFile.isFile() && QByteArray(file).endsWith("/elf")) { + if (!debugLinkFile.isFile() && QByteArray::fromRawData(file, strlen(file)).endsWith("/elf")) { // fall-back to original file if it's in a build-id path - debugLinkFile.setFile(file); + debugLinkFile.setFile(QString::fromUtf8(file)); } if (!debugLinkFile.isFile()) @@ -612,10 +609,10 @@ static QByteArray fakeSymbolFromSection(Dwfl_Module *mod, Dwarf_Addr addr) } auto str = elf_strptr(elf, textSectionIndex, nameOffset); - if (!str || str == QLatin1String(".text")) + if (!str || str == QByteArrayLiteral(".text")) return {}; - if (str == QLatin1String(".plt") && entsize > 0) { + if (str == QByteArrayLiteral(".plt") && entsize > 0) { const auto *pltSymbol = findPltSymbol(elf, addr / entsize); if (pltSymbol) return demangle(pltSymbol) + "@plt"; diff --git a/app/perfsymboltable.h b/app/perfsymboltable.h index ea09c28..3387245 100644 --- a/app/perfsymboltable.h +++ b/app/perfsymboltable.h @@ -85,8 +85,7 @@ private: // Report an mmap to dwfl and parse it for symbols and inlines, or simply return it if dwfl has // it already Dwfl_Module *reportElf(const PerfElfMap::ElfInfo& elf); - QFileInfo findFile(const char *path, const QString &fileName, - const QByteArray &buildId = QByteArray()) const; + QFileInfo findFile(const QString& path, const QString& fileName, const QByteArray& buildId = QByteArray()) const; class ElfAndFile { public: diff --git a/tests/auto/perfdata/tst_perfdata.cpp b/tests/auto/perfdata/tst_perfdata.cpp index caa20e3..68436e0 100644 --- a/tests/auto/perfdata/tst_perfdata.cpp +++ b/tests/auto/perfdata/tst_perfdata.cpp @@ -119,32 +119,38 @@ void TestPerfData::testTracingData() QVERIFY(output.open(QIODevice::WriteOnly)); // Don't try to load any system files. They are not the same as the ones we use to report. - PerfUnwind unwind(&output, ":/", QString(), QString(), QString(), stats); + PerfUnwind unwind(&output, QStringLiteral(":/"), QString(), QString(), QString(), stats); if (!stats) { QTest::ignoreMessage(QtWarningMsg, - QRegularExpression(QRegularExpression::escape("Could not find ELF file for " - "/home/ulf/dev/untitled1-Qt_5_9_1_gcc_64-Profile/untitled1. " - "This can break stack unwinding and lead to missing symbols."))); + QRegularExpression(QRegularExpression::escape( + QStringLiteral("Could not find ELF file for " + "/home/ulf/dev/untitled1-Qt_5_9_1_gcc_64-Profile/untitled1. " + "This can break stack unwinding and lead to missing symbols.")))); QTest::ignoreMessage(QtWarningMsg, - QRegularExpression(QRegularExpression::escape("Could not find ELF file for " - "/lib/x86_64-linux-gnu/ld-2.24.so. " - "This can break stack unwinding and lead to missing symbols."))); + QRegularExpression(QRegularExpression::escape( + QStringLiteral("Could not find ELF file for " + "/lib/x86_64-linux-gnu/ld-2.24.so. " + "This can break stack unwinding and lead to missing symbols.")))); QTest::ignoreMessage(QtWarningMsg, - QRegularExpression(QRegularExpression::escape("Could not find ELF file for " - "/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.22. " - "This can break stack unwinding and lead to missing symbols."))); + QRegularExpression(QRegularExpression::escape( + QStringLiteral("Could not find ELF file for " + "/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.22. " + "This can break stack unwinding and lead to missing symbols.")))); QTest::ignoreMessage(QtWarningMsg, - QRegularExpression(QRegularExpression::escape("Could not find ELF file for " - "/lib/x86_64-linux-gnu/libm-2.24.so. " - "This can break stack unwinding and lead to missing symbols."))); + QRegularExpression(QRegularExpression::escape( + QStringLiteral("Could not find ELF file for " + "/lib/x86_64-linux-gnu/libm-2.24.so. " + "This can break stack unwinding and lead to missing symbols.")))); QTest::ignoreMessage(QtWarningMsg, - QRegularExpression(QRegularExpression::escape("Could not find ELF file for " - "/lib/x86_64-linux-gnu/libgcc_s.so.1. " - "This can break stack unwinding and lead to missing symbols."))); + QRegularExpression(QRegularExpression::escape( + QStringLiteral("Could not find ELF file for " + "/lib/x86_64-linux-gnu/libgcc_s.so.1. " + "This can break stack unwinding and lead to missing symbols.")))); QTest::ignoreMessage(QtWarningMsg, - QRegularExpression(QRegularExpression::escape("Could not find ELF file for " - "/lib/x86_64-linux-gnu/libc-2.24.so. " - "This can break stack unwinding and lead to missing symbols."))); + QRegularExpression(QRegularExpression::escape( + QStringLiteral("Could not find ELF file for " + "/lib/x86_64-linux-gnu/libc-2.24.so. " + "This can break stack unwinding and lead to missing symbols.")))); } process(&unwind, &input, QByteArray("0.5")); @@ -190,7 +196,7 @@ void TestPerfData::testTracingData() void TestPerfData::testContentSize() { - QString file(":/contentsize.data"); + QString file(QStringLiteral(":/contentsize.data")); QBuffer output; QFile input(file); @@ -199,7 +205,7 @@ void TestPerfData::testContentSize() QVERIFY(output.open(QIODevice::WriteOnly)); // Don't try to load any system files. They are not the same as the ones we use to report. - PerfUnwind unwind(&output, ":/", QString(), QString(), QString(), true); + PerfUnwind unwind(&output, QStringLiteral(":/"), QString(), QString(), QString(), true); process(&unwind, &input, QByteArray("0.5")); QCOMPARE(unwind.stats().numSamples, 69u); @@ -210,7 +216,7 @@ Q_DECL_UNUSED static void compressFile(const QString& input, const QString& outp QVERIFY(!input.isEmpty() && QFile::exists(input)); if (output.isEmpty()) { - compressFile(input, input + ".zlib"); + compressFile(input, input + QLatin1String(".zlib")); return; } @@ -276,32 +282,35 @@ void TestPerfData::testFiles() QSKIP("zstd support disabled, skipping test"); #endif - const auto perfDataFileCompressed = QFINDTESTDATA(dataFile + ".zlib"); + const auto perfDataFileCompressed = QFINDTESTDATA(dataFile + QLatin1String(".zlib")); QVERIFY(!perfDataFileCompressed.isEmpty() && QFile::exists(perfDataFileCompressed)); uncompressFile(perfDataFileCompressed); const auto perfDataFile = QFINDTESTDATA(dataFile); QVERIFY(!perfDataFile.isEmpty() && QFile::exists(perfDataFile)); - const auto expectedOutputFileCompressed = QString(perfDataFile + ".expected.txt.zlib"); - const auto expectedOutputFileUncompressed = QString(perfDataFile + ".expected.txt"); - const auto actualOutputFile = QString(perfDataFile + ".actual.txt"); + const auto expectedOutputFileCompressed = QString(perfDataFile + QLatin1String(".expected.txt.zlib")); + const auto expectedOutputFileUncompressed = QString(perfDataFile + QLatin1String(".expected.txt")); + const auto actualOutputFile = QString(perfDataFile + QLatin1String(".actual.txt")); QBuffer output; QVERIFY(output.open(QIODevice::WriteOnly)); // Don't try to load any system files. They are not the same as the ones we use to report. - PerfUnwind unwind(&output, ":/", QString(), QString(), QFileInfo(perfDataFile).absolutePath()); + PerfUnwind unwind(&output, QStringLiteral(":/"), QString(), QString(), QFileInfo(perfDataFile).absolutePath()); { QFile input(perfDataFile); QVERIFY(input.open(QIODevice::ReadOnly)); // don't try to parse kallsyms here, it's not the main point and it wouldn't be portable without the mapping file // from where we recorded the data. these files are usually large, and we don't want to bloat the repo too much - if (QTest::currentDataTag() != QLatin1String("fork_static_gcc/perf.data.zstd")) - QTest::ignoreMessage(QtWarningMsg, QRegularExpression("Failed to parse kernel symbol mapping file \".+\": Mapping is empty")); + if (QLatin1String(QTest::currentDataTag()) != QLatin1String("fork_static_gcc/perf.data.zstd")) { + QTest::ignoreMessage(QtWarningMsg, + QRegularExpression(QStringLiteral( + "Failed to parse kernel symbol mapping file \".+\": Mapping is empty"))); + } unwind.setKallsymsPath(QProcess::nullDevice()); auto version = QByteArray("0.5"); - if (dataFile == "parallel_static_gcc/perf.data.zstd") + if (dataFile == QLatin1String("parallel_static_gcc/perf.data.zstd")) version = "0.6"; process(&unwind, &input, version); } @@ -332,7 +341,7 @@ void TestPerfData::testFiles() "std::enable_if<std::__is_bitwise_relocatable<double>::value, double*>::type std::__relocate_a_1<double, " "double>(double*, double*, double*, std::allocator<double>&)"}}; for (const auto& replacement : replacements) { - actualText.replace(replacement.first, replacement.second); + actualText.replace(QLatin1String(replacement.first), QLatin1String(replacement.second)); } QFile actual(actualOutputFile); @@ -350,14 +359,14 @@ void TestPerfData::testFiles() if (actualText != expectedText) { compressFile(actualOutputFile); - const auto diff = QStandardPaths::findExecutable("diff"); + const auto diff = QStandardPaths::findExecutable(QStringLiteral("diff")); if (!diff.isEmpty()) { { QFile expectedUncompressed(expectedOutputFileUncompressed); QVERIFY(expectedUncompressed.open(QIODevice::WriteOnly | QIODevice::Text)); expectedUncompressed.write(expectedText.toUtf8()); } - QProcess::execute(diff, {"-u", expectedOutputFileUncompressed, actualOutputFile}); + QProcess::execute(diff, {QStringLiteral("-u"), expectedOutputFileUncompressed, actualOutputFile}); } } QCOMPARE(actualText, expectedText); |