diff options
author | Andrew Knight <andrew.knight@digia.com> | 2014-03-14 09:00:26 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-03-14 22:40:32 +0100 |
commit | 9ceeaaac7984523fdc08c2040fcadf5698254c2d (patch) | |
tree | cabcc9206db38b6c19ecdccf2d083344a40cb226 | |
parent | 60f0a97eddfad0cfe2c00dd7a6fb15b94a2260c9 (diff) |
WinRT: Add debug message handler for winrtrunner
By placing debug messages in shared memory, the application can share
debug messages with winrtrunner (or any utility which passes -qdevel
to the app and opens the corresponding shared memory area).
Task-number: QTBUG-37308
Change-Id: Id0e04cfd5f0f701d552a448f780788c7cbf9b438
Reviewed-by: Oliver Wolff <oliver.wolff@digia.com>
-rw-r--r-- | src/winmain/qtmain_winrt.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/winmain/qtmain_winrt.cpp b/src/winmain/qtmain_winrt.cpp index 151294d2c4..22d3f5bd91 100644 --- a/src/winmain/qtmain_winrt.cpp +++ b/src/winmain/qtmain_winrt.cpp @@ -81,6 +81,27 @@ typedef ITypedEventHandler<Core::CoreApplicationView *, Activation::IActivatedEv static int g_mainExitCode; +static QtMessageHandler defaultMessageHandler; +static void devMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &message) +{ +#ifndef Q_OS_WINPHONE + static HANDLE shmem = 0; + static HANDLE event = 0; + if (!shmem) + shmem = CreateFileMappingFromApp(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 4096, L"qdebug-shmem"); + if (!event) + event = CreateEventEx(NULL, L"qdebug-event", 0, EVENT_ALL_ACCESS); + + void *data = MapViewOfFileFromApp(shmem, FILE_MAP_WRITE, 0, 4096); + memset(data, quint32(type), sizeof(quint32)); + memcpy_s(static_cast<quint32 *>(data) + 1, 4096 - sizeof(quint32), + message.data(), (message.length() + 1) * sizeof(wchar_t)); + UnmapViewOfFile(data); + SetEvent(event); +#endif // !Q_OS_WINPHONE + defaultMessageHandler(type, context, message); +} + class AppContainer : public Microsoft::WRL::RuntimeClass<Core::IFrameworkView> { public: @@ -127,6 +148,10 @@ public: // (Unused) handle will automatically be closed when the app exits CreateFile2(reinterpret_cast<LPCWSTR>(pidFileName.utf16()), 0, FILE_SHARE_READ|FILE_SHARE_DELETE, CREATE_ALWAYS, ¶ms); + // Install the develMode message handler +#ifndef Q_OS_WINPHONE + defaultMessageHandler = qInstallMessageHandler(devMessageHandler); +#endif } // Wait for debugger before continuing if (debugWait) { |