core/DebugReporter.cpp
changeset 1339 02e8f2c0f8af
parent 1330 ab94316bb52b
child 1340 031de7d14eca
     1.1 --- a/core/DebugReporter.cpp	Wed Aug 15 18:26:15 2007 +0000
     1.2 +++ b/core/DebugReporter.cpp	Wed Aug 15 20:18:15 2007 +0000
     1.3 @@ -75,12 +75,51 @@
     1.4  			sp_public_t *function;
     1.5  			if (ctx->GetPublicByIndex(func_idx, &function) == SP_ERROR_NONE)
     1.6  			{
     1.7 -				g_Logger.LogError("[SM] Unable to call function \"%s\" due to above errors.", function->name);
     1.8 +				g_Logger.LogError("[SM] Unable to call function \"%s\" due to above error(s).", function->name);
     1.9  			}
    1.10  		}
    1.11  	}
    1.12  }
    1.13  
    1.14 +void DebugReport::GenerateCodeError(IPluginContext *pContext, uint32_t code_addr, int err, const char *message, ...)
    1.15 +{
    1.16 +	va_list ap;
    1.17 +	char buffer[512];
    1.18 +
    1.19 +	va_start(ap, message);
    1.20 +	UTIL_FormatArgs(buffer, sizeof(buffer), message, ap);
    1.21 +	va_end(ap);
    1.22 +
    1.23 +	const char *plname = g_PluginSys.FindPluginByContext(pContext->GetContext())->GetFilename();
    1.24 +	const char *error = GetSourcePawnErrorMessage(err);
    1.25 +
    1.26 +	if (error)
    1.27 +	{
    1.28 +		g_Logger.LogError("[SM] Plugin \"%s\" encountered error %d: %s", plname, err, error);
    1.29 +	} else {
    1.30 +		g_Logger.LogError("[SM] Plugin \"%s\" encountered unknown error %d", plname, err);
    1.31 +	}
    1.32 +
    1.33 +	g_Logger.LogError("[SM] %s", buffer);
    1.34 +
    1.35 +	IPluginDebugInfo *pDebug;
    1.36 +	if ((pDebug = pContext->GetDebugInfo()) == NULL)
    1.37 +	{
    1.38 +		g_Logger.LogError("[SM] Debug mode is not enabled for \"%s\"", plname);
    1.39 +		g_Logger.LogError("[SM] To enable debug mode, edit plugin_settings.cfg, or type: sm plugins debug %d on",
    1.40 +			_GetPluginIndex(pContext));
    1.41 +		return;
    1.42 +	}
    1.43 +
    1.44 +	const char *name;
    1.45 +	if (pDebug->LookupFunction(code_addr, &name) == SP_ERROR_NONE)
    1.46 +	{
    1.47 +		g_Logger.LogError("[SM] Unable to call function \"%s\" due to above error(s).", name);
    1.48 +	} else {
    1.49 +		g_Logger.LogError("[SM] Unable to call function (name unknown, address \"%x\").", code_addr);
    1.50 +	}
    1.51 +}
    1.52 +
    1.53  void DebugReport::OnContextExecuteError(IPluginContext *ctx, IContextTrace *error)
    1.54  {
    1.55  	const char *lastname;