catch.pas 3.1 KB

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