Remove nsTraceRefcnt::LoadLibrarySymbols, which is no longer needed due to the error handling in SymGetModuleInfoEspecial. b=391793 r+a=bsmedberg
authordbaron@dbaron.org
Mon, 13 Aug 2007 12:36:57 -0700
changeset 4571 a03831062314f20de7c9c49db9f70c9b19164702
parent 4570 2dfc71975e82a39c742252f54d7db3c551357ace
child 4572 76e63cbe4d5ea891ea4f8620f4da709a447bb240
push idunknown
push userunknown
push dateunknown
bugs391793
milestone1.9a8pre
Remove nsTraceRefcnt::LoadLibrarySymbols, which is no longer needed due to the error handling in SymGetModuleInfoEspecial. b=391793 r+a=bsmedberg
xpcom/base/nsStackFrameWin.cpp
xpcom/base/nsTraceRefcntImpl.cpp
xpcom/base/nsTraceRefcntImpl.h
xpcom/components/nsNativeComponentLoader.cpp
--- a/xpcom/base/nsStackFrameWin.cpp
+++ b/xpcom/base/nsStackFrameWin.cpp
@@ -446,18 +446,18 @@ EnsureSymInitialized()
 EXPORT_XPCOM_API(nsresult)
 NS_StackWalk(NS_WalkStackCallback aCallback, PRUint32 aSkipFrames,
              void *aClosure)
 {
     HANDLE myProcess, myThread, walkerThread;
     DWORD walkerReturn;
     struct WalkStackData data;
 
-    if (!EnsureSymInitialized())
-        return NS_ERROR_FAILURE;
+    if (!EnsureImageHlpInitialized())
+        return PR_FALSE;
 
     // Have to duplicate handle to get a real handle.
     if (!::DuplicateHandle(::GetCurrentProcess(),
                            ::GetCurrentProcess(),
                            ::GetCurrentProcess(),
                            &myProcess,
                            THREAD_ALL_ACCESS, FALSE, 0)) {
         PrintError("DuplicateHandle (process)");
@@ -734,16 +734,19 @@ NS_DescribeCodeAddress(void *aPC, nsCode
 {
     aDetails->library[0] = '\0';
     aDetails->loffset = 0;
     aDetails->filename[0] = '\0';
     aDetails->lineno = 0;
     aDetails->function[0] = '\0';
     aDetails->foffset = 0;
 
+    if (!EnsureSymInitialized())
+        return NS_ERROR_FAILURE;
+
     HANDLE myProcess = ::GetCurrentProcess();
     BOOL ok;
 
     // debug routines are not threadsafe, so grab the lock.
     DWORD dwWaitResult;
     dwWaitResult = WaitForSingleObject(hStackWalkMutex, INFINITE);
     if (dwWaitResult != WAIT_OBJECT_0)
         return NS_ERROR_UNEXPECTED;
--- a/xpcom/base/nsTraceRefcntImpl.cpp
+++ b/xpcom/base/nsTraceRefcntImpl.cpp
@@ -45,21 +45,16 @@
 #include "plstr.h"
 #include "prlink.h"
 #include <stdlib.h>
 #include "nsCOMPtr.h"
 #include "nsCRT.h"
 #include <math.h>
 #include "nsStackWalk.h"
 
-#if defined(_WIN32)
-#include <windows.h>
-#include "nsStackFrameWin.h" // XXX LoadLibrarySymbols no longer belongs here
-#endif
-
 #ifdef HAVE_LIBDL
 #include <dlfcn.h>
 #endif
 
 ////////////////////////////////////////////////////////////////////////////////
 
 NS_COM void 
 NS_MeanAndStdDev(double n, double sumOfValues, double sumOfSquaredValues,
@@ -878,75 +873,16 @@ nsTraceRefcntImpl::DemangleSymbol(const 
     free(demangled);
   }
 #endif // MOZ_DEMANGLE_SYMBOLS
 }
 
 
 //----------------------------------------------------------------------
 
-NS_COM void
-nsTraceRefcntImpl::LoadLibrarySymbols(const char* aLibraryName,
-                                  void* aLibrayHandle)
-{
-#ifdef NS_IMPL_REFCNT_LOGGING
-#if defined(_WIN32) && defined(_M_IX86) /* Win32 x86 only */
-  if (!gInitialized)
-    InitTraceLog();
-
-  if (gAllocLog || gRefcntsLog) {
-    fprintf(stdout, "### Loading symbols for %s\n", aLibraryName);
-    fflush(stdout);
-
-    HANDLE myProcess = ::GetCurrentProcess();    
-    BOOL ok = EnsureSymInitialized();
-    if (ok) {
-      const char* baseName = aLibraryName;
-      // just get the base name of the library if a full path was given:
-      PRInt32 len = strlen(aLibraryName);
-      for (PRInt32 i = len - 1; i >= 0; i--) {
-        if (aLibraryName[i] == '\\') {
-          baseName = &aLibraryName[i + 1];
-          break;
-        }
-      }
-      DWORD baseAddr = _SymLoadModule(myProcess,
-                                     NULL,
-                                     (char*)baseName,
-                                     (char*)baseName,
-                                     0,
-                                     0);
-      ok = (baseAddr != nsnull);
-    }
-    if (!ok) {
-      LPVOID lpMsgBuf;
-      FormatMessage( 
-        FORMAT_MESSAGE_ALLOCATE_BUFFER | 
-        FORMAT_MESSAGE_FROM_SYSTEM | 
-        FORMAT_MESSAGE_IGNORE_INSERTS,
-        NULL,
-        GetLastError(),
-        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
-        (LPTSTR) &lpMsgBuf,
-        0,
-        NULL 
-        );
-      fprintf(stdout, "### ERROR: LoadLibrarySymbols for %s: %s\n",
-              aLibraryName, lpMsgBuf);
-      fflush(stdout);
-      LocalFree( lpMsgBuf );
-    }
-  }
-#endif
-#endif
-}
-
-//----------------------------------------------------------------------
-
-
 EXPORT_XPCOM_API(void)
 NS_LogInit()
 {
 #ifdef NS_IMPL_REFCNT_LOGGING
   if (++gInitCount)
     nsTraceRefcntImpl::SetActivityIsLegal(PR_TRUE);
 #endif
 }
--- a/xpcom/base/nsTraceRefcntImpl.h
+++ b/xpcom/base/nsTraceRefcntImpl.h
@@ -55,20 +55,16 @@ public:
     NEW_STATS
   };
 
   static NS_COM nsresult DumpStatistics(StatisticsType type = ALL_STATS,
                                         FILE* out = 0);
   
   static NS_COM void ResetStatistics(void);
 
-  static NS_COM void LoadLibrarySymbols(const char* aLibraryName,
-                                        void* aLibrayHandle);
-
-
   static NS_COM void DemangleSymbol(const char * aSymbol, 
                                     char * aBuffer,
                                     int aBufLen);
 
   static NS_COM void WalkTheStack(FILE* aStream);
   /**
    * Tell nsTraceRefcnt whether refcounting, allocation, and destruction
    * activity is legal.  This is used to trigger assertions for any such
--- a/xpcom/components/nsNativeComponentLoader.cpp
+++ b/xpcom/components/nsNativeComponentLoader.cpp
@@ -153,22 +153,16 @@ nsNativeModuleLoader::LoadModule(nsILoca
                 "nsNativeModuleLoader::LoadModule(\"%s\") - load FAILED, "
                 "rv: %lx, error:\n\t%s\n",
                 filePath.get(), rv, errorMsg);
 #endif
 
         return rv;
     }
 
-#ifdef NS_BUILD_REFCNT_LOGGING
-    // Inform refcnt tracer of new library so that calls through the
-    // new library can be traced.
-    nsTraceRefcntImpl::LoadLibrarySymbols(filePath.get(), data.library);
-#endif
-
 #ifdef IMPLEMENT_BREAK_AFTER_LOAD
     nsCAutoString leafName;
     aFile->GetNativeLeafName(leafName);
 
     char *env = getenv("XPCOM_BREAK_ON_LOAD");
     char *blist;
     if (env && *env && (blist = strdup(env))) {
         char *nextTok = blist;