fpcatch.pas 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. Unit fpcatch;
  13. interface
  14. {$i globdir.inc}
  15. {$ifdef Unix}
  16. uses
  17. linux;
  18. {$endif}
  19. {$ifdef go32v2}
  20. uses
  21. dpmiexcp;
  22. {$endif}
  23. {$ifdef win32}
  24. uses
  25. signals;
  26. {$endif}
  27. {$ifdef HasSignal}
  28. Var
  29. NewSignal,OldSigSegm,OldSigILL,
  30. OldSigInt,OldSigFPE : SignalHandler;
  31. {$endif}
  32. Const
  33. CtrlCPressed : Boolean = false;
  34. Implementation
  35. uses
  36. {$ifdef FPC}
  37. keyboard,
  38. drivers,
  39. {$endif FPC}
  40. app,commands,msgbox,
  41. FPString,FPCompil,FPIDE;
  42. {$ifdef HasSignal}
  43. {$ifdef Unix}
  44. Procedure CatchSignal(Sig : Integer);cdecl;
  45. {$else}
  46. Function CatchSignal(Sig : longint):longint;
  47. {$endif}
  48. var MustQuit: boolean;
  49. begin
  50. case Sig of
  51. SIGSEGV : begin
  52. if StopJmpValid then
  53. LongJmp(StopJmp,SIGSEGV);
  54. if Assigned(Application) then IDEApp.Done;
  55. Writeln('Internal SIGSEGV Error caught');
  56. {$ifndef DEBUG}
  57. Halt;
  58. {$else DEBUG}
  59. RunError(216);
  60. {$endif DEBUG}
  61. end;
  62. SIGFPE : begin
  63. if StopJmpValid then
  64. LongJmp(StopJmp,SIGFPE);
  65. if Assigned(Application) then IDEApp.Done;
  66. Writeln('Internal SIGFPE Error caught');
  67. {$ifndef DEBUG}
  68. Halt;
  69. {$else DEBUG}
  70. RunError(207);
  71. {$endif DEBUG}
  72. end;
  73. SIGILL : begin
  74. if StopJmpValid then
  75. LongJmp(StopJmp,SIGILL);
  76. if Assigned(Application) then IDEApp.Done;
  77. Writeln('Internal SIGILL Error caught');
  78. {$ifndef DEBUG}
  79. Halt;
  80. {$else DEBUG}
  81. RunError(216);
  82. {$endif DEBUG}
  83. end;
  84. SIGINT : begin
  85. if StopJmpValid then
  86. LongJmp(StopJmp,SIGINT);
  87. IF NOT CtrlCPressed and Assigned(Application) then
  88. begin
  89. MustQuit:=false;
  90. {$ifdef FPC}
  91. CtrlCPressed:=true;
  92. Keyboard.PutKeyEvent((kbCtrl shl 16) or kbCtrlC);
  93. {$endif FPC}
  94. end
  95. else
  96. begin
  97. if Assigned(Application) then
  98. MustQuit:=MessageBox(#3+msg_QuitConfirm,nil,mferror+mfyesbutton+mfnobutton)=cmYes
  99. else
  100. MustQuit:=true;
  101. end;
  102. if MustQuit then
  103. begin
  104. if Assigned(Application) then IDEApp.Done;
  105. {$ifndef DEBUG}
  106. Halt;
  107. {$else DEBUG}
  108. RunError(216);
  109. {$endif DEBUG}
  110. end;
  111. end;
  112. end;
  113. {$ifndef Unix}
  114. CatchSignal:=0;
  115. {$endif}
  116. end;
  117. {$endif def HasSignal}
  118. begin
  119. {$ifdef HasSignal}
  120. {$ifndef TP}
  121. NewSignal:=SignalHandler(@CatchSignal);
  122. {$else TP}
  123. NewSignal:=SignalHandler(CatchSignal);
  124. {$endif TP}
  125. OldSigSegm:=Signal (SIGSEGV,NewSignal);
  126. OldSigInt:=Signal (SIGINT,NewSignal);
  127. OldSigFPE:=Signal (SIGFPE,NewSignal);
  128. OldSigILL:=Signal (SIGILL,NewSignal);
  129. {$endif}
  130. end.
  131. {
  132. $Log$
  133. Revision 1.3 2000-11-15 00:14:10 pierre
  134. new merge
  135. Revision 1.1.2.2 2000/11/14 09:23:55 marco
  136. * Second batch
  137. Revision 1.2 2000/10/31 22:35:54 pierre
  138. * New big merge from fixes branch
  139. Revision 1.1.2.1 2000/10/31 07:52:55 pierre
  140. * recover gracefully if compiler generates a signal
  141. Revision 1.1 2000/07/13 09:48:34 michael
  142. + Initial import
  143. Revision 1.6 2000/06/22 09:07:11 pierre
  144. * Gabor changes: see fixes.txt
  145. Revision 1.5 2000/05/02 08:42:26 pierre
  146. * new set of Gabor changes: see fixes.txt
  147. Revision 1.4 2000/03/07 21:09:20 pierre
  148. * Use globdir.inc HasSignal conditional
  149. + Uses PutKeyEvent for CtrlC
  150. Revision 1.3 1999/12/20 14:23:16 pierre
  151. * MyApp renamed IDEApp
  152. * TDebugController.ResetDebuggerRows added to
  153. get resetting of debugger rows
  154. Revision 1.2 1999/04/07 21:55:42 peter
  155. + object support for browser
  156. * html help fixes
  157. * more desktop saving things
  158. * NODEBUG directive to exclude debugger
  159. Revision 1.1 1999/02/20 15:18:28 peter
  160. + ctrl-c capture with confirm dialog
  161. + ascii table in the tools menu
  162. + heapviewer
  163. * empty file fixed
  164. * fixed callback routines in fpdebug to have far for tp7
  165. }