2016-01-15 14:57:40 +01:00
|
|
|
/****************************************************************************
|
2013-10-18 10:45:43 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 BlackBerry Limited. All rights reserved.
|
|
|
|
|
** Contact: BlackBerry (qt@blackberry.com), KDAB (info@kdab.com)
|
2013-10-18 10:45:43 +02:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** 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
|
2016-01-15 14:57:40 +01:00
|
|
|
** 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.
|
2013-10-18 10:45:43 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** 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-3.0.html.
|
2013-10-18 10:45:43 +02:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "slog2inforunner.h"
|
|
|
|
|
|
2017-05-09 10:25:11 +02:00
|
|
|
#include "qnxdevice.h"
|
2015-11-09 14:20:46 +02:00
|
|
|
#include "qnxdeviceprocess.h"
|
2017-05-09 10:25:11 +02:00
|
|
|
#include "qnxrunconfiguration.h"
|
2014-11-27 17:46:45 +01:00
|
|
|
|
2016-01-27 18:25:13 +01:00
|
|
|
#include <projectexplorer/runnables.h>
|
2013-10-18 10:45:43 +02:00
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
2017-03-09 23:02:32 +01:00
|
|
|
#include <QRegExp>
|
|
|
|
|
|
2016-01-27 18:25:13 +01:00
|
|
|
using namespace ProjectExplorer;
|
2017-05-09 10:25:11 +02:00
|
|
|
using namespace Utils;
|
2016-01-27 18:25:13 +01:00
|
|
|
|
2016-01-23 10:37:02 +01:00
|
|
|
namespace Qnx {
|
|
|
|
|
namespace Internal {
|
2013-10-18 10:45:43 +02:00
|
|
|
|
2017-05-09 10:25:11 +02:00
|
|
|
Slog2InfoRunner::Slog2InfoRunner(RunControl *runControl)
|
|
|
|
|
: RunWorker(runControl)
|
2013-10-18 10:45:43 +02:00
|
|
|
{
|
2017-05-09 10:25:11 +02:00
|
|
|
auto qnxRunConfig = qobject_cast<QnxRunConfiguration *>(runControl->runConfiguration());
|
|
|
|
|
QTC_ASSERT(qnxRunConfig, return);
|
|
|
|
|
m_applicationId = FileName::fromString(qnxRunConfig->remoteExecutableFilePath()).fileName();
|
|
|
|
|
|
2013-11-14 09:11:25 +01:00
|
|
|
// See QTCREATORBUG-10712 for details.
|
|
|
|
|
// We need to limit length of ApplicationId to 63 otherwise it would not match one in slog2info.
|
|
|
|
|
m_applicationId.truncate(63);
|
|
|
|
|
|
2017-05-09 10:25:11 +02:00
|
|
|
m_testProcess = new QnxDeviceProcess(device(), this);
|
2016-03-15 09:26:34 +01:00
|
|
|
connect(m_testProcess, &DeviceProcess::finished, this, &Slog2InfoRunner::handleTestProcessCompleted);
|
2013-10-18 10:45:43 +02:00
|
|
|
|
2017-05-09 10:25:11 +02:00
|
|
|
m_launchDateTimeProcess = new SshDeviceProcess(device(), this);
|
2016-03-15 09:26:34 +01:00
|
|
|
connect(m_launchDateTimeProcess, &DeviceProcess::finished, this, &Slog2InfoRunner::launchSlog2Info);
|
2013-10-18 10:45:43 +02:00
|
|
|
|
2017-05-09 10:25:11 +02:00
|
|
|
m_logProcess = new QnxDeviceProcess(device(), this);
|
2016-03-15 09:26:34 +01:00
|
|
|
connect(m_logProcess, &DeviceProcess::readyReadStandardOutput, this, &Slog2InfoRunner::readLogStandardOutput);
|
|
|
|
|
connect(m_logProcess, &DeviceProcess::readyReadStandardError, this, &Slog2InfoRunner::readLogStandardError);
|
|
|
|
|
connect(m_logProcess, &DeviceProcess::error, this, &Slog2InfoRunner::handleLogError);
|
|
|
|
|
connect(m_logProcess, &DeviceProcess::started, this, &Slog2InfoRunner::started);
|
|
|
|
|
connect(m_logProcess, &DeviceProcess::finished, this, &Slog2InfoRunner::finished);
|
2013-10-18 10:45:43 +02:00
|
|
|
}
|
|
|
|
|
|
2017-08-10 17:00:03 +02:00
|
|
|
void Slog2InfoRunner::printMissingWarning()
|
|
|
|
|
{
|
|
|
|
|
appendMessage(tr("Warning: \"slog2info\" is not found on the device, debug output not available."), ErrorMessageFormat);
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-18 10:45:43 +02:00
|
|
|
void Slog2InfoRunner::start()
|
|
|
|
|
{
|
2016-01-27 18:25:13 +01:00
|
|
|
StandardRunnable r;
|
|
|
|
|
r.executable = QLatin1String("slog2info");
|
|
|
|
|
m_testProcess->start(r);
|
2013-10-18 10:45:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Slog2InfoRunner::stop()
|
|
|
|
|
{
|
|
|
|
|
if (m_testProcess->state() == QProcess::Running)
|
|
|
|
|
m_testProcess->kill();
|
|
|
|
|
|
2013-11-14 09:11:25 +01:00
|
|
|
if (m_logProcess->state() == QProcess::Running) {
|
2013-10-18 10:45:43 +02:00
|
|
|
m_logProcess->kill();
|
2013-11-14 09:11:25 +01:00
|
|
|
processLog(true);
|
|
|
|
|
}
|
2013-10-18 10:45:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Slog2InfoRunner::commandFound() const
|
|
|
|
|
{
|
|
|
|
|
return m_found;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Slog2InfoRunner::handleTestProcessCompleted()
|
|
|
|
|
{
|
|
|
|
|
m_found = (m_testProcess->exitCode() == 0);
|
2017-05-09 10:25:11 +02:00
|
|
|
if (m_found) {
|
2013-10-18 10:45:43 +02:00
|
|
|
readLaunchTime();
|
2017-05-09 10:25:11 +02:00
|
|
|
} else {
|
|
|
|
|
QnxDevice::ConstPtr qnxDevice = device().dynamicCast<const QnxDevice>();
|
|
|
|
|
if (qnxDevice->qnxVersion() > 0x060500) {
|
|
|
|
|
printMissingWarning();
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-10-18 10:45:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Slog2InfoRunner::readLaunchTime()
|
|
|
|
|
{
|
2016-01-27 18:25:13 +01:00
|
|
|
StandardRunnable r;
|
|
|
|
|
r.executable = QLatin1String("date");
|
|
|
|
|
r.commandLineArguments = QLatin1String("+\"%d %H:%M:%S\"");
|
|
|
|
|
m_launchDateTimeProcess->start(r);
|
2013-10-18 10:45:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Slog2InfoRunner::launchSlog2Info()
|
|
|
|
|
{
|
|
|
|
|
QTC_CHECK(!m_applicationId.isEmpty());
|
|
|
|
|
QTC_CHECK(m_found);
|
|
|
|
|
|
2016-12-05 15:17:56 +01:00
|
|
|
if (m_logProcess->state() == QProcess::Running)
|
2013-10-18 10:45:43 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
m_launchDateTime = QDateTime::fromString(QString::fromLatin1(m_launchDateTimeProcess->readAllStandardOutput()).trimmed(),
|
|
|
|
|
QString::fromLatin1("dd HH:mm:ss"));
|
|
|
|
|
|
2016-01-27 18:25:13 +01:00
|
|
|
StandardRunnable r;
|
|
|
|
|
r.executable = QLatin1String("slog2info");
|
|
|
|
|
r.commandLineArguments = QLatin1String("-w");
|
|
|
|
|
m_logProcess->start(r);
|
2013-10-18 10:45:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Slog2InfoRunner::readLogStandardOutput()
|
|
|
|
|
{
|
2013-11-14 09:11:25 +01:00
|
|
|
processLog(false);
|
|
|
|
|
}
|
2013-10-18 10:45:43 +02:00
|
|
|
|
2013-11-14 09:11:25 +01:00
|
|
|
void Slog2InfoRunner::processLog(bool force)
|
|
|
|
|
{
|
|
|
|
|
QString input = QString::fromLatin1(m_logProcess->readAllStandardOutput());
|
|
|
|
|
QStringList lines = input.split(QLatin1Char('\n'));
|
|
|
|
|
if (lines.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
lines.first().prepend(m_remainingData);
|
|
|
|
|
if (force)
|
|
|
|
|
m_remainingData.clear();
|
|
|
|
|
else
|
|
|
|
|
m_remainingData = lines.takeLast();
|
|
|
|
|
foreach (const QString &line, lines)
|
|
|
|
|
processLogLine(line);
|
2013-10-18 10:45:43 +02:00
|
|
|
}
|
|
|
|
|
|
2013-11-14 09:11:25 +01:00
|
|
|
void Slog2InfoRunner::processLogLine(const QString &line)
|
2013-10-18 10:45:43 +02:00
|
|
|
{
|
2013-11-14 09:11:25 +01:00
|
|
|
// The "(\\s+\\S+)?" represents a named buffer. If message has noname (aka empty) buffer
|
|
|
|
|
// then the message might get cut for the first number in the message.
|
|
|
|
|
// The "\\s+(\\b.*)?$" represents a space followed by a message. We are unable to determinate
|
|
|
|
|
// how many spaces represent separators and how many are a part of the messages, so resulting
|
|
|
|
|
// messages has all whitespaces at the beginning of the message trimmed.
|
|
|
|
|
static QRegExp regexp(QLatin1String(
|
2014-01-07 11:47:16 +01:00
|
|
|
"^[a-zA-Z]+\\s+([0-9]+ [0-9]+:[0-9]+:[0-9]+.[0-9]+)\\s+(\\S+)(\\s+(\\S+))?\\s+([0-9]+)\\s+(.*)?$"));
|
2013-11-14 09:11:25 +01:00
|
|
|
|
|
|
|
|
if (!regexp.exactMatch(line) || regexp.captureCount() != 6)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// Note: This is useless if/once slog2info -b displays only logs from recent launches
|
|
|
|
|
if (!m_launchDateTime.isNull()) {
|
|
|
|
|
// Check if logs are from the recent launch
|
|
|
|
|
if (!m_currentLogs) {
|
|
|
|
|
QDateTime dateTime = QDateTime::fromString(regexp.cap(1),
|
|
|
|
|
QLatin1String("dd HH:mm:ss.zzz"));
|
|
|
|
|
m_currentLogs = dateTime >= m_launchDateTime;
|
|
|
|
|
if (!m_currentLogs)
|
|
|
|
|
return;
|
|
|
|
|
}
|
2013-10-18 10:45:43 +02:00
|
|
|
}
|
2013-11-14 09:11:25 +01:00
|
|
|
|
|
|
|
|
QString applicationId = regexp.cap(2);
|
|
|
|
|
if (!applicationId.startsWith(m_applicationId))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
QString bufferName = regexp.cap(4);
|
|
|
|
|
int bufferId = regexp.cap(5).toInt();
|
|
|
|
|
// filtering out standard BB10 messages
|
|
|
|
|
if (bufferName == QLatin1String("default") && bufferId == 8900)
|
|
|
|
|
return;
|
|
|
|
|
|
2017-05-09 10:25:11 +02:00
|
|
|
appendMessage(regexp.cap(6).trimmed() + '\n', Utils::StdOutFormat);
|
2013-10-18 10:45:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Slog2InfoRunner::readLogStandardError()
|
|
|
|
|
{
|
2017-05-09 10:25:11 +02:00
|
|
|
appendMessage(QString::fromLatin1(m_logProcess->readAllStandardError()), Utils::StdErrFormat);
|
2013-10-18 10:45:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Slog2InfoRunner::handleLogError()
|
|
|
|
|
{
|
2017-05-09 10:25:11 +02:00
|
|
|
appendMessage(tr("Cannot show slog2info output. Error: %1")
|
|
|
|
|
.arg(m_logProcess->errorString()), Utils::StdErrFormat);
|
2013-10-18 10:45:43 +02:00
|
|
|
}
|
2016-01-23 10:37:02 +01:00
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Qnx
|