Enable Linux stack walking code on Mac OS X. b=336517 r+a=bsmedberg
authordbaron@dbaron.org
Wed, 15 Aug 2007 17:03:29 -0700
changeset 4701 5c27a0fafb0f6720de04309a79b80a0b0d81796c
parent 4700 22cff1bbf34f2a7435eddf76095c917a6a238e23
child 4702 a99e7ad10e38c908d8d7d5d696adc764165adbf4
push idunknown
push userunknown
push dateunknown
bugs336517
milestone1.9a8pre
Enable Linux stack walking code on Mac OS X. b=336517 r+a=bsmedberg
xpcom/base/nsStackWalk.cpp
--- a/xpcom/base/nsStackWalk.cpp
+++ b/xpcom/base/nsStackWalk.cpp
@@ -1027,34 +1027,34 @@ 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 (defined(linux) && defined(__GNUC__) && (defined(__i386) || defined(PPC) || defined(__x86_64__))) || (defined(__sun) && (defined(__sparc) || defined(sparc) || defined(__i386) || defined(i386)))
+#elif (defined(linux) && defined(__GNUC__) && (defined(__i386) || defined(PPC) || defined(__x86_64__))) || (defined(__sun) && (defined(__sparc) || defined(sparc) || defined(__i386) || defined(i386))) || (defined(XP_MACOSX) && (defined(__ppc__) || defined(__i386)))
 
 #include <stdlib.h>
 #include <string.h>
 #include <math.h>
 #include "nscore.h"
 #include <stdio.h>
 #include "plstr.h"
 
 // On glibc 2.1, the Dl_info api defined in <dlfcn.h> is only exposed
 // if __USE_GNU is defined.  I suppose its some kind of standards
 // adherence thing.
 //
 #if (__GLIBC_MINOR__ >= 1) && !defined(__USE_GNU)
 #define __USE_GNU
 #endif
 
-#ifdef HAVE_LIBDL
+#if defined(HAVE_LIBDL) || defined(XP_MACOSX)
 #include <dlfcn.h>
 #endif
 
 
 
 // This thing is exported by libstdc++
 // Yes, this is a gcc only hack
 #if defined(MOZ_DEMANGLE_SYMBOLS)
@@ -1076,17 +1076,17 @@ void DemangleSymbol(const char * aSymbol
     {
         strncpy(aBuffer,demangled,aBufLen);
         free(demangled);
     }
 #endif // MOZ_DEMANGLE_SYMBOLS
 }
 
 
-#if defined(linux) && defined(__GNUC__) && (defined(__i386) || defined(PPC) || defined(__x86_64__)) // i386 or PPC Linux stackwalking code
+#if (defined(linux) && defined(__GNUC__) && (defined(__i386) || defined(PPC) || defined(__x86_64__))) || (defined(XP_MACOSX) && (defined(__i386) || defined(__ppc__))) // i386 or PPC Linux stackwalking code
 
 
 EXPORT_XPCOM_API(nsresult)
 NS_StackWalk(NS_WalkStackCallback aCallback, PRUint32 aSkipFrames,
              void *aClosure)
 {
   // Stack walking code courtesy Kipp's "leaky".
 
@@ -1100,17 +1100,21 @@ NS_StackWalk(NS_WalkStackCallback aCallb
   // It would be nice if this worked uniformly, but at least on i386 and
   // x86_64, it stopped working with gcc 4.1, because it points to the
   // end of the saved registers instead of the start.
   bp = (void**) __builtin_frame_address(0);
 #endif
 
   int skip = aSkipFrames;
   for ( ; (void**)*bp > bp; bp = (void**)*bp) {
+#if defined(__ppc__) && defined(XP_MACOSX) // other PPC platforms?
+    void *pc = *(bp+2);
+#else
     void *pc = *(bp+1);
+#endif
     if (--skip < 0) {
       (*aCallback)(pc, aClosure);
     }
   }
   return NS_OK;
 }
 
 EXPORT_XPCOM_API(nsresult)