catch.pas 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 fpcdefs.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 unix}
  31. {$define has_signal}
  32. {$ifdef ver1_0}
  33. Linux,
  34. {$else}
  35. Unix,
  36. {$endif}
  37. {$endif}
  38. {$ifdef go32v2}
  39. {$define has_signal}
  40. dpmiexcp,
  41. {$endif}
  42. verbose;
  43. {$ifdef has_signal}
  44. Var
  45. NewSignal,OldSigSegm,
  46. OldSigInt,OldSigFPE : SignalHandler;
  47. {$endif}
  48. Const in_const_evaluation : boolean = false;
  49. Implementation
  50. {$ifdef has_signal}
  51. {$ifdef unix}
  52. Procedure CatchSignal(Sig : SmallInt);cdecl;
  53. {$else}
  54. Function CatchSignal(Sig : longint):longint;
  55. {$endif}
  56. begin
  57. case Sig of
  58. SIGSEGV : begin
  59. { Temporary message - until we get an error number... }
  60. writeln ('Panic : Internal compiler error, exiting.');
  61. internalerror(9999);
  62. end;
  63. SIGFPE : begin
  64. If in_const_evaluation then
  65. Writeln('FPE error computing constant expression')
  66. else
  67. Writeln('FPE error inside compiler');
  68. Stop;
  69. end;
  70. SIGINT : begin
  71. WriteLn('Ctrl-C Signaled!');
  72. Stop;
  73. end;
  74. end;
  75. {$ifndef unix}
  76. CatchSignal:=0;
  77. {$endif}
  78. end;
  79. {$endif def has_signal}
  80. begin
  81. {$ifndef nocatch}
  82. {$ifdef has_signal}
  83. NewSignal:=SignalHandler({$ifdef fpcprocvar}@{$endif}CatchSignal);
  84. {$ifndef sunos}
  85. OldSigSegm:=Signal (SIGSEGV,NewSignal);
  86. {$endif} // lxrun on solaris hooks this for handling linux-calls!
  87. OldSigInt:=Signal (SIGINT,NewSignal);
  88. OldSigFPE:=Signal (SIGFPE,NewSignal);
  89. {$endif}
  90. {$endif nocatch}
  91. end.
  92. {
  93. $Log$
  94. Revision 1.10 2002-05-16 19:46:35 carl
  95. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  96. + try to fix temp allocation (still in ifdef)
  97. + generic constructor calls
  98. + start of tassembler / tmodulebase class cleanup
  99. Revision 1.8 2001/02/26 19:44:52 peter
  100. * merged generic m68k updates from fixes branch
  101. Revision 1.7 2001/02/05 20:47:00 peter
  102. * support linux unit for ver1_0 compilers
  103. Revision 1.6 2001/01/21 20:32:45 marco
  104. * Renamefest. Compiler part. Not that hard.
  105. Revision 1.5 2000/11/13 15:26:12 marco
  106. * Renamefest
  107. Revision 1.4 2000/09/24 15:06:11 peter
  108. * use defines.inc
  109. Revision 1.3 2000/09/10 20:26:55 peter
  110. * bsd patches from marco
  111. Revision 1.2 2000/07/13 11:32:32 michael
  112. + removed logs
  113. }