Bug 1309573 - Part 1: Define the crash reason in MFBT to let everything use it. r=froydnj
authorEmanuel Hoogeveen <emanuel.hoogeveen@gmail.com>
Sun, 06 Nov 2016 22:57:00 -0500
changeset 435810 c5f08b96183010934b96dbb637933d77eac6212b
parent 435809 de39b88af6c226c8cbe2ba0e3e14a8d0dcc7ebe1
child 435811 151ddb5b85a1661a59ed528ccab7e6fe2bbad9de
push id35126
push userbmo:mh+mozilla@glandium.org
push dateWed, 09 Nov 2016 06:43:04 +0000
reviewersfroydnj
bugs1309573
milestone52.0a1
Bug 1309573 - Part 1: Define the crash reason in MFBT to let everything use it. r=froydnj
mfbt/Assertions.cpp
mfbt/Assertions.h
mfbt/objs.mozbuild
toolkit/crashreporter/nsExceptionHandler.cpp
toolkit/crashreporter/nsExceptionHandler.h
new file mode 100644
--- /dev/null
+++ b/mfbt/Assertions.cpp
@@ -0,0 +1,17 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "mozilla/Types.h"
+
+/*
+ * The crash reason is defined as a global variable here rather than in the
+ * crash reporter itself to make it available to all code, even libraries like
+ * JS that don't link with the crash reporter directly. This value will only
+ * be consumed if the crash reporter is used by the target application.
+ */
+
+MOZ_BEGIN_EXTERN_C
+MOZ_EXPORT const char* gMozCrashReason = nullptr;
+MOZ_END_EXTERN_C
--- a/mfbt/Assertions.h
+++ b/mfbt/Assertions.h
@@ -13,33 +13,38 @@
 #define MOZ_DUMP_ASSERTION_STACK
 #endif
 
 #include "mozilla/Attributes.h"
 #include "mozilla/Compiler.h"
 #include "mozilla/Likely.h"
 #include "mozilla/MacroArgs.h"
 #include "mozilla/StaticAnalysisFunctions.h"
+#include "mozilla/Types.h"
 #ifdef MOZ_DUMP_ASSERTION_STACK
 #include "nsTraceRefcnt.h"
 #endif
 
-#if defined(MOZ_CRASHREPORTER) && defined(MOZILLA_INTERNAL_API) && \
-    !defined(MOZILLA_EXTERNAL_LINKAGE) && defined(__cplusplus)
-namespace CrashReporter {
-// This declaration is present here as well as in nsExceptionHandler.h
-// nsExceptionHandler.h is not directly included in this file as it includes
-// windows.h, which can cause problems when it is imported into some files due
-// to the number of macros defined.
-// XXX If you change this definition - also change the definition in
-// nsExceptionHandler.h
-void AnnotateMozCrashReason(const char* aReason);
-} // namespace CrashReporter
+#if defined(MOZ_HAS_MOZGLUE) || defined(MOZILLA_INTERNAL_API)
+/*
+ * The crash reason set by MOZ_CRASH_ANNOTATE is consumed by the crash reporter
+ * if present. It is declared here (and defined in Assertions.cpp) to make it
+ * available to all code, even libraries that don't link with the crash reporter
+ * directly.
+ */
+MOZ_BEGIN_EXTERN_C
+extern MFBT_DATA const char* gMozCrashReason;
+MOZ_END_EXTERN_C
 
-#  define MOZ_CRASH_ANNOTATE(...) CrashReporter::AnnotateMozCrashReason(__VA_ARGS__)
+static inline void
+AnnotateMozCrashReason(const char* reason)
+{
+  gMozCrashReason = reason;
+}
+#  define MOZ_CRASH_ANNOTATE(...) AnnotateMozCrashReason(__VA_ARGS__)
 #else
 #  define MOZ_CRASH_ANNOTATE(...) do { /* nothing */ } while (0)
 #endif
 
 #include <stddef.h>
 #include <stdio.h>
 #include <stdlib.h>
 #ifdef WIN32
--- a/mfbt/objs.mozbuild
+++ b/mfbt/objs.mozbuild
@@ -1,15 +1,16 @@
 # -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
 # vim: set filetype=python:
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 mfbt_src_lcppsrcs = [
+    'Assertions.cpp',
     'ChaosMode.cpp',
     'double-conversion/bignum-dtoa.cc',
     'double-conversion/bignum.cc',
     'double-conversion/cached-powers.cc',
     'double-conversion/diy-fp.cc',
     'double-conversion/double-conversion.cc',
     'double-conversion/fast-dtoa.cc',
     'double-conversion/fixed-dtoa.cc',
--- a/toolkit/crashreporter/nsExceptionHandler.cpp
+++ b/toolkit/crashreporter/nsExceptionHandler.cpp
@@ -553,23 +553,16 @@ Concat(XP_CHAR* str, const XP_CHAR* toAp
   memcpy(str, toAppend, appendLen * sizeof(XP_CHAR));
   str += appendLen;
   *str = '\0';
   *size -= appendLen;
 
   return str;
 }
 
-static const char* gMozCrashReason = nullptr;
-
-void AnnotateMozCrashReason(const char* aReason)
-{
-  gMozCrashReason = aReason;
-}
-
 static size_t gOOMAllocationSize = 0;
 
 void AnnotateOOMAllocationSize(size_t size)
 {
   gOOMAllocationSize = size;
 }
 
 static size_t gTexturesSize = 0;
--- a/toolkit/crashreporter/nsExceptionHandler.h
+++ b/toolkit/crashreporter/nsExceptionHandler.h
@@ -1,16 +1,18 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef nsExceptionHandler_h__
 #define nsExceptionHandler_h__
 
+#include "mozilla/Assertions.h"
+
 #include <stddef.h>
 #include <stdint.h>
 #include "nsError.h"
 #include "nsStringGlue.h"
 
 #if defined(XP_WIN32)
 #ifdef WIN32_LEAN_AND_MEAN
 #undef WIN32_LEAN_AND_MEAN
@@ -68,19 +70,16 @@ nsresult SetMinidumpPath(const nsAString
 
 // AnnotateCrashReport, RemoveCrashReportAnnotation and
 // AppendAppNotesToCrashReport may be called from any thread in a chrome
 // process, but may only be called from the main thread in a content process.
 nsresult AnnotateCrashReport(const nsACString& key, const nsACString& data);
 nsresult RemoveCrashReportAnnotation(const nsACString& key);
 nsresult AppendAppNotesToCrashReport(const nsACString& data);
 
-// NOTE: If you change this definition, also change the definition in Assertions.h
-// as it is intended to be defining this same function.
-void AnnotateMozCrashReason(const char* aReason);
 void AnnotateOOMAllocationSize(size_t size);
 void AnnotateTexturesSize(size_t size);
 void AnnotatePendingIPC(size_t aNumOfPendingIPC,
                         uint32_t aTopPendingIPCCount,
                         const char* aTopPendingIPCName,
                         uint32_t aTopPendingIPCType);
 nsresult SetGarbageCollecting(bool collecting);
 void SetEventloopNestingLevel(uint32_t level);