From 12134ceb2b87e0f180eb67f44e2fafd5ec66d49e Mon Sep 17 00:00:00 2001 From: Jeff Hutchinson Date: Tue, 10 Apr 2018 22:21:40 -0400 Subject: [PATCH 1/3] Check for NULL on the thisObject before using it. Also cleanup break to goto. --- Engine/source/console/codeInterpreter.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/Engine/source/console/codeInterpreter.cpp b/Engine/source/console/codeInterpreter.cpp index 46d58476e..cd25d47f3 100644 --- a/Engine/source/console/codeInterpreter.cpp +++ b/Engine/source/console/codeInterpreter.cpp @@ -400,11 +400,11 @@ ConsoleValueRef CodeInterpreter::exec(U32 ip, breakContinueLabel: OPCodeReturn ret = (this->*gOpCodeArray[mCurrentInstruction])(ip); if (ret == OPCodeReturn::exitCode) - goto exitLabel; + break; else if (ret == OPCodeReturn::breakContinue) goto breakContinueLabel; } -exitLabel: + if (telDebuggerOn && setFrame < 0) TelDebugger->popStackFrame(); @@ -2133,7 +2133,7 @@ OPCodeReturn CodeInterpreter::op_callfunc(U32 &ip) if (!mExec.noCalls && !(routingId == MethodOnComponent)) { Con::warnf(ConsoleLogEntry::General, "%s: Unknown command %s.", mCodeBlock->getFileLine(ip - 6), fnName); - if (callType == FuncCallExprNode::MethodCall) + if (callType == FuncCallExprNode::MethodCall && gEvalState.thisObject != NULL) { Con::warnf(ConsoleLogEntry::General, " Object %s(%d) %s", gEvalState.thisObject->getName() ? gEvalState.thisObject->getName() : "", @@ -2522,9 +2522,17 @@ OPCodeReturn CodeInterpreter::op_callfunc_this(U32 &ip) if (!mExec.noCalls) { Con::warnf(ConsoleLogEntry::General, "%s: Unknown command %s.", mCodeBlock->getFileLine(ip - 6), fnName); - Con::warnf(ConsoleLogEntry::General, " Object %s(%d) %s", - mThisObject->getName() ? mThisObject->getName() : "", - mThisObject->getId(), Con::getNamespaceList(ns)); + if (mThisObject) + { + Con::warnf(ConsoleLogEntry::General, " Object %s(%d) %s", + mThisObject->getName() ? mThisObject->getName() : "", + mThisObject->getId(), Con::getNamespaceList(ns)); + } + else + { + // At least let the scripter know that they access the object. + Con::warnf(ConsoleLogEntry::General, " Object is NULL."); + } } STR.popFrame(); CSTK.popFrame(); From c75eecbf53836f73d9d6fcaff31d24c120571eab Mon Sep 17 00:00:00 2001 From: Jeff Hutchinson Date: Thu, 12 Apr 2018 23:14:57 -0400 Subject: [PATCH 2/3] fix this pointer in op_callfunc_this --- Engine/source/console/codeInterpreter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Engine/source/console/codeInterpreter.cpp b/Engine/source/console/codeInterpreter.cpp index cd25d47f3..8f5d829ed 100644 --- a/Engine/source/console/codeInterpreter.cpp +++ b/Engine/source/console/codeInterpreter.cpp @@ -2511,7 +2511,7 @@ OPCodeReturn CodeInterpreter::op_callfunc_this(U32 &ip) ip += 2; CSTK.getArgcArgv(fnName, &mCallArgc, &mCallArgv); - Namespace *ns = mThisObject->getNamespace(); + Namespace *ns = mThisObject ? mThisObject->getNamespace() : NULL; if (ns) mNSEntry = ns->lookup(fnName); else From c6ec1f8d86bf9a2a926394fa3b106b090353310d Mon Sep 17 00:00:00 2001 From: Jeff Hutchinson Date: Sat, 14 Apr 2018 10:59:09 -0400 Subject: [PATCH 3/3] Added better script interpreter logging. --- Engine/source/console/codeInterpreter.cpp | 36 ++++++++++++++++------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/Engine/source/console/codeInterpreter.cpp b/Engine/source/console/codeInterpreter.cpp index 8f5d829ed..7654a6da1 100644 --- a/Engine/source/console/codeInterpreter.cpp +++ b/Engine/source/console/codeInterpreter.cpp @@ -2132,12 +2132,27 @@ OPCodeReturn CodeInterpreter::op_callfunc(U32 &ip) { if (!mExec.noCalls && !(routingId == MethodOnComponent)) { - Con::warnf(ConsoleLogEntry::General, "%s: Unknown command %s.", mCodeBlock->getFileLine(ip - 6), fnName); - if (callType == FuncCallExprNode::MethodCall && gEvalState.thisObject != NULL) + if (callType == FuncCallExprNode::MethodCall) { - Con::warnf(ConsoleLogEntry::General, " Object %s(%d) %s", - gEvalState.thisObject->getName() ? gEvalState.thisObject->getName() : "", - gEvalState.thisObject->getId(), Con::getNamespaceList(ns)); + if (gEvalState.thisObject != NULL) + { + // Try to use the name instead of the id + StringTableEntry name = gEvalState.thisObject->getName() ? gEvalState.thisObject->getName() : gEvalState.thisObject->getIdString(); + Con::warnf(ConsoleLogEntry::General, "%s: Unknown method %s.%s Namespace List: %s", mCodeBlock->getFileLine(ip - 6), name, fnName, Con::getNamespaceList(ns)); + } + else + { + // NULL. + Con::warnf(ConsoleLogEntry::General, "%s: Unknown method NULL.%s", mCodeBlock->getFileLine(ip - 6), fnName); + } + } + else if (callType == FuncCallExprNode::ParentCall) + { + Con::warnf(ConsoleLogEntry::General, "%s: Unknown parent call %s.", mCodeBlock->getFileLine(ip - 6), fnName); + } + else + { + Con::warnf(ConsoleLogEntry::General, "%s: Unknown function %s.", mCodeBlock->getFileLine(ip - 6), fnName); } } STR.popFrame(); @@ -2328,7 +2343,7 @@ OPCodeReturn CodeInterpreter::op_callfunc_pointer(U32 &ip) { if (!mExec.noCalls) { - Con::warnf(ConsoleLogEntry::General, "%s: Unknown command %s.", mCodeBlock->getFileLine(ip - 6), fnName); + Con::warnf(ConsoleLogEntry::General, "%s: Unknown function %s.", mCodeBlock->getFileLine(ip - 6), fnName); } STR.popFrame(); CSTK.popFrame(); @@ -2521,17 +2536,16 @@ OPCodeReturn CodeInterpreter::op_callfunc_this(U32 &ip) { if (!mExec.noCalls) { - Con::warnf(ConsoleLogEntry::General, "%s: Unknown command %s.", mCodeBlock->getFileLine(ip - 6), fnName); if (mThisObject) { - Con::warnf(ConsoleLogEntry::General, " Object %s(%d) %s", - mThisObject->getName() ? mThisObject->getName() : "", - mThisObject->getId(), Con::getNamespaceList(ns)); + // Try to use the name instead of the id + StringTableEntry name = mThisObject->getName() ? mThisObject->getName() : mThisObject->getIdString(); + Con::warnf(ConsoleLogEntry::General, "%s: Unknown method %s.%s Namespace List: %s", mCodeBlock->getFileLine(ip - 6), name, fnName, Con::getNamespaceList(ns)); } else { // At least let the scripter know that they access the object. - Con::warnf(ConsoleLogEntry::General, " Object is NULL."); + Con::warnf(ConsoleLogEntry::General, "%s: Unknown method NULL.%s", mCodeBlock->getFileLine(ip - 6), fnName); } } STR.popFrame();