Commit 6f0a600b authored by hjk's avatar hjk

Debugger: Streamline error string handling

Let the workers keep track of errors instead of passing around
string pointers in some but not all interesting places.

Change-Id: I3956bc947a50747dd3a0c9302b9f9873d192e9c6
Reviewed-by: Christian Stenger's avatarChristian Stenger <christian.stenger@qt.io>
Reviewed-by: David Schulz's avatarDavid Schulz <david.schulz@qt.io>
parent 8637d04c
......@@ -347,7 +347,7 @@ void TestRunner::debugTests()
return;
}
(void) new Debugger::DebuggerRunTool(runControl, sp, &errorMessage);
(void) new Debugger::DebuggerRunTool(runControl, sp);
bool useOutputProcessor = true;
if (ProjectExplorer::Target *targ = config->project()->activeTarget()) {
......
......@@ -506,26 +506,25 @@ DebuggerRunTool::DebuggerRunTool(RunControl *runControl)
});
}
DebuggerRunTool::DebuggerRunTool(RunControl *runControl, const DebuggerStartParameters &sp, QString *errorMessage)
DebuggerRunTool::DebuggerRunTool(RunControl *runControl, const DebuggerStartParameters &sp)
: DebuggerRunTool(runControl)
{
setStartParameters(sp, errorMessage);
setStartParameters(sp);
}
DebuggerRunTool::DebuggerRunTool(RunControl *runControl, const DebuggerRunParameters &rp, QString *errorMessage)
DebuggerRunTool::DebuggerRunTool(RunControl *runControl, const DebuggerRunParameters &rp)
: DebuggerRunTool(runControl)
{
setRunParameters(rp, errorMessage);
setRunParameters(rp);
}
void DebuggerRunTool::setStartParameters(const DebuggerStartParameters &sp, QString *errorMessage)
void DebuggerRunTool::setStartParameters(const DebuggerStartParameters &sp)
{
setRunParameters(sp, errorMessage);
setRunParameters(sp);
}
void DebuggerRunTool::setRunParameters(const DebuggerRunParameters &rp, QString *errorMessage)
void DebuggerRunTool::setRunParameters(const DebuggerRunParameters &rp)
{
Q_UNUSED(errorMessage);
m_runParameters = rp;
}
......@@ -618,15 +617,13 @@ public:
: IRunControlFactory(parent)
{}
RunControl *create(RunConfiguration *runConfig,
Core::Id mode, QString *errorMessage) override
RunControl *create(RunConfiguration *runConfig, Core::Id mode, QString *) override
{
QTC_ASSERT(runConfig, return 0);
QTC_ASSERT(mode == DebugRunMode || mode == DebugRunModeWithBreakOnMain, return 0);
DebuggerStartParameters sp;
auto runControl = new RunControl(runConfig, mode);
(void) new DebuggerRunTool(runControl, sp, errorMessage);
(void) new DebuggerRunTool(runControl);
return runControl;
}
......
......@@ -44,17 +44,13 @@ public:
DebuggerRunTool(ProjectExplorer::RunControl *runControl); // Use.
DebuggerRunTool(ProjectExplorer::RunControl *runControl,
const DebuggerStartParameters &sp,
QString *errorMessage = nullptr); // Use rarely.
const DebuggerStartParameters &sp); // Use rarely.
DebuggerRunTool(ProjectExplorer::RunControl *runControl,
const Internal::DebuggerRunParameters &rp,
QString *errorMessage = nullptr); // FIXME: Don't use.
const Internal::DebuggerRunParameters &rp); // FIXME: Don't use.
~DebuggerRunTool();
void setStartParameters(const DebuggerStartParameters &sp,
QString *errorMessage = nullptr); // Use rarely.
void setRunParameters(const Internal::DebuggerRunParameters &rp,
QString *errorMessage = nullptr); // FIXME: Don't use.
void setStartParameters(const DebuggerStartParameters &sp); // Use rarely.
void setRunParameters(const Internal::DebuggerRunParameters &rp); // FIXME: Don't use.
Internal::DebuggerEngine *engine() const { return m_engine; }
Internal::DebuggerEngine *activeEngine() const;
......
......@@ -1550,6 +1550,11 @@ bool RunWorker::supportsReRunning() const
return d->supportsReRunning;
}
bool RunWorker::hasFailed() const
{
return d->state == RunWorkerState::Failed;
}
QString RunWorker::userMessageForProcessError(QProcess::ProcessError error, const QString &program)
{
QString failedToStart = tr("The process failed to start.");
......
......@@ -361,6 +361,7 @@ public:
void reportFailure(const QString &msg = QString());
void setSupportsReRunning(bool reRunningSupported);
bool supportsReRunning() const;
bool hasFailed() const;
static QString userMessageForProcessError(QProcess::ProcessError, const QString &programName);
......
......@@ -131,18 +131,7 @@ void QnxAttachDebugSupport::attachToProcess()
sp.solibSearchPath = QnxUtils::searchPaths(qtVersion);
auto runControl = new RunControl(nullptr, ProjectExplorer::Constants::DEBUG_RUN_MODE);
if (!runControl) {
handleError(tr("Attaching failed."));
stopPDebug();
return;
}
QString errorMessage;
(void) new Debugger::DebuggerRunTool(runControl, sp, &errorMessage);
if (!errorMessage.isEmpty()) {
handleError(errorMessage);
stopPDebug();
return;
}
(void) new Debugger::DebuggerRunTool(runControl, sp);
// connect(qobject_cast<Debugger::DebuggerRunTool *>(runControl->toolRunner()),
// &Debugger::DebuggerRunTool::stateChanged,
// this, &QnxAttachDebugSupport::handleDebuggerStateChanged);
......
......@@ -45,7 +45,7 @@ using namespace ProjectExplorer;
namespace WinRt {
namespace Internal {
WinRtDebugSupport::WinRtDebugSupport(RunControl *runControl, QString *errorMessage)
WinRtDebugSupport::WinRtDebugSupport(RunControl *runControl)
: DebuggerRunTool(runControl)
{
// FIXME: This is just working for local debugging;
......@@ -57,35 +57,38 @@ WinRtDebugSupport::WinRtDebugSupport(RunControl *runControl, QString *errorMessa
QFileInfo debuggerHelper(QCoreApplication::applicationDirPath()
+ QLatin1String("/winrtdebughelper.exe"));
if (!debuggerHelper.isExecutable()) {
*errorMessage = tr("The WinRT debugging helper is missing from your Qt Creator "
reportFailure(tr("The WinRT debugging helper is missing from your Qt Creator "
"installation. It was assumed to be located at %1").arg(
debuggerHelper.absoluteFilePath());
debuggerHelper.absoluteFilePath()));
return;
}
if (isQmlDebugging()) {
Utils::Port qmlDebugPort;
if (!getFreePort(qmlDebugPort, errorMessage))
if (!getFreePort(qmlDebugPort))
return;
params.qmlServer.host = QHostAddress(QHostAddress::LocalHost).toString();
params.qmlServer.port = qmlDebugPort;
}
m_runner = new WinRtRunnerHelper(this, errorMessage);
if (!errorMessage->isEmpty())
QString errorMessage;
m_runner = new WinRtRunnerHelper(this, &errorMessage);
if (!errorMessage.isEmpty()) {
reportFailure(errorMessage);
return;
}
QLocalServer server;
server.listen(QLatin1String("QtCreatorWinRtDebugPIDPipe"));
m_runner->debug(debuggerHelper.absoluteFilePath());
if (!m_runner->waitForStarted()) {
*errorMessage = tr("Cannot start the WinRT Runner Tool.");
reportFailure(tr("Cannot start the WinRT Runner Tool."));
return;
}
if (!server.waitForNewConnection(10000)) {
*errorMessage = tr("Cannot establish connection to the WinRT debugging helper.");
reportFailure(tr("Cannot establish connection to the WinRT debugging helper."));
return;
}
......@@ -98,12 +101,12 @@ WinRtDebugSupport::WinRtDebugSupport(RunControl *runControl, QString *errorMessa
bool ok =false;
params.attachPID = Utils::ProcessHandle(arg.last().toInt(&ok));
if (!ok) {
*errorMessage = tr("Cannot extract the PID from the WinRT debugging helper. "
"(output: %1)").arg(QString::fromLocal8Bit(output));
reportFailure(tr("Cannot extract the PID from the WinRT debugging helper. "
"(output: %1)").arg(QString::fromLocal8Bit(output)));
return;
}
server.close();
setStartParameters(params, errorMessage);
setStartParameters(params);
return;
}
}
......@@ -111,16 +114,16 @@ WinRtDebugSupport::WinRtDebugSupport(RunControl *runControl, QString *errorMessa
server.close();
*errorMessage = tr("Cannot create an appropriate run control for "
"the current run configuration.");
reportFailure(tr("Cannot create an appropriate run control for "
"the current run configuration."));
}
bool WinRtDebugSupport::getFreePort(Utils::Port &qmlDebuggerPort, QString *errorMessage)
bool WinRtDebugSupport::getFreePort(Utils::Port &qmlDebuggerPort)
{
QTcpServer server;
if (!server.listen(QHostAddress::LocalHost,
qmlDebuggerPort.isValid() ? qmlDebuggerPort.number() : 0)) {
*errorMessage = tr("Not enough free ports for QML debugging.");
reportFailure(tr("Not enough free ports for QML debugging."));
return false;
}
qmlDebuggerPort = Utils::Port(server.serverPort());
......
......@@ -38,11 +38,11 @@ class WinRtDebugSupport : public Debugger::DebuggerRunTool
Q_OBJECT
public:
WinRtDebugSupport(ProjectExplorer::RunControl *runControl, QString *errorMessage);
explicit WinRtDebugSupport(ProjectExplorer::RunControl *runControl);
~WinRtDebugSupport();
private:
static bool getFreePort(Utils::Port &qmlDebuggerPort, QString *errorMessage);
bool getFreePort(Utils::Port &qmlDebuggerPort);
WinRtRunnerHelper *m_runner = nullptr;
};
......
......@@ -151,7 +151,7 @@ bool WinRtRunControlFactory::canRun(RunConfiguration *runConfiguration,
}
RunControl *WinRtRunControlFactory::create(
RunConfiguration *runConfiguration, Core::Id mode, QString *errorMessage)
RunConfiguration *runConfiguration, Core::Id mode, QString *)
{
RunControl *runControl = nullptr;
if (mode == ProjectExplorer::Constants::NORMAL_RUN_MODE) {
......@@ -161,15 +161,10 @@ RunControl *WinRtRunControlFactory::create(
} else if (mode == ProjectExplorer::Constants::DEBUG_RUN_MODE
|| mode == ProjectExplorer::Constants::DEBUG_RUN_MODE_WITH_BREAK_ON_MAIN) {
runControl = new RunControl(runConfiguration, mode);
(void) new WinRtDebugSupport(runControl, errorMessage);
} else {
*errorMessage = tr("Unsupported run mode %1.").arg(mode.toString());
}
if (errorMessage->isEmpty())
(void) new WinRtDebugSupport(runControl);
return runControl;
}
delete runControl;
return nullptr;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment