From 69e78b9a0764ea5ec56689f09311741d4fc5870e Mon Sep 17 00:00:00 2001 From: Andrew Knight Date: Thu, 3 Oct 2013 12:19:52 +0300 Subject: WinRT winmain: enable debugger waiting WinRT applications are not invoked directly, so a debugger may attach too late to be useful. While the application can be launched with a debugging server, attaching directly to the running process is simpler and less resource-intensive. For this reason, it is useful for applications to wait for the direct debugger to attach. If the existing -qdebug parameter is passed to the application, wait idly until the debugger attaches. Change-Id: I7b4957beb9728ab6311b459e4d809dc5f4767780 Reviewed-by: Friedemann Kleint --- src/winmain/qtmain_winrt.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/winmain/qtmain_winrt.cpp b/src/winmain/qtmain_winrt.cpp index d0f138269f..c0542ff242 100644 --- a/src/winmain/qtmain_winrt.cpp +++ b/src/winmain/qtmain_winrt.cpp @@ -69,7 +69,7 @@ typedef ITypedEventHandler { public: - AppContainer(int argc, wchar_t **argv) : m_argc(argc) + AppContainer(int argc, wchar_t **argv) : m_argc(argc), m_debugWait(false) { m_argv.reserve(argc); for (int i = 0; i < argc; ++i) { @@ -95,6 +95,11 @@ public: HRESULT __stdcall Load(HSTRING) { return S_OK; } HRESULT __stdcall Run() { + // Wait for debugger before continuing + if (m_debugWait) { + while (!IsDebuggerPresent()) + WaitForSingleObjectEx(GetCurrentThread(), 1, true); + } return main(m_argv.count(), m_argv.data()); } HRESULT __stdcall Uninitialize() { return S_OK; } @@ -113,6 +118,8 @@ private: foreach (const QByteArray &arg, QString::fromWCharArray( WindowsGetStringRawBuffer(arguments, nullptr)).toLocal8Bit().split(' ')) { m_argv.append(qstrdup(arg.constData())); + if (arg == "-qdebug") + m_debugWait = true; } } return S_OK; @@ -120,6 +127,7 @@ private: int m_argc; QVector m_argv; + bool m_debugWait; EventRegistrationToken m_activationToken; }; -- cgit v1.2.3