From 4b89c18e2373e4d7b0107d14dd11c024600d8e30 Mon Sep 17 00:00:00 2001 From: Assam Boudjelthia Date: Sun, 13 Oct 2024 03:26:56 +0300 Subject: [PATCH] Android: print crash logs even if they are not from same pid Crash logs can be printed by the system from a process other than the currently running app, in cases of crash, it's good to have such logs immediately available in the IDE. So, always print Fatal logs when the app is running. There are other potentially related errors or warnings that might be printed from different pids, but filtering those while keeping the logs uncluttered might need some more work, that could be done some other time. Ideally, all this work would be done using: ``` adb logcat -v color -v tag --uid ``` which prints logs of the app uid, which includes the process itself and crash/fatal logs, and doesn't print the pid which we're filtering out. However, that works only for Android 7+, so two log processing ways would have to be maintained. Change-Id: I90bff561a70b78f3c184ebd609df194cd7ef7984 Reviewed-by: Jarek Kobus --- src/plugins/android/androidrunnerworker.cpp | 22 +++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/plugins/android/androidrunnerworker.cpp b/src/plugins/android/androidrunnerworker.cpp index c19ca7abba7..eaed72b3d23 100644 --- a/src/plugins/android/androidrunnerworker.cpp +++ b/src/plugins/android/androidrunnerworker.cpp @@ -415,7 +415,10 @@ static ExecutableItem logcatRecipe(const Storage &storage) const QString pidString = QString::number(storagePtr->m_processPID); for (const QByteArray &msg : std::as_const(lines)) { const QString line = QString::fromUtf8(msg).trimmed() + QLatin1Char('\n'); - if (!line.contains(pidString)) + // Get type excluding the initial color characters + const QString msgType = line.mid(5, 2); + const bool isFatal = msgType == "F/"; + if (!line.contains(pidString) && !isFatal) continue; if (storagePtr->m_useCppDebugger) { @@ -427,32 +430,31 @@ static ExecutableItem logcatRecipe(const Storage &storage) static const QRegularExpression regExpLogcat{ "^\\x1B\\[[0-9]+m" // color - "(\\w/)" // message type 1. capture + "\\w/" // message type ".*" // source - "(\\(\\s*\\d*\\)):" // pid 2. capture + "(\\(\\s*\\d*\\)):" // pid 1. capture "\\s*" ".*" // message "\\x1B\\[[0-9]+m" // color "[\\n\\r]*$" }; - static QStringList errorMsgTypes{"F/", "E/", "W/"}; + static QStringList errorMsgTypes{"W/", "E/", "F/"}; const bool onlyError = channel == QProcess::StandardError; const QRegularExpressionMatch match = regExpLogcat.match(line); if (match.hasMatch()) { - const QString pidMatch = match.captured(2); + const QString pidMatch = match.captured(1); const QString cleanPidMatch = pidMatch.mid(1, pidMatch.size() - 2).trimmed(); - if (cleanPidMatch == pidString) { - const QString msgType = match.captured(1); - const QString output = QString(line).remove(pidMatch); + const QString output = QString(line).remove(pidMatch); + if (isFatal) { + storagePtr->m_glue->addStdErr(output); + } else if (cleanPidMatch == pidString) { if (onlyError || errorMsgTypes.contains(msgType)) storagePtr->m_glue->addStdErr(output); else storagePtr->m_glue->addStdOut(output); } } else { - // Get type excluding the initial color characters - const QString msgType = line.mid(5, 7); if (onlyError || errorMsgTypes.contains(msgType)) storagePtr->m_glue->addStdErr(line); else