bug 382541 - Mozilla Crash Reporter supresses writing of Mac OS X crash log - short term workaround. r=mento
authorted.mielczarek@gmail.com
Tue, 24 Jul 2007 18:06:09 -0700
changeset 3908 0bc459662ce5209cb9f800b3961814e3ffd485d9
parent 3907 a7db7bd3dca51c1750702fe35d2e2c574914aa9f
child 3909 ebbb1910f9d1402be60730b151ac0529b8f05cb5
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmento
bugs382541
milestone1.9a7pre
bug 382541 - Mozilla Crash Reporter supresses writing of Mac OS X crash log - short term workaround. r=mento
toolkit/crashreporter/Makefile.in
toolkit/crashreporter/mac_utils.h
toolkit/crashreporter/mac_utils.mm
toolkit/crashreporter/nsExceptionHandler.cpp
--- a/toolkit/crashreporter/Makefile.in
+++ b/toolkit/crashreporter/Makefile.in
@@ -56,16 +56,18 @@ DIRS = \
 
 ifeq  ($(OS_ARCH),WINNT)
 	DIRS += airbag/src/common/windows \
 		airbag/src/client/windows \
 		$(NULL)
 endif
 
 ifeq ($(OS_ARCH),Darwin)
+CMMSRCS = mac_utils.mm
+
 DIRS += \
   airbag/src/common \
   airbag/src/common/mac \
   airbag/src/client \
   airbag/src/client/mac/handler \
   airbag/src/tools/mac/dump_syms \
   $(NULL)
 endif
new file mode 100644
--- /dev/null
+++ b/toolkit/crashreporter/mac_utils.h
@@ -0,0 +1,47 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Mozilla Breakpad integration
+ *
+ * The Initial Developer of the Original Code is
+ * Ted Mielczarek <ted.mielczarek@gmail.com>
+ * Portions created by the Initial Developer are Copyright (C) 2007
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+#ifndef toolkit_breakpad_mac_utils_h__
+#define toolkit_breakpad_mac_utils_h__
+
+/*
+ * Look up a setting in our user defaults indicating
+ * that the user wants to see the OS crash reporting dialog.
+ */
+bool PassToOSCrashReporter();
+
+#endif /* toolkit_breakpad_mac_utils_h__ */
new file mode 100644
--- /dev/null
+++ b/toolkit/crashreporter/mac_utils.mm
@@ -0,0 +1,50 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Mozilla Breakpad integration
+ *
+ * The Initial Developer of the Original Code is
+ * Ted Mielczarek <ted.mielczarek@gmail.com>
+ * Portions created by the Initial Developer are Copyright (C) 2007
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+#include <Foundation/Foundation.h>
+
+#include "mac_utils.h"
+
+bool PassToOSCrashReporter()
+{
+  NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
+  NSUserDefaults* userDefaults = [NSUserDefaults standardUserDefaults];
+  BOOL osCrashReporter = [userDefaults boolForKey:@"OSCrashReporter"];
+  [pool release];
+
+  return osCrashReporter == YES;
+}
--- a/toolkit/crashreporter/nsExceptionHandler.cpp
+++ b/toolkit/crashreporter/nsExceptionHandler.cpp
@@ -44,16 +44,17 @@
 
 #include "client/windows/handler/exception_handler.h"
 #include <string.h>
 #elif defined(XP_MACOSX)
 #include "client/mac/handler/exception_handler.h"
 #include <string>
 #include <Carbon/Carbon.h>
 #include <fcntl.h>
+#include "mac_utils.h"
 #elif defined(XP_LINUX)
 #include "client/linux/handler/exception_handler.h"
 #include <fcntl.h>
 #else
 #error "Not yet implemented for this platform"
 #endif // defined(XP_WIN32)
 
 #ifndef HAVE_CPP_2BYTE_WCHAR_T
@@ -99,16 +100,19 @@ static const XP_CHAR extraFileExtension[
 
 static google_breakpad::ExceptionHandler* gExceptionHandler = nsnull;
 
 static XP_CHAR* crashReporterPath;
 
 // if this is false, we don't launch the crash reporter
 static bool doReport = true;
 
+// if this is true, we pass the exception on to the OS crash reporter
+static bool showOSCrashReporter = false;
+
 // this holds additional data sent via the API
 static nsDataHashtable<nsCStringHashKey,nsCString>* crashReporterAPIData_Hash;
 static nsCString* crashReporterAPIData = nsnull;
 
 static XP_CHAR*
 Concat(XP_CHAR* str, const XP_CHAR* toAppend, int* size)
 {
   int appendLen = XP_STRLEN(toAppend);
@@ -126,17 +130,17 @@ bool MinidumpCallback(const XP_CHAR* dum
                       const XP_CHAR* minidump_id,
                       void* context,
 #ifdef XP_WIN32
                       EXCEPTION_POINTERS* exinfo,
                       MDRawAssertionInfo* assertion,
 #endif
                       bool succeeded)
 {
-  printf("Wrote minidump ID %s\n", minidump_id);
+  bool returnValue = showOSCrashReporter ? false : succeeded;
 
   XP_CHAR minidumpPath[XP_PATH_MAX];
   int size = XP_PATH_MAX;
   XP_CHAR* p = Concat(minidumpPath, dump_path, &size);
   p = Concat(p, XP_PATH_SEPARATOR, &size);
   p = Concat(p, minidump_id, &size);
   Concat(p, dumpFileExtension, &size);
 
@@ -165,17 +169,17 @@ bool MinidumpCallback(const XP_CHAR* dum
       DWORD nBytes;
       WriteFile(hFile, crashReporterAPIData->get(),
                 crashReporterAPIData->Length(), &nBytes, NULL);
       CloseHandle(hFile);
     }
   }
 
   if (!doReport) {
-    return succeeded;
+    return returnValue;
   }
 
   STARTUPINFO si;
   PROCESS_INFORMATION pi;
 
   ZeroMemory(&si, sizeof(si));
   si.cb = sizeof(si);
   si.dwFlags = STARTF_USESHOWWINDOW;
@@ -199,31 +203,31 @@ bool MinidumpCallback(const XP_CHAR* dum
     if (fd != -1) {
       // not much we can do in case of error
       write(fd, crashReporterAPIData->get(), crashReporterAPIData->Length());
       close (fd);
     }
   }
 
   if (!doReport) {
-    return succeeded;
+    return returnValue;
   }
 
   pid_t pid = fork();
 
   if (pid == -1)
     return false;
   else if (pid == 0) {
     (void) execl(crashReporterPath,
                  crashReporterPath, minidumpPath, (char*)0);
     _exit(1);
   }
 #endif
 
- return succeeded;
+ return returnValue;
 }
 
 nsresult SetExceptionHandler(nsILocalFile* aXREDirectory,
                              const char* aServerURL)
 {
   nsresult rv;
 
   if (gExceptionHandler)
@@ -306,16 +310,23 @@ nsresult SetExceptionHandler(nsILocalFil
   if (!gExceptionHandler)
     return NS_ERROR_OUT_OF_MEMORY;
 
   // store server URL with the API data
   if (aServerURL)
     AnnotateCrashReport(NS_LITERAL_CSTRING("ServerURL"),
                         nsDependentCString(aServerURL));
 
+#if defined(XP_MACOSX)
+  // On OS X, many testers like to see the OS crash reporting dialog
+  // since it offers immediate stack traces.  We allow them to set
+  // a default to pass exceptions to the OS handler.
+  showOSCrashReporter = PassToOSCrashReporter();
+#endif
+
   return NS_OK;
 }
 
 nsresult SetMinidumpPath(const nsAString& aPath)
 {
   if (!gExceptionHandler)
     return NS_ERROR_NOT_INITIALIZED;