Bug 1751281 - Enable Windows Event logging with separate logging module and message parameters r=cmartin

Differential Revision: https://phabricator.services.mozilla.com/D141728
This commit is contained in:
Max Vollmer 2022-03-25 15:27:39 +00:00
parent c6f02ebaa8
commit d4159632e0
7 changed files with 385 additions and 370 deletions

View File

@ -212,14 +212,12 @@ static void DumpNeuteredMessage(HWND hwnd, UINT uMsg) {
nsAutoCString log("Received \"nonqueued\" "); nsAutoCString log("Received \"nonqueued\" ");
// classify messages // classify messages
if (uMsg < WM_USER) { if (uMsg < WM_USER) {
int idx = 0; const auto eventMsgInfo = mozilla::widget::gAllEvents.find(uMsg);
while (mozilla::widget::gAllEvents[idx].mId != uMsg && const char* msgText = eventMsgInfo != mozilla::widget::gAllEvents.end()
mozilla::widget::gAllEvents[idx].mStr != nullptr) { ? eventMsgInfo->second.mStr
idx++; : nullptr;
} if (msgText) {
if (mozilla::widget::gAllEvents[idx].mStr) { log.AppendPrintf("ui message \"%s\"", msgText);
log.AppendPrintf("ui message \"%s\"",
mozilla::widget::gAllEvents[idx].mStr);
} else { } else {
log.AppendPrintf("ui message (0x%X)", uMsg); log.AppendPrintf("ui message (0x%X)", uMsg);
} }

View File

@ -73,8 +73,11 @@ namespace mozilla {
namespace widget { namespace widget {
#define ENTRY(_msg) \ #define ENTRY(_msg) \
{ #_msg, _msg } { \
EventMsgInfo gAllEvents[] = {ENTRY(WM_NULL), _msg, { #_msg, _msg } \
}
std::unordered_map<UINT, EventMsgInfo> gAllEvents = {
ENTRY(WM_NULL),
ENTRY(WM_CREATE), ENTRY(WM_CREATE),
ENTRY(WM_DESTROY), ENTRY(WM_DESTROY),
ENTRY(WM_MOVE), ENTRY(WM_MOVE),
@ -407,7 +410,7 @@ EventMsgInfo gAllEvents[] = {ENTRY(WM_NULL),
ENTRY(WM_GESTURE), ENTRY(WM_GESTURE),
ENTRY(WM_GESTURENOTIFY), ENTRY(WM_GESTURENOTIFY),
ENTRY(WM_GETTITLEBARINFOEX), ENTRY(WM_GETTITLEBARINFOEX),
{nullptr, 0x0}}; {0x0, {nullptr, 0x0}}};
#undef ENTRY #undef ENTRY
#ifdef MOZ_PLACES #ifdef MOZ_PLACES

View File

@ -96,7 +96,7 @@ typedef struct {
const char* mStr; const char* mStr;
UINT mId; UINT mId;
} EventMsgInfo; } EventMsgInfo;
extern EventMsgInfo gAllEvents[]; extern std::unordered_map<UINT, EventMsgInfo> gAllEvents;
// More complete QS definitions for MsgWaitForMultipleObjects() and // More complete QS definitions for MsgWaitForMultipleObjects() and
// GetQueueStatus() that include newer win8 specific defines. // GetQueueStatus() that include newer win8 specific defines.

View File

@ -5014,15 +5014,24 @@ bool nsWindow::ExternalHandlerProcessMessage(UINT aMessage, WPARAM& aWParam,
return false; return false;
} }
// The main windows message processing method. // The main windows message processing method. Wraps ProcessMessageInternal so
// we can log aRetValue.
bool nsWindow::ProcessMessage(UINT msg, WPARAM& wParam, LPARAM& lParam, bool nsWindow::ProcessMessage(UINT msg, WPARAM& wParam, LPARAM& lParam,
LRESULT* aRetValue) { LRESULT* aRetValue) {
#if defined(EVENT_DEBUG_OUTPUT) bool result = ProcessMessageInternal(msg, wParam, lParam, aRetValue);
// First param shows all events, second param indicates whether
// to show mouse move events. See nsWindowDbg for details.
PrintEvent(msg, SHOW_REPEAT_EVENTS, SHOW_MOUSEMOVE_EVENTS);
#endif
// SHOW_REPEAT_EVENTS indicates whether to show all (repeating) events,
// SHOW_MOUSEMOVE_EVENTS indicates whether to show mouse move events.
// See nsWindowDbg for details.
PrintEvent(msg, wParam, lParam, *aRetValue, result, SHOW_REPEAT_EVENTS,
SHOW_MOUSEMOVE_EVENTS);
return result;
}
// The main windows message processing method. Called by ProcessMessage.
bool nsWindow::ProcessMessageInternal(UINT msg, WPARAM& wParam, LPARAM& lParam,
LRESULT* aRetValue) {
MSGResult msgResult(aRetValue); MSGResult msgResult(aRetValue);
if (ExternalHandlerProcessMessage(msg, wParam, lParam, msgResult)) { if (ExternalHandlerProcessMessage(msg, wParam, lParam, msgResult)) {
return (msgResult.mConsumed || !mWnd); return (msgResult.mConsumed || !mWnd);

View File

@ -554,6 +554,9 @@ class nsWindow final : public nsBaseWidget {
void RelayMouseEvent(UINT aMsg, WPARAM wParam, LPARAM lParam); void RelayMouseEvent(UINT aMsg, WPARAM wParam, LPARAM lParam);
bool ProcessMessage(UINT msg, WPARAM& wParam, LPARAM& lParam, bool ProcessMessage(UINT msg, WPARAM& wParam, LPARAM& lParam,
LRESULT* aRetValue); LRESULT* aRetValue);
// We wrap this in ProcessMessage so we can log the return value
bool ProcessMessageInternal(UINT msg, WPARAM& wParam, LPARAM& lParam,
LRESULT* aRetValue);
bool ExternalHandlerProcessMessage(UINT aMessage, WPARAM& aWParam, bool ExternalHandlerProcessMessage(UINT aMessage, WPARAM& aWParam,
LPARAM& aLParam, MSGResult& aResult); LPARAM& aLParam, MSGResult& aResult);
LRESULT ProcessCharMessage(const MSG& aMsg, bool* aEventDispatched); LRESULT ProcessCharMessage(const MSG& aMsg, bool* aEventDispatched);

View File

@ -14,6 +14,7 @@
using namespace mozilla; using namespace mozilla;
using namespace mozilla::widget; using namespace mozilla::widget;
extern mozilla::LazyLogModule gWindowsLog; extern mozilla::LazyLogModule gWindowsLog;
static mozilla::LazyLogModule gWindowsEventLog("WindowsEvent");
#if defined(POPUP_ROLLUP_DEBUG_OUTPUT) #if defined(POPUP_ROLLUP_DEBUG_OUTPUT)
MSGFEventMsgInfo gMSGFEvents[] = { MSGFEventMsgInfo gMSGFEvents[] = {
@ -23,19 +24,24 @@ MSGFEventMsgInfo gMSGFEvents[] = {
#endif #endif
static long gEventCounter = 0; static long gEventCounter = 0;
static long gLastEventMsg = 0; static UINT gLastEventMsg = 0;
void PrintEvent(UINT msg, bool aShowAllEvents, bool aShowMouseMoves) { // Size of WPARAM, LPARAM, and LRESULT depends on 32 or 64 bit build,
int inx = 0; // we use 64 bit types here to ensure it works in either case.
while (gAllEvents[inx].mId != msg && gAllEvents[inx].mStr != nullptr) { void PrintEvent(UINT msg, uint64_t wParam, uint64_t lParam, uint64_t retValue,
inx++; bool result, bool aShowAllEvents, bool aShowMouseMoves) {
} const auto eventMsgInfo = gAllEvents.find(msg);
if (aShowAllEvents || (!aShowAllEvents && gLastEventMsg != (long)msg)) { const char* msgText =
eventMsgInfo != gAllEvents.end() ? eventMsgInfo->second.mStr : nullptr;
if (aShowAllEvents || (gLastEventMsg != msg)) {
if (aShowMouseMoves || if (aShowMouseMoves ||
(!aShowMouseMoves && msg != 0x0020 && msg != 0x0200 && msg != 0x0084)) { (msg != WM_SETCURSOR && msg != WM_MOUSEMOVE && msg != WM_NCHITTEST)) {
MOZ_LOG(gWindowsLog, LogLevel::Info, MOZ_LOG(
("%6d - 0x%04X %s\n", gEventCounter++, msg, gWindowsEventLog, LogLevel::Info,
gAllEvents[inx].mStr ? gAllEvents[inx].mStr : "Unknown")); ("%6d - 0x%04X (0x%08llX 0x%08llX) %s: 0x%08llX (%s)\n",
gEventCounter++, msg, wParam, lParam, msgText ? msgText : "Unknown",
retValue, result ? "true" : "false"));
gLastEventMsg = msg; gLastEventMsg = msg;
} }
} }

View File

@ -12,9 +12,6 @@
#include "nsWindowDefs.h" #include "nsWindowDefs.h"
// Enabled main event loop debug event output
//#define EVENT_DEBUG_OUTPUT
// Enables debug output for popup rollup hooks // Enables debug output for popup rollup hooks
//#define POPUP_ROLLUP_DEBUG_OUTPUT //#define POPUP_ROLLUP_DEBUG_OUTPUT
@ -29,12 +26,11 @@
//#define DEBUG_VK //#define DEBUG_VK
// Main event loop debug output flags // Main event loop debug output flags
#if defined(EVENT_DEBUG_OUTPUT)
#define SHOW_REPEAT_EVENTS true #define SHOW_REPEAT_EVENTS true
#define SHOW_MOUSEMOVE_EVENTS false #define SHOW_MOUSEMOVE_EVENTS false
#endif // defined(EVENT_DEBUG_OUTPUT)
void PrintEvent(UINT msg, bool aShowAllEvents, bool aShowMouseMoves); void PrintEvent(UINT msg, uint64_t wParam, uint64_t lParam, uint64_t retValue,
bool result, bool aShowAllEvents, bool aShowMouseMoves);
#if defined(POPUP_ROLLUP_DEBUG_OUTPUT) #if defined(POPUP_ROLLUP_DEBUG_OUTPUT)
typedef struct { typedef struct {