Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2010-12

Firebird 2.5 embedded bug? Debugging skills needed

2 messages · 1 person · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Jim

(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).
Tried a later 2.5.1 snapshot, didn't work either.
It does work with a separate regular Firebird 2.x 64 bit server. It also works as a 32 bit program with Firebird 2.5 embedded 32 bit Windows.

Thanks to Firebird's Vlad Khorsun, Martin Schreiber and FreePascal's Marco van de Voort, FreePascal has implemented a patch that got rid of one error.

However, my test program still does not run correctly. It tries deliberately running SQL that will fail, e.g. inserting data in a non-existing table, inserting duplicate values in a column with unique constraints, triggering a... trigger that raises a custom Firebird exception.
All these cases seem to lead to access violations (or other errors) in the Firebird code.

As my debugging skills are weak at best, could a kind soul extract the zip (includes all dlls and database) in
https://bitbucket-assetroot.s3.amazonaws.com/jb/flocate/20101220/6/fbembedtest64_20December.zip run fbservertest.exe using a debugger, generally work your spells and tell me if I should go back to the FreePascal team or if this error seems to be in Firebird itself (or my test code).

For comparison, a comparable exe/source code in 32 bit windows can be found here:
https://bitbucket-assetroot.s3.amazonaws.com/jb/flocate/20100616/5/fbembedtest16June_15.10.zip

FreePascal bug report: http://mantis.freepascal.org/view.php?id=17360 Sample program run for 32 bit and 64 bit: see below:

If you need additional info, please let me know.

Finally, could someone tell me how I can run Windows x64 embedded using the 3.0 snapshots? Simply renaming fbclient.dll to fbembedded.dll didn't seem to work...

Thanks,

Regards, jb Program run on 32 bit (works) and 64 bit (doesn't work). Note the 64 bit program has grown some more tests. D:\Cop\embed32>fbembedtest.exe Debug: 20-12-2010 18:07:51: Starting database setup: Debug: 20-12-2010 18:07:51: SetUp: Connecting to database: Debug: 20-12-2010 18:07:51: DB/Setup/Going to start transaction. Debug: 20-12-2010 18:07:51: Getting query =============================================================== fbembedtest: information. Test program for firebird 2.1 embedded database and custom stored procedures. Please see fbembedtest_readme.TXT for details on setting up database etc. Freeware but no warranties, express or implied. For full copyright and license, please see the source code. =============================================================== Debug: 20-12-2010 18:07:51: Application started. *** First, clear any existing numbers out of database: Debug: 20-12-2010 18:07:51: ClearData: going to run query DELETE FROM NUMBERS; *** Insert number 5. This should work: Debug: 20-12-2010 18:07:51: SaveNumber: going to add parameters for insert query Debug: 20-12-2010 18:07:51: SaveNumber: insert query code done. *** Insert number 5 again. This shold fail because of the unique index. *** We should get a generic database error. Debug: 20-12-2010 18:07:51: SaveNumber: going to add parameters for insert query Debug: 20-12-2010 18:07:51: Database error running insert query. Database error message: : Execute : -violation of PRIMARY or UNIQUE KEY constraint "NUMBERUNIQUE" on table "NUMBERS "; Database error code: 335544665 Debug: 20-12-2010 18:07:51: Parameters were: BINGONUMBER: *5* Debug: 20-12-2010 18:07:51: Rolling back transaction. Debug: 20-12-2010 18:07:51: SaveNumber: insert query code done. *** Now test our custom Firebird exception by trying to insert 13: Debug: 20-12-2010 18:07:51: SaveNumber: going to add parameters for insert query Debug: 20-12-2010 18:07:51: Database error running insert query. Database error message: : Execute : -exception 1 -EXCNOT13 -No, not 13, I can't handle that! -At trigger 'TRIGCHECK13' line: 7, col: 28; Database error code: 335544517 Debug: 20-12-2010 18:07:51: Parameters were: BINGONUMBER: *13* Debug: 20-12-2010 18:07:51: Rolling back transaction. Debug: 20-12-2010 18:07:51: SaveNumber: insert query code done. *** Ok, done. Let's close down the connection Debug: 20-12-2010 18:07:51: Application finished. Debug: 20-12-2010 18:07:51: DB/Destroy/Going to commit active transaction. Debug: 20-12-2010 18:07:51: Disconnecting from database/running FreeAll Heap dump by heaptrc unit 569 memory blocks allocated : 24092/25824 569 memory blocks freed : 24092/25824 0 unfreed memory blocks : 0 True heap size : 196608 (96 used in System startup) True free heap : 196512 64 bit test doesn't work correctly: D:\Cop\embed64>fbembedtest.exe Debug: 20-12-2010 18:11:17: Starting database setup: Debug: 20-12-2010 18:11:17: SetUp: Connecting to database: Debug: 20-12-2010 18:11:17: DB/Setup/Going to start transaction. Debug: 20-12-2010 18:11:17: Getting query =============================================================== fbembedtest: information. Test program for firebird 2.x embedded database and custom stored procedures. Please see fbembedtest_readme.TXT for details on setting up database etc. Freeware but no warranties, express or implied. For full copyright and license, please see the source code. =============================================================== Debug: 20-12-2010 18:11:17: Application started. *** First, clear any existing numbers out of database: Debug: 20-12-2010 18:11:17: ClearData: going to run query DELETE FROM NUMBERS; Debug: 20-12-2010 18:11:17: ClearData: query code done. *** Executing an insert query with the wrong table, should give a db error: Debug: 20-12-2010 18:11:17: RunSQL: going to run query INSERT INTO THISTABLEDOES NTEXIST (BINGONUMBER) VALUES (91) Debug: 20-12-2010 18:11:17: RunSQL: exception running delete query. Exception me ssage: Control-C hitException type: EControlC *** Executing a simple insert query without parameters: Debug: 20-12-2010 18:11:17: RunSQL: going to run query INSERT INTO NUMBERS (BING ONUMBER) VALUES (91); Debug: 20-12-2010 18:11:17: RunSQL: query code done. *** Executing a simple insert query without parameters for the same value. This should fail: Debug: 20-12-2010 18:11:17: RunSQL: going to run query INSERT INTO NUMBERS (BING ONUMBER) VALUES (91); Debug: 20-12-2010 18:11:17: RunSQL: exception running delete query. Exception me ssage: Control-C hitException type: EControlC *** Executing a simple delete query without parameters: Debug: 20-12-2010 18:11:17: RunSQL: going to run query DELETE FROM NUMBERS WHERE BINGONUMBER=91; Debug: 20-12-2010 18:11:17: RunSQL: exception running delete query. Exception me ssage: Access violationException type: EAccessViolation *** Insert number 5. This should work: Debug: 20-12-2010 18:11:17: SaveNumber: going to add parameters for insert query Debug: 20-12-2010 18:11:17: SaveNumber: going to execute the insert query. Debug: 20-12-2010 18:11:17: SaveNumber: insert query code done. *** Insert number 5 again. This should fail because of the unique index. *** We should get a generic database error. Debug: 20-12-2010 18:11:17: SaveNumber: going to add parameters for insert query Debug: 20-12-2010 18:11:17: SaveNumber: going to execute the insert query. Debug: 20-12-2010 18:11:17: SaveNumber: non-database exception running query. Ex ception message: Access violationException type: EAccessViolation Debug: 20-12-2010 18:11:17: For reference, the parameters were: BINGONUMBER: *5* Debug: 20-12-2010 18:11:17: SaveNumber: insert query code done. *** Now test our custom Firebird exception by trying to insert 13: Debug: 20-12-2010 18:11:17: SaveNumber: going to add parameters for insert query Debug: 20-12-2010 18:11:17: SaveNumber: going to execute the insert query. Debug: 20-12-2010 18:11:17: SaveNumber: non-database exception running query. Ex ception message: Access violationException type: EAccessViolation Debug: 20-12-2010 18:11:17: For reference, the parameters were: BINGONUMBER: *13* Debug: 20-12-2010 18:11:17: SaveNumber: insert query code done. *** Ok, done. Let's close down the connection Debug: 20-12-2010 18:11:17: Application finished. Debug: 20-12-2010 18:11:17: Destroy: Going to commit active transaction. Debug: 20-12-2010 18:11:17: Destroy: Transaction committed. Debug: 20-12-2010 18:11:17: FreeAll: Disconnecting from database. Heap dump by heaptrc unit 689 memory blocks allocated : 45093/47256 689 memory blocks freed : 45093/47256 0 unfreed memory blocks : 0 True heap size : 196608 (160 used in System startup) True free heap : 196448

Reply by email

Jim
to Jim
Jim wrote 6 lines
(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:

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

Show quoted text 7 lines
Note, it used Vectored Exception Handling technique : 871 procedure install_exception_handlers; 872 begin 873
AddVectoredExceptionHandler(1,@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 :

Show quoted text 7 lines
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

Reply by email