1999-09-01 01:40:21 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2001-09-29 00:14:13 +04:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
1999-02-02 01:40:48 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 1.1 (the "License"); you may not use this file except in
|
|
|
|
* compliance with the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/NPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
1999-02-02 01:40:48 +03:00
|
|
|
*
|
1999-11-06 06:43:54 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 06:43:54 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the NPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the NPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1999-02-02 01:40:48 +03:00
|
|
|
|
1999-02-03 18:39:13 +03:00
|
|
|
/* nsDll
|
1999-02-02 01:40:48 +03:00
|
|
|
*
|
|
|
|
* Abstraction of a Dll. Stores modifiedTime and size for easy detection of
|
|
|
|
* change in dll.
|
|
|
|
*
|
|
|
|
* dp Suresh <dp@netscape.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "xcDll.h"
|
1999-08-09 04:19:08 +04:00
|
|
|
#include "nsDebug.h"
|
1999-06-22 18:02:58 +04:00
|
|
|
#include "nsIComponentManager.h"
|
2002-06-15 01:33:05 +04:00
|
|
|
#include "nsIComponentLoaderManager.h"
|
1999-08-09 04:19:08 +04:00
|
|
|
#include "nsIModule.h"
|
2000-01-25 00:28:28 +03:00
|
|
|
#include "nsILocalFile.h"
|
2003-03-05 06:22:12 +03:00
|
|
|
#include "nsDirectoryServiceDefs.h"
|
|
|
|
#include "nsDirectoryServiceUtils.h"
|
1999-08-13 23:27:58 +04:00
|
|
|
#include "nsCOMPtr.h"
|
2000-01-25 00:28:28 +03:00
|
|
|
#include "nsCRT.h"
|
2000-01-28 12:44:05 +03:00
|
|
|
#include "nsString.h"
|
2001-08-17 06:03:34 +04:00
|
|
|
#include "nsITimelineService.h"
|
2001-11-28 06:52:34 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
#if defined(VMS)
|
2000-02-22 01:56:55 +03:00
|
|
|
#include <lib$routines.h>
|
|
|
|
#include <ssdef.h>
|
2001-11-28 06:52:34 +03:00
|
|
|
#elif defined(XP_MACOSX)
|
|
|
|
#include <signal.h>
|
2000-02-22 01:56:55 +03:00
|
|
|
#endif
|
2001-11-28 06:52:34 +03:00
|
|
|
#endif /* defined(DEBUG) */
|
1999-10-06 05:09:13 +04:00
|
|
|
|
2002-01-24 04:29:40 +03:00
|
|
|
#include "nsNativeComponentLoader.h"
|
|
|
|
|
2003-03-05 06:22:12 +03:00
|
|
|
extern nsresult NS_GetComponentLoaderManager(nsIComponentLoaderManager* *result);
|
1999-09-14 02:34:42 +04:00
|
|
|
|
2003-03-05 06:22:12 +03:00
|
|
|
nsDll::nsDll(nsIFile *dllSpec,
|
|
|
|
const char *registryLocation)
|
|
|
|
:
|
|
|
|
m_dllSpec(do_QueryInterface(dllSpec)),
|
|
|
|
m_instance(NULL),
|
|
|
|
m_status(DLL_OK),
|
|
|
|
m_moduleObject(NULL),
|
|
|
|
m_markForUnload(PR_FALSE)
|
1999-02-02 01:40:48 +03:00
|
|
|
{
|
2003-03-05 06:22:12 +03:00
|
|
|
NS_ASSERTION(registryLocation, "registryLocation is null");
|
2000-01-25 00:28:28 +03:00
|
|
|
|
1999-09-01 01:40:21 +04:00
|
|
|
m_registryLocation = nsCRT::strdup(registryLocation);
|
1999-02-09 23:30:34 +03:00
|
|
|
}
|
|
|
|
|
1999-02-03 18:39:13 +03:00
|
|
|
nsDll::~nsDll(void)
|
1999-02-02 01:40:48 +03:00
|
|
|
{
|
2002-06-21 23:58:54 +04:00
|
|
|
#if DEBUG_dougt
|
1999-09-28 23:42:06 +04:00
|
|
|
// The dll gets deleted when the dllStore is destroyed. This happens on
|
|
|
|
// app shutdown. At that point, unloading dlls can cause crashes if we have
|
|
|
|
// - dll dependencies
|
|
|
|
// - callbacks
|
|
|
|
// - static dtors
|
|
|
|
// Hence turn it back on after all the above have been removed.
|
1999-07-31 04:28:51 +04:00
|
|
|
Unload();
|
1999-09-28 23:42:06 +04:00
|
|
|
#endif
|
1999-09-01 01:40:21 +04:00
|
|
|
if (m_registryLocation)
|
|
|
|
nsCRT::free(m_registryLocation);
|
1999-02-02 01:40:48 +03:00
|
|
|
}
|
|
|
|
|
1999-06-22 18:02:58 +04:00
|
|
|
const char *
|
2000-01-25 00:28:28 +03:00
|
|
|
nsDll::GetDisplayPath()
|
1999-06-22 18:02:58 +04:00
|
|
|
{
|
2003-03-05 06:22:12 +03:00
|
|
|
if (m_registryLocation)
|
|
|
|
return m_registryLocation;
|
|
|
|
return "unknown!";
|
1999-06-22 18:02:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsDll::HasChanged()
|
|
|
|
{
|
2002-06-15 01:33:05 +04:00
|
|
|
nsCOMPtr<nsIComponentLoaderManager> manager;
|
|
|
|
NS_GetComponentLoaderManager(getter_AddRefs(manager));
|
|
|
|
if (!manager)
|
|
|
|
return PR_TRUE;
|
|
|
|
|
1999-06-22 18:02:58 +04:00
|
|
|
// If mod date has changed, then dll has changed
|
2000-01-25 00:28:28 +03:00
|
|
|
PRInt64 currentDate;
|
2001-11-26 11:05:05 +03:00
|
|
|
nsresult rv = m_dllSpec->GetLastModifiedTime(¤tDate);
|
2003-03-05 06:22:12 +03:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return PR_TRUE;
|
2002-06-15 01:33:05 +04:00
|
|
|
PRBool changed = PR_TRUE;
|
|
|
|
manager->HasFileChanged(m_dllSpec, nsnull, currentDate, &changed);
|
|
|
|
return changed;
|
1999-06-22 18:02:58 +04:00
|
|
|
}
|
|
|
|
|
1999-02-03 18:39:13 +03:00
|
|
|
PRBool nsDll::Load(void)
|
1999-02-02 01:40:48 +03:00
|
|
|
{
|
|
|
|
if (m_status != DLL_OK)
|
|
|
|
{
|
|
|
|
return (PR_FALSE);
|
|
|
|
}
|
|
|
|
if (m_instance != NULL)
|
|
|
|
{
|
|
|
|
// Already loaded
|
|
|
|
return (PR_TRUE);
|
|
|
|
}
|
1999-06-22 18:02:58 +04:00
|
|
|
|
2000-01-25 00:28:28 +03:00
|
|
|
if (m_dllSpec)
|
1999-06-22 18:02:58 +04:00
|
|
|
{
|
2000-12-23 19:43:32 +03:00
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
nsTraceRefcnt::SetActivityIsLegal(PR_FALSE);
|
|
|
|
#endif
|
2000-01-25 00:28:28 +03:00
|
|
|
|
2003-03-05 06:22:12 +03:00
|
|
|
// Load any library dependencies
|
|
|
|
// The Component Loader Manager may hold onto some extra data
|
|
|
|
// set by either the native component loader or the native
|
|
|
|
// component. We assume that this data is a space delimited
|
|
|
|
// listing of dependent libraries which are required to be
|
|
|
|
// loaded prior to us loading the given component. Once, the
|
|
|
|
// component is loaded into memory, we can release our hold
|
|
|
|
// on the dependent libraries with the assumption that the
|
|
|
|
// component library holds a reference via the OS so loader.
|
|
|
|
|
|
|
|
nsCOMPtr<nsIComponentLoaderManager> manager;
|
|
|
|
NS_GetComponentLoaderManager(getter_AddRefs(manager));
|
|
|
|
if (!manager)
|
|
|
|
return PR_TRUE;
|
|
|
|
|
|
|
|
#if defined(XP_UNIX) && !defined(MACOSX)
|
|
|
|
nsXPIDLCString extraData;
|
|
|
|
manager->GetOptionalData(m_dllSpec, m_registryLocation, getter_Copies(extraData));
|
|
|
|
|
|
|
|
nsVoidArray dependentLibArray;
|
|
|
|
|
|
|
|
// if there was any extra data, treat it as a listing of dependent libs
|
|
|
|
if (extraData != nsnull)
|
|
|
|
{
|
|
|
|
|
|
|
|
// all dependent libraries are suppose to be in the "gre" directory.
|
|
|
|
// note that the gre directory is the same as the "bin" directory,
|
|
|
|
// when there isn't a real "gre" found.
|
|
|
|
|
|
|
|
nsXPIDLCString path;
|
|
|
|
nsCOMPtr<nsIFile> file;
|
|
|
|
NS_GetSpecialDirectory(NS_GRE_DIR, getter_AddRefs(file));
|
|
|
|
|
|
|
|
if (!file)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
// we are talking about a file in the GRE dir. Lets append something
|
|
|
|
// stupid right now, so that later we can just set the leaf name.
|
|
|
|
file->AppendNative(NS_LITERAL_CSTRING("dummy"));
|
|
|
|
|
|
|
|
char *buffer = strdup(extraData);
|
|
|
|
if (!buffer)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
char* newStr;
|
|
|
|
char *token = nsCRT::strtok(buffer, " ", &newStr);
|
|
|
|
while (token!=nsnull)
|
|
|
|
{
|
|
|
|
nsXPIDLCString libpath;
|
|
|
|
file->SetNativeLeafName(nsDependentCString(token));
|
|
|
|
file->GetNativePath(path);
|
|
|
|
if (!path)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
// Load this dependent library with the global flag and stash
|
|
|
|
// the result for later so that we can unload it.
|
|
|
|
PRLibSpec libSpec;
|
|
|
|
libSpec.type = PR_LibSpec_Pathname;
|
|
|
|
|
|
|
|
// if the depend library path starts with a / we are
|
|
|
|
// going to assume that it is a full path and should
|
|
|
|
// be loaded without prepending the gre diretory
|
|
|
|
// location. We could have short circuited the
|
|
|
|
// SetNativeLeafName above, but this is clearer and
|
|
|
|
// the common case is a relative path.
|
|
|
|
|
|
|
|
if (token[0] == '/')
|
|
|
|
libSpec.value.pathname = token;
|
|
|
|
else
|
|
|
|
libSpec.value.pathname = path;
|
|
|
|
|
|
|
|
PRLibrary* lib = PR_LoadLibraryWithFlags(libSpec, PR_LD_LAZY|PR_LD_GLOBAL);
|
|
|
|
// if we couldn't load the dependent library. We did the best we
|
|
|
|
// can. Now just let us fail later if this really was a required
|
|
|
|
// dependency.
|
|
|
|
if (lib)
|
|
|
|
dependentLibArray.AppendElement((void*)lib);
|
|
|
|
|
|
|
|
token = nsCRT::strtok(newStr, " ", &newStr);
|
2003-03-01 00:30:35 +03:00
|
|
|
}
|
2003-03-05 06:22:12 +03:00
|
|
|
free(buffer);
|
2003-03-01 00:30:35 +03:00
|
|
|
}
|
2003-03-05 06:22:12 +03:00
|
|
|
#endif
|
|
|
|
// load the component
|
|
|
|
|
|
|
|
nsCOMPtr<nsILocalFile> lf(do_QueryInterface(m_dllSpec));
|
|
|
|
NS_ASSERTION(lf, "nsIFile here must implement a nsILocalFile");
|
|
|
|
lf->Load(&m_instance);
|
|
|
|
|
|
|
|
#if defined(XP_UNIX) && !defined(MACOSX)
|
|
|
|
// Unload any of library dependencies we loaded earlier. The assumption
|
|
|
|
// here is that the component will have a "internal" reference count to
|
|
|
|
// the dependency library we just loaded.
|
|
|
|
// XXX should we unload later - or even at all?
|
|
|
|
|
|
|
|
if (extraData != nsnull)
|
2003-03-04 00:00:07 +03:00
|
|
|
{
|
2003-03-05 06:22:12 +03:00
|
|
|
PRInt32 arrayCount = dependentLibArray.Count();
|
|
|
|
for (PRInt32 index = 0; index < arrayCount; index++)
|
|
|
|
PR_UnloadLibrary((PRLibrary*)dependentLibArray.ElementAt(index));
|
|
|
|
}
|
2003-03-03 04:19:58 +03:00
|
|
|
#endif
|
|
|
|
|
2000-01-25 00:28:28 +03:00
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
2000-12-23 19:43:32 +03:00
|
|
|
nsTraceRefcnt::SetActivityIsLegal(PR_TRUE);
|
2000-01-25 00:28:28 +03:00
|
|
|
if (m_instance) {
|
|
|
|
// Inform refcnt tracer of new library so that calls through the
|
|
|
|
// new library can be traced.
|
2003-03-05 06:22:12 +03:00
|
|
|
nsCAutoString displayPath;
|
|
|
|
m_dllSpec->GetNativePath(displayPath);
|
|
|
|
nsTraceRefcnt::LoadLibrarySymbols(displayPath.get(), m_instance);
|
2000-01-25 00:28:28 +03:00
|
|
|
}
|
2003-03-05 06:22:12 +03:00
|
|
|
#endif
|
1999-06-22 18:02:58 +04:00
|
|
|
}
|
2000-01-25 00:28:28 +03:00
|
|
|
|
2003-03-05 06:22:12 +03:00
|
|
|
#ifdef SHOULD_IMPLEMENT_BREAKAFTERLOAD
|
2000-01-28 12:44:05 +03:00
|
|
|
// Debugging help for components. Component dlls need to have their
|
|
|
|
// symbols loaded before we can put a breakpoint in the debugger.
|
|
|
|
// This will help figureing out the point when the dll was loaded.
|
|
|
|
BreakAfterLoad(GetDisplayPath());
|
|
|
|
#endif
|
|
|
|
|
1999-06-22 18:02:58 +04:00
|
|
|
return ((m_instance == NULL) ? PR_FALSE : PR_TRUE);
|
1999-02-02 01:40:48 +03:00
|
|
|
}
|
|
|
|
|
1999-02-03 18:39:13 +03:00
|
|
|
PRBool nsDll::Unload(void)
|
1999-02-02 01:40:48 +03:00
|
|
|
{
|
|
|
|
if (m_status != DLL_OK || m_instance == NULL)
|
|
|
|
return (PR_FALSE);
|
1999-08-09 04:19:08 +04:00
|
|
|
|
1999-09-26 22:06:41 +04:00
|
|
|
// Shutdown the dll
|
|
|
|
Shutdown();
|
1999-08-09 04:19:08 +04:00
|
|
|
|
2000-12-23 19:43:32 +03:00
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
nsTraceRefcnt::SetActivityIsLegal(PR_FALSE);
|
|
|
|
#endif
|
1999-02-02 01:40:48 +03:00
|
|
|
PRStatus ret = PR_UnloadLibrary(m_instance);
|
2000-12-23 19:43:32 +03:00
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
nsTraceRefcnt::SetActivityIsLegal(PR_TRUE);
|
|
|
|
#endif
|
|
|
|
|
1999-02-02 01:40:48 +03:00
|
|
|
if (ret == PR_SUCCESS)
|
|
|
|
{
|
|
|
|
m_instance = NULL;
|
|
|
|
return (PR_TRUE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return (PR_FALSE);
|
|
|
|
}
|
|
|
|
|
1999-02-03 18:39:13 +03:00
|
|
|
void * nsDll::FindSymbol(const char *symbol)
|
1999-02-02 01:40:48 +03:00
|
|
|
{
|
|
|
|
if (symbol == NULL)
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
// If not already loaded, load it now.
|
|
|
|
if (Load() != PR_TRUE)
|
|
|
|
return (NULL);
|
|
|
|
|
1999-09-01 01:40:21 +04:00
|
|
|
return(PR_FindSymbol(m_instance, symbol));
|
1999-02-02 01:40:48 +03:00
|
|
|
}
|
1999-08-09 04:19:08 +04:00
|
|
|
|
|
|
|
|
|
|
|
// Component dll specific functions
|
2000-01-25 00:28:28 +03:00
|
|
|
nsresult nsDll::GetDllSpec(nsIFile **fsobj)
|
1999-08-09 04:19:08 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(m_dllSpec, "m_dllSpec NULL");
|
|
|
|
NS_ASSERTION(fsobj, "xcDll::GetModule : Null argument" );
|
|
|
|
|
|
|
|
*fsobj = m_dllSpec;
|
2000-01-25 00:28:28 +03:00
|
|
|
NS_ADDREF(*fsobj);
|
1999-08-09 04:19:08 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsDll::GetModule(nsISupports *servMgr, nsIModule **cobj)
|
|
|
|
{
|
2001-12-19 03:12:41 +03:00
|
|
|
nsCOMPtr<nsIComponentManager> compMgr;
|
|
|
|
nsresult rv = NS_GetComponentManager(getter_AddRefs(compMgr));
|
1999-08-13 23:27:58 +04:00
|
|
|
NS_ASSERTION(compMgr, "Global Component Manager is null" );
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
1999-08-09 04:19:08 +04:00
|
|
|
NS_ASSERTION(cobj, "xcDll::GetModule : Null argument" );
|
|
|
|
|
|
|
|
if (m_moduleObject)
|
|
|
|
{
|
|
|
|
NS_ADDREF(m_moduleObject);
|
|
|
|
*cobj = m_moduleObject;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If not already loaded, load it now.
|
|
|
|
if (Load() != PR_TRUE) return NS_ERROR_FAILURE;
|
|
|
|
|
2003-03-05 06:22:12 +03:00
|
|
|
// We need a nsIFile for location
|
|
|
|
if (!m_dllSpec)
|
1999-08-09 04:19:08 +04:00
|
|
|
{
|
2003-03-05 06:22:12 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
1999-08-09 04:19:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsGetModuleProc proc =
|
|
|
|
(nsGetModuleProc) FindSymbol(NS_GET_MODULE_SYMBOL);
|
|
|
|
|
1999-09-01 01:40:21 +04:00
|
|
|
if (proc == NULL)
|
|
|
|
return NS_ERROR_FACTORY_NOT_LOADED;
|
1999-08-09 04:19:08 +04:00
|
|
|
|
1999-08-13 23:27:58 +04:00
|
|
|
rv = (*proc) (compMgr, m_dllSpec, &m_moduleObject);
|
1999-08-09 04:19:08 +04:00
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
{
|
|
|
|
NS_ADDREF(m_moduleObject);
|
|
|
|
*cobj = m_moduleObject;
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
1999-09-26 22:06:41 +04:00
|
|
|
|
2000-06-28 01:54:28 +04:00
|
|
|
|
|
|
|
// These are used by BreakAfterLoad, below.
|
|
|
|
#ifdef SHOULD_IMPLEMENT_BREAKAFTERLOAD
|
|
|
|
static nsCString *sBreakList[16];
|
|
|
|
static int sBreakListCount = 0;
|
|
|
|
#endif
|
|
|
|
|
1999-09-26 22:06:41 +04:00
|
|
|
nsresult nsDll::Shutdown(void)
|
|
|
|
{
|
|
|
|
// Release the module object if we got one
|
|
|
|
nsrefcnt refcnt;
|
|
|
|
if (m_moduleObject)
|
|
|
|
{
|
|
|
|
NS_RELEASE2(m_moduleObject, refcnt);
|
|
|
|
NS_ASSERTION(refcnt == 0, "Dll moduleObject refcount non zero");
|
|
|
|
}
|
2000-06-28 01:54:28 +04:00
|
|
|
#ifdef SHOULD_IMPLEMENT_BREAKAFTERLOAD
|
|
|
|
for (int i = 0; i < sBreakListCount; i++)
|
|
|
|
{
|
|
|
|
delete sBreakList[i];
|
|
|
|
sBreakList[i] = nsnull;
|
|
|
|
}
|
|
|
|
sBreakListCount = 0;
|
|
|
|
#endif
|
1999-09-26 22:06:41 +04:00
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
}
|
2003-03-05 06:22:12 +03:00
|
|
|
#ifdef SHOULD_IMPLEMENT_BREAKAFTERLOAD
|
2000-01-28 12:44:05 +03:00
|
|
|
void nsDll::BreakAfterLoad(const char *nsprPath)
|
|
|
|
{
|
|
|
|
static PRBool firstTime = PR_TRUE;
|
|
|
|
|
|
|
|
// return if invalid input
|
|
|
|
if (!nsprPath || !*nsprPath) return;
|
|
|
|
|
|
|
|
// return if nothing to break on
|
2000-06-28 01:54:28 +04:00
|
|
|
if (!firstTime && sBreakListCount == 0) return;
|
2000-01-28 12:44:05 +03:00
|
|
|
|
|
|
|
if (firstTime)
|
|
|
|
{
|
|
|
|
firstTime = PR_FALSE;
|
|
|
|
// Form the list of dlls to break on load
|
|
|
|
nsCAutoString envList(getenv("XPCOM_BREAK_ON_LOAD"));
|
|
|
|
if (envList.IsEmpty()) return;
|
|
|
|
PRInt32 ofset = 0;
|
|
|
|
PRInt32 start = 0;
|
|
|
|
do
|
|
|
|
{
|
2002-02-01 04:53:09 +03:00
|
|
|
ofset = envList.FindChar(':', start);
|
2000-06-28 01:54:28 +04:00
|
|
|
sBreakList[sBreakListCount] = new nsCString();
|
|
|
|
envList.Mid(*(sBreakList[sBreakListCount]), start, ofset);
|
|
|
|
sBreakListCount++;
|
2000-01-28 12:44:05 +03:00
|
|
|
start = ofset + 1;
|
|
|
|
}
|
2000-06-28 01:54:28 +04:00
|
|
|
while (ofset != -1 && 16 > sBreakListCount); // avoiding vc6.0 compiler issue. count < thinks it is starting a template
|
2000-01-28 12:44:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Find the dllname part of the string
|
|
|
|
nsCString currentPath(nsprPath);
|
|
|
|
PRInt32 lastSep = currentPath.RFindCharInSet(":\\/");
|
|
|
|
|
2000-06-28 01:54:28 +04:00
|
|
|
for (int i=0; i<sBreakListCount; i++)
|
|
|
|
if (currentPath.Find(*(sBreakList[i]), PR_TRUE, lastSep) > 0)
|
2000-01-28 12:44:05 +03:00
|
|
|
{
|
|
|
|
// Loading a dll that we want to break on
|
|
|
|
// Put your breakpoint here
|
2002-05-12 01:15:06 +04:00
|
|
|
fprintf(stderr, "...Loading module %s\n", nsprPath);
|
2000-01-28 12:44:05 +03:00
|
|
|
// Break in the debugger here.
|
2000-03-25 11:54:22 +03:00
|
|
|
#if defined(linux) && defined(__i386)
|
2000-01-28 12:44:05 +03:00
|
|
|
asm("int $3");
|
2000-03-25 11:54:22 +03:00
|
|
|
#elif defined(VMS)
|
|
|
|
lib$signal(SS$_DEBUG);
|
2001-11-28 06:52:34 +03:00
|
|
|
#elif defined(XP_MACOSX)
|
|
|
|
raise(SIGTRAP);
|
2000-02-22 01:56:55 +03:00
|
|
|
#endif
|
2000-01-28 12:44:05 +03:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2003-03-05 06:22:12 +03:00
|
|
|
#endif /* SHOULD_IMPLEMENT_BREAKAFTERLOAD */
|