Bug 1183355 - Annotate crash reports triggered by MOZ_CRASH in release builds, r=froydnj
authorMichael Layzell <michael@thelayzells.com>
Mon, 13 Jul 2015 17:29:40 -0400
changeset 299482 fe0d2b85c47a948ccfa0eab804a24d0d183eae0e
parent 299481 e58caa8dad52c74d16600ab5b15b38e7ec0fd9c6
child 299483 d052f1bd09c55cac73a8df4ae14d68a7a034c6a0
push id1001
push userraliiev@mozilla.com
push dateMon, 18 Jan 2016 19:06:03 +0000
treeherdermozilla-release@8b89261f3ac4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1183355
milestone44.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1183355 - Annotate crash reports triggered by MOZ_CRASH in release builds, r=froydnj
mfbt/Assertions.h
toolkit/xre/nsAppRunner.cpp
--- a/mfbt/Assertions.h
+++ b/mfbt/Assertions.h
@@ -16,16 +16,26 @@
 #include "mozilla/Attributes.h"
 #include "mozilla/Compiler.h"
 #include "mozilla/Likely.h"
 #include "mozilla/MacroArgs.h"
 #ifdef MOZ_DUMP_ASSERTION_STACK
 #include "nsTraceRefcnt.h"
 #endif
 
+// In libraries where the user wants to enable crash reporting when MOZ_CRASH is enabled,
+// MOZ_CRASH_CRASHREPORT must be defined, and the MOZ_ReportMozCrashToCrashReporter method
+// must be provided by the library. This ifdef defines the macro within libXUL, when
+// MOZ_CRASHREPORTER is enabled. The implementation of MOZ_ReportMozCrashToCrashReporter
+// for libXUL is defined in /toolkit/xre/nsAppRunner.cpp
+#if defined(MOZ_CRASHREPORTER) && defined(MOZILLA_INTERNAL_API) && \
+    !defined(MOZILLA_EXTERNAL_LINKAGE)
+#  define MOZ_CRASH_CRASHREPORT
+#endif
+
 #include <stddef.h>
 #include <stdio.h>
 #include <stdlib.h>
 #ifdef WIN32
    /*
     * TerminateProcess and GetCurrentProcess are defined in <winbase.h>, which
     * further depends on <windef.h>.  We hardcode these few definitions manually
     * because those headers clutter the global namespace with a significant
@@ -118,16 +128,25 @@ TerminateProcess(void* hProcess, unsigne
 #else
 #define MOZ_STATIC_ASSERT_IF(cond, expr, reason)  static_assert(!(cond) || (expr), reason)
 #endif
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
+#ifdef MOZ_CRASH_CRASHREPORT
+/*
+ * Associates the given string with a crash report. This function must be
+ * provided by the library which mfbt is being used in if MOZ_CRASH_CRASHREPORT
+ * is defined (by default, MOZ_CRASH_CRASHREPORT is only defined in libXUL).
+ */
+void MOZ_ReportMozCrashToCrashReporter(const char* aStr);
+#endif // MOZ_CRASH_CRASHREPORT
+
 /*
  * Prints |aStr| as an assertion failure (using aFilename and aLine as the
  * location of the assertion) to the standard debug-output channel.
  *
  * Usually you should use MOZ_ASSERT or MOZ_CRASH instead of this method.  This
  * method is primarily for internal use in this header, and only secondarily
  * for use in implementing release-build assertions.
  */
@@ -244,17 +263,25 @@ MOZ_ReportCrash(const char* aStr, const 
  *
  * If we're a DEBUG build and we crash at a MOZ_CRASH which provides an
  * explanation-string, we print the string to stderr.  Otherwise, we don't
  * print anything; this is because we want MOZ_CRASH to be 100% safe in release
  * builds, and it's hard to print to stderr safely when memory might have been
  * corrupted.
  */
 #ifndef DEBUG
-#  define MOZ_CRASH(...) MOZ_REALLY_CRASH()
+#  ifdef MOZ_CRASH_CRASHREPORT
+#    define MOZ_CRASH(...) \
+       do { \
+         MOZ_ReportMozCrashToCrashReporter("" __VA_ARGS__); \
+         MOZ_REALLY_CRASH(); \
+       } while (0)
+#  else
+#    define MOZ_CRASH(...) MOZ_REALLY_CRASH()
+#  endif
 #else
 #  define MOZ_CRASH(...) \
      do { \
        MOZ_ReportCrash("" __VA_ARGS__, __FILE__, __LINE__); \
        MOZ_REALLY_CRASH(); \
      } while (0)
 #endif
 
@@ -504,10 +531,11 @@ struct AssertionConditionType
   do { \
     if ( ( expr ) ) {                       \
       /* Silence MOZ_WARN_UNUSED_RESULT. */ \
     } \
   } while (0)
 #endif
 
 #undef MOZ_DUMP_ASSERTION_STACK
+#undef MOZ_CRASH_CRASHREPORT
 
 #endif /* mozilla_Assertions_h */
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -188,16 +188,27 @@
 #endif
 
 #ifdef MOZ_CRASHREPORTER
 #include "nsExceptionHandler.h"
 #include "nsICrashReporter.h"
 #define NS_CRASHREPORTER_CONTRACTID "@mozilla.org/toolkit/crash-reporter;1"
 #include "nsIPrefService.h"
 #include "nsIMemoryInfoDumper.h"
+
+// Provide MOZ_ReportMozCrashToCrashReporter for reporting MOZ_CRASH errors
+// See /mfbt/Assertions.h for more information
+extern "C" {
+void
+MOZ_ReportMozCrashToCrashReporter(const char* aStr)
+{
+  nsDependentCString msg(aStr);
+  CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("MOZ_CRASH"), msg);
+}
+}
 #endif
 
 #include "base/command_line.h"
 #ifdef MOZ_ENABLE_TESTS
 #include "GTestRunner.h"
 #endif
 
 #ifdef MOZ_B2G_LOADER