in the middle of adding diagnostics

This commit is contained in:
jband%netscape.com 1999-02-19 05:59:59 +00:00
parent f5fcd41a95
commit 4ca272f218
10 changed files with 400 additions and 4 deletions

View File

@ -33,6 +33,7 @@ DEFINES=-DWIN32_LEAN_AND_MEAN -DEXPORT_XPC_API -DJS_THREADSAFE -DDEBUG
OBJS= \
.\$(OBJDIR)\xpt_cpp.obj \
.\$(OBJDIR)\nsXPConnect.obj \
.\$(OBJDIR)\xpclog.obj \
.\$(OBJDIR)\xpcarbitrary.obj \
.\$(OBJDIR)\xpccontext.obj \
.\$(OBJDIR)\xpcconvert.obj \
@ -51,6 +52,7 @@ EXPORTS = \
nsIInterfaceInfo.h \
nsIInterfaceInfoManager.h \
nsIXPConnect.h \
xpclog.h \
$(NULL)
LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\js -I$(PUBLIC)\raptor -I$(PUBLIC)\libxpt

View File

@ -145,6 +145,7 @@ public:
JSObject* aJSObj,
nsIXPConnectWrappedNative** aWrapper) = 0;
NS_IMETHOD DebugDump(int depth) = 0;
// other stuff...
};
@ -153,6 +154,15 @@ JS_BEGIN_EXTERN_C
// XXX remove this and use ServiceManager instead
XPC_PUBLIC_API(nsIXPConnect*)
XPC_GetXPConnect();
#ifdef DEBUG
XPC_PUBLIC_API(void)
XPC_Dump(nsISupports* p, int depth);
#define XPC_DUMP(x,d) XPC_Dump(x,d)
#else
#define XPC_DUMP(x,d) ((void*)0)
#endif
JS_END_EXTERN_C
#ifdef DEBUG

View File

@ -280,6 +280,38 @@ nsXPConnect::GetWrappedNativeOfJSObject(JSContext* aJSContext,
return NS_OK;
}
#ifdef DEBUG
ContextMapDumpEnumerator(JSHashEntry *he, intN i, void *arg)
{
((XPCContext*)he->value)->DebugDump(*(int*)arg);
return HT_ENUMERATE_NEXT;
}
#endif
NS_IMETHODIMP
nsXPConnect::DebugDump(int depth)
{
#ifdef DEBUG
depth-- ;
XPC_LOG_ALWAYS(("nsXPConnect @ %x with mRefCnt = %d", this, mRefCnt));
XPC_LOG_INDENT();
XPC_LOG_ALWAYS(("mAllocator @ %x", mAllocator));
XPC_LOG_ALWAYS(("mArbitraryScriptable @ %x", mArbitraryScriptable));
XPC_LOG_ALWAYS(("mInterfaceInfoManager @ %x", mInterfaceInfoManager));
XPC_LOG_ALWAYS(("mContextMap @ %x with %d context(s)", \
mContextMap, mContextMap ? mContextMap->Count() : 0));
// iterate contexts...
if(depth && mContextMap && mContextMap->Count())
{
XPC_LOG_INDENT();
mContextMap->Enumerate(ContextMapDumpEnumerator, &depth);
XPC_LOG_OUTDENT();
}
XPC_LOG_OUTDENT();
#endif
return NS_OK;
}
XPC_PUBLIC_API(nsIXPConnect*)
XPC_GetXPConnect()
{
@ -288,3 +320,29 @@ XPC_GetXPConnect()
// p->Stub5();
return nsXPConnect::GetXPConnect();
}
#ifdef DEBUG
XPC_PUBLIC_API(void)
XPC_Dump(nsISupports* p, int depth)
{
if(!p || !depth)
return;
nsIXPConnect* xpc;
nsIXPCWrappedNativeClass* wnc;
if(NS_SUCCEEDED(p->QueryInterface(nsIXPConnect::IID(),(void**)&xpc)))
{
XPC_LOG_ALWAYS(("Dumping a nsIXPConnect..."));
xpc->DebugDump(depth);
NS_RELEASE(xpc);
}
else if(NS_SUCCEEDED(p->QueryInterface(nsIXPCWrappedNativeClass::IID(),(void**)&wnc)))
{
XPC_LOG_ALWAYS(("Dumping a nsIXPCWrappedNativeClass..."));
wnc->DebugDump(depth);
NS_RELEASE(xpc);
}
}
#endif

View File

@ -7,6 +7,7 @@
#include "nsIServiceManager.h"
#include "jsapi.h"
#include <stdio.h>
#include "xpclog.h"
// XXX this should not be necessary, but the nsIAllocator service is not being
@ -568,6 +569,9 @@ int main()
for(char** p = txt; *p; p++)
JS_EvaluateScript(cx, glob, *p, strlen(*p), "builtin", 1, &rval);
// dump to log test...
XPC_DUMP(xpc, 50);
if(JS_GetProperty(cx, glob, "bar", &v) && JSVAL_IS_OBJECT(v))
{
JSObject* bar = JSVAL_TO_OBJECT(v);
@ -592,6 +596,9 @@ int main()
test_js_obj == JSVAL_TO_OBJECT(v) ?
"expected result" : "WRONG RESULT" );
// dump to log test...
XPC_DUMP(xpc, 1);
NS_RELEASE(methods);
NS_RELEASE(wrapper);
@ -650,4 +657,6 @@ DumpSymbol(JSHashEntry *he, int i, void *arg)
JS_BEGIN_EXTERN_C
void Dsym(JSSymbol *sym) { if (sym) DumpSymbol(&sym->entry, 0, gErrFile); }
void Datom(JSAtom *atom) { if (atom) DumpAtom(&atom->entry, 0, gErrFile); }
void Dobj(nsISupports* p, int depth) {if(p)XPC_DUMP(p,depth);}
void Dxpc(int depth) {Dobj(XPC_GetXPConnect(), depth);}
JS_END_EXTERN_C

View File

@ -96,3 +96,43 @@ XPCContext::Init(JSObject* aGlobalObj /*= NULL*/)
nsXPCWrappedJSClass::InitForContext(this) &&
nsXPCWrappedNativeClass::InitForContext(this);
}
#ifdef DEBUG
WrappedNativeClassMapDumpEnumerator(JSHashEntry *he, intN i, void *arg)
{
((nsXPCWrappedNativeClass*)he->value)->DebugDump(*(int*)arg);
return HT_ENUMERATE_NEXT;
}
#endif
void
XPCContext::DebugDump(int depth)
{
#ifdef DEBUG
depth--;
XPC_LOG_ALWAYS(("XPCContext @ %x", this));
XPC_LOG_INDENT();
XPC_LOG_ALWAYS(("mJSContext @ %x", mJSContext));
XPC_LOG_ALWAYS(("mGlobalObj @ %x", mGlobalObj));
XPC_LOG_ALWAYS(("mWrappedNativeClassMap @ %x with %d classes", \
mWrappedNativeClassMap, \
mWrappedNativeClassMap ? mWrappedNativeClassMap->Count() : 0));
if(depth && mWrappedNativeClassMap && mWrappedNativeClassMap->Count())
{
XPC_LOG_INDENT();
mWrappedNativeClassMap->Enumerate(WrappedNativeClassMapDumpEnumerator, &depth);
XPC_LOG_OUTDENT();
}
XPC_LOG_ALWAYS(("mWrappedJSClassMap @ %x with %d classes", \
mWrappedJSClassMap, \
mWrappedJSClassMap ? mWrappedJSClassMap->Count() : 0));
XPC_LOG_ALWAYS(("mWrappedNativeMap @ %x with %d wrappers", \
mWrappedNativeMap, \
mWrappedNativeMap ? mWrappedNativeMap->Count() : 0));
XPC_LOG_ALWAYS(("mWrappedJSMap @ %x with %d wrappers", \
mWrappedJSMap, \
mWrappedJSMap ? mWrappedJSMap->Count() : 0));
XPC_LOG_OUTDENT();
#endif
}

View File

@ -0,0 +1,95 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* Debug Logging support. */
#include <stdarg.h>
#include <string.h>
#include "prprf.h"
#include "xpclog.h"
#ifdef DEBUG
#define SPACE_COUNT 200
#define LINE_LEN 200
#define INDENT_FACTOR 2
#define CAN_RUN (g_InitState == 1 || (g_InitState == 0 && Init()))
static char* g_Spaces;
static int g_InitState = 0;
static int g_Indent = 0;
static PRLogModuleInfo* g_LogMod = NULL;
static PRBool Init()
{
g_LogMod = PR_NewLogModule("xpclog");
g_Spaces = new char[SPACE_COUNT+1];
memset(g_Spaces, ' ', SPACE_COUNT);
g_Spaces[SPACE_COUNT] = 0;
if(!g_LogMod || !g_Spaces || !PR_LOG_TEST(g_LogMod,1))
{
g_InitState = -1;
return PR_FALSE;
}
g_InitState = 1;
return PR_TRUE;
}
XPC_PUBLIC_API(void)
XPC_Log_print(const char *fmt, ...)
{
va_list ap;
char line[LINE_LEN];
va_start(ap, fmt);
PR_vsnprintf(line, sizeof(line)-1, fmt, ap);
va_end(ap);
if(g_Indent)
PR_LogPrint("%s%s",g_Spaces+SPACE_COUNT-(INDENT_FACTOR*g_Indent),line);
else
PR_LogPrint("%s",line);
}
XPC_PUBLIC_API(PRBool)
XPC_Log_Check(int i)
{
return CAN_RUN && PR_LOG_TEST(g_LogMod,1);
}
XPC_PUBLIC_API(void)
XPC_Log_Indent()
{
if(INDENT_FACTOR*(++g_Indent) > SPACE_COUNT)
g_Indent-- ;
}
XPC_PUBLIC_API(void)
XPC_Log_Outdent()
{
if(--g_Indent < 0)
g_Indent++;
}
XPC_PUBLIC_API(void)
XPC_Log_Clear_Indent()
{
g_Indent = 0;
}
#endif

78
js/src/xpconnect/xpclog.h Normal file
View File

@ -0,0 +1,78 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* Debug Logging support. */
#ifndef xpclog_h___
#define xpclog_h___
#include "nsIXPConnect.h"
#include "prtypes.h"
#include "prlog.h"
/*
* This uses prlog.h See prlog.h for environment settings for output.
* The module name used here is 'xpclog'. These environment settings
* should work...
*
* SET NSPR_LOG_MODULES=xpclog:5
* SET NSPR_LOG_FILE=logfile.txt
*
* use:
* XPC_LOG_ERROR(("my comment number %d", 5)) // note the double parens
*
*/
#ifdef DEBUG
#define XPC_LOG_INTERNAL(number,_args) \
do{if(XPC_Log_Check(number)){XPC_Log_print _args;}}while(0)
#define XPC_LOG_ALWAYS(_args) XPC_LOG_INTERNAL(1,_args)
#define XPC_LOG_ERROR(_args) XPC_LOG_INTERNAL(2,_args)
#define XPC_LOG_WARNING(_args) XPC_LOG_INTERNAL(3,_args)
#define XPC_LOG_DEBUG(_args) XPC_LOG_INTERNAL(4,_args)
#define XPC_LOG_FLUSH() PR_LogFlush()
#define XPC_LOG_INDENT() XPC_Log_Indent()
#define XPC_LOG_OUTDENT() XPC_Log_Outdent()
#define XPC_LOG_CLEAR_INDENT() XPC_Log_Clear_Indent()
JS_BEGIN_EXTERN_C
XPC_PUBLIC_API(void) XPC_Log_print(const char *fmt, ...);
XPC_PUBLIC_API(PRBool) XPC_Log_Check(int i);
XPC_PUBLIC_API(void) XPC_Log_Indent();
XPC_PUBLIC_API(void) XPC_Log_Outdent();
XPC_PUBLIC_API(void) XPC_Log_Clear_Indent();
JS_END_EXTERN_C
#else
#define XPC_LOG_ALWAYS(_args) ((void)0)
#define XPC_LOG_ERROR(_args) ((void)0)
#define XPC_LOG_WARNING(_args) ((void)0)
#define XPC_LOG_DEBUG(_args) ((void)0)
#define XPC_LOG(_args) ((void)0)
#define XPC_LOG_FLUSH() ((void)0)
#define XPC_LOG_INDENT() ((void)0)
#define XPC_LOG_OUTDENT() ((void)0)
#define XPC_LOG_CLEAR_INDENT() ((void)0)
#endif
#endif /* xpclog_h___ */

View File

@ -49,6 +49,10 @@ public:
JS_HashTableRemove(mHashtable, xpcc->GetJSContext());
}
inline uint32 Count() {return mHashtable->nentries;}
inline intN Enumerate(JSHashEnumerator f, void *arg)
{return JS_HashTableEnumerateEntries(mHashtable, f, arg);}
~JSContext2XPCContextMap();
private:
JSContext2XPCContextMap(); // no implementation
@ -82,6 +86,10 @@ public:
JS_HashTableRemove(mHashtable, Wrapper->GetJSObject());
}
inline uint32 Count() {return mHashtable->nentries;}
inline intN Enumerate(JSHashEnumerator f, void *arg)
{return JS_HashTableEnumerateEntries(mHashtable, f, arg);}
~JSObject2WrappedJSMap();
private:
JSObject2WrappedJSMap(); // no implementation
@ -115,6 +123,10 @@ public:
JS_HashTableRemove(mHashtable, Wrapper->GetNative());
}
inline uint32 Count() {return mHashtable->nentries;}
inline intN Enumerate(JSHashEnumerator f, void *arg)
{return JS_HashTableEnumerateEntries(mHashtable, f, arg);}
~Native2WrappedNativeMap();
private:
Native2WrappedNativeMap(); // no implementation
@ -147,6 +159,10 @@ public:
JS_HashTableRemove(mHashtable, &Class->GetIID());
}
inline uint32 Count() {return mHashtable->nentries;}
inline intN Enumerate(JSHashEnumerator f, void *arg)
{return JS_HashTableEnumerateEntries(mHashtable, f, arg);}
~IID2WrappedJSClassMap();
private:
IID2WrappedJSClassMap(); // no implementation
@ -179,6 +195,10 @@ public:
JS_HashTableRemove(mHashtable, &Class->GetIID());
}
inline uint32 Count() {return mHashtable->nentries;}
inline intN Enumerate(JSHashEnumerator f, void *arg)
{return JS_HashTableEnumerateEntries(mHashtable, f, arg);}
~IID2WrappedNativeClassMap();
private:
IID2WrappedNativeClassMap(); // no implementation

View File

@ -36,6 +36,7 @@
#include "xpt_cpp.h"
#include "xpcforwards.h"
#include "xpcvariant.h"
#include "xpclog.h"
extern const char* XPC_VAL_STR; // 'value' property name for out params
@ -68,6 +69,8 @@ class nsXPConnect : public nsIXPConnect
JSObject* aJSObj,
nsIXPConnectWrappedNative** aWrapper);
NS_IMETHOD DebugDump(int depth);
// non-interface implementation
public:
static nsXPConnect* GetXPConnect();
@ -117,6 +120,7 @@ public:
IID2WrappedNativeClassMap* GetWrappedNativeClassMap() {return mWrappedNativeClassMap;}
JSBool Init(JSObject* aGlobalObj = NULL);
void DebugDump(int depth);
~XPCContext();
private:
@ -288,8 +292,7 @@ public:
void SetReadOnlyAttribute() {flags=(flags&~NMD_CAT_MASK)|NMD_ATTRIB_RO;}
void SetWritableAttribute() {flags=(flags&~NMD_CAT_MASK)|NMD_ATTRIB_RW;}
XPCNativeMemberDescriptor()
: invokeFuncObj(NULL), id(0), flags(0) {}
XPCNativeMemberDescriptor();
private:
uint16 flags;
};
@ -305,7 +308,7 @@ private:
class nsIXPCWrappedNativeClass : public nsISupports
{
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IXPCONNECT_WRAPPED_NATIVE_CLASS_IID)
// no methods
NS_IMETHOD DebugDump(int depth) = 0;
};
/*************************/
@ -314,7 +317,7 @@ class nsXPCWrappedNativeClass : public nsIXPCWrappedNativeClass
{
// all the interface method declarations...
NS_DECL_ISUPPORTS;
NS_IMETHOD DebugDump(int depth);
public:
static nsXPCWrappedNativeClass* GetNewOrUsedClass(XPCContext* xpcc,
REFNSIID aIID);

View File

@ -20,6 +20,11 @@
#include "xpcprivate.h"
/***************************************************************************/
XPCNativeMemberDescriptor::XPCNativeMemberDescriptor()
: invokeFuncObj(NULL), id(0), index(0), index2(0), flags(0) {}
/***************************************************************************/
const char* XPC_VAL_STR = "value";
extern "C" JS_IMPORT_DATA(JSObjectOps) js_ObjectOps;
@ -1195,3 +1200,79 @@ nsXPCWrappedNativeClass::GetWrappedNativeOfJSObject(JSContext* cx,
/***************************************************************************/
NS_IMETHODIMP
nsXPCWrappedNativeClass::DebugDump(int depth)
{
#ifdef DEBUG
depth-- ;
XPC_LOG_ALWAYS(("nsXPCWrappedNativeClass @ %x with mRefCnt = %d", this, mRefCnt));
XPC_LOG_INDENT();
XPC_LOG_ALWAYS(("interface name is %s", GetInterfaceName()));
char * iid = mIID.ToString();
XPC_LOG_ALWAYS(("IID number is %s", iid));
free(iid);
XPC_LOG_ALWAYS(("InterfaceInfo @ %x", mInfo));
if(depth)
{
uint16 i;
nsIInterfaceInfo* parent;
XPC_LOG_INDENT();
mInfo->GetParent(&parent);
XPC_LOG_ALWAYS(("parent @ %x", parent));
mInfo->GetMethodCount(&i);
XPC_LOG_ALWAYS(("MethodCount = %d", i));
mInfo->GetConstantCount(&i);
XPC_LOG_ALWAYS(("ConstantCount = %d", i));
XPC_LOG_OUTDENT();
}
XPC_LOG_ALWAYS(("mXPCContext @ %x", mXPCContext));
XPC_LOG_ALWAYS(("JSContext @ %x", GetJSContext()));
XPC_LOG_ALWAYS(("mDescriptors @ %x count = %d", mDescriptors, mMemberCount));
if(depth && mDescriptors)
{
depth--;
XPC_LOG_INDENT();
for(int i = 0; i < mMemberCount; i++)
{
const XPCNativeMemberDescriptor& desc = mDescriptors[i];
XPC_LOG_ALWAYS(("Descriptor @ %x", &desc));
if(depth)
{
depth--;
XPC_LOG_INDENT();
XPC_LOG_ALWAYS(("category: %s %s %s %s", \
desc.IsConstant() ? "Constant" : "", \
desc.IsMethod() ? "Method" : "", \
desc.IsWritableAttribute() ? "WritableAttribute" : "", \
desc.IsReadOnlyAttribute() ? "ReadOnlyAttribute" : ""));
XPC_LOG_ALWAYS(("id is %x", desc.id));
if(depth)
{
XPC_LOG_INDENT();
jsval idval;
const char *name;
if (JS_IdToValue(GetJSContext(), desc.id, &idval) &&
JSVAL_IS_STRING(idval) &&
(name = JS_GetStringBytes(
JSVAL_TO_STRING(idval))) != NULL)
{
XPC_LOG_ALWAYS(("property name is %s", name));
}
XPC_LOG_OUTDENT();
}
XPC_LOG_ALWAYS(("index is %d", desc.index));
XPC_LOG_ALWAYS(("index2 is %d", desc.index2));
XPC_LOG_ALWAYS(("invokeFuncObj @ %x", desc.invokeFuncObj));
XPC_LOG_OUTDENT();
depth++;
}
}
XPC_LOG_OUTDENT();
depth++;
}
XPC_LOG_OUTDENT();
#endif
return NS_OK;
}