From f3df57e7b839fe8cee0ea377a4f2951073e7255a Mon Sep 17 00:00:00 2001 From: Andrew Knight Date: Mon, 20 Jan 2014 19:33:16 +0200 Subject: [PATCH] WinRT winmain: handle -qdevel parameter for additional debugging tooling This adds an additional command line argument, -qdevel, for tooling support. Since Windows Phone deployment APIs don't return the PID, this writes the PID to a lock file that can be read by deployment tools. Since arguments may be passed from one of several entry points, the special argument checks are now done in Run() instead of onActivated(). Change-Id: Ib3af157ccf687769d43d60adef9a0ab480e835b7 Reviewed-by: Oliver Wolff --- src/winmain/qtmain_winrt.cpp | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/src/winmain/qtmain_winrt.cpp b/src/winmain/qtmain_winrt.cpp index 18bd619383..151294d2c4 100644 --- a/src/winmain/qtmain_winrt.cpp +++ b/src/winmain/qtmain_winrt.cpp @@ -65,6 +65,8 @@ extern "C" { #include #include #include +#include +#include #include #include @@ -82,7 +84,7 @@ static int g_mainExitCode; class AppContainer : public Microsoft::WRL::RuntimeClass { public: - AppContainer(int argc, char *argv[]) : m_argc(argc), m_debugWait(false) + AppContainer(int argc, char *argv[]) : m_argc(argc) { m_argv.reserve(argc); for (int i = 0; i < argc; ++i) @@ -106,8 +108,28 @@ public: HRESULT __stdcall Load(HSTRING) { return S_OK; } HRESULT __stdcall Run() { + bool develMode = false; + bool debugWait = false; + foreach (const QByteArray &arg, m_argv) { + if (arg == "-qdevel") + develMode = true; + if (arg == "-qdebug") + debugWait = true; + } + if (develMode) { + // Write a PID file to help runner + const QString pidFileName = QDir(QStandardPaths::writableLocation(QStandardPaths::DataLocation)) + .absoluteFilePath(QString::number(uint(GetCurrentProcessId())) + QStringLiteral(".pid")); + CREATEFILE2_EXTENDED_PARAMETERS params = { + sizeof(CREATEFILE2_EXTENDED_PARAMETERS), + FILE_ATTRIBUTE_NORMAL, FILE_FLAG_DELETE_ON_CLOSE + }; + // (Unused) handle will automatically be closed when the app exits + CreateFile2(reinterpret_cast(pidFileName.utf16()), + 0, FILE_SHARE_READ|FILE_SHARE_DELETE, CREATE_ALWAYS, ¶ms); + } // Wait for debugger before continuing - if (m_debugWait) { + if (debugWait) { while (!IsDebuggerPresent()) WaitForSingleObjectEx(GetCurrentThread(), 1, true); } @@ -131,8 +153,6 @@ private: foreach (const QByteArray &arg, QString::fromWCharArray( WindowsGetStringRawBuffer(arguments, nullptr)).toLocal8Bit().split(' ')) { m_argv.append(qstrdup(arg.constData())); - if (arg == "-qdebug") - m_debugWait = true; } } } @@ -141,7 +161,6 @@ private: int m_argc; QVector m_argv; - bool m_debugWait; EventRegistrationToken m_activationToken; };