3 * ===============================================================
4 * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
5 * ===============================================================
7 * This file is not open source and may not be copied without explicit
8 * written permission of AlliedModders LLC. This file may not be redistributed
9 * in whole or significant part.
10 * For information, see LICENSE.txt or http://www.sourcemod.net/license.php
15 #include "DebugReporter.h"
17 #include "PluginSys.h"
19 DebugReport g_DbgReporter;
21 void DebugReport::OnSourceModAllInitialized()
23 g_pSourcePawn->SetDebugListener(this);
26 void DebugReport::OnContextExecuteError(IPluginContext *ctx, IContextTrace *error)
29 const char *plname = g_PluginSys.FindPluginByContext(ctx->GetContext())->GetFilename();
30 int n_err = error->GetErrorCode();
32 if (n_err != SP_ERROR_NATIVE)
34 g_Logger.LogError("[SM] Plugin encountered error %d: %s",
36 error->GetErrorString());
39 if ((lastname=error->GetLastNative(NULL)) != NULL)
42 if ((custerr=error->GetCustomErrorString()) != NULL)
44 g_Logger.LogError("[SM] Native \"%s\" reported: %s", lastname, custerr);
46 g_Logger.LogError("[SM] Native \"%s\" encountered a generic error.", lastname);
50 if (!error->DebugInfoAvailable())
52 g_Logger.LogError("[SM] Debug mode is not enabled for \"%s\"", plname);
53 g_Logger.LogError("[SM] To enable debug mode, edit plugin_settings.cfg, or type: sm plugins debug %d on",
54 _GetPluginIndex(ctx));
58 CallStackInfo stk_info;
60 g_Logger.LogError("[SM] Displaying call stack trace:");
61 while (error->GetTraceInfo(&stk_info))
63 g_Logger.LogError("[SM] [%d] Line %d, %s::%s()",
71 int DebugReport::_GetPluginIndex(IPluginContext *ctx)
74 IPluginIterator *iter = g_PluginSys.GetPluginIterator();
76 for (; iter->MorePlugins(); iter->NextPlugin(), id++)
78 IPlugin *pl = iter->GetPlugin();
79 if (pl->GetBaseContext() == ctx)