Fix bug and modularity loss introduced by patch for 424405 (424614, r/a=shaver, bug a=beltzner).

This commit is contained in:
brendan@mozilla.org 2008-03-24 01:06:39 -07:00
parent cbe8463a59
commit ac7abb892a
3 changed files with 75 additions and 62 deletions

View File

@ -45,6 +45,7 @@
#include <string.h>
#include "jstypes.h"
#include "jsutil.h" /* Added by JSIFY */
#include "jsclist.h"
#include "jsapi.h"
#include "jscntxt.h"
#include "jsconfig.h"
@ -61,9 +62,18 @@
#include "jsscript.h"
#include "jsstr.h"
#ifdef MOZ_SHARK
#include <CHUD/CHUD.h>
#endif
typedef struct JSTrap {
JSCList links;
JSScript *script;
jsbytecode *pc;
JSOp op;
JSTrapHandler handler;
void *closure;
} JSTrap;
#define DBG_LOCK(rt) JS_ACQUIRE_LOCK((rt)->debuggerLock)
#define DBG_UNLOCK(rt) JS_RELEASE_LOCK((rt)->debuggerLock)
#define DBG_LOCK_EVAL(rt,expr) (DBG_LOCK(rt), (expr), DBG_UNLOCK(rt))
/*
* NB: FindTrap must be called with rt->debuggerLock acquired.
@ -82,18 +92,32 @@ FindTrap(JSRuntime *rt, JSScript *script, jsbytecode *pc)
return NULL;
}
void
js_PatchOpcode(JSContext *cx, JSScript *script, jsbytecode *pc, JSOp op)
jsbytecode *
js_UntrapScriptCode(JSContext *cx, JSScript *script)
{
jsbytecode *code;
JSRuntime *rt;
JSTrap *trap;
DBG_LOCK(cx->runtime);
trap = FindTrap(cx->runtime, script, pc);
if (trap)
trap->op = op;
else
*pc = (jsbytecode)op;
DBG_UNLOCK(cx->runtime);
code = script->code;
rt = cx->runtime;
DBG_LOCK(rt);
for (trap = (JSTrap *)rt->trapList.next;
trap != (JSTrap *)&rt->trapList;
trap = (JSTrap *)trap->links.next) {
if (trap->script == script) {
if (code == script->code) {
code = JS_malloc(cx, script->length * sizeof(jsbytecode));
if (!code)
break;
memcpy(code, script->code,
script->length * sizeof(jsbytecode));
}
code[trap->pc - script->code] = trap->op;
}
}
DBG_UNLOCK(rt);
return code;
}
JS_PUBLIC_API(JSBool)
@ -1708,6 +1732,8 @@ JS_SetContextDebugHooks(JSContext *cx, JSDebugHooks *hooks)
#ifdef MOZ_SHARK
#include <CHUD/CHUD.h>
JS_PUBLIC_API(JSBool)
JS_StartChudRemote()
{

View File

@ -1,4 +1,5 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* vim: set ts=8 sw=4 et tw=78:
*
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
@ -43,27 +44,18 @@
* JS debugger API.
*/
#include "jsapi.h"
#include "jsclist.h"
#include "jsopcode.h"
#include "jsprvtd.h"
JS_BEGIN_EXTERN_C
typedef struct JSTrap {
JSCList links;
JSScript *script;
jsbytecode *pc;
JSOp op;
JSTrapHandler handler;
void *closure;
} JSTrap;
#define DBG_LOCK(rt) JS_ACQUIRE_LOCK((rt)->debuggerLock)
#define DBG_UNLOCK(rt) JS_RELEASE_LOCK((rt)->debuggerLock)
#define DBG_LOCK_EVAL(rt,expr) (DBG_LOCK(rt), (expr), DBG_UNLOCK(rt))
extern void
js_PatchOpcode(JSContext *cx, JSScript *script, jsbytecode *pc, JSOp op);
/*
* Unexported library-private helper used to unpatch all traps in a script.
* Returns script->code if script has no traps, else a JS_malloc'ed copy of
* script->code which the caller must JS_free, or null on JS_malloc OOM.
*/
extern jsbytecode *
js_UntrapScriptCode(JSContext *cx, JSScript *script);
extern JS_PUBLIC_API(JSBool)
JS_SetTrap(JSContext *cx, JSScript *script, jsbytecode *pc,
@ -436,24 +428,35 @@ extern JS_PUBLIC_API(JSDebugHooks *)
JS_SetContextDebugHooks(JSContext *cx, JSDebugHooks *hooks);
#ifdef MOZ_SHARK
extern JS_PUBLIC_API(JSBool) JS_StartChudRemote();
extern JS_PUBLIC_API(JSBool) JS_StopChudRemote();
extern JS_PUBLIC_API(JSBool) JS_ConnectShark();
extern JS_PUBLIC_API(JSBool) JS_DisconnectShark();
extern JS_FRIEND_API(JSBool) js_StopShark(JSContext *cx, JSObject *obj,
uintN argc, jsval *argv, jsval *rval);
extern JS_PUBLIC_API(JSBool)
JS_StartChudRemote();
extern JS_FRIEND_API(JSBool) js_StartShark(JSContext *cx, JSObject *obj,
uintN argc, jsval *argv, jsval *rval);
extern JS_PUBLIC_API(JSBool)
JS_StopChudRemote();
extern JS_FRIEND_API(JSBool) js_ConnectShark(JSContext *cx, JSObject *obj,
uintN argc, jsval *argv,
jsval *rval);
extern JS_PUBLIC_API(JSBool)
JS_ConnectShark();
extern JS_PUBLIC_API(JSBool)
JS_DisconnectShark();
extern JS_FRIEND_API(JSBool)
js_StopShark(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
jsval *rval);
extern JS_FRIEND_API(JSBool)
js_StartShark(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
jsval *rval);
extern JS_FRIEND_API(JSBool)
js_ConnectShark(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
jsval *rval);
extern JS_FRIEND_API(JSBool)
js_DisconnectShark(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
jsval *rval);
extern JS_FRIEND_API(JSBool) js_DisconnectShark(JSContext *cx, JSObject *obj,
uintN argc, jsval *argv,
jsval *rval);
#endif /* MOZ_SHARK */
JS_END_EXTERN_C

View File

@ -518,30 +518,14 @@ js_XDRScript(JSXDRState *xdr, JSScript **scriptp, JSBool *hasMagic)
* Control hereafter must goto error on failure, in order for the
* DECODE case to destroy script.
*/
oldscript = xdr->script;
code = script->code;
if (xdr->mode == JSXDR_ENCODE) {
JSTrap *trap;
JSRuntime *rt;
rt = cx->runtime;
DBG_LOCK(rt);
for (trap = (JSTrap *)rt->trapList.next;
trap != (JSTrap *)&rt->trapList;
trap = (JSTrap *)trap->links.next) {
if (trap->script == script) {
if (code == script->code) {
code = JS_malloc(cx, length * sizeof(jsbytecode));
if (!code)
goto error;
memcpy(code, script->code, length * sizeof(jsbytecode));
}
code[trap->pc - script->code] = trap->op;
}
}
DBG_UNLOCK(rt);
code = js_UntrapScriptCode(cx, script);
if (!code)
goto error;
}
oldscript = xdr->script;
xdr->script = script;
ok = JS_XDRBytes(xdr, (char *) code, length * sizeof(jsbytecode));