catch.pas 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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.3 2000-09-10 20:26:55 peter
  92. * bsd patches from marco
  93. Revision 1.2 2000/07/13 11:32:32 michael
  94. + removed logs
  95. }