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>
This commit is contained in:
Andrew Knight 2014-03-14 09:00:26 +02:00 committed by The Qt Project
parent 60f0a97edd
commit 9ceeaaac79

View File

@ -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, &params);
// Install the develMode message handler
#ifndef Q_OS_WINPHONE
defaultMessageHandler = qInstallMessageHandler(devMessageHandler);
#endif
}
// Wait for debugger before continuing
if (debugWait) {