catch.pas 3.1 KB

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