Skip to content

Commit

Permalink
Bug 699528. Make pausing/unpausing JSD try to turn off/on debug mode …
Browse files Browse the repository at this point in the history
…as needed. r=sfink a=LegNeato

The new boolean argument to SetDebugModeWhenPossible is needed because if we allow sync-disable of debug mode we seem to crash when loading pages with Firebug active.
  • Loading branch information
bzbarsky committed Nov 9, 2011
1 parent b868c53 commit 217073f
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 32 deletions.
5 changes: 4 additions & 1 deletion js/jsd/idl/jsdIDebuggerService.idl
Expand Up @@ -274,7 +274,10 @@ interface jsdIDebuggerService : nsISupports
*/
unsigned long pause();
/**
* Undo a pause.
* Undo a pause. Once this is called, the debugger won't start
* getting execution callbacks until the stack is fully unwound so
* that no JS scripts are live. There is no way to query whether
* there are such scripts left to unwind at a given point in time.
*
* @return depth The number of remaining pending pause calls.
*/
Expand Down
79 changes: 52 additions & 27 deletions js/jsd/jsd_xpc.cpp
Expand Up @@ -471,7 +471,7 @@ jsds_NotifyPendingDeadScripts (JSContext *cx)
if (jsds) {
NS_ADDREF(jsds);
jsds->GetScriptHook (getter_AddRefs(hook));
jsds->Pause(nsnull);
jsds->DoPause(nsnull, true);
}

DeadScript *deadScripts = gDeadScripts;
Expand Down Expand Up @@ -506,7 +506,7 @@ jsds_NotifyPendingDeadScripts (JSContext *cx)
}

if (jsds) {
jsds->UnPause(nsnull);
jsds->DoUnPause(nsnull, true);
NS_RELEASE(jsds);
}
}
Expand Down Expand Up @@ -583,9 +583,9 @@ jsds_ErrorHookProc (JSDContext *jsdc, JSContext *cx, const char *message,
errnum = 0;
}

gJsds->Pause(nsnull);
gJsds->DoPause(nsnull, true);
hook->OnError (nsDependentCString(message), fileName, line, pos, flags, errnum, val, &rval);
gJsds->UnPause(nsnull);
gJsds->DoUnPause(nsnull, true);

running = PR_FALSE;
if (!rval)
Expand Down Expand Up @@ -626,9 +626,9 @@ jsds_CallHookProc (JSDContext* jsdc, JSDThreadState* jsdthreadstate,
nsCOMPtr<jsdIStackFrame> frame =
getter_AddRefs(jsdStackFrame::FromPtr(jsdc, jsdthreadstate,
native_frame));
gJsds->Pause(nsnull);
gJsds->DoPause(nsnull, true);
hook->OnCall(frame, type);
gJsds->UnPause(nsnull);
gJsds->DoUnPause(nsnull, true);
jsdStackFrame::InvalidateAll();

return JS_TRUE;
Expand Down Expand Up @@ -688,13 +688,13 @@ jsds_ExecutionHookProc (JSDContext* jsdc, JSDThreadState* jsdthreadstate,
nsCOMPtr<jsdIStackFrame> frame =
getter_AddRefs(jsdStackFrame::FromPtr(jsdc, jsdthreadstate,
native_frame));
gJsds->Pause(nsnull);
gJsds->DoPause(nsnull, true);
jsdIValue *inout_rv = js_rv;
NS_IF_ADDREF(inout_rv);
hook->OnExecute (frame, type, &inout_rv, &hook_rv);
js_rv = inout_rv;
NS_IF_RELEASE(inout_rv);
gJsds->UnPause(nsnull);
gJsds->DoUnPause(nsnull, true);
jsdStackFrame::InvalidateAll();

if (hook_rv == JSD_HOOK_RETURN_RET_WITH_VAL ||
Expand Down Expand Up @@ -734,9 +734,9 @@ jsds_ScriptHookProc (JSDContext* jsdc, JSDScript* jsdscript, JSBool creating,
#ifdef CAUTIOUS_SCRIPTHOOK
JS_UNKEEP_ATOMS(rt);
#endif
gJsds->Pause(nsnull);
gJsds->DoPause(nsnull, true);
hook->OnScriptCreated (script);
gJsds->UnPause(nsnull);
gJsds->DoUnPause(nsnull, true);
#ifdef CAUTIOUS_SCRIPTHOOK
JS_KEEP_ATOMS(rt);
#endif
Expand All @@ -763,9 +763,9 @@ jsds_ScriptHookProc (JSDContext* jsdc, JSDScript* jsdscript, JSBool creating,
JS_UNKEEP_ATOMS(rt);
#endif

gJsds->Pause(nsnull);
gJsds->DoPause(nsnull, true);
hook->OnScriptDestroyed (jsdis);
gJsds->UnPause(nsnull);
gJsds->DoUnPause(nsnull, true);
#ifdef CAUTIOUS_SCRIPTHOOK
JS_KEEP_ATOMS(rt);
#endif
Expand Down Expand Up @@ -2546,21 +2546,13 @@ jsdService::AsyncOn (jsdIActivationCallback *activationCallback)
{
nsresult rv;

/* get JS things from the CallContext */
nsCOMPtr<nsIXPConnect> xpc = do_GetService(nsIXPConnect::GetCID(), &rv);
if (NS_FAILED(rv)) return rv;

nsAXPCNativeCallContext *cc = nsnull;
rv = xpc->GetCurrentNativeCallContext(&cc);
if (NS_FAILED(rv)) return rv;

JSContext *cx;
rv = cc->GetJSContext (&cx);
nsCOMPtr<nsIXPConnect_MOZILLA_10_BRANCH> xpc =
do_GetService(nsIXPConnect::GetCID(), &rv);
if (NS_FAILED(rv)) return rv;

mActivationCallback = activationCallback;

return xpc->SetDebugModeWhenPossible(PR_TRUE);
return xpc->SetDebugModeWhenPossible(PR_TRUE, PR_TRUE);
}

NS_IMETHODIMP
Expand Down Expand Up @@ -2702,11 +2694,12 @@ jsdService::Off (void)
#endif

nsresult rv;
nsCOMPtr<nsIXPConnect> xpc = do_GetService(nsIXPConnect::GetCID(), &rv);
nsCOMPtr<nsIXPConnect_MOZILLA_10_BRANCH> xpc =
do_GetService(nsIXPConnect::GetCID(), &rv);
if (NS_FAILED(rv))
return rv;

xpc->SetDebugModeWhenPossible(PR_FALSE);
xpc->SetDebugModeWhenPossible(PR_FALSE, PR_TRUE);

return NS_OK;
}
Expand All @@ -2721,6 +2714,12 @@ jsdService::GetPauseDepth(PRUint32 *_rval)

NS_IMETHODIMP
jsdService::Pause(PRUint32 *_rval)
{
return DoPause(_rval, false);
}

nsresult
jsdService::DoPause(PRUint32 *_rval, bool internalCall)
{
if (!mCx)
return NS_ERROR_NOT_INITIALIZED;
Expand All @@ -2734,6 +2733,16 @@ jsdService::Pause(PRUint32 *_rval)
JSD_ClearTopLevelHook (mCx);
JSD_ClearFunctionHook (mCx);
JSD_DebuggerPause (mCx);

nsresult rv;
nsCOMPtr<nsIXPConnect_MOZILLA_10_BRANCH> xpc =
do_GetService(nsIXPConnect::GetCID(), &rv);
if (NS_FAILED(rv)) return rv;

if (!internalCall) {
rv = xpc->SetDebugModeWhenPossible(PR_FALSE, PR_FALSE);
NS_ENSURE_SUCCESS(rv, rv);
}
}

if (_rval)
Expand All @@ -2744,6 +2753,12 @@ jsdService::Pause(PRUint32 *_rval)

NS_IMETHODIMP
jsdService::UnPause(PRUint32 *_rval)
{
return DoUnPause(_rval, false);
}

nsresult
jsdService::DoUnPause(PRUint32 *_rval, bool internalCall)
{
if (!mCx)
return NS_ERROR_NOT_INITIALIZED;
Expand Down Expand Up @@ -2774,6 +2789,16 @@ jsdService::UnPause(PRUint32 *_rval)
JSD_SetFunctionHook (mCx, jsds_CallHookProc, NULL);
else
JSD_ClearFunctionHook (mCx);

nsresult rv;
nsCOMPtr<nsIXPConnect_MOZILLA_10_BRANCH> xpc =
do_GetService(nsIXPConnect::GetCID(), &rv);
if (NS_FAILED(rv)) return rv;

if (!internalCall) {
rv = xpc->SetDebugModeWhenPossible(PR_TRUE, PR_FALSE);
NS_ENSURE_SUCCESS(rv, rv);
}
}

if (_rval)
Expand Down Expand Up @@ -3110,9 +3135,9 @@ jsdService::EnterNestedEventLoop (jsdINestCallback *callback, PRUint32 *_rval)

if (NS_SUCCEEDED(stack->Push(nsnull))) {
if (callback) {
Pause(nsnull);
DoPause(nsnull, true);
rv = callback->OnNest();
UnPause(nsnull);
DoUnPause(nsnull, true);
}

while (NS_SUCCEEDED(rv) && mNestedLoopLevel >= nestLevel) {
Expand Down
3 changes: 3 additions & 0 deletions js/jsd/jsd_xpc.h
Expand Up @@ -291,6 +291,9 @@ class jsdService : public jsdIDebuggerService

PRBool CheckInterruptHook() { return !!mInterruptHook; }

nsresult DoPause(PRUint32 *_rval, bool internalCall);
nsresult DoUnPause(PRUint32 *_rval, bool internalCall);

private:
PRBool mOn;
PRUint32 mPauseLevel;
Expand Down
9 changes: 9 additions & 0 deletions js/src/xpconnect/idl/nsIXPConnect.idl
Expand Up @@ -797,3 +797,12 @@ interface nsIXPConnect : nsISupports
*/
[noscript] void setDebugModeWhenPossible(in boolean mode);
};

[uuid(44bf9047-914a-4f47-a1ec-e417927bacd1)]
interface nsIXPConnect_MOZILLA_10_BRANCH : nsISupports
{
// A 2-argument form of setDebugModeWhenPossible that allows
// controlling whether sync disable of debug mode is allowed.
[noscript] void setDebugModeWhenPossible(in boolean mode,
in boolean allowSyncDisable);
};
13 changes: 10 additions & 3 deletions js/src/xpconnect/src/nsXPConnect.cpp
Expand Up @@ -67,14 +67,15 @@

#include "xpcquickstubs.h"

NS_IMPL_THREADSAFE_ISUPPORTS7(nsXPConnect,
NS_IMPL_THREADSAFE_ISUPPORTS8(nsXPConnect,
nsIXPConnect,
nsISupportsWeakReference,
nsIThreadObserver,
nsIJSRuntimeService,
nsIJSContextStack,
nsIThreadJSContextStack,
nsIJSEngineTelemetryStats)
nsIJSEngineTelemetryStats,
nsIXPConnect_MOZILLA_10_BRANCH)

nsXPConnect* nsXPConnect::gSelf = nsnull;
JSBool nsXPConnect::gOnceAliveNowDead = JS_FALSE;
Expand Down Expand Up @@ -2884,9 +2885,15 @@ nsXPConnect::Base64Decode(JSContext *cx, jsval val, jsval *out)

NS_IMETHODIMP
nsXPConnect::SetDebugModeWhenPossible(PRBool mode)
{
return SetDebugModeWhenPossible(mode, PR_FALSE);
}

NS_IMETHODIMP
nsXPConnect::SetDebugModeWhenPossible(PRBool mode, PRBool allowSyncDisable)
{
gDesiredDebugMode = mode;
if (!mode)
if (!mode && allowSyncDisable)
CheckForDebugMode(mRuntime->GetJSRuntime());
return NS_OK;
}
Expand Down
4 changes: 3 additions & 1 deletion js/src/xpconnect/src/xpcprivate.h
Expand Up @@ -462,7 +462,8 @@ class nsXPConnect : public nsIXPConnect,
public nsCycleCollectionParticipant,
public nsIJSRuntimeService,
public nsIThreadJSContextStack,
public nsIJSEngineTelemetryStats
public nsIJSEngineTelemetryStats,
public nsIXPConnect_MOZILLA_10_BRANCH
{
public:
// all the interface method declarations...
Expand All @@ -473,6 +474,7 @@ class nsXPConnect : public nsIXPConnect,
NS_DECL_NSIJSCONTEXTSTACK
NS_DECL_NSITHREADJSCONTEXTSTACK
NS_DECL_NSIJSENGINETELEMETRYSTATS
NS_DECL_NSIXPCONNECT_MOZILLA_10_BRANCH

// non-interface implementation
public:
Expand Down

0 comments on commit 217073f

Please sign in to comment.