home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / gnu / gplibs07 / xeh_sunl.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-24  |  1.9 KB  |  79 lines

  1. // I nominate this to be the Spring libg++ exception handling code.
  2. // 
  3. // Note that it contains Sparc dependent machine code for the log.
  4. // 
  5. //                                                    - Graham
  6.  
  7.  
  8. typedef int jmp_buf[9];
  9.  
  10. struct
  11. ExceptionHandler
  12. {
  13.   ExceptionHandler *prev;
  14.   jmp_buf handler;
  15.   void *name;
  16.   void *parameters;
  17.   ExceptionHandler ();
  18.   ExceptionHandler (int x, int y, int z);
  19.   ~ExceptionHandler ();
  20. };
  21.  
  22. #include <stdio.h>
  23. #undef _X_H
  24. #pragma implementation "x.h"
  25. #include "/tools/cygnus/test-os/interfaces/util/x.h"
  26.  
  27. extern "C" void exit (int);
  28.  
  29. ExceptionHandler EHS (1,2,3);
  30.  
  31. ExceptionHandler::ExceptionHandler (int x, int y, int z)
  32. {
  33.     exceptionHandlerStack = &EHS;
  34.     if (setjmp (EHS.handler)) {
  35.         printf ("*** Unhandled exception ***\n");
  36.         exit (22);
  37.     }
  38. }
  39.  
  40. extern "C" void __unhandled_exception (const char*, int);
  41. extern "C" void __raise_exception (void **, void *);
  42.  
  43. // The history of raises is mainatined as acourtesy to our users.
  44. // It is only approximately true - we don't lock on updates.
  45. int raises_pcs[32];
  46. void *raises_exceptions[32];
  47. int raises_index;
  48.  
  49. void
  50. __unhandled_exception(const char *filename, int lineno) {
  51.     printf ("unhandled exception caught in file `%s' at line %d\n",filename, lineno);
  52.     printf ("Recent raises : \n");
  53.     int index = raises_index;
  54.     for (int i = 0 ; i < 6 ; i++) {
  55.         index = (index-1) & 31;
  56.         if (raises_pcs[index] == 0) {
  57.             break;
  58.         }
  59.         printf ("    raising pc = 0x%X, exception = 0x%X\n", raises_pcs[index], raises_exceptions[index]);
  60.     }
  61.     printf ("     ......\n");
  62.     printf ("*** Unhandled exception ***\n");
  63.     exit(22);
  64. }
  65.  
  66.  
  67. void
  68. __raise_exception (void **addr, void *id)
  69. {
  70.     // Log the exception
  71.     register int ____return_pc asm ("%i7");
  72.     raises_pcs[raises_index] = ____return_pc;
  73.     raises_exceptions[raises_index] = id;
  74.     raises_index = (raises_index + 1) & 31;
  75.  
  76.     // Do the real work:
  77.     *addr = id;
  78. }
  79.