Go to the first, previous, next, last section, table of contents.

"Hooks" to change RTS failure messages

GHC lets you exercise rudimentary control over the messages printed when the runtime system "blows up," e.g., on stack overflow.

Simply write some of the following procedures in C and then make sure they get linked in, in preference to those in the RTS library:

`void ErrorHdrHook (FILE *)':
What's printed out before the message from `error'.
`void OutOfHeapHook (unsigned long, unsigned long)':
The heap-overflow message.
`void StackOverflowHook (long int)':
The stack-overflow message.
`void MallocFailHook (long int)':
The message printed if `malloc' fails.
`void PatErrorHdrHook (FILE *)':
The message printed if a pattern-match fails (the failures that were not handled by the Haskell programmer).
`void PreTraceHook (FILE *)':
What's printed out before a `trace' message.
`void PostTraceHook (FILE *)':
What's printed out after a `trace' message.

For example, here is the "hooks" code used by GHC itself:

#include <stdio.h>
#define W_ unsigned long int
#define I_ long int

void
ErrorHdrHook (where)
  FILE *where;
{
    fprintf(where, "\n"); /* no "Fail: " */
}

void
OutOfHeapHook (request_size, heap_size)
  W_ request_size; /* in bytes */
  W_ heap_size;    /* in bytes */
{
    fprintf(stderr, "GHC's heap exhausted;\nwhile trying to 
        allocate %lu bytes in a %lu-byte heap;\nuse the `-H<size>'
        option to increase the total heap size.\n",
        request_size,
        heap_size);
}

void
StackOverflowHook (stack_size)
  I_ stack_size;    /* in bytes */
{
    fprintf(stderr, "GHC stack-space overflow: current size
        %ld bytes.\nUse the `-K<size>' option to increase it.\n",
        stack_size);
}

void
PatErrorHdrHook (where)
  FILE *where;
{
    fprintf(where, "\n*** Pattern-matching error within GHC!\n\n
        This is a compiler bug; please report it to
        [email protected]\n\nFail: ");
}

void
PreTraceHook (where)
  FILE *where;
{
    fprintf(where, "\n"); /* not "Trace On" */
}

void
PostTraceHook (where)
  FILE *where;
{
    fprintf(where, "\n"); /* not "Trace Off" */
}


Go to the first, previous, next, last section, table of contents.