Adding debug option to the winrtrunner.
authorDavid Schulz <david.schulz@digia.com>
Tue, 18 Mar 2014 13:14:08 +0000 (14:14 +0100)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Wed, 19 Mar 2014 07:30:34 +0000 (08:30 +0100)
Added an option that automatically enables debugging for a package with a
provided debugger. An additinal winrtrunner option was introduced to pass
arguments to the debugger.

Change-Id: I55dbc809d26748674e5633f3eb31e7a4b8963655
Reviewed-by: Andrew Knight <andrew.knight@digia.com>
Reviewed-by: Oliver Wolff <oliver.wolff@digia.com>
src/winrtrunner/appxengine.cpp
src/winrtrunner/appxengine.h
src/winrtrunner/main.cpp
src/winrtrunner/runner.cpp
src/winrtrunner/runner.h
src/winrtrunner/runnerengine.h
src/winrtrunner/xapengine.cpp
src/winrtrunner/xapengine.h

index 32f8471..8151284 100644 (file)
@@ -685,6 +685,37 @@ bool AppxEngine::start()
     return true;
 }
 
+bool AppxEngine::enableDebugging(const QString &debuggerExecutable, const QString &debuggerArguments)
+{
+    Q_D(AppxEngine);
+
+    const QString &debuggerCommand = debuggerExecutable + QLatin1Char(' ') + debuggerArguments;
+    HRESULT hr = d->packageDebug->EnableDebugging(wchar(d->packageFullName),
+                                                  wchar(debuggerCommand),
+                                                  NULL);
+    if (FAILED(hr)) {
+        qCWarning(lcWinRtRunner).nospace() << "Failed to enable debugging for application. (0x"
+                                           << QByteArray::number(hr, 16).constData()
+                                           << ' ' << qt_error_string(hr) << ')';
+        return false;
+    }
+    return true;
+}
+
+bool AppxEngine::disableDebugging()
+{
+    Q_D(AppxEngine);
+
+    HRESULT hr = d->packageDebug->DisableDebugging(wchar(d->packageFullName));
+    if (FAILED(hr)) {
+        qCWarning(lcWinRtRunner).nospace() << "Failed to disable debugging for application. (0x"
+                                           << QByteArray::number(hr, 16).constData()
+                                           << ' ' << qt_error_string(hr) << ')';
+        return false;
+    }
+    return true;
+}
+
 bool AppxEngine::suspend()
 {
     Q_D(AppxEngine);
index 1a78937..7bc3694 100644 (file)
@@ -61,6 +61,9 @@ public:
     bool install(bool removeFirst = false) Q_DECL_OVERRIDE;
     bool remove() Q_DECL_OVERRIDE;
     bool start() Q_DECL_OVERRIDE;
+    bool enableDebugging(const QString &debuggerExecutable,
+                        const QString &debuggerArguments) Q_DECL_OVERRIDE;
+    bool disableDebugging() Q_DECL_OVERRIDE;
     bool suspend() Q_DECL_OVERRIDE;
     bool waitForFinished(int secs) Q_DECL_OVERRIDE;
     bool stop() Q_DECL_OVERRIDE;
index 9311a47..115bc7a 100644 (file)
@@ -75,6 +75,22 @@ int main(int argc, char *argv[])
                                                  "force reinstallation."));
     parser.addOption(startOption);
 
+    QCommandLineOption debugOption(QStringLiteral("debug"),
+                                   QLatin1String("Start the package with the debugger attached. "
+                                                 "The package is installed if it is not already "
+                                                 "installed. Pass --install to force "
+                                                 "reinstallation."),
+                                   QLatin1Literal("debugger"));
+    parser.addOption(debugOption);
+
+    QCommandLineOption debuggerArgumentsOption(QStringLiteral("debugger-arguments"),
+                                               QLatin1String("Arguments that are passed to the "
+                                                             "debugger when --debug is used. If no "
+                                                             "debugger was provided this option is "
+                                                             "ignored."),
+                                               QLatin1String("arguments"));
+    parser.addOption(debuggerArgumentsOption);
+
     QCommandLineOption suspendOption(QStringLiteral("suspend"),
                                      QLatin1String("Suspend a running package. When combined "
                                                    "with --stop or --test, the app will be "
@@ -196,11 +212,12 @@ int main(int argc, char *argv[])
     // 7 - Stop failed
     // 8 - Test setup failed
     // 9 - Test results retrieval failed
+    // 10 - Enabling debugging failed
     // In "test" mode, the exit code of the app is returned
 
     bool ignoreErrors = parser.isSet(ignoreErrorsOption);
     bool testEnabled = parser.isSet(testOption);
-    bool startEnabled = testEnabled || parser.isSet(startOption);
+    bool startEnabled = testEnabled || parser.isSet(startOption) || parser.isSet(debugOption);
     bool suspendEnabled = parser.isSet(suspendOption);
     bool waitEnabled = testEnabled || parser.isSet(waitOption);
     bool stopEnabled = !testEnabled && parser.isSet(stopOption); // test and stop are mutually exclusive
@@ -230,7 +247,24 @@ int main(int argc, char *argv[])
         return ignoreErrors ? 0 : 3;
     }
 
-    if (startEnabled && !runner.start()) {
+    if (parser.isSet(debugOption)) {
+        const QString &debuggerExecutable = parser.value(debugOption);
+        const QString &debuggerArguments = parser.value(debuggerArgumentsOption);
+        qCDebug(lcWinRtRunner) << "Debugger:         " << debuggerExecutable;
+        qCDebug(lcWinRtRunner) << "Debugger Options: " << debuggerArguments;
+        if (debuggerExecutable.isEmpty()
+                || !runner.enableDebugging(debuggerExecutable, debuggerArguments)) {
+            qCDebug(lcWinRtRunner) << "Failed to enable debugging, exiting with code 10.";
+            return ignoreErrors ? 0 : 10;
+        }
+    }
+
+    bool startFailed = startEnabled && !runner.start();
+
+    if (parser.isSet(debugOption) && !runner.disableDebugging())
+        qCDebug(lcWinRtRunner) << "Failed to disable debugging";
+
+    if (startFailed) {
         qCDebug(lcWinRtRunner) << "Start failed, exiting with code 5.";
         return ignoreErrors ? 0 : 5;
     }
index 4e5ba43..9bf6a91 100644 (file)
@@ -187,6 +187,22 @@ bool Runner::start()
     return d->engine->start();
 }
 
+bool Runner::enableDebugging(const QString &debuggerExecutable, const QString &debuggerArguments)
+{
+    Q_D(Runner);
+    Q_ASSERT(d->engine);
+
+    return d->engine->enableDebugging(debuggerExecutable, debuggerArguments);
+}
+
+bool Runner::disableDebugging()
+{
+    Q_D(Runner);
+    Q_ASSERT(d->engine);
+
+    return d->engine->disableDebugging();
+}
+
 bool Runner::suspend()
 {
     Q_D(Runner);
index b5f108e..fe0c900 100644 (file)
@@ -68,6 +68,8 @@ public:
     bool install(bool removeFirst = false);
     bool remove();
     bool start();
+    bool enableDebugging(const QString &debuggerExecutable, const QString &debuggerArguments);
+    bool disableDebugging();
     bool suspend();
     bool stop();
     bool wait(int maxWaitTime = 0);
index 187be5f..de2c12e 100644 (file)
@@ -53,6 +53,8 @@ public:
     virtual bool install(bool removeFirst = false) = 0;
     virtual bool remove() = 0;
     virtual bool start() = 0;
+    virtual bool enableDebugging(const QString &debugger, const QString &debuggerArguments) = 0;
+    virtual bool disableDebugging() = 0;
     virtual bool suspend() = 0;
     virtual bool waitForFinished(int secs) = 0;
     virtual bool stop() = 0;
index 53c64c6..21466c9 100644 (file)
@@ -517,6 +517,18 @@ bool XapEngine::start()
     return true;
 }
 
+bool XapEngine::enableDebugging(const QString &debuggerExecutable, const QString &debuggerArguments)
+{
+    Q_UNUSED(debuggerExecutable);
+    Q_UNUSED(debuggerArguments);
+    return false;
+}
+
+bool XapEngine::disableDebugging()
+{
+    return false;
+}
+
 bool XapEngine::suspend()
 {
     qCDebug(lcWinRtRunner) << __FUNCTION__;
index cd0df78..7c96273 100644 (file)
@@ -60,6 +60,9 @@ public:
     bool install(bool removeFirst = false) Q_DECL_OVERRIDE;
     bool remove() Q_DECL_OVERRIDE;
     bool start() Q_DECL_OVERRIDE;
+    bool enableDebugging(const QString &debuggerExecutable,
+                        const QString &debuggerArguments) Q_DECL_OVERRIDE;
+    bool disableDebugging() Q_DECL_OVERRIDE;
     bool suspend() Q_DECL_OVERRIDE;
     bool waitForFinished(int secs) Q_DECL_OVERRIDE;
     bool stop() Q_DECL_OVERRIDE;