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 <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 <jaroslaw.kobus@qt.io>
This commit is contained in:
Assam Boudjelthia
2024-10-13 03:26:56 +03:00
parent 01a3d636db
commit 4b89c18e23

View File

@@ -415,7 +415,10 @@ static ExecutableItem logcatRecipe(const Storage<RunnerStorage> &storage)
const QString pidString = QString::number(storagePtr->m_processPID); const QString pidString = QString::number(storagePtr->m_processPID);
for (const QByteArray &msg : std::as_const(lines)) { for (const QByteArray &msg : std::as_const(lines)) {
const QString line = QString::fromUtf8(msg).trimmed() + QLatin1Char('\n'); 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; continue;
if (storagePtr->m_useCppDebugger) { if (storagePtr->m_useCppDebugger) {
@@ -427,32 +430,31 @@ static ExecutableItem logcatRecipe(const Storage<RunnerStorage> &storage)
static const QRegularExpression regExpLogcat{ static const QRegularExpression regExpLogcat{
"^\\x1B\\[[0-9]+m" // color "^\\x1B\\[[0-9]+m" // color
"(\\w/)" // message type 1. capture "\\w/" // message type
".*" // source ".*" // source
"(\\(\\s*\\d*\\)):" // pid 2. capture "(\\(\\s*\\d*\\)):" // pid 1. capture
"\\s*" "\\s*"
".*" // message ".*" // message
"\\x1B\\[[0-9]+m" // color "\\x1B\\[[0-9]+m" // color
"[\\n\\r]*$" "[\\n\\r]*$"
}; };
static QStringList errorMsgTypes{"F/", "E/", "W/"}; static QStringList errorMsgTypes{"W/", "E/", "F/"};
const bool onlyError = channel == QProcess::StandardError; const bool onlyError = channel == QProcess::StandardError;
const QRegularExpressionMatch match = regExpLogcat.match(line); const QRegularExpressionMatch match = regExpLogcat.match(line);
if (match.hasMatch()) { 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(); 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)) if (onlyError || errorMsgTypes.contains(msgType))
storagePtr->m_glue->addStdErr(output); storagePtr->m_glue->addStdErr(output);
else else
storagePtr->m_glue->addStdOut(output); storagePtr->m_glue->addStdOut(output);
} }
} else { } else {
// Get type excluding the initial color characters
const QString msgType = line.mid(5, 7);
if (onlyError || errorMsgTypes.contains(msgType)) if (onlyError || errorMsgTypes.contains(msgType))
storagePtr->m_glue->addStdErr(line); storagePtr->m_glue->addStdErr(line);
else else