From bd4105def7c361f1bb80540f18005116a3cb4dbe Mon Sep 17 00:00:00 2001 From: Andreas Holzammer Date: Thu, 28 Mar 2013 08:14:09 +0100 Subject: [PATCH] QNX: Enable QML debugging for pure QNX devices This includes fixing the application arguments when launching the application through gdb. As the application is launched by passing it as an argument to -exec-run (or run), the application arguments needs to go in the same command. -exec-run won't care about arguments set with -exec-arguments when being passed the application binary. Change-Id: I869acbedd2593a931bf5c3d88559ea2bda2c3ff1 Reviewed-by: hjk Reviewed-by: Andreas Holzammer Reviewed-by: Aurindam Jana --- .../debugger/gdb/remotegdbserveradapter.cpp | 9 +++- src/plugins/qnx/qnxdebugsupport.cpp | 51 +++++++++++++++---- src/plugins/qnx/qnxdebugsupport.h | 11 ++-- src/plugins/qnx/qnxruncontrolfactory.cpp | 22 ++++++++ 4 files changed, 78 insertions(+), 15 deletions(-) diff --git a/src/plugins/debugger/gdb/remotegdbserveradapter.cpp b/src/plugins/debugger/gdb/remotegdbserveradapter.cpp index 9b372262220..cba6d0c6725 100644 --- a/src/plugins/debugger/gdb/remotegdbserveradapter.cpp +++ b/src/plugins/debugger/gdb/remotegdbserveradapter.cpp @@ -397,8 +397,13 @@ void GdbRemoteServerEngine::runEngine() if (!remoteExecutable.isEmpty()) { // Cannot use -exec-run for QNX gdb 7.4 as it does not support path parameter for the MI call const bool useRun = m_isQnxGdb && m_gdbVersion > 70300; - const QByteArray command = useRun ? "run" : "-exec-run"; - postCommand(command + " " + remoteExecutable.toLocal8Bit(), GdbEngine::RunRequest, CB(handleExecRun)); + QByteArray command = useRun ? "run" : "-exec-run"; + command += " " + remoteExecutable.toLocal8Bit(); + + const QByteArray arguments = isMasterEngine() ? startParameters().processArgs.toLocal8Bit() : masterEngine()->startParameters().processArgs.toLocal8Bit(); + command += " " + arguments; + + postCommand(command, GdbEngine::RunRequest, CB(handleExecRun)); } else { notifyEngineRunAndInferiorStopOk(); continueInferiorInternal(); diff --git a/src/plugins/qnx/qnxdebugsupport.cpp b/src/plugins/qnx/qnxdebugsupport.cpp index e647d543a57..fdc7b447c0a 100644 --- a/src/plugins/qnx/qnxdebugsupport.cpp +++ b/src/plugins/qnx/qnxdebugsupport.cpp @@ -34,6 +34,8 @@ #include "qnxrunconfiguration.h" #include +#include +#include #include #include #include @@ -49,12 +51,14 @@ using namespace Qnx::Internal; QnxDebugSupport::QnxDebugSupport(QnxRunConfiguration *runConfig, Debugger::DebuggerEngine *engine) : QObject(engine) - , m_executable(QLatin1String(Constants::QNX_DEBUG_EXECUTABLE)) + , m_remoteExecutable(runConfig->remoteExecutableFilePath()) , m_commandPrefix(runConfig->commandPrefix()) - , m_arguments(runConfig->arguments()) , m_device(DeviceKitInformation::device(runConfig->target()->kit())) , m_engine(engine) - , m_port(-1) + , m_pdebugPort(-1) + , m_qmlPort(-1) + , m_useCppDebugger(runConfig->extraAspect()->useCppDebugger()) + , m_useQmlDebugger(runConfig->extraAspect()->useQmlDebugger()) , m_state(Inactive) { m_runner = new DeviceApplicationRunner(this); @@ -68,6 +72,7 @@ QnxDebugSupport::QnxDebugSupport(QnxRunConfiguration *runConfig, Debugger::Debug connect(m_runner, SIGNAL(finished(bool)), SLOT(handleRemoteProcessFinished(bool))); connect(m_runner, SIGNAL(reportProgress(QString)), this, SLOT(handleProgressReport(QString))); connect(m_runner, SIGNAL(remoteStdout(QByteArray)), this, SLOT(handleRemoteOutput(QByteArray))); + connect(m_runner, SIGNAL(remoteStderr(QByteArray)), this, SLOT(handleRemoteOutput(QByteArray))); connect(m_engine, SIGNAL(requestRemoteSetup()), this, SLOT(handleAdapterSetupRequested())); } @@ -93,19 +98,38 @@ void QnxDebugSupport::startExecution() if (m_state == Inactive) return; - m_state = StartingRemoteProcess; Utils::PortList portList = m_device->freePorts(); - m_port = m_portsGatherer->getNextFreePort(&portList); + if (m_useCppDebugger) + m_pdebugPort = m_portsGatherer->getNextFreePort(&portList); + if (m_useQmlDebugger) + m_qmlPort = m_portsGatherer->getNextFreePort(&portList); + + if ((m_useCppDebugger && m_pdebugPort == -1) || (m_useQmlDebugger && m_qmlPort == -1)) { + handleError(tr("Not enough free ports on device for debugging.")); + return; + } + + m_state = StartingRemoteProcess; + + if (m_useQmlDebugger) + m_engine->startParameters().processArgs += QString::fromLocal8Bit(" -qmljsdebugger=port:%1,block").arg(m_qmlPort); + + QString remoteCommandLine; + if (m_useCppDebugger) + remoteCommandLine = QString::fromLatin1("%1 %2 %3") + .arg(m_commandPrefix, executable()).arg(m_pdebugPort); + else if (m_useQmlDebugger && !m_useCppDebugger) + remoteCommandLine = QString::fromLatin1("%1 %2 %3") + .arg(m_commandPrefix, executable(), m_engine->startParameters().processArgs); - const QString remoteCommandLine = QString::fromLatin1("%1 %2 %3") - .arg(m_commandPrefix, m_executable).arg(m_port); m_runner->start(m_device, remoteCommandLine.toUtf8()); } void QnxDebugSupport::handleRemoteProcessStarted() { + m_state = Debugging; if (m_engine) - m_engine->notifyEngineRemoteSetupDone(m_port, -1); + m_engine->notifyEngineRemoteSetupDone(m_pdebugPort, m_qmlPort); } void QnxDebugSupport::handleRemoteProcessFinished(bool success) @@ -118,7 +142,7 @@ void QnxDebugSupport::handleRemoteProcessFinished(bool success) m_engine->notifyInferiorIll(); } else { - const QString errorMsg = tr("The %1 process closed unexpectedly.").arg(m_executable); + const QString errorMsg = tr("The %1 process closed unexpectedly.").arg(executable()); m_engine->notifyEngineRemoteSetupFailed(errorMsg); } } @@ -130,8 +154,15 @@ void QnxDebugSupport::handleDebuggingFinished() void QnxDebugSupport::setFinished() { + if (m_state != GatheringPorts && m_state != Inactive) + m_runner->stop(m_device->processSupport()->killProcessByNameCommandLine(executable()).toUtf8()); + m_state = Inactive; - m_runner->stop(m_device->processSupport()->killProcessByNameCommandLine(m_executable).toUtf8()); +} + +QString QnxDebugSupport::executable() const +{ + return m_useCppDebugger? QLatin1String(Constants::QNX_DEBUG_EXECUTABLE) : m_remoteExecutable; } void QnxDebugSupport::handleProgressReport(const QString &progressOutput) diff --git a/src/plugins/qnx/qnxdebugsupport.h b/src/plugins/qnx/qnxdebugsupport.h index 95d71921f11..891b6acd87b 100644 --- a/src/plugins/qnx/qnxdebugsupport.h +++ b/src/plugins/qnx/qnxdebugsupport.h @@ -72,6 +72,8 @@ private: void startExecution(); void setFinished(); + QString executable() const; + enum State { Inactive, GatheringPorts, @@ -79,14 +81,17 @@ private: Debugging }; - const QString m_executable; + const QString m_remoteExecutable; const QString m_commandPrefix; - const QString m_arguments; ProjectExplorer::IDevice::ConstPtr m_device; ProjectExplorer::DeviceApplicationRunner *m_runner; ProjectExplorer::DeviceUsedPortsGatherer * m_portsGatherer; Debugger::DebuggerEngine *m_engine; - int m_port; + int m_pdebugPort; + int m_qmlPort; + + bool m_useCppDebugger; + bool m_useQmlDebugger; State m_state; }; diff --git a/src/plugins/qnx/qnxruncontrolfactory.cpp b/src/plugins/qnx/qnxruncontrolfactory.cpp index dd511f3b9cd..34794d46ee9 100644 --- a/src/plugins/qnx/qnxruncontrolfactory.cpp +++ b/src/plugins/qnx/qnxruncontrolfactory.cpp @@ -41,8 +41,11 @@ #include #include #include +#include #include #include +#include +#include #include #include #include @@ -76,6 +79,25 @@ DebuggerStartParameters createStartParameters(const QnxRunConfiguration *runConf params.displayName = runConfig->displayName(); params.remoteSetupNeeded = true; params.closeMode = DetachAtClose; + params.processArgs = runConfig->arguments(); + + Debugger::DebuggerRunConfigurationAspect *aspect + = runConfig->extraAspect(); + if (aspect->useQmlDebugger()) { + params.languages |= QmlLanguage; + params.qmlServerAddress = device->sshParameters().host; + params.qmlServerPort = 0; // QML port is handed out later + } + + if (aspect->useCppDebugger()) + params.languages |= Debugger::CppLanguage; + + if (const ProjectExplorer::Project *project = runConfig->target()->project()) { + params.projectSourceDirectory = project->projectDirectory(); + if (const ProjectExplorer::BuildConfiguration *buildConfig = runConfig->target()->activeBuildConfiguration()) + params.projectBuildDirectory = buildConfig->buildDirectory(); + params.projectSourceFiles = project->files(ProjectExplorer::Project::ExcludeGeneratedFiles); + } QnxQtVersion *qtVersion = dynamic_cast(QtSupport::QtKitInformation::qtVersion(k));