Bug 708031 - refactor the ifdefs in nsStackWalk.cpp. r=dbaron.
authorRafael Ávila de Espíndola <respindola@mozilla.com>
Thu, 22 Dec 2011 11:00:48 -0500
changeset 84485 6707b24155987811ad405d6158f19ad0f2910b45
parent 84484 38344f96b3e3763be2d1d4d919e3615ac2fa640d
child 84486 13a57f89f8cc91f584d7653c85b5d6acab3952cc
push id805
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 18:17:35 +0000
treeherdermozilla-aurora@6fb3bf232436 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdbaron
bugs708031
milestone12.0a1
Bug 708031 - refactor the ifdefs in nsStackWalk.cpp. r=dbaron.
xpcom/base/nsStackWalk.cpp
--- a/xpcom/base/nsStackWalk.cpp
+++ b/xpcom/base/nsStackWalk.cpp
@@ -53,17 +53,30 @@ struct CriticalAddress {
   bool mInit;
 };
 static CriticalAddress gCriticalAddress;
 
 #if defined(HAVE_DLOPEN) || defined(XP_MACOSX)
 #include <dlfcn.h>
 #endif
 
-#if defined(XP_MACOSX) && (defined(__i386) || defined(__ppc__) || defined(HAVE__UNWIND_BACKTRACE))
+#define NSSTACKWALK_SUPPORTS_MACOSX \
+    (defined(XP_MACOSX) && \
+     (defined(__i386) || defined(__ppc__) || defined(HAVE__UNWIND_BACKTRACE)))
+
+#define NSSTACKWALK_SUPPORTS_LINUX \
+    (defined(linux) && \
+     ((defined(__GNUC__) && (defined(__i386) || defined(PPC))) || \
+      defined(HAVE__UNWIND_BACKTRACE)))
+
+#define NSSTACKWALK_SUPPORTS_SOLARIS \
+    (defined(__sun) && \
+     (defined(__sparc) || defined(sparc) || defined(__i386) || defined(i386)))
+
+#if NSSTACKWALK_SUPPORTS_MACOSX
 #include <pthread.h>
 #include <errno.h>
 #include <CoreServices/CoreServices.h>
 
 typedef void
 malloc_logger_t(uint32_t type, uintptr_t arg1, uintptr_t arg2, uintptr_t arg3,
                 uintptr_t result, uint32_t num_hot_frames_to_skip);
 extern malloc_logger_t *malloc_logger;
@@ -1246,17 +1259,17 @@ NS_FormatCodeAddressDetails(void *aPC, c
     }
     aBuffer[aBufferSize - 2] = '\n';
     aBuffer[aBufferSize - 1] = '\0';
     return NS_OK;
 }
 
 // WIN32 x86 stack walking code
 // i386 or PPC Linux stackwalking code or Solaris
-#elif HAVE_DLADDR && (HAVE__UNWIND_BACKTRACE || (defined(linux) && defined(__GNUC__) && (defined(__i386) || defined(PPC))) || (defined(__sun) && (defined(__sparc) || defined(sparc) || defined(__i386) || defined(i386))) || (defined(XP_MACOSX) && (defined(__ppc__) || defined(__i386))))
+#elif HAVE_DLADDR && (HAVE__UNWIND_BACKTRACE || NSSTACKWALK_SUPPORTS_LINUX || NSSTACKWALK_SUPPORTS_SOLARIS || NSSTACKWALK_SUPPORTS_MACOSX)
 
 #include <stdlib.h>
 #include <string.h>
 #include <math.h>
 #include "nscore.h"
 #include <stdio.h>
 #include "plstr.h"
 
@@ -1289,17 +1302,17 @@ void DemangleSymbol(const char * aSymbol
     {
         strncpy(aBuffer,demangled,aBufLen);
         free(demangled);
     }
 #endif // MOZ_DEMANGLE_SYMBOLS
 }
 
 
-#if defined(__sun) && (defined(__sparc) || defined(sparc) || defined(__i386) || defined(i386))
+#if NSSTACKWALK_SUPPORTS_SOLARIS
 
 /*
  * Stack walking code for Solaris courtesy of Bart Smaalder's "memtrak".
  */
 
 #include <synch.h>
 #include <ucontext.h>
 #include <sys/frame.h>
@@ -1528,17 +1541,18 @@ NS_FormatCodeAddressDetails(void *aPC, c
              aDetails->library[0] ? aDetails->library : "??",
              aDetails->function[0] ? aDetails->function : "??",
              aDetails->foffset);
     return NS_OK;
 }
 
 #else // not __sun-specific
 
-#if (defined(linux) && defined(__GNUC__) && (defined(__i386) || defined(PPC))) || (defined(XP_MACOSX) && (defined(__i386) || defined(__ppc__))) // i386 or PPC Linux or Mac stackwalking code
+#define X86_OR_PPC (defined(__i386) || defined(PPC) || defined(__ppc__))
+#if X86_OR_PPC && (NSSTACKWALK_SUPPORTS_MACOSX || NSSTACKWALK_SUPPORTS_LINUX) // i386 or PPC Linux or Mac stackwalking code
 
 #if __GLIBC__ > 2 || __GLIBC_MINOR > 1
 #define HAVE___LIBC_STACK_END 1
 #else
 #define HAVE___LIBC_STACK_END 0
 #endif
 
 #if HAVE___LIBC_STACK_END