Olivier SANNIER wrote:
Does any of you have any suggestion as to explain this behavior, and best of
all, how to fix it?
I went further and changed the code this so that I can get better details as to where the exception is coming from:

program test;

uses
  sysutils,
  classes;

function GetMXCSR: Cardinal;
asm
  stmxcsr Result
end;

var
  PreviousExceptProc: TExceptProc;
  PreviousErrorProc: TErrorProc;

procedure MyExceptProc(Obj: TObject; Addr: Pointer; FrameCount: LongInt; Frame: PPointer);
begin
  WriteLn('MyExceptProc: ' + IntToHex(GetMXCSR, 2));
  WriteLn(Obj.ClassName);
  PreviousExceptProc(Obj, Addr, FrameCount, Frame);
end;

Procedure MyErrorProc(ErrNo : Longint; Address,Frame : Pointer);
begin
  WriteLn('MyErrorProc: ' + IntToHex(GetMXCSR, 2));
  WriteLn(ErrNo);
  PreviousErrorProc(ErrNo, Address, Frame);
end;

procedure MyTestExcept;
var
  Tmp: Double;
begin
  Tmp := 0.0;
  Tmp := 5.0 / Tmp;
end;

begin
  PreviousExceptProc := ExceptProc;
  ExceptProc := MyExceptProc;
  PreviousErrorProc := ErrorProc;
  ErrorProc := MyErrorProc;

  MyTestExcept;
end.

I compiled it in both x86 and x64 and then ran it. Here are the results:

============================== x86 ========================================
MyErrorProc: 1900
217
MyExceptProc: 1900
EControlC
An unhandled exception occurred at $004017CE :
EControlC : Control-C hit
  $004017CE  MYTESTEXCEPT,  line 64 of test.dpr
  $00401815  main,  line 76 of test.dpr

============================== x64 ========================================
MyErrorProc: 1900
200
MyExceptProc: 1900
EDivByZero
An unhandled exception occurred at $000000000040189B :
EDivByZero : Division by zero
  $000000000040189B  MYTESTEXCEPT,  line 64 of test.dpr
  $00000000004018FA  main,  line 76 of test.dpr

So clearly, there is an issue in the x86 build because the ErrorProc has the wrong runtime error code. Strangely enough, the MXCSR has none of its exception flags set, so it seems they are reset before ErrorProc is called

I would very much appreciate any help in solving this issue.

Regards
Olivier
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to