bug 1264242 - Write memory info streams for Windows Minidumps of child processes. r?bsmedberg draft
authorTed Mielczarek <ted@mielczarek.org>
Wed, 13 Apr 2016 08:05:46 -0400
changeset 350401 d564f5034e5814e8979b63214cb83febca3c2e06
parent 350335 564b225d553547fe4aa9a1039278f695c9507db9
child 518324 c5d2a9270edd64253fc10aa388079be430a5cd04
push id15330
push usertmielczarek@mozilla.com
push dateWed, 13 Apr 2016 16:39:27 +0000
reviewersbsmedberg
bugs1264242
milestone48.0a1
bug 1264242 - Write memory info streams for Windows Minidumps of child processes. r?bsmedberg MozReview-Commit-ID: COHFdNiJIqm
toolkit/crashreporter/nsExceptionHandler.cpp
toolkit/crashreporter/test/unit/test_crashreporter_crash.js
toolkit/crashreporter/test/unit_ipc/test_content_memory_list.js
toolkit/crashreporter/test/unit_ipc/xpcshell.ini
--- a/toolkit/crashreporter/nsExceptionHandler.cpp
+++ b/toolkit/crashreporter/nsExceptionHandler.cpp
@@ -1359,16 +1359,51 @@ ChildFPEFilter(void* context, EXCEPTION_
 {
   bool result = FPEFilter(context, exinfo, assertion);
   if (result) {
     PrepareChildExceptionTimeAnnotations();
   }
   return result;
 }
 
+MINIDUMP_TYPE GetMinidumpType()
+{
+  MINIDUMP_TYPE minidump_type = MiniDumpNormal;
+
+  // Try to determine what version of dbghelp.dll we're using.
+  // MinidumpWithFullMemoryInfo is only available in 6.1.x or newer.
+
+  DWORD version_size = GetFileVersionInfoSizeW(L"dbghelp.dll", nullptr);
+  if (version_size > 0) {
+    std::vector<BYTE> buffer(version_size);
+    if (GetFileVersionInfoW(L"dbghelp.dll",
+                            0,
+                            version_size,
+                            &buffer[0])) {
+      UINT len;
+      VS_FIXEDFILEINFO* file_info;
+      VerQueryValue(&buffer[0], L"\\", (void**)&file_info, &len);
+      WORD major = HIWORD(file_info->dwFileVersionMS),
+        minor = LOWORD(file_info->dwFileVersionMS),
+        revision = HIWORD(file_info->dwFileVersionLS);
+      if (major > 6 || (major == 6 && minor > 1) ||
+          (major == 6 && minor == 1 && revision >= 7600)) {
+        minidump_type = MiniDumpWithFullMemoryInfo;
+      }
+    }
+  }
+
+  const char* e = PR_GetEnv("MOZ_CRASHREPORTER_FULLDUMP");
+  if (e && *e) {
+    minidump_type = MiniDumpWithFullMemory;
+  }
+
+  return minidump_type;
+}
+
 #endif // XP_WIN
 
 static bool ShouldReport()
 {
   // this environment variable prevents us from launching
   // the crash reporter client
   const char *envvar = PR_GetEnv("MOZ_CRASHREPORTER_NO_REPORT");
   if (envvar && *envvar) {
@@ -1516,46 +1551,16 @@ nsresult SetExceptionHandler(nsIFile* aX
       attr_ocount != attr_count) {
     posix_spawnattr_destroy(&spawnattr);
     return NS_ERROR_FAILURE;
   }
 #endif
 
 #ifdef XP_WIN32
   ReserveBreakpadVM();
-
-  MINIDUMP_TYPE minidump_type = MiniDumpNormal;
-
-  // Try to determine what version of dbghelp.dll we're using.
-  // MinidumpWithFullMemoryInfo is only available in 6.1.x or newer.
-
-  DWORD version_size = GetFileVersionInfoSizeW(L"dbghelp.dll", nullptr);
-  if (version_size > 0) {
-    std::vector<BYTE> buffer(version_size);
-    if (GetFileVersionInfoW(L"dbghelp.dll",
-                            0,
-                            version_size,
-                            &buffer[0])) {
-      UINT len;
-      VS_FIXEDFILEINFO* file_info;
-      VerQueryValue(&buffer[0], L"\\", (void**)&file_info, &len);
-      WORD major = HIWORD(file_info->dwFileVersionMS),
-           minor = LOWORD(file_info->dwFileVersionMS),
-           revision = HIWORD(file_info->dwFileVersionLS);
-      if (major > 6 || (major == 6 && minor > 1) ||
-          (major == 6 && minor == 1 && revision >= 7600)) {
-        minidump_type = MiniDumpWithFullMemoryInfo;
-      }
-    }
-  }
-
-  const char* e = PR_GetEnv("MOZ_CRASHREPORTER_FULLDUMP");
-  if (e && *e) {
-    minidump_type = MiniDumpWithFullMemory;
-  }
 #endif // XP_WIN32
 
 #ifdef MOZ_WIDGET_ANDROID
   androidUserSerial = getenv("MOZ_ANDROID_USER_SERIAL_NUMBER");
 #endif
 
   // Initialize the flag and mutex used to avoid dump processing
   // once browser termination has begun.
@@ -1589,17 +1594,17 @@ nsresult SetExceptionHandler(nsIFile* aX
                      FPEFilter,
 #else
                      Filter,
 #endif
                      MinidumpCallback,
                      nullptr,
 #ifdef XP_WIN32
                      google_breakpad::ExceptionHandler::HANDLER_ALL,
-                     minidump_type,
+                     GetMinidumpType(),
                      (const wchar_t*) nullptr,
                      nullptr);
 #else
                      true
 #ifdef XP_MACOSX
                        , nullptr
 #endif
 #ifdef XP_LINUX
@@ -3477,17 +3482,17 @@ SetRemoteExceptionHandler(const nsACStri
   MOZ_ASSERT(!gExceptionHandler, "crash client already init'd");
 
   gExceptionHandler = new google_breakpad::
     ExceptionHandler(L"",
                      ChildFPEFilter,
                      nullptr,    // no minidump callback
                      nullptr,    // no callback context
                      google_breakpad::ExceptionHandler::HANDLER_ALL,
-                     MiniDumpNormal,
+                     GetMinidumpType(),
                      NS_ConvertASCIItoUTF16(crashPipe).get(),
                      nullptr);
   gExceptionHandler->set_handle_debug_exceptions(true);
 
   mozalloc_set_oom_abort_handler(AnnotateOOMAllocationSize);
 
   // we either do remote or nothing, no fallback to regular crash reporting
   return gExceptionHandler->IsOutOfProcess();
--- a/toolkit/crashreporter/test/unit/test_crashreporter_crash.js
+++ b/toolkit/crashreporter/test/unit/test_crashreporter_crash.js
@@ -1,15 +1,10 @@
 function run_test()
 {
-  if (!("@mozilla.org/toolkit/crash-reporter;1" in Components.classes)) {
-    dump("INFO | test_crashreporter.js | Can't test crashreporter in a non-libxul build.\n");
-    return;
-  }
-
   var is_win7_or_newer = false;
   var is_windows = false;
   var ph = Components.classes["@mozilla.org/network/protocol;1?name=http"]
              .getService(Components.interfaces.nsIHttpProtocolHandler);
   var match = ph.userAgent.match(/Windows NT (\d+).(\d+)/);
   if (match) {
       is_windows = true;
   }
copy from toolkit/crashreporter/test/unit/test_crashreporter_crash.js
copy to toolkit/crashreporter/test/unit_ipc/test_content_memory_list.js
--- a/toolkit/crashreporter/test/unit/test_crashreporter_crash.js
+++ b/toolkit/crashreporter/test/unit_ipc/test_content_memory_list.js
@@ -1,56 +1,23 @@
+// Any copyright is dedicated to the Public Domain.
+// http://creativecommons.org/publicdomain/zero/1.0/
+
+load("../unit/head_crashreporter.js");
+
 function run_test()
 {
-  if (!("@mozilla.org/toolkit/crash-reporter;1" in Components.classes)) {
-    dump("INFO | test_crashreporter.js | Can't test crashreporter in a non-libxul build.\n");
-    return;
-  }
-
   var is_win7_or_newer = false;
-  var is_windows = false;
   var ph = Components.classes["@mozilla.org/network/protocol;1?name=http"]
              .getService(Components.interfaces.nsIHttpProtocolHandler);
   var match = ph.userAgent.match(/Windows NT (\d+).(\d+)/);
-  if (match) {
-      is_windows = true;
-  }
   if (match && (parseInt(match[1]) > 6 ||
                 parseInt(match[1]) == 6 && parseInt(match[2]) >= 1)) {
       is_win7_or_newer = true;
   }
 
-  // try a basic crash
-  do_crash(null, function(mdump, extra) {
+  do_content_crash(null, function(mdump, extra) {
              do_check_true(mdump.exists());
              do_check_true(mdump.fileSize > 0);
-             do_check_true('StartupTime' in extra);
-             do_check_true('CrashTime' in extra);
-             do_check_true(CrashTestUtils.dumpHasStream(mdump.path, CrashTestUtils.MD_THREAD_LIST_STREAM));
-             do_check_true(CrashTestUtils.dumpHasInstructionPointerMemory(mdump.path));
-             if (is_windows) {
-               ['SystemMemoryUsePercentage', 'TotalVirtualMemory', 'AvailableVirtualMemory',
-                'AvailablePageFile', 'AvailablePhysicalMemory'].forEach(function(prop) {
-                  do_check_true(/^\d+$/.test(extra[prop].toString()));
-               });
-             }
              if (is_win7_or_newer)
                do_check_true(CrashTestUtils.dumpHasStream(mdump.path, CrashTestUtils.MD_MEMORY_INFO_LIST_STREAM));
            });
-
-  // check setting some basic data
-  do_crash(function() {
-             crashReporter.annotateCrashReport("TestKey", "TestValue");
-             crashReporter.annotateCrashReport("\u2665", "\u{1F4A9}");
-             crashReporter.appendAppNotesToCrashReport("Junk");
-             crashReporter.appendAppNotesToCrashReport("MoreJunk");
-             // TelemetrySession setup will trigger the session annotation
-             let scope = {};
-             Components.utils.import("resource://gre/modules/TelemetrySession.jsm", scope);
-             scope.TelemetrySession.setup();
-           },
-           function(mdump, extra) {
-             do_check_eq(extra.TestKey, "TestValue");
-             do_check_eq(extra["\u2665"], "\u{1F4A9}");
-             do_check_eq(extra.Notes, "JunkMoreJunk");
-             do_check_true(!("TelemetrySessionId" in extra));
-           });
 }
--- a/toolkit/crashreporter/test/unit_ipc/xpcshell.ini
+++ b/toolkit/crashreporter/test/unit_ipc/xpcshell.ini
@@ -6,8 +6,10 @@ support-files =
   !/toolkit/crashreporter/test/unit/crasher_subprocess_head.js
   !/toolkit/crashreporter/test/unit/crasher_subprocess_tail.js
   !/toolkit/crashreporter/test/unit/head_crashreporter.js
 
 [test_content_annotation.js]
 [test_content_exception_time_annotation.js]
 [test_content_oom_annotation_windows.js]
 skip-if = os != 'win'
+[test_content_memory_list.js]
+skip-if = os != 'win'