Bug 962140 Append unexpected message log to crash report r=jimm, a=sledru
authorMasayuki Nakano <masayuki@d-toybox.com>
Tue, 04 Feb 2014 20:46:20 +0900
changeset 182883 687a3cf84d324c39aa1ad2540dfc47ba9e9b2c39
parent 182882 7a729101e50356f4ae3394afc860c02da7138c30
child 182884 fe56f56eafbc5b3d4369c99b801160cdb708188e
push id3343
push userffxbld
push dateMon, 17 Mar 2014 21:55:32 +0000
treeherdermozilla-beta@2f7d3415f79f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimm, sledru
bugs962140
milestone29.0a2
Bug 962140 Append unexpected message log to crash report r=jimm, a=sledru
widget/windows/KeyboardLayout.cpp
--- a/widget/windows/KeyboardLayout.cpp
+++ b/widget/windows/KeyboardLayout.cpp
@@ -1261,34 +1261,109 @@ NativeKey::NeedsToHandleWithoutFollowing
     return false;
   }
 
   // Even if the key is a printable key, it might cause non-printable character
   // input with modifier key(s).
   return mIsPrintableKey;
 }
 
+#ifdef MOZ_CRASHREPORTER
+
+static nsCString
+GetResultOfInSendMessageEx()
+{
+  DWORD ret = ::InSendMessageEx(nullptr);
+  if (!ret) {
+    return NS_LITERAL_CSTRING("ISMEX_NOSEND");
+  }
+  nsAutoCString result;
+  if (ret & ISMEX_CALLBACK) {
+    result = "ISMEX_CALLBACK";
+  }
+  if (ret & ISMEX_NOTIFY) {
+    if (!result.IsEmpty()) {
+      result += " | ";
+    }
+    result += "ISMEX_NOTIFY";
+  }
+  if (ret & ISMEX_REPLIED) {
+    if (!result.IsEmpty()) {
+      result += " | ";
+    }
+    result += "ISMEX_REPLIED";
+  }
+  if (ret & ISMEX_SEND) {
+    if (!result.IsEmpty()) {
+      result += " | ";
+    }
+    result += "ISMEX_SEND";
+  }
+  return result;
+}
+
+static const char*
+GetMessageName(UINT aMessage)
+{
+  switch (aMessage) {
+    case WM_KEYDOWN:     return "WM_KEYDOWN";
+    case WM_SYSKEYDOWN:  return "WM_SYSKEYDOWN";
+    case WM_KEYUP:       return "WM_KEYUP";
+    case WM_SYSKEYUP:    return "WM_SYSKEYUP";
+    case WM_CHAR:        return "WM_CHAR";
+    case WM_DEADCHAR:    return "WM_DEADCHAR";
+    case WM_SYSCHAR:     return "WM_SYSCHAR";
+    case WM_SYSDEADCHAR: return "WM_SYSDEADCHAR";
+    case WM_UNICHAR:     return "WM_UNICHAR";
+    default:             return "Unknown";
+  }
+}
+
+#endif // #ifdef MOZ_CRASHREPORTER
+
 MSG
 NativeKey::RemoveFollowingCharMessage() const
 {
   MOZ_ASSERT(IsFollowedByCharMessage());
 
   if (mFakeCharMsgs) {
     MOZ_ASSERT(!mFakeCharMsgs->ElementAt(0).mConsumed,
       "Doesn't assume that it's used for removing two or more char messages");
     mFakeCharMsgs->ElementAt(0).mConsumed = true;
     return mFakeCharMsgs->ElementAt(0).GetCharMsg(mMsg.hwnd);
   }
 
   MSG msg;
   if (!WinUtils::PeekMessage(&msg, mMsg.hwnd, WM_KEYFIRST, WM_KEYLAST,
-                             PM_REMOVE | PM_NOYIELD) ||
-      !IsCharMessage(msg)) {
+                             PM_REMOVE | PM_NOYIELD)) {
+#ifdef MOZ_CRASHREPORTER
+    nsPrintfCString info("Handling message: %s (0x%08X), wParam: 0x%08X, "
+                         "lParam: 0x%08X, InSendMessageEx()=%s",
+                         GetMessageName(mMsg.message),
+                         mMsg.message, mMsg.wParam, mMsg.lParam,
+                         GetResultOfInSendMessageEx().get());
+    CrashReporter::AppendAppNotesToCrashReport(info);
+#endif // #ifdef MOZ_CRASHREPORTER
     MOZ_CRASH("We lost the following char message");
   }
+  if (!IsCharMessage(msg)) {
+#ifdef MOZ_CRASHREPORTER
+    nsPrintfCString info("Handling message: %s (0x%08X), wParam: 0x%08X, "
+                         "lParam: 0x%08X, InSendMessageEx()=%s, "
+                         "Next key message: %s (0x%08X), "
+                         "wParam: 0x%08X, lParam: 0x%08X",
+                         GetMessageName(mMsg.message),
+                         mMsg.message, mMsg.wParam, mMsg.lParam,
+                         GetResultOfInSendMessageEx().get(),
+                         GetMessageName(msg.message),
+                         msg.message, msg.wParam, msg.lParam);
+    CrashReporter::AppendAppNotesToCrashReport(info);
+#endif // #ifdef MOZ_CRASHREPORTER
+    MOZ_CRASH("Next key message isn't a char message");
+  }
 
   return msg;
 }
 
 bool
 NativeKey::RemoveMessageAndDispatchPluginEvent(UINT aFirstMsg,
                                                UINT aLastMsg) const
 {