Move DebugReporter from core to logic (bug 5607, r=psychonic).
authorDavid Anderson <dvander@alliedmods.net>
Sat Feb 16 15:57:00 2013 -0800 (2013-02-16)
changeset 3792d8a07e40bcb6
parent 3791 47e1ee9cea86
child 3793 7818566b29f4
Move DebugReporter from core to logic (bug 5607, r=psychonic).
core/AMBuilder
core/DebugReporter.cpp
core/DebugReporter.h
core/ForwardSys.cpp
core/logic/AMBuilder
core/logic/DebugReporter.cpp
core/logic/DebugReporter.h
core/logic/common_logic.cpp
core/logic/intercom.h
core/logic/smn_timers.cpp
core/logic_bridge.cpp
core/smn_menus.cpp
core/sourcemod.cpp
     1.1 --- a/core/AMBuilder	Sat Feb 16 15:52:11 2013 -0800
     1.2 +++ b/core/AMBuilder	Sat Feb 16 15:57:00 2013 -0800
     1.3 @@ -86,7 +86,6 @@
     1.4  		'smn_core.cpp',
     1.5  		'smn_hudtext.cpp',
     1.6  		'smn_usermsgs.cpp',
     1.7 -		'DebugReporter.cpp',
     1.8  		'MenuStyle_Base.cpp',
     1.9  		'ShareSys.cpp',
    1.10  		'smn_database.cpp',
     2.1 --- a/core/DebugReporter.cpp	Sat Feb 16 15:52:11 2013 -0800
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,201 +0,0 @@
     2.4 -/**
     2.5 - * vim: set ts=4 :
     2.6 - * =============================================================================
     2.7 - * SourceMod
     2.8 - * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
     2.9 - * =============================================================================
    2.10 - *
    2.11 - * This program is free software; you can redistribute it and/or modify it under
    2.12 - * the terms of the GNU General Public License, version 3.0, as published by the
    2.13 - * Free Software Foundation.
    2.14 - * 
    2.15 - * This program is distributed in the hope that it will be useful, but WITHOUT
    2.16 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    2.17 - * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    2.18 - * details.
    2.19 - *
    2.20 - * You should have received a copy of the GNU General Public License along with
    2.21 - * this program.  If not, see <http://www.gnu.org/licenses/>.
    2.22 - *
    2.23 - * As a special exception, AlliedModders LLC gives you permission to link the
    2.24 - * code of this program (as well as its derivative works) to "Half-Life 2," the
    2.25 - * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    2.26 - * by the Valve Corporation.  You must obey the GNU General Public License in
    2.27 - * all respects for all other code used.  Additionally, AlliedModders LLC grants
    2.28 - * this exception to all derivative works.  AlliedModders LLC defines further
    2.29 - * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    2.30 - * or <http://www.sourcemod.net/license.php>.
    2.31 - *
    2.32 - * Version: $Id$
    2.33 - */
    2.34 -
    2.35 -#include "DebugReporter.h"
    2.36 -#include "Logger.h"
    2.37 -#include "PluginSys.h"
    2.38 -#include "sm_stringutil.h"
    2.39 -
    2.40 -DebugReport g_DbgReporter;
    2.41 -
    2.42 -void DebugReport::OnSourceModAllInitialized()
    2.43 -{
    2.44 -	g_pSourcePawn->SetDebugListener(this);
    2.45 -}
    2.46 -
    2.47 -void DebugReport::OnDebugSpew(const char *msg, ...)
    2.48 -{
    2.49 -	va_list ap;
    2.50 -	char buffer[512];
    2.51 -
    2.52 -	va_start(ap, msg);
    2.53 -	UTIL_FormatArgs(buffer, sizeof(buffer), msg, ap);
    2.54 -	va_end(ap);
    2.55 -
    2.56 -	g_Logger.LogMessage("[SM] %s", buffer);
    2.57 -}
    2.58 -
    2.59 -void DebugReport::GenerateError(IPluginContext *ctx, cell_t func_idx, int err, const char *message, ...)
    2.60 -{
    2.61 -	va_list ap;
    2.62 -
    2.63 -	va_start(ap, message);
    2.64 -	GenerateErrorVA(ctx, func_idx, err, message, ap);
    2.65 -	va_end(ap);
    2.66 -}
    2.67 -
    2.68 -void DebugReport::GenerateErrorVA(IPluginContext *ctx, cell_t func_idx, int err, const char *message, va_list ap)
    2.69 -{
    2.70 -	char buffer[512];
    2.71 -	UTIL_FormatArgs(buffer, sizeof(buffer), message, ap);
    2.72 -
    2.73 -	const char *plname = g_PluginSys.FindPluginByContext(ctx->GetContext())->GetFilename();
    2.74 -	const char *error = g_pSourcePawn2->GetErrorString(err);
    2.75 -
    2.76 -	if (error)
    2.77 -	{
    2.78 -		g_Logger.LogError("[SM] Plugin \"%s\" encountered error %d: %s", plname, err, error);
    2.79 -	} else {
    2.80 -		g_Logger.LogError("[SM] Plugin \"%s\" encountered unknown error %d", plname, err);
    2.81 -	}
    2.82 -
    2.83 -	g_Logger.LogError("[SM] %s", buffer);
    2.84 -
    2.85 -	if (func_idx != -1)
    2.86 -	{
    2.87 -		if (func_idx & 1)
    2.88 -		{
    2.89 -			func_idx >>= 1;
    2.90 -			sp_public_t *function;
    2.91 -			if (ctx->GetRuntime()->GetPublicByIndex(func_idx, &function) == SP_ERROR_NONE)
    2.92 -			{
    2.93 -				g_Logger.LogError("[SM] Unable to call function \"%s\" due to above error(s).", function->name);
    2.94 -			}
    2.95 -		}
    2.96 -	}
    2.97 -}
    2.98 -
    2.99 -void DebugReport::GenerateCodeError(IPluginContext *pContext, uint32_t code_addr, int err, const char *message, ...)
   2.100 -{
   2.101 -	va_list ap;
   2.102 -	char buffer[512];
   2.103 -
   2.104 -	va_start(ap, message);
   2.105 -	UTIL_FormatArgs(buffer, sizeof(buffer), message, ap);
   2.106 -	va_end(ap);
   2.107 -
   2.108 -	const char *plname = g_PluginSys.FindPluginByContext(pContext->GetContext())->GetFilename();
   2.109 -	const char *error = g_pSourcePawn2->GetErrorString(err);
   2.110 -
   2.111 -	if (error)
   2.112 -	{
   2.113 -		g_Logger.LogError("[SM] Plugin \"%s\" encountered error %d: %s", plname, err, error);
   2.114 -	} else {
   2.115 -		g_Logger.LogError("[SM] Plugin \"%s\" encountered unknown error %d", plname, err);
   2.116 -	}
   2.117 -
   2.118 -	g_Logger.LogError("[SM] %s", buffer);
   2.119 -
   2.120 -	IPluginDebugInfo *pDebug;
   2.121 -	if ((pDebug = pContext->GetRuntime()->GetDebugInfo()) == NULL)
   2.122 -	{
   2.123 -		g_Logger.LogError("[SM] Debug mode is not enabled for \"%s\"", plname);
   2.124 -		g_Logger.LogError("[SM] To enable debug mode, edit plugin_settings.cfg, or type: sm plugins debug %d on",
   2.125 -			_GetPluginIndex(pContext));
   2.126 -		return;
   2.127 -	}
   2.128 -
   2.129 -	const char *name;
   2.130 -	if (pDebug->LookupFunction(code_addr, &name) == SP_ERROR_NONE)
   2.131 -	{
   2.132 -		g_Logger.LogError("[SM] Unable to call function \"%s\" due to above error(s).", name);
   2.133 -	} else {
   2.134 -		g_Logger.LogError("[SM] Unable to call function (name unknown, address \"%x\").", code_addr);
   2.135 -	}
   2.136 -}
   2.137 -
   2.138 -void DebugReport::OnContextExecuteError(IPluginContext *ctx, IContextTrace *error)
   2.139 -{
   2.140 -	const char *lastname;
   2.141 -	const char *plname = g_PluginSys.FindPluginByContext(ctx->GetContext())->GetFilename();
   2.142 -	int n_err = error->GetErrorCode();
   2.143 -
   2.144 -	if (n_err != SP_ERROR_NATIVE)
   2.145 -	{
   2.146 -		g_Logger.LogError("[SM] Plugin encountered error %d: %s",
   2.147 -			n_err,
   2.148 -			error->GetErrorString());
   2.149 -	}
   2.150 -
   2.151 -	if ((lastname=error->GetLastNative(NULL)) != NULL)
   2.152 -	{
   2.153 -		const char *custerr;
   2.154 -		if ((custerr=error->GetCustomErrorString()) != NULL)
   2.155 -		{
   2.156 -			g_Logger.LogError("[SM] Native \"%s\" reported: %s", lastname, custerr);
   2.157 -		} else {
   2.158 -			g_Logger.LogError("[SM] Native \"%s\" encountered a generic error.", lastname);
   2.159 -		}
   2.160 -	}
   2.161 -
   2.162 -	if (!error->DebugInfoAvailable())
   2.163 -	{
   2.164 -		g_Logger.LogError("[SM] Debug mode is not enabled for \"%s\"", plname);
   2.165 -		g_Logger.LogError("[SM] To enable debug mode, edit plugin_settings.cfg, or type: sm plugins debug %d on",
   2.166 -			_GetPluginIndex(ctx));
   2.167 -		return;
   2.168 -	}
   2.169 -
   2.170 -	CallStackInfo stk_info;
   2.171 -	int i = 0;
   2.172 -	g_Logger.LogError("[SM] Displaying call stack trace for plugin \"%s\":", plname);
   2.173 -	while (error->GetTraceInfo(&stk_info))
   2.174 -	{
   2.175 -		g_Logger.LogError("[SM]   [%d]  Line %d, %s::%s()",
   2.176 -			i++,
   2.177 -			stk_info.line,
   2.178 -			stk_info.filename,
   2.179 -			stk_info.function);
   2.180 -	}
   2.181 -}
   2.182 -
   2.183 -int DebugReport::_GetPluginIndex(IPluginContext *ctx)
   2.184 -{
   2.185 -	int id = 1;
   2.186 -	IPluginIterator *iter = g_PluginSys.GetPluginIterator();
   2.187 -
   2.188 -	for (; iter->MorePlugins(); iter->NextPlugin(), id++)
   2.189 -	{
   2.190 -		IPlugin *pl = iter->GetPlugin();
   2.191 -		if (pl->GetBaseContext() == ctx)
   2.192 -		{
   2.193 -			iter->Release();
   2.194 -			return id;
   2.195 -		}
   2.196 -	}
   2.197 -
   2.198 -	iter->Release();
   2.199 -
   2.200 -	/* If we don't know which plugin this is, it's one being loaded.  Fake its index for now. */
   2.201 -
   2.202 -	return g_PluginSys.GetPluginCount() + 1;
   2.203 -}
   2.204 -
     3.1 --- a/core/DebugReporter.h	Sat Feb 16 15:52:11 2013 -0800
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,58 +0,0 @@
     3.4 -/**
     3.5 - * vim: set ts=4 :
     3.6 - * =============================================================================
     3.7 - * SourceMod
     3.8 - * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
     3.9 - * =============================================================================
    3.10 - *
    3.11 - * This program is free software; you can redistribute it and/or modify it under
    3.12 - * the terms of the GNU General Public License, version 3.0, as published by the
    3.13 - * Free Software Foundation.
    3.14 - * 
    3.15 - * This program is distributed in the hope that it will be useful, but WITHOUT
    3.16 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    3.17 - * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    3.18 - * details.
    3.19 - *
    3.20 - * You should have received a copy of the GNU General Public License along with
    3.21 - * this program.  If not, see <http://www.gnu.org/licenses/>.
    3.22 - *
    3.23 - * As a special exception, AlliedModders LLC gives you permission to link the
    3.24 - * code of this program (as well as its derivative works) to "Half-Life 2," the
    3.25 - * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    3.26 - * by the Valve Corporation.  You must obey the GNU General Public License in
    3.27 - * all respects for all other code used.  Additionally, AlliedModders LLC grants
    3.28 - * this exception to all derivative works.  AlliedModders LLC defines further
    3.29 - * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    3.30 - * or <http://www.sourcemod.net/license.php>.
    3.31 - *
    3.32 - * Version: $Id$
    3.33 - */
    3.34 -
    3.35 -#ifndef _INCLUDE_SOURCEMOD_CDBGREPORTER_H_
    3.36 -#define _INCLUDE_SOURCEMOD_CDBGREPORTER_H_
    3.37 -
    3.38 -#include "sp_vm_api.h"
    3.39 -#include "sm_globals.h"
    3.40 -
    3.41 -class DebugReport : 
    3.42 -	public SMGlobalClass, 
    3.43 -	public IDebugListener
    3.44 -{
    3.45 -public: // SMGlobalClass
    3.46 -	void OnSourceModAllInitialized();
    3.47 -public: // IDebugListener
    3.48 -	void OnContextExecuteError(IPluginContext *ctx, IContextTrace *error);
    3.49 -	void OnDebugSpew(const char *msg, ...);
    3.50 -public:
    3.51 -	void GenerateError(IPluginContext *ctx, cell_t func_idx, int err, const char *message, ...);
    3.52 -	void GenerateErrorVA(IPluginContext *ctx, cell_t func_idx, int err, const char *message, va_list ap); 
    3.53 -	void GenerateCodeError(IPluginContext *ctx, uint32_t code_addr, int err, const char *message, ...);
    3.54 -private:
    3.55 -	int _GetPluginIndex(IPluginContext *ctx);
    3.56 -};
    3.57 -
    3.58 -extern DebugReport g_DbgReporter;
    3.59 -
    3.60 -#endif // _INCLUDE_SOURCEMOD_CDBGREPORTER_H_
    3.61 -
     4.1 --- a/core/ForwardSys.cpp	Sat Feb 16 15:52:11 2013 -0800
     4.2 +++ b/core/ForwardSys.cpp	Sat Feb 16 15:57:00 2013 -0800
     4.3 @@ -35,7 +35,7 @@
     4.4  #include "ForwardSys.h"
     4.5  #include "PluginSys.h"
     4.6  #include "ShareSys.h"
     4.7 -#include "DebugReporter.h"
     4.8 +#include "logic_bridge.h"
     4.9  
    4.10  CForwardManager g_Forwards;
    4.11  
    4.12 @@ -356,7 +356,7 @@
    4.13  
    4.14  			if (err != SP_ERROR_NONE)
    4.15  			{
    4.16 -				g_DbgReporter.GenerateError(func->GetParentContext(), 
    4.17 +				logicore.GenerateError(func->GetParentContext(), 
    4.18  					func->GetFunctionID(), 
    4.19  					err, 
    4.20  					"Failed to push parameter while executing forward");
     5.1 --- a/core/logic/AMBuilder	Sat Feb 16 15:52:11 2013 -0800
     5.2 +++ b/core/logic/AMBuilder	Sat Feb 16 15:57:00 2013 -0800
     5.3 @@ -49,7 +49,8 @@
     5.4  	'smn_gameconfigs.cpp',
     5.5  	'GameConfigs.cpp',
     5.6  	'sm_crc32.cpp',
     5.7 -	'smn_profiler.cpp'
     5.8 +	'smn_profiler.cpp',
     5.9 +	'DebugReporter.cpp'
    5.10  	]
    5.11  if AMBuild.target['platform'] == 'windows':
    5.12  	files.append('thread/WinThreads.cpp')
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/core/logic/DebugReporter.cpp	Sat Feb 16 15:57:00 2013 -0800
     6.3 @@ -0,0 +1,199 @@
     6.4 +/**
     6.5 + * vim: set ts=4 :
     6.6 + * =============================================================================
     6.7 + * SourceMod
     6.8 + * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
     6.9 + * =============================================================================
    6.10 + *
    6.11 + * This program is free software; you can redistribute it and/or modify it under
    6.12 + * the terms of the GNU General Public License, version 3.0, as published by the
    6.13 + * Free Software Foundation.
    6.14 + * 
    6.15 + * This program is distributed in the hope that it will be useful, but WITHOUT
    6.16 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    6.17 + * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    6.18 + * details.
    6.19 + *
    6.20 + * You should have received a copy of the GNU General Public License along with
    6.21 + * this program.  If not, see <http://www.gnu.org/licenses/>.
    6.22 + *
    6.23 + * As a special exception, AlliedModders LLC gives you permission to link the
    6.24 + * code of this program (as well as its derivative works) to "Half-Life 2," the
    6.25 + * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    6.26 + * by the Valve Corporation.  You must obey the GNU General Public License in
    6.27 + * all respects for all other code used.  Additionally, AlliedModders LLC grants
    6.28 + * this exception to all derivative works.  AlliedModders LLC defines further
    6.29 + * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    6.30 + * or <http://www.sourcemod.net/license.php>.
    6.31 + *
    6.32 + * Version: $Id$
    6.33 + */
    6.34 +
    6.35 +#include <IPluginSys.h>
    6.36 +#include "DebugReporter.h"
    6.37 +
    6.38 +DebugReport g_DbgReporter;
    6.39 +
    6.40 +void DebugReport::OnSourceModAllInitialized()
    6.41 +{
    6.42 +	g_pSourcePawn->SetDebugListener(this);
    6.43 +}
    6.44 +
    6.45 +void DebugReport::OnDebugSpew(const char *msg, ...)
    6.46 +{
    6.47 +	va_list ap;
    6.48 +	char buffer[512];
    6.49 +
    6.50 +	va_start(ap, msg);
    6.51 +	smcore.FormatArgs(buffer, sizeof(buffer), msg, ap);
    6.52 +	va_end(ap);
    6.53 +
    6.54 +	smcore.Log("[SM] %s", buffer);
    6.55 +}
    6.56 +
    6.57 +void DebugReport::GenerateError(IPluginContext *ctx, cell_t func_idx, int err, const char *message, ...)
    6.58 +{
    6.59 +	va_list ap;
    6.60 +
    6.61 +	va_start(ap, message);
    6.62 +	GenerateErrorVA(ctx, func_idx, err, message, ap);
    6.63 +	va_end(ap);
    6.64 +}
    6.65 +
    6.66 +void DebugReport::GenerateErrorVA(IPluginContext *ctx, cell_t func_idx, int err, const char *message, va_list ap)
    6.67 +{
    6.68 +	char buffer[512];
    6.69 +	smcore.FormatArgs(buffer, sizeof(buffer), message, ap);
    6.70 +
    6.71 +	const char *plname = pluginsys->FindPluginByContext(ctx->GetContext())->GetFilename();
    6.72 +	const char *error = g_pSourcePawn2->GetErrorString(err);
    6.73 +
    6.74 +	if (error)
    6.75 +	{
    6.76 +		smcore.LogError("[SM] Plugin \"%s\" encountered error %d: %s", plname, err, error);
    6.77 +	} else {
    6.78 +		smcore.LogError("[SM] Plugin \"%s\" encountered unknown error %d", plname, err);
    6.79 +	}
    6.80 +
    6.81 +	smcore.LogError("[SM] %s", buffer);
    6.82 +
    6.83 +	if (func_idx != -1)
    6.84 +	{
    6.85 +		if (func_idx & 1)
    6.86 +		{
    6.87 +			func_idx >>= 1;
    6.88 +			sp_public_t *function;
    6.89 +			if (ctx->GetRuntime()->GetPublicByIndex(func_idx, &function) == SP_ERROR_NONE)
    6.90 +			{
    6.91 +				smcore.LogError("[SM] Unable to call function \"%s\" due to above error(s).", function->name);
    6.92 +			}
    6.93 +		}
    6.94 +	}
    6.95 +}
    6.96 +
    6.97 +void DebugReport::GenerateCodeError(IPluginContext *pContext, uint32_t code_addr, int err, const char *message, ...)
    6.98 +{
    6.99 +	va_list ap;
   6.100 +	char buffer[512];
   6.101 +
   6.102 +	va_start(ap, message);
   6.103 +	smcore.FormatArgs(buffer, sizeof(buffer), message, ap);
   6.104 +	va_end(ap);
   6.105 +
   6.106 +	const char *plname = pluginsys->FindPluginByContext(pContext->GetContext())->GetFilename();
   6.107 +	const char *error = g_pSourcePawn2->GetErrorString(err);
   6.108 +
   6.109 +	if (error)
   6.110 +	{
   6.111 +		smcore.LogError("[SM] Plugin \"%s\" encountered error %d: %s", plname, err, error);
   6.112 +	} else {
   6.113 +		smcore.LogError("[SM] Plugin \"%s\" encountered unknown error %d", plname, err);
   6.114 +	}
   6.115 +
   6.116 +	smcore.LogError("[SM] %s", buffer);
   6.117 +
   6.118 +	IPluginDebugInfo *pDebug;
   6.119 +	if ((pDebug = pContext->GetRuntime()->GetDebugInfo()) == NULL)
   6.120 +	{
   6.121 +		smcore.LogError("[SM] Debug mode is not enabled for \"%s\"", plname);
   6.122 +		smcore.LogError("[SM] To enable debug mode, edit plugin_settings.cfg, or type: sm plugins debug %d on",
   6.123 +			_GetPluginIndex(pContext));
   6.124 +		return;
   6.125 +	}
   6.126 +
   6.127 +	const char *name;
   6.128 +	if (pDebug->LookupFunction(code_addr, &name) == SP_ERROR_NONE)
   6.129 +	{
   6.130 +		smcore.LogError("[SM] Unable to call function \"%s\" due to above error(s).", name);
   6.131 +	} else {
   6.132 +		smcore.LogError("[SM] Unable to call function (name unknown, address \"%x\").", code_addr);
   6.133 +	}
   6.134 +}
   6.135 +
   6.136 +void DebugReport::OnContextExecuteError(IPluginContext *ctx, IContextTrace *error)
   6.137 +{
   6.138 +	const char *lastname;
   6.139 +	const char *plname = pluginsys->FindPluginByContext(ctx->GetContext())->GetFilename();
   6.140 +	int n_err = error->GetErrorCode();
   6.141 +
   6.142 +	if (n_err != SP_ERROR_NATIVE)
   6.143 +	{
   6.144 +		smcore.LogError("[SM] Plugin encountered error %d: %s",
   6.145 +			n_err,
   6.146 +			error->GetErrorString());
   6.147 +	}
   6.148 +
   6.149 +	if ((lastname=error->GetLastNative(NULL)) != NULL)
   6.150 +	{
   6.151 +		const char *custerr;
   6.152 +		if ((custerr=error->GetCustomErrorString()) != NULL)
   6.153 +		{
   6.154 +			smcore.LogError("[SM] Native \"%s\" reported: %s", lastname, custerr);
   6.155 +		} else {
   6.156 +			smcore.LogError("[SM] Native \"%s\" encountered a generic error.", lastname);
   6.157 +		}
   6.158 +	}
   6.159 +
   6.160 +	if (!error->DebugInfoAvailable())
   6.161 +	{
   6.162 +		smcore.LogError("[SM] Debug mode is not enabled for \"%s\"", plname);
   6.163 +		smcore.LogError("[SM] To enable debug mode, edit plugin_settings.cfg, or type: sm plugins debug %d on",
   6.164 +			_GetPluginIndex(ctx));
   6.165 +		return;
   6.166 +	}
   6.167 +
   6.168 +	CallStackInfo stk_info;
   6.169 +	int i = 0;
   6.170 +	smcore.LogError("[SM] Displaying call stack trace for plugin \"%s\":", plname);
   6.171 +	while (error->GetTraceInfo(&stk_info))
   6.172 +	{
   6.173 +		smcore.LogError("[SM]   [%d]  Line %d, %s::%s()",
   6.174 +			i++,
   6.175 +			stk_info.line,
   6.176 +			stk_info.filename,
   6.177 +			stk_info.function);
   6.178 +	}
   6.179 +}
   6.180 +
   6.181 +int DebugReport::_GetPluginIndex(IPluginContext *ctx)
   6.182 +{
   6.183 +	int id = 1;
   6.184 +	IPluginIterator *iter = pluginsys->GetPluginIterator();
   6.185 +
   6.186 +	for (; iter->MorePlugins(); iter->NextPlugin(), id++)
   6.187 +	{
   6.188 +		IPlugin *pl = iter->GetPlugin();
   6.189 +		if (pl->GetBaseContext() == ctx)
   6.190 +		{
   6.191 +			iter->Release();
   6.192 +			return id;
   6.193 +		}
   6.194 +	}
   6.195 +
   6.196 +	iter->Release();
   6.197 +
   6.198 +	/* If we don't know which plugin this is, it's one being loaded.  Fake its index for now. */
   6.199 +
   6.200 +	return pluginsys->GetPluginCount() + 1;
   6.201 +}
   6.202 +
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/core/logic/DebugReporter.h	Sat Feb 16 15:57:00 2013 -0800
     7.3 @@ -0,0 +1,58 @@
     7.4 +/**
     7.5 + * vim: set ts=4 :
     7.6 + * =============================================================================
     7.7 + * SourceMod
     7.8 + * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
     7.9 + * =============================================================================
    7.10 + *
    7.11 + * This program is free software; you can redistribute it and/or modify it under
    7.12 + * the terms of the GNU General Public License, version 3.0, as published by the
    7.13 + * Free Software Foundation.
    7.14 + * 
    7.15 + * This program is distributed in the hope that it will be useful, but WITHOUT
    7.16 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    7.17 + * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    7.18 + * details.
    7.19 + *
    7.20 + * You should have received a copy of the GNU General Public License along with
    7.21 + * this program.  If not, see <http://www.gnu.org/licenses/>.
    7.22 + *
    7.23 + * As a special exception, AlliedModders LLC gives you permission to link the
    7.24 + * code of this program (as well as its derivative works) to "Half-Life 2," the
    7.25 + * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    7.26 + * by the Valve Corporation.  You must obey the GNU General Public License in
    7.27 + * all respects for all other code used.  Additionally, AlliedModders LLC grants
    7.28 + * this exception to all derivative works.  AlliedModders LLC defines further
    7.29 + * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    7.30 + * or <http://www.sourcemod.net/license.php>.
    7.31 + *
    7.32 + * Version: $Id$
    7.33 + */
    7.34 +
    7.35 +#ifndef _INCLUDE_SOURCEMOD_CDBGREPORTER_H_
    7.36 +#define _INCLUDE_SOURCEMOD_CDBGREPORTER_H_
    7.37 +
    7.38 +#include "sp_vm_api.h"
    7.39 +#include "common_logic.h"
    7.40 +
    7.41 +class DebugReport : 
    7.42 +	public SMGlobalClass, 
    7.43 +	public IDebugListener
    7.44 +{
    7.45 +public: // SMGlobalClass
    7.46 +	void OnSourceModAllInitialized();
    7.47 +public: // IDebugListener
    7.48 +	void OnContextExecuteError(IPluginContext *ctx, IContextTrace *error);
    7.49 +	void OnDebugSpew(const char *msg, ...);
    7.50 +public:
    7.51 +	void GenerateError(IPluginContext *ctx, cell_t func_idx, int err, const char *message, ...);
    7.52 +	void GenerateErrorVA(IPluginContext *ctx, cell_t func_idx, int err, const char *message, va_list ap); 
    7.53 +	void GenerateCodeError(IPluginContext *ctx, uint32_t code_addr, int err, const char *message, ...);
    7.54 +private:
    7.55 +	int _GetPluginIndex(IPluginContext *ctx);
    7.56 +};
    7.57 +
    7.58 +extern DebugReport g_DbgReporter;
    7.59 +
    7.60 +#endif // _INCLUDE_SOURCEMOD_CDBGREPORTER_H_
    7.61 +
     8.1 --- a/core/logic/common_logic.cpp	Sat Feb 16 15:52:11 2013 -0800
     8.2 +++ b/core/logic/common_logic.cpp	Sat Feb 16 15:57:00 2013 -0800
     8.3 @@ -41,6 +41,7 @@
     8.4  #include "ThreadSupport.h"
     8.5  #include "Translator.h"
     8.6  #include "GameConfigs.h"
     8.7 +#include "DebugReporter.h"
     8.8  
     8.9  sm_core_t smcore;
    8.10  IHandleSys *handlesys;
    8.11 @@ -59,6 +60,8 @@
    8.12  IPlayerManager *playerhelpers;
    8.13  IAdminSystem *adminsys;
    8.14  IGameHelpers *gamehelpers;
    8.15 +ISourcePawnEngine *g_pSourcePawn;
    8.16 +ISourcePawnEngine2 *g_pSourcePawn2;
    8.17  
    8.18  static void AddCorePhraseFile(const char *filename)
    8.19  {
    8.20 @@ -73,6 +76,14 @@
    8.21  // Defined in smn_filesystem.cpp.
    8.22  extern bool OnLogPrint(const char *msg);
    8.23  
    8.24 +static void GenerateError(IPluginContext *ctx, cell_t idx, int err, const char *msg, ...)
    8.25 +{
    8.26 +	va_list ap;
    8.27 +	va_start(ap, msg);
    8.28 +	g_DbgReporter.GenerateErrorVA(ctx, idx, err, msg, ap);
    8.29 +	va_end(ap);
    8.30 +}
    8.31 +
    8.32  static sm_logic_t logic =
    8.33  {
    8.34  	NULL,
    8.35 @@ -86,7 +97,9 @@
    8.36  	UTIL_ReplaceEx,
    8.37  	UTIL_DecodeHexString,
    8.38  	GetCoreGameConfig,
    8.39 -	OnLogPrint
    8.40 +	OnLogPrint,
    8.41 +	&g_DbgReporter,
    8.42 +	GenerateError
    8.43  };
    8.44  
    8.45  static void logic_init(const sm_core_t* core, sm_logic_t* _logic)
    8.46 @@ -110,6 +123,8 @@
    8.47  	playerhelpers = core->playerhelpers;
    8.48  	adminsys = core->adminsys;
    8.49  	gamehelpers = core->gamehelpers;
    8.50 +	g_pSourcePawn = core->spe1;
    8.51 +	g_pSourcePawn2 = core->spe2;
    8.52  }
    8.53  
    8.54  PLATFORM_EXTERN_C ITextParsers *get_textparsers()
     9.1 --- a/core/logic/intercom.h	Sat Feb 16 15:52:11 2013 -0800
     9.2 +++ b/core/logic/intercom.h	Sat Feb 16 15:57:00 2013 -0800
     9.3 @@ -42,7 +42,7 @@
     9.4   * Add 1 to the RHS of this expression to bump the intercom file
     9.5   * This is to prevent mismatching core/logic binaries
     9.6   */
     9.7 -#define SM_LOGIC_MAGIC		(0x0F47C0DE - 17)
     9.8 +#define SM_LOGIC_MAGIC		(0x0F47C0DE - 18)
     9.9  
    9.10  #if defined SM_LOGIC
    9.11  class IVEngineServer
    9.12 @@ -99,6 +99,8 @@
    9.13  	IPlayerManager  *playerhelpers;
    9.14  	IAdminSystem	*adminsys;
    9.15  	IGameHelpers    *gamehelpers;
    9.16 +	ISourcePawnEngine *spe1;
    9.17 +	ISourcePawnEngine2 *spe2;
    9.18  	/* Functions */
    9.19  	void			(*AddNatives)(sp_nativeinfo_t* nlist);
    9.20  	ConVar *		(*FindConVar)(const char*);
    9.21 @@ -111,7 +113,7 @@
    9.22  	bool			(*FileExists)(const char *path);
    9.23  	const char *	(*GetCvarString)(ConVar*);
    9.24  	size_t			(*Format)(char*, size_t, const char*, ...);
    9.25 -	void			(*GenerateError)(IPluginContext *, cell_t, int, const char *, ...);
    9.26 +	size_t			(*FormatArgs)(char*, size_t, const char*,va_list ap);
    9.27  	bool			(*gnprintf)(char *, size_t, const char *, IPhraseCollection *, void **,
    9.28  	                            unsigned int, unsigned int &, size_t *, const char **);
    9.29  	size_t			(*atcprintf)(char *, size_t, const char *, IPluginContext *, const cell_t *, int *);
    9.30 @@ -141,6 +143,8 @@
    9.31  	size_t          (*DecodeHexString)(unsigned char *, size_t, const char *);
    9.32  	IGameConfig *   (*GetCoreGameConfig)();
    9.33  	bool			(*OnLogPrint)(const char *msg);	// true to supercede
    9.34 +	IDebugListener   *debugger;
    9.35 +	void			(*GenerateError)(IPluginContext *, cell_t, int, const char *, ...);
    9.36  };
    9.37  
    9.38  typedef void (*LogicInitFunction)(const sm_core_t *core, sm_logic_t *logic);
    10.1 --- a/core/logic/smn_timers.cpp	Sat Feb 16 15:52:11 2013 -0800
    10.2 +++ b/core/logic/smn_timers.cpp	Sat Feb 16 15:57:00 2013 -0800
    10.3 @@ -35,6 +35,7 @@
    10.4  #include <ITimerSystem.h>
    10.5  #include <IPluginSys.h>
    10.6  #include <sh_stack.h>
    10.7 +#include "DebugReporter.h"
    10.8  
    10.9  using namespace SourceHook;
   10.10  
   10.11 @@ -155,7 +156,7 @@
   10.12  	{
   10.13  		if ((herr=handlesys->FreeHandle(usrhndl, &sec)) != HandleError_None)
   10.14  		{
   10.15 -			smcore.GenerateError(pInfo->pContext, pInfo->Hook->GetFunctionID(), 
   10.16 +			g_DbgReporter.GenerateError(pInfo->pContext, pInfo->Hook->GetFunctionID(), 
   10.17  							  	 SP_ERROR_NATIVE, 
   10.18  							  	 "Invalid data handle %x (error %d) passed during timer end with TIMER_DATA_HNDL_CLOSE",
   10.19  							  	 usrhndl, herr);
   10.20 @@ -166,7 +167,7 @@
   10.21  	{
   10.22  		if ((herr=handlesys->FreeHandle(pInfo->TimerHandle, &sec)) != HandleError_None)
   10.23  		{
   10.24 -			smcore.GenerateError(pInfo->pContext, pInfo->Hook->GetFunctionID(), 
   10.25 +			g_DbgReporter.GenerateError(pInfo->pContext, pInfo->Hook->GetFunctionID(), 
   10.26  				SP_ERROR_NATIVE, 
   10.27  				"Invalid timer handle %x (error %d) during timer end, displayed function is timer callback, not the stack trace", 
   10.28  				pInfo->TimerHandle, herr);
    11.1 --- a/core/logic_bridge.cpp	Sat Feb 16 15:52:11 2013 -0800
    11.2 +++ b/core/logic_bridge.cpp	Sat Feb 16 15:57:00 2013 -0800
    11.3 @@ -45,7 +45,6 @@
    11.4  #include "ForwardSys.h"
    11.5  #include "TimerSys.h"
    11.6  #include "logic_bridge.h"
    11.7 -#include "DebugReporter.h"
    11.8  #include "PlayerManager.h"
    11.9  #include "AdminCache.h"
   11.10  #include "HalfLife2.h"
   11.11 @@ -135,15 +134,6 @@
   11.12  	return basefilesystem->FileExists(path);
   11.13  }
   11.14  
   11.15 -static void generate_error(IPluginContext *ctx, cell_t func_idx, int err, const char *fmt, ...)
   11.16 -{
   11.17 -	va_list ap;
   11.18 -	
   11.19 -	va_start(ap, fmt);
   11.20 -	g_DbgReporter.GenerateErrorVA(ctx, func_idx, err, fmt, ap);
   11.21 -	va_end(ap);
   11.22 -}
   11.23 -
   11.24  static const char *get_cvar_string(ConVar* cvar)
   11.25  {
   11.26  	return cvar->GetString();
   11.27 @@ -234,6 +224,8 @@
   11.28  	&g_Players,
   11.29  	&g_Admins,
   11.30  	&g_HL2,
   11.31 +	g_pSourcePawn,
   11.32 +	g_pSourcePawn2,
   11.33  	/* Functions */
   11.34  	add_natives,
   11.35  	find_convar,
   11.36 @@ -246,7 +238,7 @@
   11.37  	file_exists,
   11.38  	get_cvar_string,
   11.39  	UTIL_Format,
   11.40 -	generate_error,
   11.41 +	UTIL_FormatArgs,
   11.42  	gnprintf,
   11.43  	atcprintf,
   11.44  	get_game_name,
    12.1 --- a/core/smn_menus.cpp	Sat Feb 16 15:52:11 2013 -0800
    12.2 +++ b/core/smn_menus.cpp	Sat Feb 16 15:57:00 2013 -0800
    12.3 @@ -31,7 +31,6 @@
    12.4  
    12.5  #include "sm_globals.h"
    12.6  #include <sh_stack.h>
    12.7 -#include "DebugReporter.h"
    12.8  #include "MenuManager.h"
    12.9  #include "MenuStyle_Valve.h"
   12.10  #include "MenuStyle_Radio.h"
   12.11 @@ -44,6 +43,7 @@
   12.12  #include "Logger.h"
   12.13  #endif
   12.14  #include "ChatTriggers.h"
   12.15 +#include "logic_bridge.h"
   12.16  
   12.17  #if defined CreateMenu
   12.18  #undef CreateMenu
   12.19 @@ -470,7 +470,7 @@
   12.20  			if ((err = pContext->HeapAlloc(client_array_size, &client_array_address, &client_array_base))
   12.21  				!= SP_ERROR_NONE)
   12.22  			{
   12.23 -				g_DbgReporter.GenerateError(pContext, m_fnVoteResult, err, "Menu callback could not allocate %d bytes for client list.", client_array_size * sizeof(cell_t));
   12.24 +				logicore.GenerateError(pContext, m_fnVoteResult, err, "Menu callback could not allocate %d bytes for client list.", client_array_size * sizeof(cell_t));
   12.25  				no_call = true;
   12.26  			} else {
   12.27  				cell_t target_offs = sizeof(cell_t) * results->num_clients;
   12.28 @@ -503,7 +503,7 @@
   12.29  			if ((err = pContext->HeapAlloc(item_array_size, &item_array_address, &item_array_base))
   12.30  				!= SP_ERROR_NONE)
   12.31  			{
   12.32 -				g_DbgReporter.GenerateError(pContext, m_fnVoteResult, err, "Menu callback could not allocate %d bytes for item list.", item_array_size);
   12.33 +				logicore.GenerateError(pContext, m_fnVoteResult, err, "Menu callback could not allocate %d bytes for item list.", item_array_size);
   12.34  				no_call = true;
   12.35  			} else {
   12.36  				cell_t target_offs = sizeof(cell_t) * results->num_items;
    13.1 --- a/core/sourcemod.cpp	Sat Feb 16 15:52:11 2013 -0800
    13.2 +++ b/core/sourcemod.cpp	Sat Feb 16 15:57:00 2013 -0800
    13.3 @@ -45,7 +45,6 @@
    13.4  #include "ForwardSys.h"
    13.5  #include "TimerSys.h"
    13.6  #include <IGameConfigs.h>
    13.7 -#include "DebugReporter.h"
    13.8  #include "frame_hooks.h"
    13.9  #include "logic_bridge.h"
   13.10  
   13.11 @@ -242,7 +241,7 @@
   13.12  		return false;
   13.13  	}
   13.14  
   13.15 -	g_pSourcePawn2->SetDebugListener(&g_DbgReporter);
   13.16 +	g_pSourcePawn2->SetDebugListener(logicore.debugger);
   13.17  
   13.18  	/* Hook this now so we can detect startup without calling StartSourceMod() */
   13.19  	SH_ADD_HOOK_MEMFUNC(IServerGameDLL, LevelInit, gamedll, this, &SourceModBase::LevelInit, false);