From eea576cb52345c78b4ec25625ea478561c033e2d Mon Sep 17 00:00:00 2001 From: Borja Ferrer Date: Fri, 12 Jan 2007 23:56:02 +0000 Subject: [PATCH] Added new debugger logger Added format errors Paused plugins now have their forwards blocked Fixed bug where pausing a plugin wouldnt make any effect --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40293 --- TODO.txt | 6 +-- core/CDbgReporter.cpp | 73 ++++++++++++++++++++++++++++++++++ core/CDbgReporter.h | 19 +++++++++ core/msvc8/sourcemod_mm.vcproj | 10 ++++- core/sm_stringutil.cpp | 15 +++---- core/systems/ForwardSys.cpp | 4 ++ core/systems/PluginSys.cpp | 2 + 7 files changed, 116 insertions(+), 13 deletions(-) create mode 100644 core/CDbgReporter.cpp create mode 100644 core/CDbgReporter.h diff --git a/TODO.txt b/TODO.txt index f1885ed6..e1049ca0 100644 --- a/TODO.txt +++ b/TODO.txt @@ -2,10 +2,10 @@ things to do for a release, in priority X finish plugin unloading X URGENT: fix compiler's sizeof(), add cellsof - do module api - - finish plugin pausing/unpausing, forwards must block execution + X finish plugin pausing/unpausing, forwards must block execution - do admin api - - add debugging output to logger + X add debugging output to logger - finish ML api, expose through interface - - add error messages to format routine + X add error messages to format routine - finish global unloading - add hex format specifier diff --git a/core/CDbgReporter.cpp b/core/CDbgReporter.cpp new file mode 100644 index 00000000..7a02fb10 --- /dev/null +++ b/core/CDbgReporter.cpp @@ -0,0 +1,73 @@ +#include "CDbgReporter.h" +#include "CLogger.h" +#include "PluginSys.h" + +void CDbgReporter::OnSourceModAllInitialized() +{ + g_pSourcePawn->SetDebugListener(this); +} + +void CDbgReporter::OnContextExecuteError(IPluginContext *ctx, IContextTrace *error) +{ + const char *lastname; + const char *plname = g_PluginSys.FindPluginByContext(ctx->GetContext())->GetFilename(); + int n_err = error->GetErrorCode(); + + if (n_err != SP_ERROR_NATIVE) + { + g_Logger.LogError("[SOURCEMOD] Plugin \"%s\" encountered error %d: %s", + plname, + n_err, + error->GetErrorString()); + } + + if ((lastname=error->GetLastNative(NULL)) != NULL) + { + const char *custerr; + if ((custerr=error->GetCustomErrorString()) != NULL) + { + g_Logger.LogError("[SOURCEMOD] Native \"%s\" reported: \"%s\"", lastname, custerr); + } else { + g_Logger.LogError("[SOURCEMOD] Native \"%s\" encountered a generic error.", lastname); + } + } + + if (!error->DebugInfoAvailable()) + { + g_Logger.LogError("[SOURCEMOD] Debug mode is not enabled for this plugin."); + g_Logger.LogError("[SOURCEMOD] 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("[SOURCEMOD] Displaying call stack trace:"); + while (error->GetTraceInfo(&stk_info)) + { + g_Logger.LogError("[SOURCEMOD] [%d] Line %d, %s::%s()", + i++, + stk_info.line, + stk_info.filename, + stk_info.function); + } +} + +int CDbgReporter::_GetPluginIndex(IPluginContext *ctx) +{ + int id = 1; + IPluginIterator *iter = g_PluginSys.GetPluginIterator(); + + for (; iter->MorePlugins(); iter->NextPlugin(), id++) + { + IPlugin *pl = iter->GetPlugin(); + if (pl->GetBaseContext() == ctx) + { + iter->Release(); + return id; + } + } + + iter->Release(); + return -1; +} \ No newline at end of file diff --git a/core/CDbgReporter.h b/core/CDbgReporter.h new file mode 100644 index 00000000..7d296a46 --- /dev/null +++ b/core/CDbgReporter.h @@ -0,0 +1,19 @@ +#ifndef _INCLUDE_SOURCEMOD_CDBGREPORTER_H_ +#define _INCLUDE_SOURCEMOD_CDBGREPORTER_H_ + +#include "sp_vm_api.h" +#include "sm_globals.h" + +class CDbgReporter : + public SMGlobalClass, + public IDebugListener +{ +public: // SMGlobalClass + void OnSourceModAllInitialized(); +public: // IDebugListener + void OnContextExecuteError(IPluginContext *ctx, IContextTrace *error); +private: + int _GetPluginIndex(IPluginContext *ctx); +}; + +#endif // _INCLUDE_SOURCEMOD_CDBGREPORTER_H_ \ No newline at end of file diff --git a/core/msvc8/sourcemod_mm.vcproj b/core/msvc8/sourcemod_mm.vcproj index 11b7fc16..e7575631 100644 --- a/core/msvc8/sourcemod_mm.vcproj +++ b/core/msvc8/sourcemod_mm.vcproj @@ -1,7 +1,7 @@ + + @@ -253,6 +257,10 @@ Filter="h;hpp;hxx;hm;inl;inc;xsd" UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" > + + diff --git a/core/sm_stringutil.cpp b/core/sm_stringutil.cpp index 47d85685..c6798224 100644 --- a/core/sm_stringutil.cpp +++ b/core/sm_stringutil.cpp @@ -2,20 +2,18 @@ #include #include #include "sm_stringutil.h" +#include "CLogger.h" #define LADJUST 0x00000004 /* left adjustment */ #define ZEROPAD 0x00000080 /* zero (as opposed to blank) pad */ #define to_digit(c) ((c) - '0') #define is_digit(c) ((unsigned)to_digit(c) <= 9) -//:TODO: fix this macro when we have a debugger - -#define CHECK_ARGS(n)/* \ - if ((arg+n) > args) { \ - LogError(amx, AMX_ERR_PARAMS, "String formatted incorrectly - parameter %d (total %d)", arg, args); \ - return 0; \ +#define CHECK_ARGS(x) \ + if ((arg+x) > args) { \ + g_Logger.LogError("String formatted incorrectly - parameter %d (total %d)", arg, args); \ + return 0; \ } -*/ //:TODO: review this code before we choose a license @@ -421,8 +419,7 @@ size_t atcprintf(char *buffer, size_t maxlen, const char *format, IPluginContext } int arg; - //int args = params[0] / sizeof(cell); //:TODO: wrong, i think params[0] has now the param count not the byte count - // either way this is only used when the above macro is fixed, until then not needed + int args = params[0]; char *buf_p; char ch; int flags; diff --git a/core/systems/ForwardSys.cpp b/core/systems/ForwardSys.cpp index e4c2ca18..0622cb6a 100644 --- a/core/systems/ForwardSys.cpp +++ b/core/systems/ForwardSys.cpp @@ -255,6 +255,10 @@ int CForward::Execute(cell_t *result, IForwardFilter *filter) for (iter=m_functions.begin(); iter!=m_functions.end(); iter++) { func = (*iter); + if (func->GetParentPlugin()->GetStatus() == Plugin_Paused) + { + continue; + } for (unsigned int i=0; i