Bug 1005730 - Print assertion stacks for MOZ_ASSERT and MOZ_CRASH for code that lives inside libxul; r=froydnj
authorEhsan Akhgari <ehsan@mozilla.com>
Mon, 05 May 2014 22:02:04 -0400
changeset 181693 62a76f959ae7e9c4c7c600ea724f967cc80d2651
parent 181692 823c0199a31dba8e6014510dda736bf4a498f63a
child 181694 79dd70f7ce7963409f01b1cb06c6ed392d3c56bd
push id26728
push usercbook@mozilla.com
push dateTue, 06 May 2014 12:23:29 +0000
treeherdermozilla-central@1b3551ab7a5d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1005730
milestone32.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 1005730 - Print assertion stacks for MOZ_ASSERT and MOZ_CRASH for code that lives inside libxul; r=froydnj The hyphenation changes are necessary because hnjalloc.h #defines FILE to a custom data structure, which clashes with using |stderr| in Assertions.h.
intl/hyphenation/src/hnjstdio.cpp
intl/hyphenation/src/moz.build
mfbt/Assertions.h
--- a/intl/hyphenation/src/hnjstdio.cpp
+++ b/intl/hyphenation/src/hnjstdio.cpp
@@ -4,16 +4,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 // This file provides substitutes for the basic stdio routines used by hyphen.c
 // to read its dictionary files. We #define the stdio names to these versions
 // in hnjalloc.h, so that we can use nsIURI and nsIInputStream to specify and
 // access the dictionary resources.
 
 #include "hnjalloc.h"
+#undef FILE // Undo the damage done in hnjalloc.h
 #include "nsNetUtil.h"
 
 #define BUFSIZE 1024
 
 struct hnjFile_ {
     nsCOMPtr<nsIInputStream> mStream;
     char                     mBuffer[BUFSIZE];
     uint32_t                 mCurPos;
--- a/intl/hyphenation/src/moz.build
+++ b/intl/hyphenation/src/moz.build
@@ -1,21 +1,22 @@
 # -*- Mode: python; c-basic-offset: 4; 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/.
 
 UNIFIED_SOURCES += [
-    'hnjstdio.cpp',
     'nsHyphenationManager.cpp',
     'nsHyphenator.cpp',
 ]
 
+# These files cannot be built in unified mode because they include hnjalloc.h.
 SOURCES += [
+    'hnjstdio.cpp',
     'hyphen.c',
 ]
 
 MSVC_ENABLE_PGO = True
 
 FINAL_LIBRARY = 'i18n'
 
 # Suppress warnings in third-party code.
--- a/mfbt/Assertions.h
+++ b/mfbt/Assertions.h
@@ -4,20 +4,27 @@
  * 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/. */
 
 /* Implementations of runtime and static assertion macros for C and C++. */
 
 #ifndef mozilla_Assertions_h
 #define mozilla_Assertions_h
 
+#if defined(MOZILLA_INTERNAL_API) && defined(__cplusplus)
+#define MOZ_DUMP_ASSERTION_STACK
+#endif
+
 #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
 
 #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
@@ -127,28 +134,34 @@ extern "C" {
 static MOZ_ALWAYS_INLINE void
 MOZ_ReportAssertionFailure(const char* s, const char* file, int ln)
 {
 #ifdef ANDROID
   __android_log_print(ANDROID_LOG_FATAL, "MOZ_Assert",
                       "Assertion failure: %s, at %s:%d\n", s, file, ln);
 #else
   fprintf(stderr, "Assertion failure: %s, at %s:%d\n", s, file, ln);
+#ifdef MOZ_DUMP_ASSERTION_STACK
+  nsTraceRefcnt::WalkTheStack(stderr);
+#endif
   fflush(stderr);
 #endif
 }
 
 static MOZ_ALWAYS_INLINE void
 MOZ_ReportCrash(const char* s, const char* file, int ln)
 {
 #ifdef ANDROID
     __android_log_print(ANDROID_LOG_FATAL, "MOZ_CRASH",
                         "Hit MOZ_CRASH(%s) at %s:%d\n", s, file, ln);
 #else
   fprintf(stderr, "Hit MOZ_CRASH(%s) at %s:%d\n", s, file, ln);
+#ifdef MOZ_DUMP_ASSERTION_STACK
+  nsTraceRefcnt::WalkTheStack(stderr);
+#endif
   fflush(stderr);
 #endif
 }
 
 /**
  * MOZ_REALLY_CRASH is used in the implementation of MOZ_CRASH().  You should
  * call MOZ_CRASH instead.
  */
@@ -479,9 +492,11 @@ void ValidateAssertConditionType()
 #ifdef DEBUG
 #  define MOZ_ALWAYS_TRUE(expr)      MOZ_ASSERT((expr))
 #  define MOZ_ALWAYS_FALSE(expr)     MOZ_ASSERT(!(expr))
 #else
 #  define MOZ_ALWAYS_TRUE(expr)      ((void)(expr))
 #  define MOZ_ALWAYS_FALSE(expr)     ((void)(expr))
 #endif
 
+#undef MOZ_DUMP_ASSERTION_STACK
+
 #endif /* mozilla_Assertions_h */