Author: andreas Date: 2010-03-10 23:15:34 -0800 (Wed, 10 Mar 2010) New Revision: 2153 Modified: trunk/platforms/win32/vm/sqPlatformSpecific.h trunk/platforms/win32/vm/sqWin32.h trunk/platforms/win32/vm/sqWin32Intel.c trunk/platforms/win32/vm/sqWin32Prefs.c Log: - Better handling of fatal errors. - Make VM version a Makefile property Modified: trunk/platforms/win32/vm/sqPlatformSpecific.h =================================================================== --- trunk/platforms/win32/vm/sqPlatformSpecific.h 2010-03-10 19:22:45 UTC (rev 2152) +++ trunk/platforms/win32/vm/sqPlatformSpecific.h 2010-03-11 07:15:34 UTC (rev 2153) @@ -21,6 +21,9 @@ #define squeakFileOffsetType unsigned long long #endif +#undef error +#define error(str) ioFatalError(str) + #ifdef WIN32_FILE_SUPPORT #undef sqImageFile Modified: trunk/platforms/win32/vm/sqWin32.h =================================================================== --- trunk/platforms/win32/vm/sqWin32.h 2010-03-10 19:22:45 UTC (rev 2152) +++ trunk/platforms/win32/vm/sqWin32.h 2010-03-11 07:15:34 UTC (rev 2153) @@ -241,9 +241,16 @@ #define VERSION "" #endif -#define VM_VERSION TEXT("Squeak 3.11.5 (beta) from ") TEXT(__DATE__) \ - TEXT("\n") TEXT("Compiler: ") TEXT(COMPILER) TEXT(VERSION) +/* Ensure that VM_VERSION (3.11.5 etc) is defined */ +#ifndef VM_VERSION +#error "VM_VERSION is undefined" +#endif +#ifndef VM_NAME +#error "VM_NAME is undefined" +#endif +#define VM_VERSION_INFO TEXT(VM_NAME) TEXT(VM_VERSION) TEXT(" from ") TEXT(__DATE__) \ + /********************************************************/ /* image reversal functions */ /********************************************************/ Modified: trunk/platforms/win32/vm/sqWin32Intel.c =================================================================== --- trunk/platforms/win32/vm/sqWin32Intel.c 2010-03-10 19:22:45 UTC (rev 2152) +++ trunk/platforms/win32/vm/sqWin32Intel.c 2010-03-11 07:15:34 UTC (rev 2153) @@ -697,6 +697,86 @@ /* Release */ /****************************************************************************/ +void +printCommonCrashDumpInfo(FILE *f) { + + fprintf(f,"\n\n%s", hwInfoString); + fprintf(f,"\n%s", osInfoString); + fprintf(f,"\n%s", gdInfoString); + + /* print VM version information */ + fprintf(f,"\nVM Version: %s\n", VM_VERSION_INFO); + fflush(f); + fprintf(f,"\n" + "Current byte code: %d\n" + "Primitive index: %d\n", + getCurrentBytecode(), + methodPrimitiveIndex()); + fflush(f); + /* print loaded plugins */ + fprintf(f,"\nLoaded plugins:\n"); + { + int index = 1; + char *pluginName; + while( (pluginName = ioListLoadedModule(index)) != NULL) { + fprintf(f,"\t%s\n", pluginName); + fflush(f); + index++; + } + } + /* print the caller's stack to "crash.dmp" */ + fprintf(f,"\nThe Smalltalk Stack:\n"); + { + FILE tmpStdout; + tmpStdout = *stdout; + *stdout = *f; + printCallStack(); + *f = *stdout; + *stdout = tmpStdout; + fprintf(f,"\n"); + } +} + +void +error(char *msg) { + FILE *f; + TCHAR crashInfo[1024]; + + wsprintf(crashInfo, + TEXT("Sorry but the VM has crashed.\n\n") + TEXT("Reason: %s\n\n") + TEXT("Current byte code: %d\n") + TEXT("Primitive index: %d\n\n") + TEXT("This information will be stored in the file\n") + TEXT("%s\\%s\n") + TEXT("with a complete stack dump"), + msg, + getCurrentBytecode(), + methodPrimitiveIndex(), + vmPath, + TEXT("crash.dmp")); + if(!fHeadlessImage) + MessageBox(stWindow,crashInfo,TEXT("Fatal VM error"), + MB_OK | MB_APPLMODAL | MB_ICONSTOP); + + SetCurrentDirectory(vmPath); + /* print the above information */ + f = fopen("crash.dmp","a"); + if(f){ + time_t crashTime = time(NULL); + fprintf(f,"---------------------------------------------------------------------\n"); + fprintf(f,"%s\n\n", ctime(&crashTime)); + + fprintf(f,"Reason: %s\n", msg); + printCommonCrashDumpInfo(f); + fclose(f); + } + /* print the caller's stack to stdout */ + printCallStack(); + exit(-1); +} + + void printCrashDebugInformation(LPEXCEPTION_POINTERS exp) { TCHAR crashInfo[1024]; FILE *f; @@ -731,7 +811,7 @@ vmPath, TEXT("crash.dmp")); if(!fHeadlessImage) - MessageBox(0,crashInfo,TEXT("Fatal VM error"), + MessageBox(stWindow,crashInfo,TEXT("Fatal VM error"), MB_OK | MB_APPLMODAL | MB_ICONSTOP); SetCurrentDirectory(vmPath); @@ -769,46 +849,12 @@ exp->ContextRecord->FloatSave.StatusWord, exp->ContextRecord->FloatSave.TagWord); - fprintf(f,"\n%s", hwInfoString); - fprintf(f,"\n%s", osInfoString); - fprintf(f,"\n%s", gdInfoString); + printCommonCrashDumpInfo(f); + fclose(f); - /* print VM version information */ - fprintf(f,"\nVM Version: %s\n", VM_VERSION); - fflush(f); - fprintf(f,"\n" - "Current byte code: %d\n" - "Primitive index: %d\n", - byteCode, - methodPrimitiveIndex()); - fflush(f); - /* print loaded plugins */ - fprintf(f,"\nLoaded plugins:\n"); - { - int index = 1; - char *pluginName; - while( (pluginName = ioListLoadedModule(index)) != NULL) { - fprintf(f,"\t%s\n", pluginName); - fflush(f); - index++; - } - } - fprintf(f, "\n\nStack dump:\n\n"); + /* print the caller's stack twice (to stdout and "crash.dmp")*/ + printCallStack(); } - fflush(f); - - /* print the caller's stack twice (to stdout and "crash.dmp")*/ - { - FILE tmpStdout; - tmpStdout = *stdout; - *stdout = *f; - printCallStack(); - *f = *stdout; - *stdout = tmpStdout; - fprintf(f,"\n"); - fclose(f); - } - } EXCEPT(EXCEPTION_EXECUTE_HANDLER) { /* that's to bad ... */ if(!fHeadlessImage) @@ -819,42 +865,11 @@ } } -void printErrors() -{ TCHAR *errorMsg; - fpos_t stdoutSize,stderrSize; - - if(*stdoutName) - { - fgetpos(stdout,&stdoutSize); - fseek(stdout,0,SEEK_SET); - } - else stdoutSize = 0; - - if(*stderrName) - { - fgetpos(stderr,&stderrSize); - fseek(stderr,0,SEEK_SET); - } - else stderrSize = 0; - - if(stdoutSize <= 0 && stderrSize <= 0) return; - errorMsg = (char*) calloc((int)(stdoutSize+stderrSize+2),1); - fread(errorMsg,(int)stdoutSize,1,stdout); - errorMsg[stdoutSize] = '\n'; - fread(&errorMsg[(int)(stdoutSize+1)],(int)stderrSize,1,stderr); - if(!fHeadlessImage) - MessageBox(0,errorMsg,TEXT("Error:"),MB_OK); - free(errorMsg); -} - extern int inCleanExit; void __cdecl Cleanup(void) { /* not all of these are essential, but they're polite... */ - if(!inCleanExit) { - printCallStack(); - } ioShutdownAllModules(); #ifndef NO_PLUGIN_SUPPORT pluginExit(); @@ -868,8 +883,6 @@ PROFILE_SHOW(ticksForReversal); PROFILE_SHOW(ticksForBlitting); /* Show errors only if not in a browser */ - if(!browserWindow) - printErrors(); if(*stderrName) { fclose(stderr); Modified: trunk/platforms/win32/vm/sqWin32Prefs.c =================================================================== --- trunk/platforms/win32/vm/sqWin32Prefs.c 2010-03-10 19:22:45 UTC (rev 2152) +++ trunk/platforms/win32/vm/sqWin32Prefs.c 2010-03-11 07:15:34 UTC (rev 2153) @@ -348,7 +348,7 @@ void HandlePrefsMenu(int cmd) { switch(cmd) { case ID_ABOUT: - MessageBox(stWindow,VM_VERSION, + MessageBox(stWindow,VM_VERSION_INFO, TEXT("About " VM_NAME " on Win32"), MB_OK); break; case ID_DEFERUPDATES: |
Free forum by Nabble | Edit this page |