From 61f242f7aaf8b21c5c0b6d5ec2602477a55c70d7 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Fri, 15 Oct 2010 15:21:51 -0700 Subject: [PATCH] Backed out changeset 2bdf648e7015 --- js/jsd/idl/jsdIDebuggerService.idl | 11 ++++++ js/jsd/jsd.h | 6 +++ js/jsd/jsd_scpt.c | 22 ++++++----- js/jsd/jsd_xpc.cpp | 22 ++++++++++- js/jsd/jsd_xpc.h | 4 +- js/jsd/jsdebug.c | 16 ++++++++ js/jsd/jsdebug.h | 13 +++++++ js/jsd/test/Makefile.in | 1 + js/jsd/test/test_bug602003.html | 62 ++++++++++++++++++++++++++++++ js/src/jscntxt.cpp | 4 +- js/src/jsdbgapi.cpp | 21 ++++++++-- js/src/jsdbgapi.h | 6 +++ 12 files changed, 172 insertions(+), 16 deletions(-) create mode 100644 js/jsd/test/test_bug602003.html diff --git a/js/jsd/idl/jsdIDebuggerService.idl b/js/jsd/idl/jsdIDebuggerService.idl index 27cd0cd0cc4..cd6b443ffc8 100644 --- a/js/jsd/idl/jsdIDebuggerService.idl +++ b/js/jsd/idl/jsdIDebuggerService.idl @@ -1001,6 +1001,17 @@ interface jsdIScript : jsdIEphemeral * The |pcmap| argument specifies which pc to source line map to use. */ boolean isLineExecutable (in unsigned long line, in unsigned long pcmap); + /** + * Get the first valid PC in the script. This will be either + * (a) the first bytecode in the script, or (b) the next bytecode + * in the script, iff the first bytecode is a JSOP_BEGIN. + */ + unsigned long getFirstValidPC (); + /** + * Return the last valid PC in the script (i.e., the PC just after + * the last bytecode). + */ + unsigned long getEndValidPC (); /** * Set a breakpoint at a PC in this script. */ diff --git a/js/jsd/jsd.h b/js/jsd/jsd.h index 58b54ef7a8f..f39070b5eb9 100644 --- a/js/jsd/jsd.h +++ b/js/jsd/jsd.h @@ -478,6 +478,12 @@ jsd_GetScriptHook(JSDContext* jsdc, JSD_ScriptHookProc* hook, void** callerdata) extern jsuword jsd_GetClosestPC(JSDContext* jsdc, JSDScript* jsdscript, uintN line); +extern jsuword +jsd_GetFirstValidPC(JSDContext* jsdc, JSDScript* jsdscript); + +extern jsuword +jsd_GetEndPC(JSDContext* jsdc, JSDScript* jsdscript); + extern uintN jsd_GetClosestLine(JSDContext* jsdc, JSDScript* jsdscript, jsuword pc); diff --git a/js/jsd/jsd_scpt.c b/js/jsd/jsd_scpt.c index 01e96c0668f..e599a7310c8 100644 --- a/js/jsd/jsd_scpt.c +++ b/js/jsd/jsd_scpt.c @@ -500,20 +500,22 @@ jsd_GetScriptLineExtent(JSDContext* jsdc, JSDScript *jsdscript) jsuword jsd_GetClosestPC(JSDContext* jsdc, JSDScript* jsdscript, uintN line) { -#ifdef LIVEWIRE - if( jsdscript && jsdscript->lwscript ) - { - uintN newline; - jsdlw_RawToProcessedLineNumber(jsdc, jsdscript, line, &newline); - if( line != newline ) - line = newline; - } -#endif - return (jsuword) JS_LineNumberToPC(jsdc->dumbContext, jsdscript->script, line ); } +jsuword +jsd_GetFirstValidPC(JSDContext* jsdc, JSDScript* jsdscript) +{ + return (jsuword) JS_FirstValidPC(jsdc->dumbContext, jsdscript->script ); +} + +jsuword +jsd_GetEndPC(JSDContext* jsdc, JSDScript* jsdscript) +{ + return (jsuword) JS_EndPC(jsdc->dumbContext, jsdscript->script ); +} + uintN jsd_GetClosestLine(JSDContext* jsdc, JSDScript* jsdscript, jsuword pc) { diff --git a/js/jsd/jsd_xpc.cpp b/js/jsd/jsd_xpc.cpp index 582852fb0fe..a2effbb6355 100644 --- a/js/jsd/jsd_xpc.cpp +++ b/js/jsd/jsd_xpc.cpp @@ -958,7 +958,9 @@ jsdScript::jsdScript (JSDContext *aCx, JSDScript *aScript) : mValid(PR_FALSE), mBaseLineNumber(0), mLineExtent(0), mPPLineMap(0), - mFirstPC(0) + mFirstValidPC(0), + mFirstPC(0), + mEndPC(0) { DEBUG_CREATE ("jsdScript", gScriptCount); @@ -972,6 +974,8 @@ jsdScript::jsdScript (JSDContext *aCx, JSDScript *aScript) : mValid(PR_FALSE), mBaseLineNumber = JSD_GetScriptBaseLineNumber(mCx, mScript); mLineExtent = JSD_GetScriptLineExtent(mCx, mScript); mFirstPC = JSD_GetClosestPC(mCx, mScript, 0); + mFirstValidPC = JSD_GetFirstValidPC(mCx, mScript); + mEndPC = JSD_GetEndPC(mCx, mScript); JSD_UnlockScriptSubsystem(mCx); mValid = PR_TRUE; @@ -1475,6 +1479,22 @@ jsdScript::IsLineExecutable(PRUint32 aLine, PRUint32 aPcmap, PRBool *_rval) return NS_OK; } +NS_IMETHODIMP +jsdScript::GetFirstValidPC(PRUint32 *_rval) +{ + ASSERT_VALID_EPHEMERAL; + *_rval = PRUint32(mFirstValidPC - mFirstPC); + return NS_OK; +} + +NS_IMETHODIMP +jsdScript::GetEndValidPC(PRUint32 *_rval) +{ + ASSERT_VALID_EPHEMERAL; + *_rval = PRUint32(mEndPC - mFirstPC); + return NS_OK; +} + NS_IMETHODIMP jsdScript::SetBreakpoint(PRUint32 aPC) { diff --git a/js/jsd/jsd_xpc.h b/js/jsd/jsd_xpc.h index 92f08799242..5751034b6f4 100644 --- a/js/jsd/jsd_xpc.h +++ b/js/jsd/jsd_xpc.h @@ -182,7 +182,9 @@ class jsdScript : public jsdIScript PRUint32 mBaseLineNumber, mLineExtent; PCMapEntry *mPPLineMap; PRUint32 mPCMapSize; - jsuword mFirstPC; + jsuword mFirstPC; /* address of first PC in script */ + jsuword mFirstValidPC; /* address of first valid bkpt PC */ + jsuword mEndPC; /* address of end of script code */ }; PRUint32 jsdScript::LastTag = 0; diff --git a/js/jsd/jsdebug.c b/js/jsd/jsdebug.c index 173c9d060fe..4d6c07b8061 100644 --- a/js/jsd/jsdebug.c +++ b/js/jsd/jsdebug.c @@ -348,6 +348,22 @@ JSD_GetClosestPC(JSDContext* jsdc, JSDScript* jsdscript, uintN line) return jsd_GetClosestPC(jsdc, jsdscript, line); } +JSD_PUBLIC_API(jsuword) +JSD_GetFirstValidPC(JSDContext* jsdc, JSDScript* jsdscript) +{ + JSD_ASSERT_VALID_CONTEXT(jsdc); + JSD_ASSERT_VALID_SCRIPT(jsdscript); + return jsd_GetFirstValidPC(jsdc, jsdscript); +} + +JSD_PUBLIC_API(jsuword) +JSD_GetEndPC(JSDContext* jsdc, JSDScript* jsdscript) +{ + JSD_ASSERT_VALID_CONTEXT(jsdc); + JSD_ASSERT_VALID_SCRIPT(jsdscript); + return jsd_GetEndPC(jsdc, jsdscript); +} + JSD_PUBLIC_API(uintN) JSD_GetClosestLine(JSDContext* jsdc, JSDScript* jsdscript, jsuword pc) { diff --git a/js/jsd/jsdebug.h b/js/jsd/jsdebug.h index fcdc2e04ee8..7f4ee911103 100644 --- a/js/jsd/jsdebug.h +++ b/js/jsd/jsdebug.h @@ -486,6 +486,19 @@ JSD_GetScriptHook(JSDContext* jsdc, JSD_ScriptHookProc* hook, void** callerdata) extern JSD_PUBLIC_API(jsuword) JSD_GetClosestPC(JSDContext* jsdc, JSDScript* jsdscript, uintN line); +/* +* Get the first 'Program Counter' value where a breakpoint can be set. +*/ +extern JSD_PUBLIC_API(jsuword) +JSD_GetFirstValidPC(JSDContext* jsdc, JSDScript* jsdscript); + +/* +* Get the 'Program Counter' value just after the last byte of the script. +* 0 is returned for invalid scripts. +*/ +extern JSD_PUBLIC_API(jsuword) +JSD_GetEndPC(JSDContext* jsdc, JSDScript* jsdscript); + /* * Get the source line number for a given 'Program Counter' location. * Returns 0 if no source line information is appropriate (or available) for diff --git a/js/jsd/test/Makefile.in b/js/jsd/test/Makefile.in index d4d75a26b14..a37da51a2a0 100644 --- a/js/jsd/test/Makefile.in +++ b/js/jsd/test/Makefile.in @@ -48,6 +48,7 @@ MODULE = jsdebug include $(topsrcdir)/config/rules.mk _TEST_FILES = test_bug507448.html \ + test_bug602003.html \ $(NULL) libs:: $(_TEST_FILES) diff --git a/js/jsd/test/test_bug602003.html b/js/jsd/test/test_bug602003.html new file mode 100644 index 00000000000..f4714f90f17 --- /dev/null +++ b/js/jsd/test/test_bug602003.html @@ -0,0 +1,62 @@ + + + + + Test for Bug 602003 + + + + + +Mozilla Bug 507448 +

+ +
+
+
+
+
+ + diff --git a/js/src/jscntxt.cpp b/js/src/jscntxt.cpp index 949561b0626..1b2ac3d535e 100644 --- a/js/src/jscntxt.cpp +++ b/js/src/jscntxt.cpp @@ -475,7 +475,9 @@ AllFramesIter::operator++() { JS_ASSERT(!done()); if (curfp == curcs->getInitialFrame()) { - curcs = curcs->getPreviousInMemory(); + do { + curcs = curcs->getPreviousInMemory(); + } while (curcs && !curcs->inContext()); curfp = curcs ? curcs->getCurrentFrame() : NULL; } else { curfp = curfp->prev(); diff --git a/js/src/jsdbgapi.cpp b/js/src/jsdbgapi.cpp index e6fc2e91fec..4d6a40be805 100644 --- a/js/src/jsdbgapi.cpp +++ b/js/src/jsdbgapi.cpp @@ -235,9 +235,11 @@ JS_SetTrap(JSContext *cx, JSScript *script, jsbytecode *pc, return JS_FALSE; } - // Do not trap BEGIN, it's a special prologue opcode. - if (JSOp(*pc) == JSOP_BEGIN) - pc += JSOP_BEGIN_LENGTH; + if (JSOp(*pc) == JSOP_BEGIN) { + JS_ReportErrorFlagsAndNumber(cx, JSREPORT_ERROR, js_GetErrorMessage, + NULL, JSMSG_READ_ONLY, "trap invalid on BEGIN opcode"); + return JS_FALSE; + } JS_ASSERT((JSOp) *pc != JSOP_TRAP); junk = NULL; @@ -1019,6 +1021,19 @@ JS_LineNumberToPC(JSContext *cx, JSScript *script, uintN lineno) return js_LineNumberToPC(script, lineno); } +JS_PUBLIC_API(jsbytecode *) +JS_FirstValidPC(JSContext *cx, JSScript *script) +{ + jsbytecode *pc = script->code; + return *pc == JSOP_BEGIN ? pc + JSOP_BEGIN_LENGTH : pc; +} + +JS_PUBLIC_API(jsbytecode *) +JS_EndPC(JSContext *cx, JSScript *script) +{ + return script->code + script->length; +} + JS_PUBLIC_API(uintN) JS_GetFunctionArgumentCount(JSContext *cx, JSFunction *fun) { diff --git a/js/src/jsdbgapi.h b/js/src/jsdbgapi.h index 5855f18c783..03028145714 100644 --- a/js/src/jsdbgapi.h +++ b/js/src/jsdbgapi.h @@ -159,6 +159,12 @@ JS_PCToLineNumber(JSContext *cx, JSScript *script, jsbytecode *pc); extern JS_PUBLIC_API(jsbytecode *) JS_LineNumberToPC(JSContext *cx, JSScript *script, uintN lineno); +extern JS_PUBLIC_API(jsbytecode *) +JS_FirstValidPC(JSContext *cx, JSScript *script); + +extern JS_PUBLIC_API(jsbytecode *) +JS_EndPC(JSContext *cx, JSScript *script); + extern JS_PUBLIC_API(uintN) JS_GetFunctionArgumentCount(JSContext *cx, JSFunction *fun);