From d6e3e1d328c27a65f53c6e170d749c20aaa492fd Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Tue, 17 Sep 2024 12:12:57 +0200 Subject: [PATCH] ProcessInfo: Add a debug info in case the assert is triggered Change-Id: I26b14ed1013200a89721c1179e5cf156bbd138a8 Reviewed-by: Marcus Tillmanns --- src/libs/utils/processinfo.cpp | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/libs/utils/processinfo.cpp b/src/libs/utils/processinfo.cpp index 0717bddbe9e..4cc9d15ba31 100644 --- a/src/libs/utils/processinfo.cpp +++ b/src/libs/utils/processinfo.cpp @@ -57,19 +57,34 @@ static QList getLocalProcessesUsingProc(const FilePath &procDir) QList processes; const auto lines = procProcess.readAllStandardOutput().split('\n'); - for (auto it = lines.begin(); it != lines.end(); ++it) { + int currentLineIndex = 0; + + const auto debugInfo = [&processes, &lines, ¤tLineIndex] { + qDebug() << "Collected processes count:" << processes.count() + << "Lines count:" << lines.count() << "Current line:" << currentLineIndex; + static const int s_printLinesCount = 10; + qDebug() << "Last" << s_printLinesCount << "lines:"; + const int minIndex = qMax(currentLineIndex - s_printLinesCount, 0); + const int maxIndex = qMin(currentLineIndex + 1, lines.size()); + for (int i = minIndex; i < maxIndex; ++i) + qDebug() << i << lines.at(i); + }; + + for (auto it = lines.begin(); it != lines.end(); ++it, ++currentLineIndex) { if (it->startsWith('p')) { ProcessInfo proc; bool ok; proc.processId = FilePath::fromUserInput(it->mid(1).trimmed()).fileName().toInt(&ok); - QTC_ASSERT(ok, continue); + QTC_ASSERT(ok, debugInfo(); continue); ++it; + ++currentLineIndex; - QTC_ASSERT(it != lines.end() && it->startsWith('e'), continue); + QTC_ASSERT(it != lines.end() && it->startsWith('e'), debugInfo(); continue); proc.executable = it->mid(1).trimmed(); ++it; + ++currentLineIndex; - QTC_ASSERT(it != lines.end() && it->startsWith('c'), continue); + QTC_ASSERT(it != lines.end() && it->startsWith('c'), debugInfo(); continue); proc.commandLine = it->mid(1).trimmed().replace('\0', ' '); if (!proc.commandLine.contains("__SKIP_ME__")) processes.append(proc);