2 * ===============================================================
3 * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
4 * ===============================================================
6 * This file is not open source and may not be copied without explicit
7 * written permission of AlliedModders LLC. This file may not be redistributed
8 * in whole or significant part.
9 * For information, see LICENSE.txt or http://www.sourcemod.net/license.php
14 #include "CDbgReporter.h"
16 #include "PluginSys.h"
18 CDbgReporter g_DbgReporter;
20 void CDbgReporter::OnSourceModAllInitialized()
22 g_pSourcePawn->SetDebugListener(this);
25 void CDbgReporter::OnContextExecuteError(IPluginContext *ctx, IContextTrace *error)
28 const char *plname = g_PluginSys.FindPluginByContext(ctx->GetContext())->GetFilename();
29 int n_err = error->GetErrorCode();
31 if (n_err != SP_ERROR_NATIVE)
33 g_Logger.LogError("[SM] Plugin \"%s\" 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 this plugin.");
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 CDbgReporter::_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)