[fpc-pascal] Re: Firebird 2.5 embedded bug? Debugging skills needed

Jim hakkie42 at gmail.com
Tue Dec 21 13:22:44 CET 2010


On 20-12-2010 18:23, Jim wrote:
> (Posted to Firebird-dev list, copied to freepascal list for info)
> 
> Hi all,
> 
> Recently I mentioned a problem running FreePascal 64 bit code with
> Firebird 2.5 embedded 64 bit on Windows (Vista).
<snip>
> All these cases seem to lead to access violations (or other errors) in
> the Firebird code.
> 
<snip>
On Firebird-devel, Vlad Khorsun replied. FYI the thread:
On 20-12-2010 21:47, Vlad Khorsun wrote:
>     Jim, all
>
>     I tried Jim's executable and run it under VC8 debugger in IDE.
Target was fbembed.dll
> and Jim's executable was used as host application. What is wondered me
is that while debugger
> was able to catch Firebird's internal exceptions, it never can
continue debugging at point
> when exception catched in code or re-throwed. This forced me to look
how exception
> handling implemented in FPC.
>
>     I'm not an expert in exception handling internals so below i could
be wrong.
>
>     The interesting code for Win64 is at
>
>
http://svn.freepascal.org/cgi-bin/viewvc.cgi/trunk/rtl/win64/system.pp?revision=16472&view=markup
>
>
>     Note, it used Vectored Exception Handling technique :
>
>   871   procedure install_exception_handlers;
>   872   begin
>   873
AddVectoredExceptionHandler(1, at syswin64_x86_64_exception_handler);
>   874   end;
>
>
> Exception handler (syswin64_x86_64_exception_handler) code is at few
lines above.
>
>     Note comment at line 837:
>
>   834               if ((excep^.ExceptionRecord^.ExceptionCode and
SEVERITY_ERROR) = SEVERITY_ERROR) then
>   835                 err := 217
>   836               else
>   837                 { pass through exceptions which aren't an error.
The problem is that vectored handlers
>   838                   always are called before structured ones so we
see also internal exceptions of libraries.
>   839                   I wonder if there is a better solution (FK)
>   840                 }
>
>     So, you see - FPC application handled exception *before* Firebird
library.
>
>     As i understand code, it handles MSVC's internal exceptions,
convert it into Pascal run-time error 217
> (Control-C) and exits with EXCEPTION_CONTINUE_EXECUTION. This gives no
chance for Firebird library
> to handle exception correctly. Also it explains messages about "Ctrl-C
hit" in Jim's application output.
>
>     I compared it with 32-bit code. Look at
>
>
http://svn.freepascal.org/cgi-bin/viewvc.cgi/trunk/rtl/win32/system.pp?revision=16472&view=markup
>
>     It used usual Frame-based Exception Handling technique and its
handler works for unhandled exceptions
> only, allowing Firebird library to catch and handle its internal
exceptions :
>
> 786 procedure install_exception_handlers;
> ...
> 801     SetUnhandledExceptionFilter(@syswin32_i386_exception_handler);
>
>
>     Should i add that Firebird handle all of its internal exceptions
by itself  ? :)
>
> Hope this helps,
> Vlad

Hi Vlad,

Thanks a million! So it is a FreePascal problem after all.

Now I also understand why using a server instead of embedded works: any
exceptions in Firebird get handled server-side, so can't be "stolen" by
the FreePascal code.

I'll update the FreePascal bugtracker with this info. Thanks!

-- 
Regards,

jb



More information about the fpc-pascal mailing list