From fec2fa3bf0cbc9093464502a0ef7b9eda5e8461e Mon Sep 17 00:00:00 2001 From: Fyren Date: Wed, 18 Nov 2015 01:24:31 +0000 Subject: [PATCH 1/2] Update SP and use BlamePluginError in sdkhooks. --- core/logic/DebugReporter.cpp | 80 ++++++++++++++++++++----------- extensions/sdkhooks/extension.cpp | 8 ++-- sourcepawn | 2 +- 3 files changed, 56 insertions(+), 34 deletions(-) diff --git a/core/logic/DebugReporter.cpp b/core/logic/DebugReporter.cpp index 01293498..e1f05a62 100644 --- a/core/logic/DebugReporter.cpp +++ b/core/logic/DebugReporter.cpp @@ -157,44 +157,66 @@ int DebugReport::_GetPluginIndex(IPluginContext *ctx) void DebugReport::ReportError(const IErrorReport &report, IFrameIterator &iter) { - // Find the nearest plugin to blame. const char *blame = nullptr; - for (; !iter.Done(); iter.Next()) { - if (iter.IsScriptedFrame()) { - IPlugin *plugin = pluginsys->FindPluginByContext(iter.Context()->GetContext()); - if (plugin) - blame = plugin->GetFilename(); - else - blame = iter.Context()->GetRuntime()->GetFilename(); - break; + if (report.Blame()) + { + blame = report.Blame()->DebugName(); + } else { + // Find the nearest plugin to blame. + for (; !iter.Done(); iter.Next()) + { + if (iter.IsScriptedFrame()) + { + IPlugin *plugin = pluginsys->FindPluginByContext(iter.Context()->GetContext()); + if (plugin) + { + blame = plugin->GetFilename(); + } else { + blame = iter.Context()->GetRuntime()->GetFilename(); + } + break; + } } } iter.Reset(); g_Logger.LogError("[SM] Exception reported: %s", report.Message()); - if (blame) - g_Logger.LogError("[SM] Blaming plugin: %s", blame); - g_Logger.LogError("[SM] Call stack trace:"); - for (int index = 0; !iter.Done(); iter.Next(), index++) { - const char *fn = iter.FunctionName(); - if (!fn) - fn = ""; + if (blame) + { + g_Logger.LogError("[SM] Blaming: %s()", blame); + } - if (iter.IsNativeFrame()) { - g_Logger.LogError("[SM] [%d] %s", index, fn); - continue; - } - if (iter.IsScriptedFrame()) { - const char *file = iter.FilePath(); - if (!file) - file = ""; - g_Logger.LogError("[SM] [%d] Line %d, %s::%s()", - index, - iter.LineNumber(), - file, - fn); + if (!iter.Done()) + { + g_Logger.LogError("[SM] Call stack trace:"); + + for (int index = 0; !iter.Done(); iter.Next(), index++) + { + const char *fn = iter.FunctionName(); + if (!fn) + { + fn = ""; + } + if (iter.IsNativeFrame()) + { + g_Logger.LogError("[SM] [%d] %s", index, fn); + continue; + } + if (iter.IsScriptedFrame()) + { + const char *file = iter.FilePath(); + if (!file) + { + file = ""; + } + g_Logger.LogError("[SM] [%d] Line %d, %s::%s()", + index, + iter.LineNumber(), + file, + fn); + } } } } diff --git a/extensions/sdkhooks/extension.cpp b/extensions/sdkhooks/extension.cpp index d0a0261d..277727d7 100644 --- a/extensions/sdkhooks/extension.cpp +++ b/extensions/sdkhooks/extension.cpp @@ -1059,13 +1059,13 @@ int SDKHooks::HandleOnTakeDamageHook(CTakeDamageInfoHack &info, SDKHookType hook CBaseEntity *pEntAttacker = gamehelpers->ReferenceToEntity(attacker); if (!pEntAttacker) { - callback->GetParentRuntime()->GetDefaultContext()->ThrowNativeError("Entity %d for attacker is invalid", attacker); + callback->GetParentContext()->BlamePluginError(callback, "Callback-provided entity %d for attacker is invalid", attacker); RETURN_META_VALUE(MRES_IGNORED, 0); } CBaseEntity *pEntInflictor = gamehelpers->ReferenceToEntity(inflictor); if (!pEntInflictor) { - callback->GetParentRuntime()->GetDefaultContext()->ThrowNativeError("Entity %d for inflictor is invalid", inflictor); + callback->GetParentContext()->BlamePluginError(callback, "Callback-provided entity %d for inflictor is invalid", inflictor); RETURN_META_VALUE(MRES_IGNORED, 0); } @@ -1442,13 +1442,13 @@ void SDKHooks::Hook_TraceAttack(CTakeDamageInfoHack &info, const Vector &vecDir, CBaseEntity *pEntAttacker = gamehelpers->ReferenceToEntity(attacker); if(!pEntAttacker) { - callback->GetParentRuntime()->GetDefaultContext()->ThrowNativeError("Entity %d for attacker is invalid", attacker); + callback->GetParentContext()->BlamePluginError(callback, "Callback-provided entity %d for attacker is invalid", attacker); RETURN_META(MRES_IGNORED); } CBaseEntity *pEntInflictor = gamehelpers->ReferenceToEntity(inflictor); if(!pEntInflictor) { - callback->GetParentRuntime()->GetDefaultContext()->ThrowNativeError("Entity %d for inflictor is invalid", inflictor); + callback->GetParentContext()->BlamePluginError(callback, "Callback-provided entity %d for inflictor is invalid", inflictor); RETURN_META(MRES_IGNORED); } diff --git a/sourcepawn b/sourcepawn index dde42ef1..22e7ddee 160000 --- a/sourcepawn +++ b/sourcepawn @@ -1 +1 @@ -Subproject commit dde42ef136c59ae125169a850298b1383e53afb6 +Subproject commit 22e7ddeeac40503d51a27e228e8de49ca49566af From cf4f500eda5c26ab4ef09d334d1d0763f0028b63 Mon Sep 17 00:00:00 2001 From: Fyren Date: Wed, 18 Nov 2015 01:37:15 +0000 Subject: [PATCH 2/2] And use it in sdktools, too. --- extensions/sdktools/vsound.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/extensions/sdktools/vsound.cpp b/extensions/sdktools/vsound.cpp index cfd4ec6a..0909118f 100644 --- a/extensions/sdktools/vsound.cpp +++ b/extensions/sdktools/vsound.cpp @@ -410,9 +410,9 @@ void SoundHooks::OnEmitSound(IRecipientFilter &filter, int iEntIndex, int iChann if (!pPlayer) { - pFunc->GetParentContext()->ThrowNativeError("Client index %d is invalid", client); + pFunc->GetParentContext()->BlamePluginError(pFunc, "Callback-provided client index %d is invalid", client); } else if (!pPlayer->IsInGame()) { - pFunc->GetParentContext()->ThrowNativeError("Client %d is not connected", client); + pFunc->GetParentContext()->BlamePluginError(pFunc, "Client %d is not connected", client); } else { continue; } @@ -548,9 +548,9 @@ void SoundHooks::OnEmitSound2(IRecipientFilter &filter, int iEntIndex, int iChan if (!pPlayer) { - pFunc->GetParentContext()->ThrowNativeError("Client index %d is invalid", client); + pFunc->GetParentContext()->BlamePluginError(pFunc, "Client index %d is invalid", client); } else if (!pPlayer->IsInGame()) { - pFunc->GetParentContext()->ThrowNativeError("Client %d is not connected", client); + pFunc->GetParentContext()->BlamePluginError(pFunc, "Client %d is not connected", client); } else { continue; }