catch.pas 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. {
  2. $Id$
  3. Copyright (c) 1997-98 by Michael Van Canneyt
  4. Unit to catch segmentation faults and Ctrl-C and exit gracefully
  5. under linux and go32v2
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. *********************************************************************
  18. }
  19. Unit catch;
  20. {$ifdef go32v2}
  21. { go32v2 stack check goes nuts if ss is not the data selector (PM) }
  22. {$S-}
  23. {$endif}
  24. interface
  25. uses
  26. {$ifdef linux}
  27. {$define has_signal}
  28. linux,
  29. {$endif}
  30. {$ifdef go32v2}
  31. {$define has_signal}
  32. dpmiexcp,
  33. {$endif}
  34. verbose;
  35. {$ifdef has_signal}
  36. Var
  37. NewSignal,OldSigSegm,
  38. OldSigInt,OldSigFPE : SignalHandler;
  39. {$endif}
  40. Const in_const_evaluation : boolean = false;
  41. Implementation
  42. {$ifdef has_signal}
  43. {$ifdef linux}
  44. Procedure CatchSignal(Sig : Integer);cdecl;
  45. {$else}
  46. Function CatchSignal(Sig : longint):longint;
  47. {$endif}
  48. begin
  49. case Sig of
  50. SIGSEGV : begin
  51. { Temporary message - until we get an error number... }
  52. writeln ('Panic : Internal compiler error, exiting.');
  53. internalerror(9999);
  54. end;
  55. SIGFPE : begin
  56. If in_const_evaluation then
  57. Writeln('FPE error computing constant expression')
  58. else
  59. Writeln('FPE error inside compiler');
  60. Stop;
  61. end;
  62. SIGINT : begin
  63. WriteLn('Ctrl-C Signaled!');
  64. Stop;
  65. end;
  66. end;
  67. {$ifndef linux}
  68. CatchSignal:=0;
  69. {$endif}
  70. end;
  71. {$endif def has_signal}
  72. begin
  73. {$ifndef nocatch}
  74. {$ifdef has_signal}
  75. {$ifndef TP}
  76. NewSignal:=SignalHandler(@CatchSignal);
  77. {$else TP}
  78. NewSignal:=SignalHandler(CatchSignal);
  79. {$endif TP}
  80. OldSigSegm:=Signal (SIGSEGV,NewSignal);
  81. OldSigInt:=Signal (SIGINT,NewSignal);
  82. OldSigFPE:=Signal (SIGFPE,NewSignal);
  83. {$endif}
  84. {$endif nocatch}
  85. end.
  86. {
  87. $Log$
  88. Revision 1.9 1999-08-25 16:41:04 peter
  89. * resources are working again
  90. Revision 1.8 1999/08/10 12:27:15 pierre
  91. * not stack check inside catch !!
  92. Revision 1.7 1999/07/05 12:13:22 florian
  93. * property reading from PPU fixed (new PPU format), it uses now writesym...
  94. Revision 1.6 1999/06/02 22:44:05 pierre
  95. * previous wrong log corrected
  96. Revision 1.5 1999/06/02 22:25:28 pierre
  97. * added SIGFPE
  98. Revision 1.4 1999/01/28 19:42:03 peter
  99. * mssing endif added
  100. Revision 1.3 1999/01/27 13:20:37 pierre
  101. * slightly rewritten code
  102. Revision 1.2 1998/09/08 13:01:09 michael
  103. Adapted to changed Signal call
  104. Revision 1.1.1.1 1998/03/25 11:18:12 root
  105. * Restored version
  106. Revision 1.5 1998/03/10 01:17:15 peter
  107. * all files have the same header
  108. * messages are fully implemented, EXTDEBUG uses Comment()
  109. + AG... files for the Assembler generation
  110. Revision 1.4 1998/03/02 01:48:07 peter
  111. * renamed target_DOS to target_GO32V1
  112. + new verbose system, merged old errors and verbose units into one new
  113. verbose.pas, so errors.pas is obsolete
  114. Revision 1.3 1998/02/13 10:34:37 daniel
  115. * Made Motorola version compilable.
  116. * Fixed optimizer
  117. Revision 1.2 1998/01/27 23:34:35 peter
  118. + SIGINT capture with exit. It works for linux and go32v2 (last one
  119. not 100% yet)
  120. Revision 1.1.1.1 1997/11/27 08:32:51 michael
  121. FPC Compiler CVS start
  122. }