From c9c3ab226246c7e0af81b790afcf9a08307be145 Mon Sep 17 00:00:00 2001 From: "warren%netscape.com" Date: Sun, 24 Oct 1999 22:01:09 +0000 Subject: [PATCH] Fixed up dll loading for Windows. It was silently failing. git-svn-id: svn://10.0.0.236/trunk@51694 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/xpcom/base/nsTraceRefcnt.cpp | 57 ++++++++++++++----- mozilla/xpcom/base/nsTraceRefcntImpl.cpp | 57 ++++++++++++++----- .../components/nsNativeComponentLoader.cpp | 7 --- mozilla/xpcom/components/xcDll.cpp | 16 ++++-- 4 files changed, 97 insertions(+), 40 deletions(-) diff --git a/mozilla/xpcom/base/nsTraceRefcnt.cpp b/mozilla/xpcom/base/nsTraceRefcnt.cpp index 8c68b3b42d7..16481427373 100644 --- a/mozilla/xpcom/base/nsTraceRefcnt.cpp +++ b/mozilla/xpcom/base/nsTraceRefcnt.cpp @@ -334,6 +334,7 @@ nsTraceRefcnt::DumpStatistics(StatisticsType type, FILE* out) #ifdef NS_BUILD_REFCNT_LOGGING if (gBloatLog == nsnull || gBloatView == nsnull) { fprintf(stdout, "### ERROR: Can't dump bloat statistics because XPCOM_MEM_BLOAT_LOG isn't set.\n"); + fflush(stdout); return NS_ERROR_FAILURE; } if (out == nsnull) { @@ -488,6 +489,7 @@ static void InitTraceLog(void) else { gLogToLeaky = PR_FALSE; fprintf(stdout, "### ERROR: XPCOM_MEM_LEAKY_LOG defined, but can't locate __log_addref and __log_release symbols\n"); + fflush(stdout); } } @@ -674,7 +676,8 @@ nsTraceRefcnt::WalkTheStack(FILE* aStream) 0, NULL ); - fprintf(stderr, "### ERROR: WalkStack: %s\n", lpMsgBuf); + fprintf(stdout, "### ERROR: WalkStack: %s", lpMsgBuf); + fflush(stdout); LocalFree( lpMsgBuf ); } if (!ok || frame.AddrPC.Offset == 0) @@ -902,22 +905,48 @@ nsTraceRefcnt::LoadLibrarySymbols(const char* aLibraryName, InitTraceLog(); if (gAllocLog || gRefcntsLog) { + fprintf(stdout, "### Loading symbols for %s\n", aLibraryName); + fflush(stdout); + HANDLE myProcess = ::GetCurrentProcess(); - if (!SymInitialize(myProcess, ".;..\\lib", TRUE)) { - return; + BOOL ok = SymInitialize(myProcess, ".;..\\lib", FALSE); + if (ok) { + const char* baseName = aLibraryName; + // just get the base name of the library if a full path was given: + PRInt32 len = nsCRT::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 ); } - - BOOL b = ::SymLoadModule(myProcess, - NULL, - (char*)aLibraryName, - (char*)aLibraryName, - 0, - 0); -// DWORD lastError = 0; -// if (!b) lastError = ::GetLastError(); -// fprintf(gLogStream, "loading symbols for library %s => %s [%d]\n", aLibraryName, -// b ? "true" : "false", lastError); } #endif #endif diff --git a/mozilla/xpcom/base/nsTraceRefcntImpl.cpp b/mozilla/xpcom/base/nsTraceRefcntImpl.cpp index 8c68b3b42d7..16481427373 100644 --- a/mozilla/xpcom/base/nsTraceRefcntImpl.cpp +++ b/mozilla/xpcom/base/nsTraceRefcntImpl.cpp @@ -334,6 +334,7 @@ nsTraceRefcnt::DumpStatistics(StatisticsType type, FILE* out) #ifdef NS_BUILD_REFCNT_LOGGING if (gBloatLog == nsnull || gBloatView == nsnull) { fprintf(stdout, "### ERROR: Can't dump bloat statistics because XPCOM_MEM_BLOAT_LOG isn't set.\n"); + fflush(stdout); return NS_ERROR_FAILURE; } if (out == nsnull) { @@ -488,6 +489,7 @@ static void InitTraceLog(void) else { gLogToLeaky = PR_FALSE; fprintf(stdout, "### ERROR: XPCOM_MEM_LEAKY_LOG defined, but can't locate __log_addref and __log_release symbols\n"); + fflush(stdout); } } @@ -674,7 +676,8 @@ nsTraceRefcnt::WalkTheStack(FILE* aStream) 0, NULL ); - fprintf(stderr, "### ERROR: WalkStack: %s\n", lpMsgBuf); + fprintf(stdout, "### ERROR: WalkStack: %s", lpMsgBuf); + fflush(stdout); LocalFree( lpMsgBuf ); } if (!ok || frame.AddrPC.Offset == 0) @@ -902,22 +905,48 @@ nsTraceRefcnt::LoadLibrarySymbols(const char* aLibraryName, InitTraceLog(); if (gAllocLog || gRefcntsLog) { + fprintf(stdout, "### Loading symbols for %s\n", aLibraryName); + fflush(stdout); + HANDLE myProcess = ::GetCurrentProcess(); - if (!SymInitialize(myProcess, ".;..\\lib", TRUE)) { - return; + BOOL ok = SymInitialize(myProcess, ".;..\\lib", FALSE); + if (ok) { + const char* baseName = aLibraryName; + // just get the base name of the library if a full path was given: + PRInt32 len = nsCRT::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 ); } - - BOOL b = ::SymLoadModule(myProcess, - NULL, - (char*)aLibraryName, - (char*)aLibraryName, - 0, - 0); -// DWORD lastError = 0; -// if (!b) lastError = ::GetLastError(); -// fprintf(gLogStream, "loading symbols for library %s => %s [%d]\n", aLibraryName, -// b ? "true" : "false", lastError); } #endif #endif diff --git a/mozilla/xpcom/components/nsNativeComponentLoader.cpp b/mozilla/xpcom/components/nsNativeComponentLoader.cpp index 2cff4185be2..7d3b3819e6c 100644 --- a/mozilla/xpcom/components/nsNativeComponentLoader.cpp +++ b/mozilla/xpcom/components/nsNativeComponentLoader.cpp @@ -129,13 +129,6 @@ nsNativeComponentLoader::GetFactory(const nsIID & aCID, } } -#ifdef NS_BUILD_REFCNT_LOGGING - // Inform refcnt tracer of new library so that calls through the - // new library can be traced. - nsTraceRefcnt::LoadLibrarySymbols(dll->GetNativePath(), - dll->GetInstance()); -#endif - /* Get service manager for factory */ nsIServiceManager* serviceMgr = NULL; rv = nsServiceManager::GetGlobalServiceManager(&serviceMgr); diff --git a/mozilla/xpcom/components/xcDll.cpp b/mozilla/xpcom/components/xcDll.cpp index 224233cccfd..5506051e369 100644 --- a/mozilla/xpcom/components/xcDll.cpp +++ b/mozilla/xpcom/components/xcDll.cpp @@ -281,14 +281,20 @@ PRBool nsDll::Load(void) nsCRT::free(nsprPath); #else - - nsFileSpec fileSpec; - m_dllSpec->GetFileSpec(&fileSpec); - FSSpec libSpec = fileSpec.GetFSSpec(); - m_instance = PR_LoadIndexedFragment(&libSpec, 0); + nsFileSpec fileSpec; + m_dllSpec->GetFileSpec(&fileSpec); + FSSpec libSpec = fileSpec.GetFSSpec(); + m_instance = PR_LoadIndexedFragment(&libSpec, 0); #endif /* XP_MAC */ } +#ifdef NS_BUILD_REFCNT_LOGGING + if (m_instance) { + // Inform refcnt tracer of new library so that calls through the + // new library can be traced. + nsTraceRefcnt::LoadLibrarySymbols(GetNativePath(), GetInstance()); + } +#endif return ((m_instance == NULL) ? PR_FALSE : PR_TRUE); }