catch.pas 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. {$i defines.inc}
  21. {$ifdef go32v2}
  22. { go32v2 stack check goes nuts if ss is not the data selector (PM) }
  23. {$S-}
  24. {$endif}
  25. {$ifdef DEBUG}
  26. {$define NOCATCH}
  27. {$endif DEBUG}
  28. interface
  29. uses
  30. {$ifdef linux}
  31. {$define has_signal}
  32. linux,
  33. {$endif}
  34. {$ifdef go32v2}
  35. {$define has_signal}
  36. dpmiexcp,
  37. {$endif}
  38. verbose;
  39. {$ifdef has_signal}
  40. Var
  41. NewSignal,OldSigSegm,
  42. OldSigInt,OldSigFPE : SignalHandler;
  43. {$endif}
  44. Const in_const_evaluation : boolean = false;
  45. Implementation
  46. {$ifdef has_signal}
  47. {$ifdef linux}
  48. Procedure CatchSignal(Sig : SmallInt);cdecl;
  49. {$else}
  50. Function CatchSignal(Sig : longint):longint;
  51. {$endif}
  52. begin
  53. case Sig of
  54. SIGSEGV : begin
  55. { Temporary message - until we get an error number... }
  56. writeln ('Panic : Internal compiler error, exiting.');
  57. internalerror(9999);
  58. end;
  59. SIGFPE : begin
  60. If in_const_evaluation then
  61. Writeln('FPE error computing constant expression')
  62. else
  63. Writeln('FPE error inside compiler');
  64. Stop;
  65. end;
  66. SIGINT : begin
  67. WriteLn('Ctrl-C Signaled!');
  68. Stop;
  69. end;
  70. end;
  71. {$ifndef linux}
  72. CatchSignal:=0;
  73. {$endif}
  74. end;
  75. {$endif def has_signal}
  76. begin
  77. {$ifndef nocatch}
  78. {$ifdef has_signal}
  79. NewSignal:=SignalHandler({$ifdef fpcprocvar}@{$endif}CatchSignal);
  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.4 2000-09-24 15:06:11 peter
  89. * use defines.inc
  90. Revision 1.3 2000/09/10 20:26:55 peter
  91. * bsd patches from marco
  92. Revision 1.2 2000/07/13 11:32:32 michael
  93. + removed logs
  94. }