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:
parent
5f0a55057e
commit
1e8a6e878d
@ -86,7 +86,6 @@ for i in SM.sdkInfo:
|
||||
'smn_core.cpp',
|
||||
'smn_hudtext.cpp',
|
||||
'smn_usermsgs.cpp',
|
||||
'DebugReporter.cpp',
|
||||
'MenuStyle_Base.cpp',
|
||||
'ShareSys.cpp',
|
||||
'smn_database.cpp',
|
||||
|
@ -35,7 +35,7 @@
|
||||
#include "ForwardSys.h"
|
||||
#include "PluginSys.h"
|
||||
#include "ShareSys.h"
|
||||
#include "DebugReporter.h"
|
||||
#include "logic_bridge.h"
|
||||
|
||||
CForwardManager g_Forwards;
|
||||
|
||||
@ -356,7 +356,7 @@ int CForward::Execute(cell_t *result, IForwardFilter *filter)
|
||||
|
||||
if (err != SP_ERROR_NONE)
|
||||
{
|
||||
g_DbgReporter.GenerateError(func->GetParentContext(),
|
||||
logicore.GenerateError(func->GetParentContext(),
|
||||
func->GetFunctionID(),
|
||||
err,
|
||||
"Failed to push parameter while executing forward");
|
||||
|
@ -49,7 +49,8 @@ files = [
|
||||
'smn_gameconfigs.cpp',
|
||||
'GameConfigs.cpp',
|
||||
'sm_crc32.cpp',
|
||||
'smn_profiler.cpp'
|
||||
'smn_profiler.cpp',
|
||||
'DebugReporter.cpp'
|
||||
]
|
||||
if AMBuild.target['platform'] == 'windows':
|
||||
files.append('thread/WinThreads.cpp')
|
||||
|
@ -29,10 +29,8 @@
|
||||
* Version: $Id$
|
||||
*/
|
||||
|
||||
#include <IPluginSys.h>
|
||||
#include "DebugReporter.h"
|
||||
#include "Logger.h"
|
||||
#include "PluginSys.h"
|
||||
#include "sm_stringutil.h"
|
||||
|
||||
DebugReport g_DbgReporter;
|
||||
|
||||
@ -47,10 +45,10 @@ void DebugReport::OnDebugSpew(const char *msg, ...)
|
||||
char buffer[512];
|
||||
|
||||
va_start(ap, msg);
|
||||
UTIL_FormatArgs(buffer, sizeof(buffer), msg, ap);
|
||||
smcore.FormatArgs(buffer, sizeof(buffer), msg, 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, ...)
|
||||
@ -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)
|
||||
{
|
||||
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);
|
||||
|
||||
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 {
|
||||
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)
|
||||
{
|
||||
@ -87,7 +85,7 @@ void DebugReport::GenerateErrorVA(IPluginContext *ctx, cell_t func_idx, int err,
|
||||
sp_public_t *function;
|
||||
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];
|
||||
|
||||
va_start(ap, message);
|
||||
UTIL_FormatArgs(buffer, sizeof(buffer), message, ap);
|
||||
smcore.FormatArgs(buffer, sizeof(buffer), message, 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);
|
||||
|
||||
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 {
|
||||
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;
|
||||
if ((pDebug = pContext->GetRuntime()->GetDebugInfo()) == NULL)
|
||||
{
|
||||
g_Logger.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] Debug mode is not enabled for \"%s\"", plname);
|
||||
smcore.LogError("[SM] To enable debug mode, edit plugin_settings.cfg, or type: sm plugins debug %d on",
|
||||
_GetPluginIndex(pContext));
|
||||
return;
|
||||
}
|
||||
@ -126,21 +124,21 @@ void DebugReport::GenerateCodeError(IPluginContext *pContext, uint32_t code_addr
|
||||
const char *name;
|
||||
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 {
|
||||
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)
|
||||
{
|
||||
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();
|
||||
|
||||
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,
|
||||
error->GetErrorString());
|
||||
}
|
||||
@ -150,26 +148,26 @@ void DebugReport::OnContextExecuteError(IPluginContext *ctx, IContextTrace *erro
|
||||
const char *custerr;
|
||||
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 {
|
||||
g_Logger.LogError("[SM] Native \"%s\" encountered a generic error.", lastname);
|
||||
smcore.LogError("[SM] Native \"%s\" encountered a generic error.", lastname);
|
||||
}
|
||||
}
|
||||
|
||||
if (!error->DebugInfoAvailable())
|
||||
{
|
||||
g_Logger.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] Debug mode is not enabled for \"%s\"", plname);
|
||||
smcore.LogError("[SM] To enable debug mode, edit plugin_settings.cfg, or type: sm plugins debug %d on",
|
||||
_GetPluginIndex(ctx));
|
||||
return;
|
||||
}
|
||||
|
||||
CallStackInfo stk_info;
|
||||
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))
|
||||
{
|
||||
g_Logger.LogError("[SM] [%d] Line %d, %s::%s()",
|
||||
smcore.LogError("[SM] [%d] Line %d, %s::%s()",
|
||||
i++,
|
||||
stk_info.line,
|
||||
stk_info.filename,
|
||||
@ -180,7 +178,7 @@ void DebugReport::OnContextExecuteError(IPluginContext *ctx, IContextTrace *erro
|
||||
int DebugReport::_GetPluginIndex(IPluginContext *ctx)
|
||||
{
|
||||
int id = 1;
|
||||
IPluginIterator *iter = g_PluginSys.GetPluginIterator();
|
||||
IPluginIterator *iter = pluginsys->GetPluginIterator();
|
||||
|
||||
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. */
|
||||
|
||||
return g_PluginSys.GetPluginCount() + 1;
|
||||
return pluginsys->GetPluginCount() + 1;
|
||||
}
|
||||
|
@ -33,7 +33,7 @@
|
||||
#define _INCLUDE_SOURCEMOD_CDBGREPORTER_H_
|
||||
|
||||
#include "sp_vm_api.h"
|
||||
#include "sm_globals.h"
|
||||
#include "common_logic.h"
|
||||
|
||||
class DebugReport :
|
||||
public SMGlobalClass,
|
@ -41,6 +41,7 @@
|
||||
#include "ThreadSupport.h"
|
||||
#include "Translator.h"
|
||||
#include "GameConfigs.h"
|
||||
#include "DebugReporter.h"
|
||||
|
||||
sm_core_t smcore;
|
||||
IHandleSys *handlesys;
|
||||
@ -59,6 +60,8 @@ ServerGlobals serverGlobals;
|
||||
IPlayerManager *playerhelpers;
|
||||
IAdminSystem *adminsys;
|
||||
IGameHelpers *gamehelpers;
|
||||
ISourcePawnEngine *g_pSourcePawn;
|
||||
ISourcePawnEngine2 *g_pSourcePawn2;
|
||||
|
||||
static void AddCorePhraseFile(const char *filename)
|
||||
{
|
||||
@ -73,6 +76,14 @@ static IGameConfig *GetCoreGameConfig()
|
||||
// Defined in smn_filesystem.cpp.
|
||||
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 =
|
||||
{
|
||||
NULL,
|
||||
@ -86,7 +97,9 @@ static sm_logic_t logic =
|
||||
UTIL_ReplaceEx,
|
||||
UTIL_DecodeHexString,
|
||||
GetCoreGameConfig,
|
||||
OnLogPrint
|
||||
OnLogPrint,
|
||||
&g_DbgReporter,
|
||||
GenerateError
|
||||
};
|
||||
|
||||
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;
|
||||
adminsys = core->adminsys;
|
||||
gamehelpers = core->gamehelpers;
|
||||
g_pSourcePawn = core->spe1;
|
||||
g_pSourcePawn2 = core->spe2;
|
||||
}
|
||||
|
||||
PLATFORM_EXTERN_C ITextParsers *get_textparsers()
|
||||
|
@ -42,7 +42,7 @@ using namespace SourceMod;
|
||||
* Add 1 to the RHS of this expression to bump the intercom file
|
||||
* This is to prevent mismatching core/logic binaries
|
||||
*/
|
||||
#define SM_LOGIC_MAGIC (0x0F47C0DE - 17)
|
||||
#define SM_LOGIC_MAGIC (0x0F47C0DE - 18)
|
||||
|
||||
#if defined SM_LOGIC
|
||||
class IVEngineServer
|
||||
@ -99,6 +99,8 @@ struct sm_core_t
|
||||
IPlayerManager *playerhelpers;
|
||||
IAdminSystem *adminsys;
|
||||
IGameHelpers *gamehelpers;
|
||||
ISourcePawnEngine *spe1;
|
||||
ISourcePawnEngine2 *spe2;
|
||||
/* Functions */
|
||||
void (*AddNatives)(sp_nativeinfo_t* nlist);
|
||||
ConVar * (*FindConVar)(const char*);
|
||||
@ -111,7 +113,7 @@ struct sm_core_t
|
||||
bool (*FileExists)(const char *path);
|
||||
const char * (*GetCvarString)(ConVar*);
|
||||
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 **,
|
||||
unsigned int, unsigned int &, size_t *, const char **);
|
||||
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 *);
|
||||
IGameConfig * (*GetCoreGameConfig)();
|
||||
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);
|
||||
|
@ -35,6 +35,7 @@
|
||||
#include <ITimerSystem.h>
|
||||
#include <IPluginSys.h>
|
||||
#include <sh_stack.h>
|
||||
#include "DebugReporter.h"
|
||||
|
||||
using namespace SourceHook;
|
||||
|
||||
@ -155,7 +156,7 @@ void TimerNatives::OnTimerEnd(ITimer *pTimer, void *pData)
|
||||
{
|
||||
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,
|
||||
"Invalid data handle %x (error %d) passed during timer end with TIMER_DATA_HNDL_CLOSE",
|
||||
usrhndl, herr);
|
||||
@ -166,7 +167,7 @@ void TimerNatives::OnTimerEnd(ITimer *pTimer, void *pData)
|
||||
{
|
||||
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,
|
||||
"Invalid timer handle %x (error %d) during timer end, displayed function is timer callback, not the stack trace",
|
||||
pInfo->TimerHandle, herr);
|
||||
|
@ -45,7 +45,6 @@
|
||||
#include "ForwardSys.h"
|
||||
#include "TimerSys.h"
|
||||
#include "logic_bridge.h"
|
||||
#include "DebugReporter.h"
|
||||
#include "PlayerManager.h"
|
||||
#include "AdminCache.h"
|
||||
#include "HalfLife2.h"
|
||||
@ -135,15 +134,6 @@ static bool file_exists(const char *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)
|
||||
{
|
||||
return cvar->GetString();
|
||||
@ -234,6 +224,8 @@ static sm_core_t core_bridge =
|
||||
&g_Players,
|
||||
&g_Admins,
|
||||
&g_HL2,
|
||||
g_pSourcePawn,
|
||||
g_pSourcePawn2,
|
||||
/* Functions */
|
||||
add_natives,
|
||||
find_convar,
|
||||
@ -246,7 +238,7 @@ static sm_core_t core_bridge =
|
||||
file_exists,
|
||||
get_cvar_string,
|
||||
UTIL_Format,
|
||||
generate_error,
|
||||
UTIL_FormatArgs,
|
||||
gnprintf,
|
||||
atcprintf,
|
||||
get_game_name,
|
||||
|
@ -31,7 +31,6 @@
|
||||
|
||||
#include "sm_globals.h"
|
||||
#include <sh_stack.h>
|
||||
#include "DebugReporter.h"
|
||||
#include "MenuManager.h"
|
||||
#include "MenuStyle_Valve.h"
|
||||
#include "MenuStyle_Radio.h"
|
||||
@ -44,6 +43,7 @@
|
||||
#include "Logger.h"
|
||||
#endif
|
||||
#include "ChatTriggers.h"
|
||||
#include "logic_bridge.h"
|
||||
|
||||
#if defined 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))
|
||||
!= 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;
|
||||
} else {
|
||||
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))
|
||||
!= 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;
|
||||
} else {
|
||||
cell_t target_offs = sizeof(cell_t) * results->num_items;
|
||||
|
@ -45,7 +45,6 @@
|
||||
#include "ForwardSys.h"
|
||||
#include "TimerSys.h"
|
||||
#include <IGameConfigs.h>
|
||||
#include "DebugReporter.h"
|
||||
#include "frame_hooks.h"
|
||||
#include "logic_bridge.h"
|
||||
|
||||
@ -242,7 +241,7 @@ bool SourceModBase::InitializeSourceMod(char *error, size_t maxlength, bool late
|
||||
return false;
|
||||
}
|
||||
|
||||
g_pSourcePawn2->SetDebugListener(&g_DbgReporter);
|
||||
g_pSourcePawn2->SetDebugListener(logicore.debugger);
|
||||
|
||||
/* Hook this now so we can detect startup without calling StartSourceMod() */
|
||||
SH_ADD_HOOK_MEMFUNC(IServerGameDLL, LevelInit, gamedll, this, &SourceModBase::LevelInit, false);
|
||||
|
Loading…
Reference in New Issue
Block a user