Move DebugReporter from core to logic (bug 5607, r=psychonic).

--HG--
rename : core/DebugReporter.cpp => core/logic/DebugReporter.cpp
rename : core/DebugReporter.h => core/logic/DebugReporter.h
This commit is contained in:
David Anderson 2013-02-16 15:57:00 -08:00
parent 5f0a55057e
commit 1e8a6e878d
11 changed files with 65 additions and 56 deletions

View File

@ -86,7 +86,6 @@ for i in SM.sdkInfo:
'smn_core.cpp', 'smn_core.cpp',
'smn_hudtext.cpp', 'smn_hudtext.cpp',
'smn_usermsgs.cpp', 'smn_usermsgs.cpp',
'DebugReporter.cpp',
'MenuStyle_Base.cpp', 'MenuStyle_Base.cpp',
'ShareSys.cpp', 'ShareSys.cpp',
'smn_database.cpp', 'smn_database.cpp',

View File

@ -35,7 +35,7 @@
#include "ForwardSys.h" #include "ForwardSys.h"
#include "PluginSys.h" #include "PluginSys.h"
#include "ShareSys.h" #include "ShareSys.h"
#include "DebugReporter.h" #include "logic_bridge.h"
CForwardManager g_Forwards; CForwardManager g_Forwards;
@ -356,7 +356,7 @@ int CForward::Execute(cell_t *result, IForwardFilter *filter)
if (err != SP_ERROR_NONE) if (err != SP_ERROR_NONE)
{ {
g_DbgReporter.GenerateError(func->GetParentContext(), logicore.GenerateError(func->GetParentContext(),
func->GetFunctionID(), func->GetFunctionID(),
err, err,
"Failed to push parameter while executing forward"); "Failed to push parameter while executing forward");

View File

@ -49,7 +49,8 @@ files = [
'smn_gameconfigs.cpp', 'smn_gameconfigs.cpp',
'GameConfigs.cpp', 'GameConfigs.cpp',
'sm_crc32.cpp', 'sm_crc32.cpp',
'smn_profiler.cpp' 'smn_profiler.cpp',
'DebugReporter.cpp'
] ]
if AMBuild.target['platform'] == 'windows': if AMBuild.target['platform'] == 'windows':
files.append('thread/WinThreads.cpp') files.append('thread/WinThreads.cpp')

View File

@ -29,10 +29,8 @@
* Version: $Id$ * Version: $Id$
*/ */
#include <IPluginSys.h>
#include "DebugReporter.h" #include "DebugReporter.h"
#include "Logger.h"
#include "PluginSys.h"
#include "sm_stringutil.h"
DebugReport g_DbgReporter; DebugReport g_DbgReporter;
@ -47,10 +45,10 @@ void DebugReport::OnDebugSpew(const char *msg, ...)
char buffer[512]; char buffer[512];
va_start(ap, msg); va_start(ap, msg);
UTIL_FormatArgs(buffer, sizeof(buffer), msg, ap); smcore.FormatArgs(buffer, sizeof(buffer), msg, ap);
va_end(ap); va_end(ap);
g_Logger.LogMessage("[SM] %s", buffer); smcore.Log("[SM] %s", buffer);
} }
void DebugReport::GenerateError(IPluginContext *ctx, cell_t func_idx, int err, const char *message, ...) void DebugReport::GenerateError(IPluginContext *ctx, cell_t func_idx, int err, const char *message, ...)
@ -65,19 +63,19 @@ void DebugReport::GenerateError(IPluginContext *ctx, cell_t func_idx, int err, c
void DebugReport::GenerateErrorVA(IPluginContext *ctx, cell_t func_idx, int err, const char *message, va_list ap) void DebugReport::GenerateErrorVA(IPluginContext *ctx, cell_t func_idx, int err, const char *message, va_list ap)
{ {
char buffer[512]; char buffer[512];
UTIL_FormatArgs(buffer, sizeof(buffer), message, ap); smcore.FormatArgs(buffer, sizeof(buffer), message, ap);
const char *plname = g_PluginSys.FindPluginByContext(ctx->GetContext())->GetFilename(); const char *plname = pluginsys->FindPluginByContext(ctx->GetContext())->GetFilename();
const char *error = g_pSourcePawn2->GetErrorString(err); const char *error = g_pSourcePawn2->GetErrorString(err);
if (error) if (error)
{ {
g_Logger.LogError("[SM] Plugin \"%s\" encountered error %d: %s", plname, err, error); smcore.LogError("[SM] Plugin \"%s\" encountered error %d: %s", plname, err, error);
} else { } else {
g_Logger.LogError("[SM] Plugin \"%s\" encountered unknown error %d", plname, err); smcore.LogError("[SM] Plugin \"%s\" encountered unknown error %d", plname, err);
} }
g_Logger.LogError("[SM] %s", buffer); smcore.LogError("[SM] %s", buffer);
if (func_idx != -1) if (func_idx != -1)
{ {
@ -87,7 +85,7 @@ void DebugReport::GenerateErrorVA(IPluginContext *ctx, cell_t func_idx, int err,
sp_public_t *function; sp_public_t *function;
if (ctx->GetRuntime()->GetPublicByIndex(func_idx, &function) == SP_ERROR_NONE) if (ctx->GetRuntime()->GetPublicByIndex(func_idx, &function) == SP_ERROR_NONE)
{ {
g_Logger.LogError("[SM] Unable to call function \"%s\" due to above error(s).", function->name); smcore.LogError("[SM] Unable to call function \"%s\" due to above error(s).", function->name);
} }
} }
} }
@ -99,26 +97,26 @@ void DebugReport::GenerateCodeError(IPluginContext *pContext, uint32_t code_addr
char buffer[512]; char buffer[512];
va_start(ap, message); va_start(ap, message);
UTIL_FormatArgs(buffer, sizeof(buffer), message, ap); smcore.FormatArgs(buffer, sizeof(buffer), message, ap);
va_end(ap); va_end(ap);
const char *plname = g_PluginSys.FindPluginByContext(pContext->GetContext())->GetFilename(); const char *plname = pluginsys->FindPluginByContext(pContext->GetContext())->GetFilename();
const char *error = g_pSourcePawn2->GetErrorString(err); const char *error = g_pSourcePawn2->GetErrorString(err);
if (error) if (error)
{ {
g_Logger.LogError("[SM] Plugin \"%s\" encountered error %d: %s", plname, err, error); smcore.LogError("[SM] Plugin \"%s\" encountered error %d: %s", plname, err, error);
} else { } else {
g_Logger.LogError("[SM] Plugin \"%s\" encountered unknown error %d", plname, err); smcore.LogError("[SM] Plugin \"%s\" encountered unknown error %d", plname, err);
} }
g_Logger.LogError("[SM] %s", buffer); smcore.LogError("[SM] %s", buffer);
IPluginDebugInfo *pDebug; IPluginDebugInfo *pDebug;
if ((pDebug = pContext->GetRuntime()->GetDebugInfo()) == NULL) if ((pDebug = pContext->GetRuntime()->GetDebugInfo()) == NULL)
{ {
g_Logger.LogError("[SM] Debug mode is not enabled for \"%s\"", plname); smcore.LogError("[SM] Debug mode is not enabled for \"%s\"", plname);
g_Logger.LogError("[SM] To enable debug mode, edit plugin_settings.cfg, or type: sm plugins debug %d on", smcore.LogError("[SM] To enable debug mode, edit plugin_settings.cfg, or type: sm plugins debug %d on",
_GetPluginIndex(pContext)); _GetPluginIndex(pContext));
return; return;
} }
@ -126,21 +124,21 @@ void DebugReport::GenerateCodeError(IPluginContext *pContext, uint32_t code_addr
const char *name; const char *name;
if (pDebug->LookupFunction(code_addr, &name) == SP_ERROR_NONE) if (pDebug->LookupFunction(code_addr, &name) == SP_ERROR_NONE)
{ {
g_Logger.LogError("[SM] Unable to call function \"%s\" due to above error(s).", name); smcore.LogError("[SM] Unable to call function \"%s\" due to above error(s).", name);
} else { } else {
g_Logger.LogError("[SM] Unable to call function (name unknown, address \"%x\").", code_addr); smcore.LogError("[SM] Unable to call function (name unknown, address \"%x\").", code_addr);
} }
} }
void DebugReport::OnContextExecuteError(IPluginContext *ctx, IContextTrace *error) void DebugReport::OnContextExecuteError(IPluginContext *ctx, IContextTrace *error)
{ {
const char *lastname; const char *lastname;
const char *plname = g_PluginSys.FindPluginByContext(ctx->GetContext())->GetFilename(); const char *plname = pluginsys->FindPluginByContext(ctx->GetContext())->GetFilename();
int n_err = error->GetErrorCode(); int n_err = error->GetErrorCode();
if (n_err != SP_ERROR_NATIVE) if (n_err != SP_ERROR_NATIVE)
{ {
g_Logger.LogError("[SM] Plugin encountered error %d: %s", smcore.LogError("[SM] Plugin encountered error %d: %s",
n_err, n_err,
error->GetErrorString()); error->GetErrorString());
} }
@ -150,26 +148,26 @@ void DebugReport::OnContextExecuteError(IPluginContext *ctx, IContextTrace *erro
const char *custerr; const char *custerr;
if ((custerr=error->GetCustomErrorString()) != NULL) if ((custerr=error->GetCustomErrorString()) != NULL)
{ {
g_Logger.LogError("[SM] Native \"%s\" reported: %s", lastname, custerr); smcore.LogError("[SM] Native \"%s\" reported: %s", lastname, custerr);
} else { } else {
g_Logger.LogError("[SM] Native \"%s\" encountered a generic error.", lastname); smcore.LogError("[SM] Native \"%s\" encountered a generic error.", lastname);
} }
} }
if (!error->DebugInfoAvailable()) if (!error->DebugInfoAvailable())
{ {
g_Logger.LogError("[SM] Debug mode is not enabled for \"%s\"", plname); smcore.LogError("[SM] Debug mode is not enabled for \"%s\"", plname);
g_Logger.LogError("[SM] To enable debug mode, edit plugin_settings.cfg, or type: sm plugins debug %d on", smcore.LogError("[SM] To enable debug mode, edit plugin_settings.cfg, or type: sm plugins debug %d on",
_GetPluginIndex(ctx)); _GetPluginIndex(ctx));
return; return;
} }
CallStackInfo stk_info; CallStackInfo stk_info;
int i = 0; int i = 0;
g_Logger.LogError("[SM] Displaying call stack trace for plugin \"%s\":", plname); smcore.LogError("[SM] Displaying call stack trace for plugin \"%s\":", plname);
while (error->GetTraceInfo(&stk_info)) while (error->GetTraceInfo(&stk_info))
{ {
g_Logger.LogError("[SM] [%d] Line %d, %s::%s()", smcore.LogError("[SM] [%d] Line %d, %s::%s()",
i++, i++,
stk_info.line, stk_info.line,
stk_info.filename, stk_info.filename,
@ -180,7 +178,7 @@ void DebugReport::OnContextExecuteError(IPluginContext *ctx, IContextTrace *erro
int DebugReport::_GetPluginIndex(IPluginContext *ctx) int DebugReport::_GetPluginIndex(IPluginContext *ctx)
{ {
int id = 1; int id = 1;
IPluginIterator *iter = g_PluginSys.GetPluginIterator(); IPluginIterator *iter = pluginsys->GetPluginIterator();
for (; iter->MorePlugins(); iter->NextPlugin(), id++) for (; iter->MorePlugins(); iter->NextPlugin(), id++)
{ {
@ -196,6 +194,6 @@ int DebugReport::_GetPluginIndex(IPluginContext *ctx)
/* If we don't know which plugin this is, it's one being loaded. Fake its index for now. */ /* If we don't know which plugin this is, it's one being loaded. Fake its index for now. */
return g_PluginSys.GetPluginCount() + 1; return pluginsys->GetPluginCount() + 1;
} }

View File

@ -33,7 +33,7 @@
#define _INCLUDE_SOURCEMOD_CDBGREPORTER_H_ #define _INCLUDE_SOURCEMOD_CDBGREPORTER_H_
#include "sp_vm_api.h" #include "sp_vm_api.h"
#include "sm_globals.h" #include "common_logic.h"
class DebugReport : class DebugReport :
public SMGlobalClass, public SMGlobalClass,

View File

@ -41,6 +41,7 @@
#include "ThreadSupport.h" #include "ThreadSupport.h"
#include "Translator.h" #include "Translator.h"
#include "GameConfigs.h" #include "GameConfigs.h"
#include "DebugReporter.h"
sm_core_t smcore; sm_core_t smcore;
IHandleSys *handlesys; IHandleSys *handlesys;
@ -59,6 +60,8 @@ ServerGlobals serverGlobals;
IPlayerManager *playerhelpers; IPlayerManager *playerhelpers;
IAdminSystem *adminsys; IAdminSystem *adminsys;
IGameHelpers *gamehelpers; IGameHelpers *gamehelpers;
ISourcePawnEngine *g_pSourcePawn;
ISourcePawnEngine2 *g_pSourcePawn2;
static void AddCorePhraseFile(const char *filename) static void AddCorePhraseFile(const char *filename)
{ {
@ -73,6 +76,14 @@ static IGameConfig *GetCoreGameConfig()
// Defined in smn_filesystem.cpp. // Defined in smn_filesystem.cpp.
extern bool OnLogPrint(const char *msg); extern bool OnLogPrint(const char *msg);
static void GenerateError(IPluginContext *ctx, cell_t idx, int err, const char *msg, ...)
{
va_list ap;
va_start(ap, msg);
g_DbgReporter.GenerateErrorVA(ctx, idx, err, msg, ap);
va_end(ap);
}
static sm_logic_t logic = static sm_logic_t logic =
{ {
NULL, NULL,
@ -86,7 +97,9 @@ static sm_logic_t logic =
UTIL_ReplaceEx, UTIL_ReplaceEx,
UTIL_DecodeHexString, UTIL_DecodeHexString,
GetCoreGameConfig, GetCoreGameConfig,
OnLogPrint OnLogPrint,
&g_DbgReporter,
GenerateError
}; };
static void logic_init(const sm_core_t* core, sm_logic_t* _logic) static void logic_init(const sm_core_t* core, sm_logic_t* _logic)
@ -110,6 +123,8 @@ static void logic_init(const sm_core_t* core, sm_logic_t* _logic)
playerhelpers = core->playerhelpers; playerhelpers = core->playerhelpers;
adminsys = core->adminsys; adminsys = core->adminsys;
gamehelpers = core->gamehelpers; gamehelpers = core->gamehelpers;
g_pSourcePawn = core->spe1;
g_pSourcePawn2 = core->spe2;
} }
PLATFORM_EXTERN_C ITextParsers *get_textparsers() PLATFORM_EXTERN_C ITextParsers *get_textparsers()

View File

@ -42,7 +42,7 @@ using namespace SourceMod;
* Add 1 to the RHS of this expression to bump the intercom file * Add 1 to the RHS of this expression to bump the intercom file
* This is to prevent mismatching core/logic binaries * This is to prevent mismatching core/logic binaries
*/ */
#define SM_LOGIC_MAGIC (0x0F47C0DE - 17) #define SM_LOGIC_MAGIC (0x0F47C0DE - 18)
#if defined SM_LOGIC #if defined SM_LOGIC
class IVEngineServer class IVEngineServer
@ -99,6 +99,8 @@ struct sm_core_t
IPlayerManager *playerhelpers; IPlayerManager *playerhelpers;
IAdminSystem *adminsys; IAdminSystem *adminsys;
IGameHelpers *gamehelpers; IGameHelpers *gamehelpers;
ISourcePawnEngine *spe1;
ISourcePawnEngine2 *spe2;
/* Functions */ /* Functions */
void (*AddNatives)(sp_nativeinfo_t* nlist); void (*AddNatives)(sp_nativeinfo_t* nlist);
ConVar * (*FindConVar)(const char*); ConVar * (*FindConVar)(const char*);
@ -111,7 +113,7 @@ struct sm_core_t
bool (*FileExists)(const char *path); bool (*FileExists)(const char *path);
const char * (*GetCvarString)(ConVar*); const char * (*GetCvarString)(ConVar*);
size_t (*Format)(char*, size_t, const char*, ...); size_t (*Format)(char*, size_t, const char*, ...);
void (*GenerateError)(IPluginContext *, cell_t, int, const char *, ...); size_t (*FormatArgs)(char*, size_t, const char*,va_list ap);
bool (*gnprintf)(char *, size_t, const char *, IPhraseCollection *, void **, bool (*gnprintf)(char *, size_t, const char *, IPhraseCollection *, void **,
unsigned int, unsigned int &, size_t *, const char **); unsigned int, unsigned int &, size_t *, const char **);
size_t (*atcprintf)(char *, size_t, const char *, IPluginContext *, const cell_t *, int *); size_t (*atcprintf)(char *, size_t, const char *, IPluginContext *, const cell_t *, int *);
@ -141,6 +143,8 @@ struct sm_logic_t
size_t (*DecodeHexString)(unsigned char *, size_t, const char *); size_t (*DecodeHexString)(unsigned char *, size_t, const char *);
IGameConfig * (*GetCoreGameConfig)(); IGameConfig * (*GetCoreGameConfig)();
bool (*OnLogPrint)(const char *msg); // true to supercede bool (*OnLogPrint)(const char *msg); // true to supercede
IDebugListener *debugger;
void (*GenerateError)(IPluginContext *, cell_t, int, const char *, ...);
}; };
typedef void (*LogicInitFunction)(const sm_core_t *core, sm_logic_t *logic); typedef void (*LogicInitFunction)(const sm_core_t *core, sm_logic_t *logic);

View File

@ -35,6 +35,7 @@
#include <ITimerSystem.h> #include <ITimerSystem.h>
#include <IPluginSys.h> #include <IPluginSys.h>
#include <sh_stack.h> #include <sh_stack.h>
#include "DebugReporter.h"
using namespace SourceHook; using namespace SourceHook;
@ -155,7 +156,7 @@ void TimerNatives::OnTimerEnd(ITimer *pTimer, void *pData)
{ {
if ((herr=handlesys->FreeHandle(usrhndl, &sec)) != HandleError_None) if ((herr=handlesys->FreeHandle(usrhndl, &sec)) != HandleError_None)
{ {
smcore.GenerateError(pInfo->pContext, pInfo->Hook->GetFunctionID(), g_DbgReporter.GenerateError(pInfo->pContext, pInfo->Hook->GetFunctionID(),
SP_ERROR_NATIVE, SP_ERROR_NATIVE,
"Invalid data handle %x (error %d) passed during timer end with TIMER_DATA_HNDL_CLOSE", "Invalid data handle %x (error %d) passed during timer end with TIMER_DATA_HNDL_CLOSE",
usrhndl, herr); usrhndl, herr);
@ -166,7 +167,7 @@ void TimerNatives::OnTimerEnd(ITimer *pTimer, void *pData)
{ {
if ((herr=handlesys->FreeHandle(pInfo->TimerHandle, &sec)) != HandleError_None) if ((herr=handlesys->FreeHandle(pInfo->TimerHandle, &sec)) != HandleError_None)
{ {
smcore.GenerateError(pInfo->pContext, pInfo->Hook->GetFunctionID(), g_DbgReporter.GenerateError(pInfo->pContext, pInfo->Hook->GetFunctionID(),
SP_ERROR_NATIVE, SP_ERROR_NATIVE,
"Invalid timer handle %x (error %d) during timer end, displayed function is timer callback, not the stack trace", "Invalid timer handle %x (error %d) during timer end, displayed function is timer callback, not the stack trace",
pInfo->TimerHandle, herr); pInfo->TimerHandle, herr);

View File

@ -45,7 +45,6 @@
#include "ForwardSys.h" #include "ForwardSys.h"
#include "TimerSys.h" #include "TimerSys.h"
#include "logic_bridge.h" #include "logic_bridge.h"
#include "DebugReporter.h"
#include "PlayerManager.h" #include "PlayerManager.h"
#include "AdminCache.h" #include "AdminCache.h"
#include "HalfLife2.h" #include "HalfLife2.h"
@ -135,15 +134,6 @@ static bool file_exists(const char *path)
return basefilesystem->FileExists(path); return basefilesystem->FileExists(path);
} }
static void generate_error(IPluginContext *ctx, cell_t func_idx, int err, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
g_DbgReporter.GenerateErrorVA(ctx, func_idx, err, fmt, ap);
va_end(ap);
}
static const char *get_cvar_string(ConVar* cvar) static const char *get_cvar_string(ConVar* cvar)
{ {
return cvar->GetString(); return cvar->GetString();
@ -234,6 +224,8 @@ static sm_core_t core_bridge =
&g_Players, &g_Players,
&g_Admins, &g_Admins,
&g_HL2, &g_HL2,
g_pSourcePawn,
g_pSourcePawn2,
/* Functions */ /* Functions */
add_natives, add_natives,
find_convar, find_convar,
@ -246,7 +238,7 @@ static sm_core_t core_bridge =
file_exists, file_exists,
get_cvar_string, get_cvar_string,
UTIL_Format, UTIL_Format,
generate_error, UTIL_FormatArgs,
gnprintf, gnprintf,
atcprintf, atcprintf,
get_game_name, get_game_name,

View File

@ -31,7 +31,6 @@
#include "sm_globals.h" #include "sm_globals.h"
#include <sh_stack.h> #include <sh_stack.h>
#include "DebugReporter.h"
#include "MenuManager.h" #include "MenuManager.h"
#include "MenuStyle_Valve.h" #include "MenuStyle_Valve.h"
#include "MenuStyle_Radio.h" #include "MenuStyle_Radio.h"
@ -44,6 +43,7 @@
#include "Logger.h" #include "Logger.h"
#endif #endif
#include "ChatTriggers.h" #include "ChatTriggers.h"
#include "logic_bridge.h"
#if defined CreateMenu #if defined CreateMenu
#undef CreateMenu #undef CreateMenu
@ -470,7 +470,7 @@ void CMenuHandler::OnMenuVoteResults(IBaseMenu *menu, const menu_vote_result_t *
if ((err = pContext->HeapAlloc(client_array_size, &client_array_address, &client_array_base)) if ((err = pContext->HeapAlloc(client_array_size, &client_array_address, &client_array_base))
!= SP_ERROR_NONE) != SP_ERROR_NONE)
{ {
g_DbgReporter.GenerateError(pContext, m_fnVoteResult, err, "Menu callback could not allocate %d bytes for client list.", client_array_size * sizeof(cell_t)); logicore.GenerateError(pContext, m_fnVoteResult, err, "Menu callback could not allocate %d bytes for client list.", client_array_size * sizeof(cell_t));
no_call = true; no_call = true;
} else { } else {
cell_t target_offs = sizeof(cell_t) * results->num_clients; cell_t target_offs = sizeof(cell_t) * results->num_clients;
@ -503,7 +503,7 @@ void CMenuHandler::OnMenuVoteResults(IBaseMenu *menu, const menu_vote_result_t *
if ((err = pContext->HeapAlloc(item_array_size, &item_array_address, &item_array_base)) if ((err = pContext->HeapAlloc(item_array_size, &item_array_address, &item_array_base))
!= SP_ERROR_NONE) != SP_ERROR_NONE)
{ {
g_DbgReporter.GenerateError(pContext, m_fnVoteResult, err, "Menu callback could not allocate %d bytes for item list.", item_array_size); logicore.GenerateError(pContext, m_fnVoteResult, err, "Menu callback could not allocate %d bytes for item list.", item_array_size);
no_call = true; no_call = true;
} else { } else {
cell_t target_offs = sizeof(cell_t) * results->num_items; cell_t target_offs = sizeof(cell_t) * results->num_items;

View File

@ -45,7 +45,6 @@
#include "ForwardSys.h" #include "ForwardSys.h"
#include "TimerSys.h" #include "TimerSys.h"
#include <IGameConfigs.h> #include <IGameConfigs.h>
#include "DebugReporter.h"
#include "frame_hooks.h" #include "frame_hooks.h"
#include "logic_bridge.h" #include "logic_bridge.h"
@ -242,7 +241,7 @@ bool SourceModBase::InitializeSourceMod(char *error, size_t maxlength, bool late
return false; return false;
} }
g_pSourcePawn2->SetDebugListener(&g_DbgReporter); g_pSourcePawn2->SetDebugListener(logicore.debugger);
/* Hook this now so we can detect startup without calling StartSourceMod() */ /* Hook this now so we can detect startup without calling StartSourceMod() */
SH_ADD_HOOK_MEMFUNC(IServerGameDLL, LevelInit, gamedll, this, &SourceModBase::LevelInit, false); SH_ADD_HOOK_MEMFUNC(IServerGameDLL, LevelInit, gamedll, this, &SourceModBase::LevelInit, false);