core/vm/sp_vm_engine.h
author Borja Ferrer <faluco@alliedmods.net>
Thu Jul 05 14:47:36 2007 +0000 (2007-07-05)
changeset 1041 f7b2073013df
parent 653 ef60870067ff
child 1147 437e1f00a590
permissions -rw-r--r--
added a time stamp argument to FormatTime
     1 /**
     2  * vim: set ts=4 :
     3  * ================================================================
     4  * SourcePawn (C)2004-2007 AlliedModders LLC.  All rights reserved.
     5  * ================================================================
     6  *
     7  * This file is not open source and may not be copied without explicit
     8  * written permission of AlliedModders LLC.  This file may not be redistributed 
     9  * in whole or significant part.
    10  * For information, see LICENSE.txt or http://www.sourcemod.net/license.php
    11  *
    12  * Version: $Id$
    13  */
    14 
    15 #ifndef _INCLUDE_SOURCEPAWN_VM_ENGINE_H_
    16 #define _INCLUDE_SOURCEPAWN_VM_ENGINE_H_
    17 
    18 #include "sp_vm_api.h"
    19 #include "sp_vm_function.h"
    20 
    21 struct TracedCall
    22 {
    23 	uint32_t cip;
    24 	uint32_t frm;
    25 	sp_context_t *ctx;
    26 	TracedCall *next;
    27 	unsigned int chain;
    28 };
    29 
    30 
    31 class CContextTrace : public IContextTrace
    32 {
    33 public:
    34 	CContextTrace(TracedCall *pStart, int error, const char *msg, uint32_t native);
    35 public:
    36 	int GetErrorCode();
    37 	const char *GetErrorString();
    38 	bool DebugInfoAvailable();
    39 	const char *GetCustomErrorString();
    40 	bool GetTraceInfo(CallStackInfo *trace);
    41 	void ResetTrace();
    42 	const char *GetLastNative(uint32_t *index);
    43 private:
    44 	int m_Error;
    45 	const char *m_pMsg;
    46 	TracedCall *m_pStart;
    47 	TracedCall *m_pIterator;
    48 	uint32_t m_Native;
    49 };
    50 
    51 class SourcePawnEngine : public ISourcePawnEngine
    52 {
    53 public:
    54 	SourcePawnEngine();
    55 	~SourcePawnEngine();
    56 public: //ISourcePawnEngine
    57 	sp_plugin_t *LoadFromFilePointer(FILE *fp, int *err);
    58 	sp_plugin_t *LoadFromMemory(void *base, sp_plugin_t *plugin, int *err);
    59 	int FreeFromMemory(sp_plugin_t *plugin);
    60 	IPluginContext *CreateBaseContext(sp_context_t *ctx);
    61 	void FreeBaseContext(IPluginContext *ctx);
    62 	void *BaseAlloc(size_t size);
    63 	void BaseFree(void *memory);
    64 	void *ExecAlloc(size_t size);
    65 	void ExecFree(void *address);
    66 	IDebugListener *SetDebugListener(IDebugListener *pListener);
    67 	unsigned int GetContextCallCount();
    68 public: //Debugger Stuff
    69 	/**
    70 	 * @brief Pushes a context onto the top of the call tracer.
    71 	 * 
    72 	 * @param ctx		Plugin context.
    73 	 */
    74 	void PushTracer(sp_context_t *ctx);
    75 
    76 	/**
    77 	 * @brief Pops a plugin off the call tracer.
    78 	 */
    79 	void PopTracer(int error, const char *msg);
    80 
    81 	/**
    82 	 * @brief Runs tracer from a debug break.
    83 	 */
    84 	void RunTracer(sp_context_t *ctx, uint32_t frame, uint32_t codeip);
    85 public: //Plugin function stuff
    86 	CFunction *GetFunctionFromPool(funcid_t f, IPluginContext  *plugin);
    87 	void ReleaseFunctionToPool(CFunction *func);
    88 private:
    89 	TracedCall *MakeTracedCall(bool new_chain);
    90 	void FreeTracedCall(TracedCall *pCall);
    91 private:
    92 	IDebugListener *m_pDebugHook;
    93 	TracedCall *m_FreedCalls;
    94 	TracedCall *m_CallStack;
    95 	unsigned int m_CurChain;
    96 	//CFunction *m_pFreeFuncs;
    97 };
    98 
    99 #endif //_INCLUDE_SOURCEPAWN_VM_ENGINE_H_