catch.pas 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. {
  2. $Id$
  3. Copyright (c) 1997-98 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. { go32v2 stack check goes nuts if ss is not the data selector (PM) }
  21. {$S-}
  22. interface
  23. uses
  24. {$ifdef linux}
  25. {$define has_signal}
  26. linux,
  27. {$endif}
  28. {$ifdef go32v2}
  29. {$define has_signal}
  30. dpmiexcp,
  31. {$endif}
  32. verbose;
  33. {$ifdef has_signal}
  34. Var
  35. NewSignal,OldSigSegm,
  36. OldSigInt,OldSigFPE : SignalHandler;
  37. {$endif}
  38. Const in_const_evaluation : boolean = false;
  39. Implementation
  40. {$ifdef has_signal}
  41. {$ifdef linux}
  42. Procedure CatchSignal(Sig : Integer);cdecl;
  43. {$else}
  44. Function CatchSignal(Sig : longint):longint;
  45. {$endif}
  46. begin
  47. case Sig of
  48. SIGSEGV : begin
  49. { Temporary message - until we get an error number... }
  50. writeln ('Panic : Internal compiler error, exiting.');
  51. internalerror(9999);
  52. end;
  53. SIGFPE : begin
  54. If in_const_evaluation then
  55. Writeln('FPE error computing constant expression')
  56. else
  57. Writeln('FPE error inside compiler');
  58. Stop;
  59. end;
  60. SIGINT : begin
  61. WriteLn('Ctrl-C Signaled!');
  62. Stop;
  63. end;
  64. end;
  65. {$ifndef linux}
  66. CatchSignal:=0;
  67. {$endif}
  68. end;
  69. {$endif def has_signal}
  70. begin
  71. {$ifndef nocatch}
  72. {$ifdef has_signal}
  73. {$ifndef TP}
  74. NewSignal:=SignalHandler(@CatchSignal);
  75. {$else TP}
  76. NewSignal:=SignalHandler(CatchSignal);
  77. {$endif TP}
  78. OldSigSegm:=Signal (SIGSEGV,NewSignal);
  79. OldSigInt:=Signal (SIGINT,NewSignal);
  80. OldSigFPE:=Signal (SIGFPE,NewSignal);
  81. {$endif}
  82. {$endif nocatch}
  83. end.
  84. {
  85. $Log$
  86. Revision 1.8 1999-08-10 12:27:15 pierre
  87. * not stack check inside catch !!
  88. Revision 1.7 1999/07/05 12:13:22 florian
  89. * property reading from PPU fixed (new PPU format), it uses now writesym...
  90. Revision 1.6 1999/06/02 22:44:05 pierre
  91. * previous wrong log corrected
  92. Revision 1.5 1999/06/02 22:25:28 pierre
  93. * added SIGFPE
  94. Revision 1.4 1999/01/28 19:42:03 peter
  95. * mssing endif added
  96. Revision 1.3 1999/01/27 13:20:37 pierre
  97. * slightly rewritten code
  98. Revision 1.2 1998/09/08 13:01:09 michael
  99. Adapted to changed Signal call
  100. Revision 1.1.1.1 1998/03/25 11:18:12 root
  101. * Restored version
  102. Revision 1.5 1998/03/10 01:17:15 peter
  103. * all files have the same header
  104. * messages are fully implemented, EXTDEBUG uses Comment()
  105. + AG... files for the Assembler generation
  106. Revision 1.4 1998/03/02 01:48:07 peter
  107. * renamed target_DOS to target_GO32V1
  108. + new verbose system, merged old errors and verbose units into one new
  109. verbose.pas, so errors.pas is obsolete
  110. Revision 1.3 1998/02/13 10:34:37 daniel
  111. * Made Motorola version compilable.
  112. * Fixed optimizer
  113. Revision 1.2 1998/01/27 23:34:35 peter
  114. + SIGINT capture with exit. It works for linux and go32v2 (last one
  115. not 100% yet)
  116. Revision 1.1.1.1 1997/11/27 08:32:51 michael
  117. FPC Compiler CVS start
  118. }