X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=rts%2FRtsMessages.c;h=6e75abc8a5b24ff95c3e43b40d72e8a52b1741a4;hb=d8334d807812e40f67770ffc37608c0ce66f96b2;hp=73af8391e952aa3ed9b65a4d7e88e4ce66f5e9d9;hpb=f07c4a158ebd4e7270266fe04077ea3c931f0672;p=ghc-hetmet.git diff --git a/rts/RtsMessages.c b/rts/RtsMessages.c index 73af839..6e75abc 100644 --- a/rts/RtsMessages.c +++ b/rts/RtsMessages.c @@ -9,7 +9,11 @@ #include "PosixSource.h" #include "Rts.h" +#include "eventlog/EventLog.h" + #include +#include +#include #ifdef HAVE_WINDOWS_H #include @@ -28,6 +32,7 @@ RtsMsgFunction *fatalInternalErrorFn = rtsFatalInternalErrorFn; RtsMsgFunction *debugMsgFn = rtsDebugMsgFn; RtsMsgFunction *errorMsgFn = rtsErrorMsgFn; +RtsMsgFunction *sysErrorMsgFn = rtsSysErrorMsgFn; void barf(const char*s, ...) @@ -68,6 +73,21 @@ verrorBelch(const char*s, va_list ap) } void +sysErrorBelch(const char*s, ...) +{ + va_list ap; + va_start(ap,s); + (*sysErrorMsgFn)(s,ap); + va_end(ap); +} + +void +vsysErrorBelch(const char*s, va_list ap) +{ + (*sysErrorMsgFn)(s,ap); +} + +void debugBelch(const char*s, ...) { va_list ap; @@ -90,7 +110,7 @@ vdebugBelch(const char*s, va_list ap) #if defined(cygwin32_HOST_OS) || defined (mingw32_HOST_OS) static int -isGUIApp() +isGUIApp(void) { PIMAGE_DOS_HEADER pDOSHeader; PIMAGE_NT_HEADERS pPEHeader; @@ -110,7 +130,7 @@ isGUIApp() #define xstr(s) str(s) #define str(s) #s -void +void GNU_ATTRIBUTE(__noreturn__) rtsFatalInternalErrorFn(const char *s, va_list ap) { #if defined(cygwin32_HOST_OS) || defined (mingw32_HOST_OS) @@ -143,6 +163,10 @@ rtsFatalInternalErrorFn(const char *s, va_list ap) fflush(stderr); } +#ifdef TRACING + if (RtsFlags.TraceFlags.tracing == TRACE_EVENTLOG) endEventLogging(); +#endif + abort(); // stg_exit(EXIT_INTERNAL_ERROR); } @@ -169,7 +193,7 @@ rtsErrorMsgFn(const char *s, va_list ap) #endif { /* don't fflush(stdout); WORKAROUND bug in Linux glibc */ - if (prog_argv != NULL && prog_name != NULL) { + if (prog_name != NULL) { fprintf(stderr, "%s: ", prog_name); } vfprintf(stderr, s, ap); @@ -178,6 +202,66 @@ rtsErrorMsgFn(const char *s, va_list ap) } void +rtsSysErrorMsgFn(const char *s, va_list ap) +{ + char *syserr; + +#if defined(cygwin32_HOST_OS) || defined (mingw32_HOST_OS) + FormatMessage( + FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + GetLastError(), + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language + (LPTSTR) &syserr, + 0, + NULL ); + + if (isGUIApp()) + { + char buf[BUFSIZE]; + int r; + + r = vsnprintf(buf, BUFSIZE, s, ap); + if (r > 0 && r < BUFSIZE) { + r = vsnprintf(buf+r, BUFSIZE-r, ": %s", syserr); + MessageBox(NULL /* hWnd */, + buf, + prog_name, + MB_OK | MB_ICONERROR | MB_TASKMODAL + ); + } + } + else +#else + syserr = strerror(errno); + // ToDo: use strerror_r() if available +#endif + { + /* don't fflush(stdout); WORKAROUND bug in Linux glibc */ + if (prog_argv != NULL && prog_name != NULL) { + fprintf(stderr, "%s: ", prog_name); + } + vfprintf(stderr, s, ap); + if (syserr) { +#if defined(cygwin32_HOST_OS) || defined (mingw32_HOST_OS) + // Win32 error messages have a terminating \n + fprintf(stderr, ": %s", syserr); +#else + fprintf(stderr, ": %s\n", syserr); +#endif + } else { + fprintf(stderr, "\n"); + } + } + +#if defined(cygwin32_HOST_OS) || defined (mingw32_HOST_OS) + if (syserr) LocalFree(syserr); +#endif +} + +void rtsDebugMsgFn(const char *s, va_list ap) { #if defined(cygwin32_HOST_OS) || defined (mingw32_HOST_OS)