more api for core
sets profiler+debugger now --HG-- branch : refac-jit extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/branches/refac-jit%402376
This commit is contained in:
parent
492c913aa9
commit
5351bbec71
@ -109,25 +109,25 @@ namespace SourceMod
|
||||
virtual PluginType GetType() =0;
|
||||
|
||||
/**
|
||||
* @brief Returns the current API context being used in the plugin.
|
||||
* @brief Returns the IPluginRuntime::GetDefaultContext() value.
|
||||
*
|
||||
* @return Pointer to an IPluginContext, or NULL if not loaded.
|
||||
*/
|
||||
virtual SourcePawn::IPluginContext *GetBaseContext() =0;
|
||||
|
||||
/**
|
||||
* @brief Returns the context structure being used in the plugin.
|
||||
* @brief Deprecated, returns NULL.
|
||||
*
|
||||
* @return Pointer to an sp_context_t, or NULL if not loaded.
|
||||
* @return NULL.
|
||||
*/
|
||||
virtual sp_context_t *GetContext() =0;
|
||||
|
||||
/**
|
||||
* @brief Returns the plugin file structure.
|
||||
* @brief Deprecated, returns NULL.
|
||||
*
|
||||
* @return Pointer to an sp_plugin_t, or NULL if not loaded.
|
||||
* @return NULL.
|
||||
*/
|
||||
virtual const sp_plugin_t *GetPluginStructure() =0;
|
||||
virtual void *GetPluginStructure() =0;
|
||||
|
||||
/**
|
||||
* @brief Returns information about the plugin by reference.
|
||||
@ -189,6 +189,13 @@ namespace SourceMod
|
||||
* @return True if the property existed, false otherwise.
|
||||
*/
|
||||
virtual bool GetProperty(const char *prop, void **ptr, bool remove=false) =0;
|
||||
|
||||
/**
|
||||
* @brief Returns the runtime representing this plugin.
|
||||
*
|
||||
* @return IPluginRuntime pointer, or NULL if not loaded.
|
||||
*/
|
||||
virtual SourcePawn::IPluginRuntime *GetRuntime() =0;
|
||||
};
|
||||
|
||||
|
||||
|
@ -234,7 +234,7 @@ namespace SourcePawn
|
||||
* @brief Executes the forward, resets the pushed parameter list, and
|
||||
* performs any copybacks.
|
||||
*
|
||||
* Note: A function can only be executed given a context it was created in.
|
||||
* Note: A function can only be executed given a runtime it was created in.
|
||||
*
|
||||
* @param ctx Context to execute the function in.
|
||||
* @param result Pointer to store return value in.
|
||||
@ -248,7 +248,7 @@ namespace SourcePawn
|
||||
* NOTE: You will get an error if you attempt to use CallFunction() with
|
||||
* previously pushed parameters.
|
||||
*
|
||||
* Note: A function can only be executed given a context it was created in.
|
||||
* Note: A function can only be executed given a runtime it was created in.
|
||||
*
|
||||
* @param ctx Context to execute the function in.
|
||||
* @param params Array of cell parameters.
|
||||
@ -466,6 +466,13 @@ namespace SourcePawn
|
||||
* @return Pause state (true = paused, false = not).
|
||||
*/
|
||||
virtual bool IsPaused() =0;
|
||||
|
||||
/**
|
||||
* @brief Returns the estimated memory usage of this plugin.
|
||||
*
|
||||
* @return Memory usage, in bytes.
|
||||
*/
|
||||
virtual size_t GetMemUsage() =0;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -765,10 +772,10 @@ namespace SourcePawn
|
||||
*/
|
||||
virtual IPluginFunction *GetFunctionById(funcid_t func_id) =0;
|
||||
|
||||
#if defined SOURCEMOD_BUILD
|
||||
/**
|
||||
* @brief Returns the identity token for this context.
|
||||
* Note: This is a helper function for native calls and the Handle System.
|
||||
*
|
||||
* Note: This is a compatibility shim and is the same as GetKey(1).
|
||||
*
|
||||
* @return Identity token.
|
||||
*/
|
||||
@ -791,7 +798,6 @@ namespace SourcePawn
|
||||
* @param addr Destination output pointer.
|
||||
*/
|
||||
virtual int LocalToStringNULL(cell_t local_addr, char **addr) =0;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Deprecated; do not use.
|
||||
@ -849,6 +855,25 @@ namespace SourcePawn
|
||||
* @return Parameter stack.
|
||||
*/
|
||||
virtual cell_t *GetLocalParams() =0;
|
||||
|
||||
/**
|
||||
* @brief Sets a local "key" that can be used for fast lookup.
|
||||
*
|
||||
* Only the "owner" of the context should be setting this.
|
||||
*
|
||||
* @param key Key number (values allowed: 1 through 4).
|
||||
* @param value Pointer value.
|
||||
*/
|
||||
virtual void SetKey(int k, void *value) =0;
|
||||
|
||||
/**
|
||||
* @brief Retrieves a previously set "key."
|
||||
*
|
||||
* @param key Key number (values allowed: 1 through 4).
|
||||
* @param value Pointer to store value.
|
||||
* @return True on success, false on failure.
|
||||
*/
|
||||
virtual bool GetKey(int k, void **value) =0;
|
||||
};
|
||||
|
||||
|
||||
@ -1190,6 +1215,14 @@ namespace SourcePawn
|
||||
* @param profiler Profiler pointer.
|
||||
*/
|
||||
virtual void SetProfiler(IProfiler *profiler) =0;
|
||||
|
||||
/**
|
||||
* @brief Returns the string representation of an error message.
|
||||
*
|
||||
* @param err Error code.
|
||||
* @return Error string, or NULL if not found.
|
||||
*/
|
||||
virtual const char *GetErrorString(int err) =0;
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include "sp_vm_engine.h"
|
||||
#include "x86/jit_x86.h"
|
||||
#include "sp_vm_basecontext.h"
|
||||
#include "engine2.h"
|
||||
|
||||
using namespace SourcePawn;
|
||||
|
||||
@ -28,6 +29,9 @@ BaseRuntime::BaseRuntime(sp_plugin_t *pl) : m_Debug(pl), m_pPlugin(pl)
|
||||
{
|
||||
m_PubFuncs = NULL;
|
||||
}
|
||||
|
||||
m_pPlugin->dbreak = GlobalDebugBreak;
|
||||
m_pPlugin->profiler = g_engine2.GetProfiler();
|
||||
}
|
||||
|
||||
BaseRuntime::~BaseRuntime()
|
||||
@ -331,3 +335,17 @@ bool BaseRuntime::IsPaused()
|
||||
{
|
||||
return ((m_pPlugin->run_flags & SPFLAG_PLUGIN_PAUSED) == SPFLAG_PLUGIN_PAUSED);
|
||||
}
|
||||
|
||||
size_t BaseRuntime::GetMemUsage()
|
||||
{
|
||||
size_t mem = 0;
|
||||
|
||||
mem += sizeof(this);
|
||||
mem += sizeof(sp_plugin_t);
|
||||
mem += sizeof(BaseContext);
|
||||
mem += m_pPlugin->base_size;
|
||||
mem += m_pPlugin->jit_codesize;
|
||||
mem += m_pPlugin->jit_memsize;
|
||||
|
||||
return mem;
|
||||
}
|
||||
|
@ -44,6 +44,7 @@ public:
|
||||
virtual int ApplyCompilationOptions(ICompilation *co);
|
||||
virtual void SetPauseState(bool paused);
|
||||
virtual bool IsPaused();
|
||||
virtual size_t GetMemUsage();
|
||||
private:
|
||||
void ClearCompile();
|
||||
void RefreshFunctionCache();
|
||||
|
@ -195,6 +195,7 @@ IPluginRuntime *SourcePawnEngine2::LoadPlugin(ICompilation *co, const char *file
|
||||
|
||||
memset(plugin, 0, sizeof(sp_plugin_t));
|
||||
|
||||
plugin->base_size = hdr.imagesize;
|
||||
if (!_ReadPlugin(&hdr, base, plugin, err))
|
||||
{
|
||||
delete plugin;
|
||||
@ -269,3 +270,8 @@ ICompilation *SourcePawnEngine2::StartCompilation()
|
||||
{
|
||||
return g_Jit1.StartCompilation();
|
||||
}
|
||||
|
||||
const char *SourcePawnEngine2::GetErrorString(int err)
|
||||
{
|
||||
return g_engine1.GetErrorString(err);
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ namespace SourcePawn
|
||||
IDebugListener *SetDebugListener(IDebugListener *listener);
|
||||
void SetProfiler(IProfiler *profiler);
|
||||
ICompilation *StartCompilation();
|
||||
const char *GetErrorString(int err);
|
||||
public:
|
||||
IProfiler *GetProfiler();
|
||||
private:
|
||||
|
@ -61,6 +61,7 @@ namespace SourcePawn
|
||||
uint16_t flags; /**< Code flags */
|
||||
sp_plugin_infotab_t info; /**< Base info table */
|
||||
sp_plugin_debug_t debug; /**< Debug info table */
|
||||
size_t base_size; /**< Size of the entire plugin base */
|
||||
void *codebase; /**< Base of generated code and memory */
|
||||
SPVM_DEBUGBREAK dbreak; /**< Debug break function */
|
||||
uint8_t *memory; /**< Data chunk */
|
||||
@ -73,6 +74,8 @@ namespace SourcePawn
|
||||
IProfiler *profiler; /**< Pointer to IProfiler */
|
||||
uint32_t prof_flags; /**< Profiling flags */
|
||||
uint32_t run_flags; /**< Runtime flags */
|
||||
size_t jit_codesize; /**< JIT compiled codesize */
|
||||
size_t jit_memsize; /**< JIT additional memory */
|
||||
} sp_plugin_t;
|
||||
}
|
||||
|
||||
|
@ -769,3 +769,26 @@ cell_t *BaseContext::GetLocalParams()
|
||||
{
|
||||
return (cell_t *)(m_pPlugin->memory + m_ctx.frm + (2 * sizeof(cell_t)));
|
||||
}
|
||||
|
||||
void BaseContext::SetKey(int k, void *value)
|
||||
{
|
||||
if (k < 1 || k > 4)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m_keys[k - 1] = value;
|
||||
m_keys_set[k - 1] = true;
|
||||
}
|
||||
|
||||
bool BaseContext::GetKey(int k, void **value)
|
||||
{
|
||||
if (k < 1 || k > 4 || m_keys_set[k - 1] == false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
*value = m_keys[k - 1];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -90,6 +90,8 @@ public: //IPluginContext
|
||||
IPluginRuntime *GetRuntime();
|
||||
int GetLastNativeError();
|
||||
cell_t *GetLocalParams();
|
||||
void SetKey(int k, void *value);
|
||||
bool GetKey(int k, void **value);
|
||||
public:
|
||||
bool IsInExec();
|
||||
private:
|
||||
@ -105,6 +107,8 @@ private:
|
||||
bool m_InExec;
|
||||
BaseRuntime *m_pRuntime;
|
||||
sp_context_t m_ctx;
|
||||
void *m_keys[4];
|
||||
bool m_keys_set[4];
|
||||
};
|
||||
|
||||
#endif //_INCLUDE_SOURCEPAWN_BASECONTEXT_H_
|
||||
|
@ -94,7 +94,7 @@ static const char *g_ErrorMsgTable[] =
|
||||
"Call was aborted",
|
||||
};
|
||||
|
||||
const char *GetSourcePawnErrorMessage(int error)
|
||||
const char *SourcePawnEngine::GetErrorString(int error)
|
||||
{
|
||||
if (error < 1 || error > ERROR_MESSAGE_MAX)
|
||||
{
|
||||
|
@ -86,6 +86,7 @@ public: //ISourcePawnEngine
|
||||
void SetReadWrite(void *ptr);
|
||||
void SetReadExecute(void *ptr);
|
||||
void FreePageMemory(void *ptr);
|
||||
const char *GetErrorString(int err);
|
||||
public: //Debugger Stuff
|
||||
/**
|
||||
* @brief Pushes a context onto the top of the call tracer.
|
||||
|
@ -2673,6 +2673,8 @@ jit_rewind:
|
||||
}
|
||||
|
||||
plugin->codebase = writer.outbase;
|
||||
plugin->jit_codesize = codemem;
|
||||
plugin->jit_memsize = 0;
|
||||
|
||||
/* setup memory */
|
||||
|
||||
@ -2691,6 +2693,7 @@ jit_rewind:
|
||||
if ((max = plugin->info.publics_num))
|
||||
{
|
||||
plugin->publics = new sp_public_t[max];
|
||||
plugin->jit_memsize += sizeof(sp_public_t) * max;
|
||||
for (iter=0; iter<max; iter++)
|
||||
{
|
||||
plugin->publics[iter].name = strbase + plugin->info.publics[iter].name;
|
||||
@ -2705,6 +2708,7 @@ jit_rewind:
|
||||
{
|
||||
uint8_t *dat = plugin->memory;
|
||||
plugin->pubvars = new sp_pubvar_t[max];
|
||||
plugin->jit_memsize += sizeof(sp_pubvar_t) * max;
|
||||
for (iter=0; iter<max; iter++)
|
||||
{
|
||||
plugin->pubvars[iter].name = strbase + plugin->info.pubvars[iter].name;
|
||||
@ -2716,6 +2720,7 @@ jit_rewind:
|
||||
if ((max = plugin->info.natives_num))
|
||||
{
|
||||
plugin->natives = new sp_native_t[max];
|
||||
plugin->jit_memsize += sizeof(sp_native_t) * max;
|
||||
for (iter=0; iter<max; iter++)
|
||||
{
|
||||
plugin->natives[iter].name = strbase + plugin->info.natives[iter].name;
|
||||
@ -2736,6 +2741,7 @@ jit_rewind:
|
||||
/* relocate files */
|
||||
max = plugin->debug.files_num;
|
||||
plugin->files = new sp_debug_file_t[max];
|
||||
plugin->jit_memsize += sizeof(sp_debug_file_t) * max;
|
||||
for (iter=0; iter<max; iter++)
|
||||
{
|
||||
plugin->files[iter].addr = RelocLookup(jit, plugin->debug.files[iter].addr, false);
|
||||
@ -2745,6 +2751,7 @@ jit_rewind:
|
||||
/* relocate lines */
|
||||
max = plugin->debug.lines_num;
|
||||
plugin->lines = new sp_debug_line_t[max];
|
||||
plugin->jit_memsize += sizeof(sp_debug_line_t) * max;
|
||||
for (iter=0; iter<max; iter++)
|
||||
{
|
||||
plugin->lines[iter].addr = RelocLookup(jit, plugin->debug.lines[iter].addr, false);
|
||||
@ -2758,6 +2765,7 @@ jit_rewind:
|
||||
|
||||
max = plugin->debug.syms_num;
|
||||
plugin->symbols = new sp_debug_symbol_t[max];
|
||||
plugin->jit_memsize += sizeof(sp_debug_symbol_t) * max;
|
||||
for (iter=0; iter<max; iter++)
|
||||
{
|
||||
sym = (sp_fdbg_symbol_t *)cursor;
|
||||
@ -2805,6 +2813,8 @@ jit_rewind:
|
||||
trk->pCur = trk->pBase;
|
||||
trk->size = 1024 / sizeof(cell_t);
|
||||
|
||||
plugin->jit_memsize += trk->size;
|
||||
|
||||
/* clean up relocation+compilation memory */
|
||||
co->Abort();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user