From 8fd19f84c800d42dfb81563116c78bcce2df5b3a Mon Sep 17 00:00:00 2001 From: Colin Snover Date: Mon, 26 Sep 2016 20:41:37 -0500 Subject: SCI: Deduplicate call origin formatting --- engines/sci/engine/selector.cpp | 10 +++++----- engines/sci/engine/state.h | 4 ++++ engines/sci/engine/vm.cpp | 27 +++++++++------------------ engines/sci/engine/vm_types.cpp | 5 +---- 4 files changed, 19 insertions(+), 27 deletions(-) (limited to 'engines/sci/engine') diff --git a/engines/sci/engine/selector.cpp b/engines/sci/engine/selector.cpp index 79126553d9..3ae902215c 100644 --- a/engines/sci/engine/selector.cpp +++ b/engines/sci/engine/selector.cpp @@ -227,12 +227,12 @@ void writeSelector(SegManager *segMan, reg_t object, Selector selectorId, reg_t if ((selectorId < 0) || (selectorId > (int)g_sci->getKernel()->getSelectorNamesSize())) { const SciCallOrigin origin = g_sci->getEngineState()->getCurrentCallOrigin(); - error("Attempt to write to invalid selector %d. Address %04x:%04x, method %s::%s (room %d, script %d, localCall %x)", selectorId, PRINT_REG(object), origin.objectName.c_str(), origin.methodName.c_str(), origin.roomNr, origin.scriptNr, origin.localCallOffset); + error("Attempt to write to invalid selector %d. Address %04x:%04x, %s", selectorId, PRINT_REG(object), origin.toString().c_str()); } if (lookupSelector(segMan, object, selectorId, &address, NULL) != kSelectorVariable) { const SciCallOrigin origin = g_sci->getEngineState()->getCurrentCallOrigin(); - error("Selector '%s' of object could not be written to. Address %04x:%04x, method %s::%s (room %d, script %d, localCall %x)", g_sci->getKernel()->getSelectorName(selectorId).c_str(), PRINT_REG(object), origin.objectName.c_str(), origin.methodName.c_str(), origin.roomNr, origin.scriptNr, origin.localCallOffset); + error("Selector '%s' of object could not be written to. Address %04x:%04x, %s", g_sci->getKernel()->getSelectorName(selectorId).c_str(), PRINT_REG(object), origin.toString().c_str()); } else { *address.getPointer(segMan) = value; #ifdef ENABLE_SCI32 @@ -255,11 +255,11 @@ void invokeSelector(EngineState *s, reg_t object, int selectorId, if (slc_type == kSelectorNone) { const SciCallOrigin origin = g_sci->getEngineState()->getCurrentCallOrigin(); - error("invokeSelector: Selector '%s' could not be invoked. Address %04x:%04x, method %s::%s (room %d, script %d, localCall %x)", g_sci->getKernel()->getSelectorName(selectorId).c_str(), PRINT_REG(object), origin.objectName.c_str(), origin.methodName.c_str(), origin.roomNr, origin.scriptNr, origin.localCallOffset); + error("invokeSelector: Selector '%s' could not be invoked. Address %04x:%04x, %s", g_sci->getKernel()->getSelectorName(selectorId).c_str(), PRINT_REG(object), origin.toString().c_str()); } if (slc_type == kSelectorVariable) { const SciCallOrigin origin = g_sci->getEngineState()->getCurrentCallOrigin(); - error("invokeSelector: Attempting to invoke variable selector %s. Address %04x:%04x, method %s::%s (room %d, script %d, localCall %x)", g_sci->getKernel()->getSelectorName(selectorId).c_str(), PRINT_REG(object), origin.objectName.c_str(), origin.methodName.c_str(), origin.roomNr, origin.scriptNr, origin.localCallOffset); + error("invokeSelector: Attempting to invoke variable selector %s. Address %04x:%04x, %s", g_sci->getKernel()->getSelectorName(selectorId).c_str(), PRINT_REG(object), origin.toString().c_str()); } for (i = 0; i < argc; i++) @@ -288,7 +288,7 @@ SelectorType lookupSelector(SegManager *segMan, reg_t obj_location, Selector sel if (!obj) { const SciCallOrigin origin = g_sci->getEngineState()->getCurrentCallOrigin(); - error("lookupSelector: Attempt to send to non-object or invalid script. Address %04x:%04x, method %s::%s (room %d, script %d, localCall %x)", PRINT_REG(obj_location), origin.objectName.c_str(), origin.methodName.c_str(), origin.roomNr, origin.scriptNr, origin.localCallOffset); + error("lookupSelector: Attempt to send to non-object or invalid script. Address %04x:%04x, %s", PRINT_REG(obj_location), origin.toString().c_str()); } index = obj->locateVarSelector(segMan, selectorId); diff --git a/engines/sci/engine/state.h b/engines/sci/engine/state.h index 36ae784260..5297a176d3 100644 --- a/engines/sci/engine/state.h +++ b/engines/sci/engine/state.h @@ -104,6 +104,10 @@ struct SciCallOrigin { Common::String methodName; //< The name of the method being called int localCallOffset; //< The byte offset of a local script subroutine called by the origin method. -1 if not in a local subroutine. int roomNr; //< The room that was loaded at the time of the call + + Common::String toString() const { + return Common::String::format("method %s::%s (room %d, script %d, localCall %x)", objectName.c_str(), methodName.c_str(), roomNr, scriptNr, localCallOffset); + } }; struct EngineState : public Common::Serializable { diff --git a/engines/sci/engine/vm.cpp b/engines/sci/engine/vm.cpp index c0334f52ad..9d8c5f7fc6 100644 --- a/engines/sci/engine/vm.cpp +++ b/engines/sci/engine/vm.cpp @@ -129,16 +129,12 @@ static reg_t read_var(EngineState *s, int type, int index) { if (solution.type == WORKAROUND_NONE) { #ifdef RELEASE_BUILD // If we are running an official ScummVM release -> fake 0 in unknown cases - warning("Uninitialized read for temp %d from method %s::%s (room %d, script %d, localCall %x)", - index, originReply.objectName.c_str(), originReply.methodName.c_str(), s->currentRoomNumber(), - originReply.scriptNr, originReply.localCallOffset); + warning("Uninitialized read for temp %d from %s", index, originReply.toString().c_str()); s->variables[type][index] = NULL_REG; break; #else - error("Uninitialized read for temp %d from method %s::%s (room %d, script %d, localCall %x)", - index, originReply.objectName.c_str(), originReply.methodName.c_str(), s->currentRoomNumber(), - originReply.scriptNr, originReply.localCallOffset); + error("Uninitialized read for temp %d from %s", index, originReply.toString().c_str()); #endif } assert(solution.type == WORKAROUND_FAKE); @@ -367,10 +363,7 @@ static void callKernelFunc(EngineState *s, int kernelCallNr, int argc) { case WORKAROUND_NONE: { Common::String signatureDetailsStr; kernel->signatureDebug(signatureDetailsStr, kernelCall.signature, argc, argv); - error("\n%s[VM] k%s[%x]: signature mismatch in method %s::%s (room %d, script %d, localCall 0x%x)", - signatureDetailsStr.c_str(), - kernelCall.name, kernelCallNr, originReply.objectName.c_str(), originReply.methodName.c_str(), - s->currentRoomNumber(), originReply.scriptNr, originReply.localCallOffset); + error("\n%s[VM] k%s[%x]: signature mismatch in %s", signatureDetailsStr.c_str(), kernelCall.name, kernelCallNr, originReply.toString().c_str()); break; } case WORKAROUND_IGNORE: // don't do kernel call, leave acc alone @@ -438,15 +431,13 @@ static void callKernelFunc(EngineState *s, int kernelCallNr, int argc) { int callNameLen = strlen(kernelCall.name); if (strncmp(kernelCall.name, kernelSubCall.name, callNameLen) == 0) { const char *subCallName = kernelSubCall.name + callNameLen; - error("\n%s[VM] k%s(%s): signature mismatch in method %s::%s (room %d, script %d, localCall %x)", - signatureDetailsStr.c_str(), - kernelCall.name, subCallName, originReply.objectName.c_str(), originReply.methodName.c_str(), - s->currentRoomNumber(), originReply.scriptNr, originReply.localCallOffset); + error("\n%s[VM] k%s(%s): signature mismatch in %s", + signatureDetailsStr.c_str(), kernelCall.name, subCallName, + originReply.toString().c_str()); } - error("\n%s[VM] k%s: signature mismatch in method %s::%s (room %d, script %d, localCall %x)", - signatureDetailsStr.c_str(), - kernelSubCall.name, originReply.objectName.c_str(), originReply.methodName.c_str(), - s->currentRoomNumber(), originReply.scriptNr, originReply.localCallOffset); + error("\n%s[VM] k%s: signature mismatch in %s", + signatureDetailsStr.c_str(), kernelSubCall.name, + originReply.toString().c_str()); break; } case WORKAROUND_IGNORE: // don't do kernel call, leave acc alone diff --git a/engines/sci/engine/vm_types.cpp b/engines/sci/engine/vm_types.cpp index 1076863ea5..b2e250ab8b 100644 --- a/engines/sci/engine/vm_types.cpp +++ b/engines/sci/engine/vm_types.cpp @@ -69,10 +69,7 @@ reg_t reg_t::lookForWorkaround(const reg_t right, const char *operation) const { SciCallOrigin originReply; SciWorkaroundSolution solution = trackOriginAndFindWorkaround(0, arithmeticWorkarounds, &originReply); if (solution.type == WORKAROUND_NONE) - error("Invalid arithmetic operation (%s - params: %04x:%04x and %04x:%04x) from method %s::%s (room %d, script %d, localCall %x)", - operation, PRINT_REG(*this), PRINT_REG(right), originReply.objectName.c_str(), - originReply.methodName.c_str(), g_sci->getEngineState()->currentRoomNumber(), originReply.scriptNr, - originReply.localCallOffset); + error("Invalid arithmetic operation (%s - params: %04x:%04x and %04x:%04x) from %s", operation, PRINT_REG(*this), PRINT_REG(right), originReply.toString().c_str()); assert(solution.type == WORKAROUND_FAKE); return make_reg(0, solution.value); } -- cgit v1.2.3