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:
David Anderson
2008-07-07 06:24:54 +00:00
parent 492c913aa9
commit 5351bbec71
12 changed files with 119 additions and 12 deletions
+18
View File
@@ -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;
}
+1
View File
@@ -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();
+6
View File
@@ -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);
}
+1
View File
@@ -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:
+3
View File
@@ -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;
}
+23
View File
@@ -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;
}
+4
View File
@@ -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_
+1 -1
View File
@@ -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)
{
+1
View File
@@ -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.
+10
View File
@@ -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();