From 079a3e8bcd75973af8c81dcc0372c11ff22d348e Mon Sep 17 00:00:00 2001 From: David Anderson Date: Wed, 8 Sep 2004 07:05:16 +0000 Subject: [PATCH] Fixed JIT line op problem --- amxmodx/CPlugin.cpp | 24 +++++++++++++++++------- amxmodx/CPlugin.h | 4 ++-- amxmodx/amx.h | 1 + amxmodx/amxmodx.h | 2 +- amxmodx/meta_api.cpp | 2 ++ amxmodx/modules.cpp | 11 +++++++++-- amxmodx/modules.h | 2 +- 7 files changed, 33 insertions(+), 13 deletions(-) diff --git a/amxmodx/CPlugin.cpp b/amxmodx/CPlugin.cpp index 6ae166a1..5ee7de64 100755 --- a/amxmodx/CPlugin.cpp +++ b/amxmodx/CPlugin.cpp @@ -34,10 +34,10 @@ #include "CForward.h" #include "CFile.h" -CPluginMngr::CPlugin* CPluginMngr::loadPlugin(const char* path, const char* name, char* error) { +CPluginMngr::CPlugin* CPluginMngr::loadPlugin(const char* path, const char* name, char* error, int debug) { CPlugin** a = &head; while( *a ) a = &(*a)->next; - *a = new CPlugin( pCounter++ ,path,name,error); + *a = new CPlugin( pCounter++ ,path,name,error, debug); return *error ? 0 : *a; } @@ -59,17 +59,27 @@ int CPluginMngr::loadPluginsFromFile( const char* filename ) } // Find now folder - char pluginName[256], line[256], error[256]; + char pluginName[256], line[256], error[256], debug[256]; + int debugFlag = 0; const char *pluginsDir = get_localinfo("amxx_pluginsdir", "addons/amxmodx/plugins"); while ( fp.getline(line , 255 ) ) { *pluginName = 0; - sscanf(line,"%s",pluginName); + *debug = 0; + debugFlag = 0; + sscanf(line,"%s %s",pluginName, debug); if (!isalnum(*pluginName)) continue; + +#ifdef JIT + if (isalnum(*debug) && strcmp(debug, "debug") == 0) + { + debugFlag = 1; + } +#endif - CPlugin* plugin = loadPlugin( pluginsDir , pluginName , error ); + CPlugin* plugin = loadPlugin( pluginsDir , pluginName , error, debugFlag); if (!plugin) AMXXLOG_Log("[AMXX] %s (plugin \"%s\")", error, pluginName ); @@ -128,14 +138,14 @@ const char* CPluginMngr::CPlugin::getStatus() const { return "error"; } -CPluginMngr::CPlugin::CPlugin(int i, const char* p,const char* n, char* e) : name(n), title(n) { +CPluginMngr::CPlugin::CPlugin(int i, const char* p,const char* n, char* e, int d) : name(n), title(n) { const char* unk = "unknown"; title.assign(unk); author.assign(unk); version.assign(unk); char* path = build_pathname("%s/%s",p,n); code = 0; - int err = load_amxscript(&amx,&code,path,e ); + int err = load_amxscript(&amx,&code,path,e, d); if ( err == AMX_ERR_NONE ) status = ps_running; else status = ps_bad_load; amx.userdata[3] = this; diff --git a/amxmodx/CPlugin.h b/amxmodx/CPlugin.h index 2c234d0f..f061475f 100755 --- a/amxmodx/CPlugin.h +++ b/amxmodx/CPlugin.h @@ -67,7 +67,7 @@ public: int status; CPlugin* next; int id; - CPlugin(int i , const char* p,const char* n, char* e); + CPlugin(int i , const char* p,const char* n, char* e, int d); ~CPlugin( ); public: @@ -104,7 +104,7 @@ public: // Interface - CPlugin* loadPlugin(const char* path, const char* name, char* error); + CPlugin* loadPlugin(const char* path, const char* name, char* error, int debug); void unloadPlugin( CPlugin** a ); int loadPluginsFromFile( const char* filename ); CPlugin* findPluginFast(AMX *amx); diff --git a/amxmodx/amx.h b/amxmodx/amx.h index b4c0c05c..455120a1 100755 --- a/amxmodx/amx.h +++ b/amxmodx/amx.h @@ -293,6 +293,7 @@ enum { #define AMX_FLAG_COMPACT 0x04 /* compact encoding */ #define AMX_FLAG_BIGENDIAN 0x08 /* big endian encoding */ #define AMX_FLAG_NOCHECKS 0x10 /* no array bounds checking */ +#define AMX_FLAG_LINEOPS 0x20 /* line ops are parsed by the JIT [loadtime only flag] */ #define AMX_FLAG_BROWSE 0x4000 /* browsing/relocating or executing */ #define AMX_FLAG_RELOC 0x8000 /* jump/call addresses relocated */ diff --git a/amxmodx/amxmodx.h b/amxmodx/amxmodx.h index 412cda8b..e70f6983 100755 --- a/amxmodx/amxmodx.h +++ b/amxmodx/amxmodx.h @@ -242,7 +242,7 @@ AMX* get_amxscript(int, void**,const char**); const char* get_amxscriptname(AMX* amx); char* get_amxstring(AMX *amx,cell amx_addr,int id,int& len); int amxstring_len(cell* cstr); -int load_amxscript(AMX* amx, void** program, const char* path, char error[64]); +int load_amxscript(AMX* amx, void** program, const char* path, char error[64], int debug); int set_amxnatives(AMX* amx,char error[64]); int set_amxstring(AMX *amx,cell amx_addr,const char *source,int max); int unload_amxscript(AMX* amx,void** program); diff --git a/amxmodx/meta_api.cpp b/amxmodx/meta_api.cpp index 02914746..6ede90c8 100755 --- a/amxmodx/meta_api.cpp +++ b/amxmodx/meta_api.cpp @@ -104,6 +104,7 @@ int g_srvindex; cvar_t init_amxmodx_version = {"amxmodx_version", "", FCVAR_SERVER | FCVAR_SPONLY}; cvar_t init_amxmodx_modules = {"amxmodx_modules", "", FCVAR_SPONLY}; +cvar_t init_amxmodx_debug = {"amx_debug", "", FCVAR_SPONLY}; cvar_t* amxmodx_version = NULL; cvar_t* amxmodx_modules = NULL; cvar_t* hostname = NULL; @@ -1033,6 +1034,7 @@ C_DLLEXPORT int Meta_Attach(PLUG_LOADTIME now, META_FUNCTIONS *pFunctionTable, m gpGamedllFuncs=pGamedllFuncs; CVAR_REGISTER(&init_amxmodx_version); CVAR_REGISTER(&init_amxmodx_modules); + CVAR_REGISTER(&init_amxmodx_debug); amxmodx_version = CVAR_GET_POINTER(init_amxmodx_version.name); REG_SVR_COMMAND("amxx",amx_command); diff --git a/amxmodx/modules.cpp b/amxmodx/modules.cpp index 512befd8..160f6955 100755 --- a/amxmodx/modules.cpp +++ b/amxmodx/modules.cpp @@ -88,7 +88,7 @@ void free_amxmemory(void **ptr) *ptr = 0; } -int load_amxscript(AMX *amx, void **program, const char *filename, char error[64]) +int load_amxscript(AMX *amx, void **program, const char *filename, char error[64], int debug) { *error = 0; CAmxxReader reader(filename, SMALL_CELL_SIZE / 8); @@ -149,6 +149,14 @@ int load_amxscript(AMX *amx, void **program, const char *filename, char error[64 return (amx->error = AMX_ERR_FORMAT); } +#ifdef JIT + if ( ((int)CVAR_GET_FLOAT("amx_debug") == 2 || (debug && (int)CVAR_GET_FLOAT("amx_debug"))) ) + { + //automatic debug mode + hdr->flags |= AMX_FLAG_LINEOPS; + } +#endif + int err; memset(amx, 0, sizeof(*amx)); if ((err = amx_Init( amx, *program )) != AMX_ERR_NONE) @@ -157,7 +165,6 @@ int load_amxscript(AMX *amx, void **program, const char *filename, char error[64 return (amx->error = AMX_ERR_INIT); } - #ifdef JIT void *np = new char[ amx->code_size ]; void *rt = new char[ amx->reloc_size ]; diff --git a/amxmodx/modules.h b/amxmodx/modules.h index a8d6c7f7..296200fc 100755 --- a/amxmodx/modules.h +++ b/amxmodx/modules.h @@ -144,7 +144,7 @@ struct pfnmodule_engine_g { const char* (*pfnget_amxscriptname)(AMX* amx); // amx char* (*pfnget_amxstring)(AMX*,cell,int, int&); // amx, src, buffer (0-3), len void (*pfnget_modname)(char*); // modname - int (*pfnload_amxscript)(AMX*, void**, const char*, char[64]); // amx, code, path, error info + int (*pfnload_amxscript)(AMX*, void**, const char*, char[64], int); // amx, code, path, error info void (*pfnprint_console)(char*, ...); // format, .... void (*pfnreport_error)(int code, char*, ... ); int (*pfnset_amxnatives)(AMX*,char[64]); // amx, error info