home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / programming / desklib / sources / DeskLib / !DLSources / OtherLibs / Debugs / c / Signal < prev    next >
Encoding:
Text File  |  1995-07-10  |  2.4 KB  |  102 lines

  1. /*
  2.     ####             #    #     # #
  3.     #   #            #    #       #          The FreeWare C library for
  4.     #   #  ##   ###  #  # #     # ###             RISC OS machines
  5.     #   # #  # #     # #  #     # #  #   ___________________________________
  6.     #   # ####  ###  ##   #     # #  #
  7.     #   # #        # # #  #     # #  #    Please refer to the accompanying
  8.     ####   ### ####  #  # ##### # ###    documentation for conditions of use
  9.     ________________________________________________________________________
  10.  
  11.     File:    Debug.c.Signal
  12.     Author:  Paul Field and Cy Booker, hacked around by Julian Smith
  13.     Version: 0.00 (04 Jun 1995)
  14.     Purpose: Provides a set of Debug_ functions which deal with signals
  15.              nicely.
  16. */
  17.  
  18. #include <signal.h>
  19.  
  20. #include "DeskLib:Debug.h"
  21.  
  22. #include "DeskLib:Event.h"    /* for event_taskname    */
  23. #include "DeskLib:Error.h"
  24.  
  25.  
  26.  
  27. typedef struct    {
  28.     debug_signalhandlerfn    fn;
  29.     void            *reference;
  30.     }
  31.     debug_sighandlerblock;
  32.  
  33. static debug_sighandlerblock debug_usersighandler = { NULL, NULL};
  34.  
  35. static debug_siginited = FALSE;
  36.     /* So we can check we are inited when Debug_ClaimSignal is called    */
  37.  
  38. static const char *debug_signalnames[] =
  39.     {
  40.     "zero signal",
  41.     "abnormal termination", 
  42.     "arithmetic exception",
  43.     "illegal instruction", 
  44.     "interrupt",
  45.     "memory violation", 
  46.     "terminate", 
  47.     "stack overflow",
  48.     "user1 signal",
  49.     "user2 signal",
  50.     "OS error signal"
  51.     };
  52.  
  53. #define debug_maxsignal 10
  54.  
  55.  
  56.  
  57. static void    Debug__SignalHandler( int sig)
  58. {
  59. if ( debug_usersighandler.fn)
  60.     debug_usersighandler.fn( sig, debug_usersighandler.reference);
  61.  
  62. Error_Report( 
  63.     0, 
  64.     "'%s' has suffered a fatal internal error, signal %i (%s) and must exit immediately",
  65.     event_taskname,
  66.     sig,
  67.     (sig>=1 && sig<=debug_maxsignal) ? debug_signalnames[ sig] : "Illegal signal"
  68.     );
  69.  
  70. /* Pass things on to the default handler     */
  71. /* (gives a useful message and a stack dump) */
  72. raise( sig);
  73. }
  74.  
  75.  
  76.     
  77. void    Debug_InitialiseSignal( void)
  78. {
  79. signal( SIGABRT, &Debug__SignalHandler);
  80. signal( SIGFPE,  &Debug__SignalHandler);
  81. signal( SIGILL,  &Debug__SignalHandler);
  82. signal( SIGSEGV, &Debug__SignalHandler);
  83. signal( SIGTERM, &Debug__SignalHandler);
  84. signal( SIGSTAK, &Debug__SignalHandler);
  85. }
  86.  
  87.  
  88.  
  89. void    Debug_ClaimSignal( debug_signalhandlerfn fn, void *reference)
  90. {
  91. if ( !debug_siginited)     Debug_InitialiseSignal();
  92. debug_usersighandler.fn        = fn;
  93. debug_usersighandler.reference    = reference;
  94. }
  95.  
  96.  
  97.  
  98. void    Debug_ReleaseSignal( void)
  99. {
  100. debug_usersighandler.fn    = NULL;
  101. }
  102.