catch.pas 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 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. {$ifdef DEBUG}
  25. {$define NOCATCH}
  26. {$endif DEBUG}
  27. interface
  28. uses
  29. {$ifdef linux}
  30. {$define has_signal}
  31. linux,
  32. {$endif}
  33. {$ifdef go32v2}
  34. {$define has_signal}
  35. dpmiexcp,
  36. {$endif}
  37. verbose;
  38. {$ifdef has_signal}
  39. Var
  40. NewSignal,OldSigSegm,
  41. OldSigInt,OldSigFPE : SignalHandler;
  42. {$endif}
  43. Const in_const_evaluation : boolean = false;
  44. Implementation
  45. {$ifdef has_signal}
  46. {$ifdef linux}
  47. Procedure CatchSignal(Sig : Integer);cdecl;
  48. {$else}
  49. Function CatchSignal(Sig : longint):longint;
  50. {$endif}
  51. begin
  52. case Sig of
  53. SIGSEGV : begin
  54. { Temporary message - until we get an error number... }
  55. writeln ('Panic : Internal compiler error, exiting.');
  56. internalerror(9999);
  57. end;
  58. SIGFPE : begin
  59. If in_const_evaluation then
  60. Writeln('FPE error computing constant expression')
  61. else
  62. Writeln('FPE error inside compiler');
  63. Stop;
  64. end;
  65. SIGINT : begin
  66. WriteLn('Ctrl-C Signaled!');
  67. Stop;
  68. end;
  69. end;
  70. {$ifndef linux}
  71. CatchSignal:=0;
  72. {$endif}
  73. end;
  74. {$endif def has_signal}
  75. begin
  76. {$ifndef nocatch}
  77. {$ifdef has_signal}
  78. {$ifndef TP}
  79. NewSignal:=SignalHandler(@CatchSignal);
  80. {$else TP}
  81. NewSignal:=SignalHandler(CatchSignal);
  82. {$endif TP}
  83. OldSigSegm:=Signal (SIGSEGV,NewSignal);
  84. OldSigInt:=Signal (SIGINT,NewSignal);
  85. OldSigFPE:=Signal (SIGFPE,NewSignal);
  86. {$endif}
  87. {$endif nocatch}
  88. end.
  89. {
  90. $Log$
  91. Revision 1.13 2000-03-20 09:37:51 florian
  92. * catching of exceptions is switched off on all targets if the define
  93. DEBUG is used
  94. Revision 1.12 2000/02/18 12:34:43 pierre
  95. DEBUG implies NOCATCH for go32v2
  96. Revision 1.11 2000/02/09 13:22:45 peter
  97. * log truncated
  98. Revision 1.10 2000/01/07 01:14:20 peter
  99. * updated copyright to 2000
  100. Revision 1.9 1999/08/25 16:41:04 peter
  101. * resources are working again
  102. Revision 1.8 1999/08/10 12:27:15 pierre
  103. * not stack check inside catch !!
  104. }