From 4ae67c92137dbb2078d933cce7c2c33a90b104c6 Mon Sep 17 00:00:00 2001 From: Borja Ferrer Date: Thu, 10 May 2007 22:51:56 +0000 Subject: [PATCH] added debug code for leak detection on plugins --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40768 --- core/vm/sp_vm_basecontext.cpp | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/core/vm/sp_vm_basecontext.cpp b/core/vm/sp_vm_basecontext.cpp index d1424119..e2d042d8 100644 --- a/core/vm/sp_vm_basecontext.cpp +++ b/core/vm/sp_vm_basecontext.cpp @@ -20,6 +20,10 @@ #include "sp_vm_basecontext.h" #include "sp_vm_engine.h" +#ifdef SOURCEMOD_BUILD +#include "Logger.h" +#endif + using namespace SourcePawn; extern SourcePawnEngine g_SourcePawn; @@ -223,11 +227,24 @@ int BaseContext::Execute(uint32_t code_addr, cell_t *result) */ g_SourcePawn.PopTracer(err, m_CustomMsg ? m_MsgCache : NULL); -#if defined _DEBUG +#if 1//defined _DEBUG + //:TODO: debug code for leak detection, remove before the release? if (err == SP_ERROR_NONE) { - assert(ctx->sp - pushcount * sizeof(cell_t) == save_sp); - assert(ctx->hp == save_hp); + if ((ctx->sp - pushcount * sizeof(cell_t)) != save_sp) + { + const char *name; + ctx->context->GetDebugInfo()->LookupFunction(code_addr, &name); + g_Logger.LogError("Stack leak detected: sp:%d should be %d on function %s", ctx->sp, save_sp, name); + } + if (ctx->hp != save_hp) + { + const char *name; + ctx->context->GetDebugInfo()->LookupFunction(code_addr, &name); + g_Logger.LogError("Heap leak detected: hp:%d should be %d on function %s", ctx->hp, save_hp, name); + } + //assert(ctx->sp - pushcount * sizeof(cell_t) == save_sp); + //assert(ctx->hp == save_hp); } #endif if (err != SP_ERROR_NONE)