Commit 1d108747 authored by simonmar's avatar simonmar

[project @ 2004-09-06 11:10:32 by simonmar]

Further to the RTS messaging tidyup: export the new message API and
hooks via RtsMessages.h, so that a client program can easily redirect
messages.
parent 770cf054
/* -----------------------------------------------------------------------------
* $Id: Rts.h,v 1.26 2004/08/22 16:40:38 panne Exp $
* $Id: Rts.h,v 1.27 2004/09/06 11:10:34 simonmar Exp $
*
* (c) The GHC Team, 1998-1999
*
......@@ -154,6 +154,7 @@ void _stgAssert (char *, unsigned int);
/* Runtime-system hooks */
#include "Hooks.h"
#include "RtsMessages.h"
#include "ieee-flpt.h"
......
/* -----------------------------------------------------------------------------
*
* (c) The GHC Team, 1998-2004
*
* Message API for use inside the RTS. All messages generated by the
* RTS should go through one of the functions declared here, and we
* also provide hooks so that messages from the RTS can be redirected
* as appropriate.
*
* ---------------------------------------------------------------------------*/
#ifndef RTSMESSAGES_H
#define RTSMESSAGES_H
#include <stdarg.h>
/* -----------------------------------------------------------------------------
* Message generation
* -------------------------------------------------------------------------- */
/*
* A fatal internal error: this is for errors that probably indicate
* bugs in the RTS or compiler. We normally output bug reporting
* instructions along with the error message.
*
* barf() invokes (*fatalInternalErrorFn)(). This function is not
* expected to return.
*/
extern void barf(char *s, ...)
GNUC3_ATTRIBUTE(__noreturn__);
extern void vbarf(char *s, va_list ap)
GNUC3_ATTRIBUTE(__noreturn__);
/*
* An error condition which is caused by and/or can be corrected by
* the user.
*
* errorBelch() invokes (*errorMsgFn)().
*/
extern void errorBelch(char *s, ...)
GNUC3_ATTRIBUTE(format (printf, 1, 2));
extern void verrorBelch(char *s, va_list ap);
/*
* A debugging message. Debugging messages are generated either as a
* virtue of having DEBUG turned on, or by being explicitly selected
* via RTS options (eg. +RTS -Ds).
*
* debugBelch() invokes (*debugMsgFn)().
*/
extern void debugBelch(char *s, ...)
GNUC3_ATTRIBUTE(format (printf, 1, 2));
extern void vdebugBelch(char *s, va_list ap);
/* Hooks for redirecting message generation: */
typedef void RtsMsgFunction(char *, va_list);
extern RtsMsgFunction *fatalInternalErrorFn;
extern RtsMsgFunction *debugMsgFn;
extern RtsMsgFunction *errorMsgFn;
/* Default stdio implementation of the message hooks: */
extern RtsMsgFunction stdioFatalInternalErrorFn;
extern RtsMsgFunction stdioDebugMsgFn;
extern RtsMsgFunction stdioErrorMsgFn;
#endif // RTSMESSAGES_H
/* -----------------------------------------------------------------------------
*
* (c) The GHC Team, 1998-2004
*
* General utility functions used in the RTS.
*
* ---------------------------------------------------------------------------*/
#include "PosixSource.h"
#include "Rts.h"
#include <stdio.h>
/* -----------------------------------------------------------------------------
General message generation functions
All messages should go through here. We can't guarantee that
stdout/stderr will be available - e.g. in a Windows program there
is no console for generating messages, so they have to either go to
to the debug console, or pop up message boxes.
-------------------------------------------------------------------------- */
// Default to the stdio implementation of these hooks.
RtsMsgFunction *fatalInternalErrorFn = stdioFatalInternalErrorFn;
RtsMsgFunction *debugMsgFn = stdioDebugMsgFn;
RtsMsgFunction *errorMsgFn = stdioErrorMsgFn;
void
barf(char *s, ...)
{
va_list ap;
va_start(ap,s);
(*fatalInternalErrorFn)(s,ap);
stg_exit(EXIT_INTERNAL_ERROR); // just in case fatalInternalErrorFn() returns
va_end(ap);
}
void
vbarf(char *s, va_list ap)
{
(*fatalInternalErrorFn)(s,ap);
stg_exit(EXIT_INTERNAL_ERROR); // just in case fatalInternalErrorFn() returns
}
void
errorBelch(char *s, ...)
{
va_list ap;
va_start(ap,s);
(*errorMsgFn)(s,ap);
va_end(ap);
}
void
verrorBelch(char *s, va_list ap)
{
(*errorMsgFn)(s,ap);
}
void
debugBelch(char *s, ...)
{
va_list ap;
va_start(ap,s);
(*debugMsgFn)(s,ap);
va_end(ap);
}
void
vdebugBelch(char *s, va_list ap)
{
(*debugMsgFn)(s,ap);
}
/* -----------------------------------------------------------------------------
stdio versions of the message functions
-------------------------------------------------------------------------- */
void
stdioFatalInternalErrorFn(char *s, va_list ap)
{
/* don't fflush(stdout); WORKAROUND bug in Linux glibc */
if (prog_argv != NULL && prog_name != NULL) {
fprintf(stderr, "%s: internal error: ", prog_name);
} else {
fprintf(stderr, "internal error: ");
}
vfprintf(stderr, s, ap);
fprintf(stderr, "\n");
fprintf(stderr, " Please report this as a bug to glasgow-haskell-bugs@haskell.org,\n or http://www.sourceforge.net/projects/ghc/\n");
fflush(stderr);
stg_exit(EXIT_INTERNAL_ERROR);
}
void
stdioErrorMsgFn(char *s, va_list ap)
{
/* 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);
fprintf(stderr, "\n");
}
void
stdioDebugMsgFn(char *s, va_list ap)
{
/* don't fflush(stdout); WORKAROUND bug in Linux glibc */
vfprintf(stderr, s, ap);
fflush(stderr);
}
......@@ -10,10 +10,8 @@
/* #include "PosixSource.h" */
#include "Rts.h"
#include "RtsTypes.h"
#include "RtsAPI.h"
#include "RtsFlags.h"
#include "Hooks.h"
#include "RtsUtils.h"
#include "Ticky.h"
......@@ -34,91 +32,6 @@
#include <stdarg.h>
#include <stdio.h>
/* -----------------------------------------------------------------------------
General message generation functions
All messages should go through here. We can't guarantee that
stdout/stderr will be available - e.g. in a Windows program there
is no console for generating messages, so they have to either go to
to the debug console, or pop up message boxes.
-------------------------------------------------------------------------- */
RtsMsgFunction *fatalInternalMsgFn = stdioFatalInternalMsgFn;
RtsMsgFunction *debugMsgFn = stdioDebugMsgFn;
RtsMsgFunction *errorMsgFn = stdioErrorMsgFn;
void
barf(char *s, ...)
{
va_list ap;
va_start(ap,s);
(*fatalInternalMsgFn)(s,ap);
stg_exit(EXIT_INTERNAL_ERROR);
va_end(ap);
}
void
errorBelch(char *s, ...)
{
va_list ap;
va_start(ap,s);
(*errorMsgFn)(s,ap);
va_end(ap);
}
void
debugBelch(char *s, ...)
{
va_list ap;
va_start(ap,s);
(*debugMsgFn)(s,ap);
va_end(ap);
}
void
vdebugBelch(char *s, va_list ap)
{
(*debugMsgFn)(s,ap);
}
/* -----------------------------------------------------------------------------
stdio versions of the message functions
-------------------------------------------------------------------------- */
void
stdioFatalInternalMsgFn(char *s, va_list ap)
{
/* don't fflush(stdout); WORKAROUND bug in Linux glibc */
if (prog_argv != NULL && prog_name != NULL) {
fprintf(stderr, "%s: internal error: ", prog_name);
} else {
fprintf(stderr, "internal error: ");
}
vfprintf(stderr, s, ap);
fprintf(stderr, "\n");
fprintf(stderr, " Please report this as a bug to glasgow-haskell-bugs@haskell.org,\n or http://www.sourceforge.net/projects/ghc/\n");
fflush(stderr);
}
void
stdioErrorMsgFn(char *s, va_list ap)
{
/* 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);
fprintf(stderr, "\n");
}
void
stdioDebugMsgFn(char *s, va_list ap)
{
/* don't fflush(stdout); WORKAROUND bug in Linux glibc */
vfprintf(stderr, s, ap);
fflush(stderr);
}
/* -----------------------------------------------------------------------------
Result-checking malloc wrappers.
-------------------------------------------------------------------------- */
......
......@@ -9,62 +9,20 @@
#ifndef RTSUTILS_H
#define RTSUTILS_H
#include <stdarg.h>
/* -----------------------------------------------------------------------------
* Message generation
* (Checked) dynamic allocation
* -------------------------------------------------------------------------- */
/*
* A fatal internal error: this is for errors that probably indicate
* bugs in the RTS or compiler. We normally output bug reporting
* instructions along with the error message.
*/
extern void barf(char *s, ...)
GNUC3_ATTRIBUTE(__noreturn__);
/*
* An error condition which is caused by and/or can be corrected by
* the user.
*/
extern void errorBelch(char *s, ...)
GNUC3_ATTRIBUTE(format (printf, 1, 2));
/*
* A debugging message. Debugging messages are generated either as a
* virtue of having DEBUG turned on, or by being explicitly selected
* via RTS options (eg. +RTS -Ds).
*/
extern void debugBelch(char *s, ...)
GNUC3_ATTRIBUTE(format (printf, 1, 2));
/* Version of debugBelch() that takes parameters as a va_list */
extern void vdebugBelch(char *s, va_list ap);
/* Hooks for redirecting message generation: */
typedef void RtsMsgFunction(char *, va_list);
extern RtsMsgFunction *fatalInternalMsgFn;
extern RtsMsgFunction *debugMsgFn;
extern RtsMsgFunction *errorMsgFn;
extern void *stgMallocBytes(int n, char *msg)
GNUC3_ATTRIBUTE(__malloc__);
/* Default stdio implementation of the message hooks: */
extern void *stgReallocBytes(void *p, int n, char *msg);
extern RtsMsgFunction stdioFatalInternalMsgFn;
extern RtsMsgFunction stdioDebugMsgFn;
extern RtsMsgFunction stdioErrorMsgFn;
extern void *stgCallocBytes(int n, int m, char *msg)
GNUC3_ATTRIBUTE(__malloc__);
/* -----------------------------------------------------------------------------
* (Checked) dynamic allocation
* -------------------------------------------------------------------------- */
extern void *stgMallocBytes(int n, char *msg) GNUC3_ATTRIBUTE(__malloc__);
extern void *stgReallocBytes(void *p, int n, char *msg);
extern void *stgCallocBytes(int n, int m, char *msg) GNUC3_ATTRIBUTE(__malloc__);
extern void stgFree(void* p);
/* -----------------------------------------------------------------------------
* Misc other utilities
* -------------------------------------------------------------------------- */
......@@ -78,11 +36,11 @@ extern void resetNonBlockingFd(int fd);
extern nat stg_strlen(char *str);
char *time_str(void);
char *ullong_format_string(ullong, char *, rtsBool);
extern char *time_str(void);
extern char *ullong_format_string(ullong, char *, rtsBool);
#ifdef PAR
ullong msTime(void);
extern ullong msTime(void);
#endif
#ifdef DEBUG
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment