1.1 --- a/core/DebugReporter.cpp Tue Aug 07 22:11:00 2007 +0000
1.2 +++ b/core/DebugReporter.cpp Wed Aug 08 02:27:10 2007 +0000
1.3 @@ -33,14 +33,56 @@
1.4 #include "DebugReporter.h"
1.5 #include "Logger.h"
1.6 #include "PluginSys.h"
1.7 +#include "sm_stringutil.h"
1.8
1.9 DebugReport g_DbgReporter;
1.10
1.11 +/* I'm really lazy. This should probably be exported to ISourcePawnEngine someday,
1.12 + * but we need to make sure the JIT will deal with the version bump.
1.13 + */
1.14 +extern const char *GetSourcePawnErrorMessage(int error);
1.15 +
1.16 void DebugReport::OnSourceModAllInitialized()
1.17 {
1.18 g_pSourcePawn->SetDebugListener(this);
1.19 }
1.20
1.21 +void DebugReport::GenerateError(IPluginContext *ctx, cell_t func_idx, int err, const char *message, ...)
1.22 +{
1.23 + va_list ap;
1.24 + char buffer[512];
1.25 +
1.26 + va_start(ap, message);
1.27 + UTIL_FormatArgs(buffer, sizeof(buffer), message, ap);
1.28 + va_end(ap);
1.29 +
1.30 + const char *plname = g_PluginSys.FindPluginByContext(ctx->GetContext())->GetFilename();
1.31 + const char *error = GetSourcePawnErrorMessage(err);
1.32 +
1.33 + if (error)
1.34 + {
1.35 + g_Logger.LogError("[SM] Plugin \"%s\" encountered error %d: %s", plname, err, error);
1.36 + } else {
1.37 + g_Logger.LogError("[SM] Plugin \"%s\" encountered unknown error %d", plname, err);
1.38 + }
1.39 +
1.40 + g_Logger.LogError("[SM] %s", buffer);
1.41 +
1.42 + const char *func_name = NULL;
1.43 + if (func_idx != -1)
1.44 + {
1.45 + if (func_idx & 1)
1.46 + {
1.47 + func_idx >>= 1;
1.48 + sp_public_t *function;
1.49 + if (ctx->GetPublicByIndex(func_idx, &function) == SP_ERROR_NONE)
1.50 + {
1.51 + g_Logger.LogError("[SM] Unable to call function \"%s\" due to above errors.", function->name);
1.52 + }
1.53 + }
1.54 + }
1.55 +}
1.56 +
1.57 void DebugReport::OnContextExecuteError(IPluginContext *ctx, IContextTrace *error)
1.58 {
1.59 const char *lastname;