catch.pas 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 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 watcom} // wiktor: pewnei nie potrzeba
  26. {$S-}
  27. {$endif}
  28. {$ifdef DEBUG}
  29. {$define NOCATCH}
  30. {$endif DEBUG}
  31. interface
  32. uses
  33. {$ifdef unix}
  34. {$ifndef beos}
  35. {$define has_signal}
  36. {$ifdef ver1_0}
  37. Linux,
  38. {$else}
  39. BaseUnix,Unix,
  40. {$endif}
  41. {$endif}
  42. {$endif}
  43. {$ifdef go32v2}
  44. {$define has_signal}
  45. dpmiexcp,
  46. {$endif}
  47. {$ifdef watcom}
  48. {$define has_signal}
  49. dpmiexcp,
  50. {$endif}
  51. verbose;
  52. {$ifdef has_signal}
  53. Var
  54. NewSignal,OldSigSegm,
  55. OldSigInt,OldSigFPE : SignalHandler;
  56. {$endif}
  57. Const in_const_evaluation : boolean = false;
  58. Implementation
  59. {$ifdef has_signal}
  60. {$ifdef unix}
  61. Procedure CatchSignal(Sig : Longint);cdecl;
  62. {$else}
  63. Function CatchSignal(Sig : longint):longint;
  64. {$endif}
  65. begin
  66. case Sig of
  67. SIGSEGV : begin
  68. { Temporary message - until we get an error number... }
  69. writeln ('Panic : Internal compiler error, exiting.');
  70. internalerror(9999);
  71. end;
  72. SIGFPE : begin
  73. If in_const_evaluation then
  74. Writeln('FPE error computing constant expression')
  75. else
  76. Writeln('FPE error inside compiler');
  77. Stop;
  78. end;
  79. SIGINT : begin
  80. WriteLn('Ctrl-C Signaled!');
  81. Stop;
  82. end;
  83. end;
  84. {$ifndef unix}
  85. CatchSignal:=0;
  86. {$endif}
  87. end;
  88. {$endif def has_signal}
  89. begin
  90. {$ifndef nocatch}
  91. {$ifdef has_signal}
  92. NewSignal:=SignalHandler({$ifdef fpcprocvar}@{$endif}CatchSignal);
  93. {$ifndef sunos}
  94. OldSigSegm:={$ifdef VER1_0}Signal{$else}{$ifdef Unix}fpSignal{$else}Signal{$endif}{$endif} (SIGSEGV,NewSignal);
  95. {$endif} // lxrun on solaris hooks this for handling linux-calls!
  96. OldSigInt:={$ifdef VER1_0}Signal{$else}{$ifdef Unix}fpSignal{$else}Signal{$endif}{$endif} (SIGINT,NewSignal);
  97. OldSigFPE:={$ifdef VER1_0}Signal{$else}{$ifdef Unix}fpSignal{$else}Signal{$endif}{$endif} (SIGFPE,NewSignal);
  98. {$endif}
  99. {$endif nocatch}
  100. end.
  101. {
  102. $Log$
  103. Revision 1.16 2003-09-18 08:50:48 marco
  104. * fix for snapshot building.
  105. Revision 1.15 2003/09/14 20:26:18 marco
  106. * Unix reform
  107. Revision 1.14 2003/09/05 17:41:12 florian
  108. * merged Wiktor's Watcom patches in 1.1
  109. Revision 1.13 2003/04/23 10:10:31 peter
  110. * unix signalhandler has longint argument
  111. Revision 1.12 2003/01/10 21:37:48 marco
  112. * beos shouldnt define hassignal (unix<-> hasunix problem)
  113. Revision 1.11 2002/05/18 13:34:05 peter
  114. * readded missing revisions
  115. Revision 1.10 2002/05/16 19:46:35 carl
  116. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  117. + try to fix temp allocation (still in ifdef)
  118. + generic constructor calls
  119. + start of tassembler / tmodulebase class cleanup
  120. }