From 748d9ac22fcd404b95e398b5e5a82b087be408bc Mon Sep 17 00:00:00 2001 From: terminx Date: Thu, 7 Jan 2016 03:30:07 +0000 Subject: [PATCH] Alter VM_ScriptInfo() to take a ptr to the script to disassemble, and dump disassembly to the log at startup when an internal compiler error occurs. git-svn-id: https://svn.eduke32.com/eduke32@5513 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/source/game.c | 4 ++-- polymer/eduke32/source/gamedef.c | 1 + polymer/eduke32/source/gamedef.h | 2 ++ polymer/eduke32/source/gameexec.c | 19 +++++++++++-------- polymer/eduke32/source/gameexec.h | 2 -- 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/polymer/eduke32/source/game.c b/polymer/eduke32/source/game.c index f55e449b1..f5c91e84a 100644 --- a/polymer/eduke32/source/game.c +++ b/polymer/eduke32/source/game.c @@ -4937,7 +4937,7 @@ static void G_DumpDebugInfo(void) int32_t i,j,x; // FILE * fp=fopen("condebug.log","w"); - VM_ScriptInfo(); + VM_ScriptInfo(insptr, 64); OSD_Printf("\n"); OSD_Printf("Current gamevar values:\n"); @@ -11417,7 +11417,7 @@ static int32_t G_EndOfLevel(void) void app_crashhandler(void) { G_CloseDemoWrite(); - VM_ScriptInfo(); + VM_ScriptInfo(insptr, 64); G_GameQuit(); } diff --git a/polymer/eduke32/source/gamedef.c b/polymer/eduke32/source/gamedef.c index 2c9e50057..2a4e93613 100644 --- a/polymer/eduke32/source/gamedef.c +++ b/polymer/eduke32/source/gamedef.c @@ -1388,6 +1388,7 @@ static int32_t C_SetScriptSize(int32_t newsize) { g_numCompilerErrors++; initprintf("Internal compiler error at %" PRIdPTR " (0x%" PRIxPTR ")\n",i,i); + VM_ScriptInfo(&script[i], 16); } scriptptrs[i] = 1; diff --git a/polymer/eduke32/source/gamedef.h b/polymer/eduke32/source/gamedef.h index e6149ddd2..865436050 100644 --- a/polymer/eduke32/source/gamedef.h +++ b/polymer/eduke32/source/gamedef.h @@ -39,6 +39,8 @@ extern "C" { #define NUMCHEATCODES (int32_t)ARRAY_SIZE(CheatStrings) extern intptr_t const * insptr; +extern void VM_ScriptInfo(intptr_t const *ptr, int32_t range); + extern hashtable_t h_gamefuncs; #if !defined LUNATIC diff --git a/polymer/eduke32/source/gameexec.c b/polymer/eduke32/source/gameexec.c index 584faeb9c..d0632f724 100644 --- a/polymer/eduke32/source/gameexec.c +++ b/polymer/eduke32/source/gameexec.c @@ -94,22 +94,22 @@ GAMEEXEC_STATIC void VM_Execute(int32_t loop); } \ } -void VM_ScriptInfo(void) +extern void VM_ScriptInfo(intptr_t const *ptr, int32_t range) { #if !defined LUNATIC if (!script) return; - if (insptr) + if (ptr) { initprintf("\n"); - for (intptr_t const *p = insptr - 32; p < insptr + 32; p++) + for (intptr_t const *p = ptr - (range>>1); p < ptr + (range>>1); p++) { if ((int32_t)(p - script) >= g_scriptSize) break; - initprintf("%5d: %3d: ", (int32_t) (p - script), (int32_t) (p - insptr)); + initprintf("%5d: %3d: ", (int32_t) (p - script), (int32_t) (p - ptr)); if (*p >> 12 && (*p & VM_INSTMASK) < CON_END) initprintf("%5d %s\n", (int32_t) (*p >> 12), keyw[*p & VM_INSTMASK]); @@ -120,10 +120,13 @@ void VM_ScriptInfo(void) initprintf("\n"); } - if (vm.g_i) - initprintf("current actor: %d (%d)\n", vm.g_i, TrackerCast(vm.g_sp->picnum)); + if (ptr == insptr) + { + if (vm.g_i) + initprintf("current actor: %d (%d)\n", vm.g_i, TrackerCast(vm.g_sp->picnum)); - initprintf("g_errorLineNum: %d, g_tw: %d\n", g_errorLineNum, g_tw); + initprintf("g_errorLineNum: %d, g_tw: %d\n", g_errorLineNum, g_tw); + } #endif } @@ -5471,7 +5474,7 @@ finish_qsprintf: continue; default: - VM_ScriptInfo(); + VM_ScriptInfo(insptr, 64); G_GameExit("An error has occurred in the EDuke32 virtual machine.\n\n" "If you are an end user, please e-mail the file eduke32.log\n" diff --git a/polymer/eduke32/source/gameexec.h b/polymer/eduke32/source/gameexec.h index f15120f88..8645b88b6 100644 --- a/polymer/eduke32/source/gameexec.h +++ b/polymer/eduke32/source/gameexec.h @@ -90,8 +90,6 @@ static inline int32_t VM_OnEvent(int32_t iEventID, int32_t iActor, int32_t iPlay return VM_HaveEvent(iEventID) ? VM_OnEvent_(iEventID, iActor, iPlayer) : 0; } -void VM_ScriptInfo(void); - #define CON_ERRPRINTF(Text, ...) do { \ OSD_Printf("Line %d, %s: " Text, g_errorLineNum, keyw[g_tw], ## __VA_ARGS__); \ } while (0)