debug break now uses context struct instead of context interface

err is renamed to 'n_err'
'n_err' is now a 'native only' member, for native errors only

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40242
This commit is contained in:
David Anderson
2006-12-31 22:33:47 +00:00
parent cf15783eb0
commit a7fe408995
6 changed files with 165 additions and 51 deletions
+112 -14
View File
@@ -314,6 +314,67 @@ namespace SourcePawn
virtual int Execute(uint32_t funcid, cell_t *result) =0;
};
struct ErrorTraceInfo
{
const char *filename;
unsigned int line;
const char *function;
};
class IContextErrorInfo
{
/**
* @brief Returns the integer error code.
*
* @return Integer error code.
*/
virtual int GetErrorCode() =0;
/**
* @brief Returns a string describing the error.
*
* @return Error string.
*/
virtual const char *GetErrorString() =0;
/**
* @brief Returns whether debug info is available.
*
* @return True if debug info is available, false otherwise.
*/
virtual bool DebugInfoAvailable() =0;
/**
* @brief Returns a custom error message.
*
* @return A pointer to a custom error message, or NULL otherwise.
*/
virtual const char *GetCustomErrorString() =0;
/**
* @brief Returns the number of calls in the call backtrace.
* NOTE: Tracers are ordered from 0 to N-1, where 0 is the top of the trace.
*
* @return Number of calls in the trace.
*/
virtual unsigned int TraceCallCount() =0;
/**
* @brief Returns trace info for a specific point in the backtrace.
*
* @param call The call trace index (from 0 to N-1).
* @param trace An ErrorTraceInfo buffer to store information.
* @return True if successful, false otherwise.
*/
virtual bool GetTraceInfo(unsigned int call, ErrorTraceInfo *trace) =0;
};
class IDebugListener
{
public:
virtual void OnContextExecuteError(IPluginContext *ctx, IContextErrorInfo *error) =0;
};
/**
* @brief Contains helper functions used by VMs and the host app
*/
@@ -321,17 +382,17 @@ namespace SourcePawn
{
public:
/**
* Loads a named file from a file pointer.
* Using this means base memory will be allocated by the VM.
*
* @param fp File pointer. May be at any offset. Not closed on return.
* @param err Optional error code pointer.
* @return A new plugin structure.
*/
* @brief Loads a named file from a file pointer.
* Note: Using this means the memory will be allocated by the VM.
*
* @param fp File pointer. May be at any offset. Not closed on return.
* @param err Optional error code pointer.
* @return A new plugin structure.
*/
virtual sp_plugin_t *LoadFromFilePointer(FILE *fp, int *err) =0;
/**
* Loads a file from a base memory address.
* @brief Loads a file from a base memory address.
*
* @param base Base address of the plugin's memory region.
* @param plugin If NULL, a new plugin pointer is returned.
@@ -349,7 +410,7 @@ namespace SourcePawn
virtual int FreeFromMemory(sp_plugin_t *plugin) =0;
/**
* Creates a new IContext from a context handle.
* @brief Creates a new IContext from a context handle.
*
* @param ctx Context to use as a basis for the IPluginContext.
* @return New IPluginContext handle.
@@ -357,14 +418,14 @@ namespace SourcePawn
virtual IPluginContext *CreateBaseContext(sp_context_t *ctx) =0;
/**
* Frees a base context. Does not free the sp_context_t it holds.
* @brief Frees a base context. Does not free the sp_context_t it holds.
*
* @param ctx Context pointer to free.
*/
virtual void FreeBaseContext(IPluginContext *ctx) =0;
/**
* Allocates large blocks of temporary memory.
* @brief Allocates large blocks of temporary memory.
*
* @param size Size of memory to allocate.
* @return Pointer to memory, NULL if allocation failed.
@@ -372,14 +433,14 @@ namespace SourcePawn
virtual void *BaseAlloc(size_t size) =0;
/**
* Frees memory allocated with BaseAlloc.
* @brief Frees memory allocated with BaseAlloc.
*
* @param memory Memory address to free.
*/
virtual void BaseFree(void *memory) =0;
/**
* Allocates executable memory.
* @brief Allocates executable memory.
*
* @param size Size of memory to allocate.
* @return Pointer to memory, NULL if allocation failed.
@@ -387,13 +448,50 @@ namespace SourcePawn
virtual void *ExecAlloc(size_t size) =0;
/**
* Frees executable memory.
* @brief Frees executable memory.
*
* @param address Address to free.
*/
virtual void ExecFree(void *address) =0;
/**
* @brief Sets the debug listener.
*
* @param listener Pointer to an IDebugListener.
* @return Old IDebugListener, or NULL if none.
*/
virtual IDebugListener *SetDebugListener(IDebugListener *pListener) =0;
/**
* @brief Returns the number of plugins on the call stack.
*
* @return Number of contexts in the call stack.
*/
virtual unsigned int GetContextCallCount() =0;
/**
* @brief Throws an error and halts any current execution.
*
* @param error The error number to set.
* @param msg Custom error message format. NULL to use default.
* @param ... Message format arguments, if any.
*/
virtual void ThrowNativeErrorEx(int error, const char *msg, ...) =0;
/**
* @brief Throws a native error and halts any current execution.
* NOTE: This is a wrapper around ThrowError() for convenience.
*
* @param msg Custom error message format. NULL to set no message.
* @param ... Message format arguments, if any.
* @return 0 for convenience.
*/
virtual void ThrowNativeError(const char *msg, ...) =0;
};
/**
* @brief Dummy class for encapsulating private compilation data.
*/
class ICompilation
{
public:
+2
View File
@@ -3,6 +3,8 @@
#include <sp_vm_api.h>
/* :TODO: rename this to sp_vm_linkage.h */
#if defined WIN32
#define EXPORT_LINK extern "C" __declspec(dllexport)
#else if defined __GNUC__
+4 -2
View File
@@ -37,6 +37,7 @@ typedef uint32_t funcid_t;
#define SP_ERROR_TRACKER_BOUNDS 20 /* Tracker stack is out of bounds */
#define SP_ERROR_INVALID_NATIVE 21 /* Native was pending or invalid */
#define SP_ERROR_PARAMS_MAX 22 /* Maximum number of parameters reached */
#define SP_ERROR_NATIVE 23 /* Error originates from a native */
/**********************************************
*** The following structures are reference structures.
@@ -204,7 +205,7 @@ typedef struct sp_debug_symbol_s
* [1] - frm
* [2] - cip
*/
typedef int (*SPVM_DEBUGBREAK)(SourcePawn::IPluginContext *, uint32_t, uint32_t);
typedef int (*SPVM_DEBUGBREAK)(struct sp_context_s *, uint32_t, uint32_t);
#define SPFLAG_PLUGIN_DEBUG (1<<0) /* plugin is in debug mode */
@@ -234,8 +235,9 @@ typedef struct sp_context_s
cell_t hp; /* heap pointer */
cell_t sp; /* stack pointer */
cell_t frm; /* frame pointer */
int32_t err; /* error code */
uint32_t pushcount; /* push count */
int32_t n_err; /* error code set by a native */
uint32_t n_idx; /* current native index being executed */
/* context rebased database */
sp_public_t *publics; /* public functions table */
sp_pubvar_t *pubvars; /* public variables table */