Discussions related to Visual Prolog
mdosnov2016
VIP Member
Posts: 73
Joined: 19 Nov 2016 7:58

error: invalid handle

Unread post by mdosnov2016 »

Hi.
I get some error when I run my .exe from the command line:
----------------------------------------
Internal API function call failed

Predicate name = readFile
SourceCursor = pfc\windowsApi\fileSystem_api\fileSystem_api.pro(432,13)
userMessage = The handle is invalid.

ErrorDescription = The handle is invalid.

ErrorCode = 6
ErrorCodeHex = 00000006
API function name = readFile
ErrorDescription = The handle is invalid.

Handle = 00000198
nativeCallException (exception) in fileSystem_api::readFile

-----------------------------------------
pfc\exception\exception.pro(208)
C:\let\ccc\vp8\backend\Exe64\vipKernel.dll (0x1400939F)
C:\let\ccc\vp8\backend\Exe64\vipKernel.dll (0x14005BB6)
C:\let\ccc\vp8\backend\Exe64\vipKernel.dll (0x140096A6)
pfc\exception\exception.pro(281)
pfc\exception\exception.pro(402)
pfc\exception\exception.pro(277)
pfc\windowsapi\filesystem_api\filesystem_api.pro(433)
pfc\filesystem\inputstream_file.pro(356)
C:\let\ccc\vp8\backend\Exe64\backend.exe (0x00000001402E9690)
pfc\filesystem\inputstream_file.pro(343)
pfc\filesystem\inputstream_file.pro(338)
C:\let\ccc\vp8\backend\Exe64\backend.exe (0x00000001402E0022)
pfc\filesystem\file.pro(599)
C:\let\ccc\vp8\backend\Exe64\vipKernel.dll (0x14006DC0)
pfc\filesystem\file.pro(598)
C:\let\ccc\vp8\backend\Exe64\backend.exe (0x00000001403185E0)
pfc\5xvip\5xfile\file5x.pro(47)
C:\let\ccc\vp8\backend\Exe64\backend.exe (0x000000014030A608)
pfc\filesystem\file.pro(592)
backend.pack(40393)
backend.pack(39482)
backend.pack(40392)
backend.pack(39453)
backend.pack(39475)
backend.pack(40389)
backend.pack(39354)
C:\let\ccc\vp8\backend\Exe64\backend.exe (0x0000000100000000)
backend.pack(40388)
backend.pack(39368)
backend.pack(39435)
backend.pack(39438)
backend.pack(40388)
backend.pack(40407)
backend.pack(40409)
pfc\windowsapi\exe_api\exe_api.pro(57)
C:\let\ccc\vp8\backend\Exe64\vipKernel.dll (0x14006DC0)
pfc\windowsapi\exe_api\exe_api.pro(57)
C:\let\ccc\vp8\backend\Exe64\backend.exe (0x00000001402B9870)
C:\let\ccc\vp8\backend\Exe64\vipRun.dll (0x145091A8)
pfc\application\exe\mainexe.pro(18)
C:\let\ccc\vp8\backend\Exe64\vipKernel.dll (0x14006DC0)
OS: Windows 10.0 Build 15063
-----------------------------------------------------

It seems that it gets stuck at streamIO code of VP8.

Does anybody know how to deal with this error?
PrologUser
Harrison Pratt
VIP Member
Posts: 439
Joined: 5 Nov 2000 0:01

Unread post by Harrison Pratt »

I get some error when I run my .exe from the command line:
Is there another way to run your application, other than from the command line, that works OK for you?

Is the readFile function being back-tracked into after a failure somewhere further down in your code?

I would suggest putting your database consultation code in a very simple new project that does nothing but consult the database file. That way you can determine if the problem is in consultation or somewhere else.
mdosnov2016
VIP Member
Posts: 73
Joined: 19 Nov 2016 7:58

Unread post by mdosnov2016 »

This is part of my top-level code:
-----------------------------------------------------

generate_top() :-
file5x::writedevice(fileSelector::screen),
file5x::write(" backend HLS CCC optimization started, please wait..."),
file5x::existfile("ITF_FACT.DBA"),

...

run() :-
generate_top,
!
or
console::write("Main run failed!").
...

goal
console::runUtf8(backend::run),
!
or
console::write("Error").

-----------------------------------------

now my 64-bit debugger cannot go beyond the command:
file5x::writedevice(fileSelector::screen),
and it says that screen is not open.

From the console I get the errors that I 've shown you.

Michael
PrologUser
Harrison Pratt
VIP Member
Posts: 439
Joined: 5 Nov 2000 0:01

Unread post by Harrison Pratt »

I wonder if there's a problem with your installation of VP8. The code below works as expected in 7.5 and I can walk through it with the debugger.

Code: Select all

class predicates     generate_top : (). clauses     generate_top():-         file5x::writedevice(fileSelector::screen()),         file5x::write(" backend HLS CCC optimization started, please wait..."),         if file5x::existfile("ITF_FACT.DBA") then                 file5x::write( "Found it!")             else                 file5x::write( "Cannot find it.")         end if,         file5x::readln(_S),         file5x::write("\nBye"), !.     generate_top().
Have you tried just the code fragment above in VIP 7.5 or in a fresh new build of a test project? Both screen and screen() play nicely on 7.5. You might check that out on your system.
mdosnov2016
VIP Member
Posts: 73
Joined: 19 Nov 2016 7:58

Unread post by mdosnov2016 »

There must be some problem with the screen predicates.
I set up a brand new project and inserted my code. I get relocation problems.
Shall I segment the code into .cl and .pro files?
Does it matter that I have everything into backend.pack? But that is what I got from migration tool.

Michael
PrologUser
Harrison Pratt
VIP Member
Posts: 439
Joined: 5 Nov 2000 0:01

Unread post by Harrison Pratt »

I set up a brand new project and inserted my code. I get relocation problems.
What do the error messages say? We can't help without that information.
Shall I segment the code into .cl and .pro files?
Predicates that need access from another class must be declared in the .cl files. Predicates used only within a class can be declared inside the class's .pro file.
Does it matter that I have everything into backend.pack? But that is what I got from migration tool.
I look at the migration tool as "informative" but not definitive. I tried it on one of my projects and got headaches, just like some other VP users!

It should not matter how many files are in your backend.pack, but I suspect that your old code has some complex .pro files that would be better broken up into smaller classes in your backend.pack. That way you can have "code that works and I understand" in several small classes and you can isolate the problem code in an easier-to-understand smaller class.

In the project window, have you tried right-clicking on your package's folder > Analysis & Refactoring > Optimal Set of Include Directories ? Sometimes that is helpful. Select the Force checkbox and click Generate. Make sure you have a copy of your project, first.

Also, I have had success deleting the Deb and Obj directories and rebuilding the project when dealing with errors that make no sense--that rarely cures the problem, but it's safe and easy to try.
mdosnov2016
VIP Member
Posts: 73
Joined: 19 Nov 2016 7:58

Unread post by mdosnov2016 »

I 've done all that but no luck still the same cituation (and this is a brand new project, structured
exactly like VP8's projects).

I 've noticed that "resourceIdentifiers.i" is empty
and pfc\\resourceidentifiers.ph doesn't exist.

but correcting this didn't help at all either.
I am really confused.
Michael
PrologUser
mdosnov2016
VIP Member
Posts: 73
Joined: 19 Nov 2016 7:58

Unread post by mdosnov2016 »

this is the error I get when I run from console the .exe.

----------------------------------------
The file is not open

Predicate name = checkOutputSelector
SourceCursor = pfc\5xVIP\5xFile\file5x.pro(332,9)
symbolic name = screen
fileNotOpen (file5x_exception) in file5x::checkOutputSelector

----------------------------------------
pfc\exception\exception.pro(208)
C:\let\ccc\vp8\backend\Exe64\vipKernel.dll (0x1400939F)
C:\let\ccc\vp8\backend\Exe64\vipKernel.dll (0x140096A6)
pfc\5xvip\5xfile\file5x.pro(332)
pfc\5xvip\5xfile\file5x.pro(311)
backend.pack(40382)
backend.pack(40408)
PrologUser
mdosnov2016
VIP Member
Posts: 73
Joined: 19 Nov 2016 7:58

Unread post by mdosnov2016 »

Please ignore my previous message,
the errors I get from my newest project version are the following:
------------------------------------------------------------------------------




The handle is invalid.


----------------------------------------
Internal API function call failed

Predicate name = readFile
SourceCursor = pfc\windowsApi\fileSystem_api\fileSystem_api.pro(432,13)
userMessage = The handle is invalid.

ErrorDescription = The handle is invalid.

ErrorCode = 6
ErrorCodeHex = 00000006
API function name = readFile
ErrorDescription = The handle is invalid.

Handle = 00000190
nativeCallException (exception) in fileSystem_api::readFile
PrologUser
Harrison Pratt
VIP Member
Posts: 439
Joined: 5 Nov 2000 0:01

Unread post by Harrison Pratt »

If you navigate in the Project Window to the file pfc\windowsApi\fileSystem_api\fileSystem_api.pro( Line 432,Column 13) you can see the readFile clause where the error occurs.

From there you can put your cursor on readFile and press Ctl-Al-Shift-F to navigate to "upstream" clauses which call that predicate ... and so on until you get to your application code and see where you might be passing an invalid parameter.
User avatar
Thomas Linder Puls
VIP Member
Posts: 1398
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls »

You should either run your code in the debugger, or use the stack traces to locate the problems in your code.

You have not included the stack trace in the last exception so I will use the previous one as example.

What you do is to copy this text (you can include more before and after without problems) to the clipboard:
----------------------------------------
pfc\exception\exception.pro(208)
C:\let\ccc\vp8\backend\Exe64\vipKernel.dll (0x1400939F)
C:\let\ccc\vp8\backend\Exe64\vipKernel.dll (0x140096A6)
pfc\5xvip\5xfile\file5x.pro(332)
pfc\5xvip\5xfile\file5x.pro(311)
backend.pack(40382)
backend.pack(40408)
_________________
Then you go into the IDE and use Go to -> Go to Position on Clipboard Shift+F2.

As a result you will get a window like this one in the image below.

If you double-click the line I have highlighted you will get to this code:

Code: Select all

clauses     writedevice(outStream) :-         !.       writedevice(SymbolicFilename) :-         bound(SymbolicFilename),         checkOutputSelector(SymbolicFilename), <----------- HERE         outStream := SymbolicFilename.
That way you can traverse the call stack and see how you ended up in that part of the code.

Using the debugger is even more informative because that can also show the value of all you variables.

Anyway, invalid handle means that you are attempting a file operation (or some other "handle" based operation) with an "invalid handle". There are several reasons that a handle can be invalid, but the most obvious ones are:
  • The handle has never been opened, perhaps because the open operation failed.
  • The handle has been closed again before this operation.
  • It is not a handle at all but something else that has been falsely converted into a handle.
It is of course impossible for us to know which of these (or some other) reasons it is.
Attachments
Go to positions
Go to positions
Go To positions.png (16.69 KiB) Viewed 13247 times
Regards Thomas Linder Puls
PDC
User avatar
Thomas Linder Puls
VIP Member
Posts: 1398
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls »

Since your code is using the file5x::file5x "method", a possible reason for the invalid handle is that you have redirected the output to a file, closed the file and "forgot" to redirect the output back to the screen again. Or later again redirected it to the file without reopening the file (i.e. so that its redirected to a file that you have previously closed).
Regards Thomas Linder Puls
PDC
mdosnov2016
VIP Member
Posts: 73
Joined: 19 Nov 2016 7:58

Unread post by mdosnov2016 »

The system behaves in an unstable way.
The first time I run the exe from the console after build everything is going OK.
Also, when I run it from within the debugger is OK too.
Second and so on times from the console (cmd windows 10) it produces write_file
errors (invalid handle).
PrologUser
mdosnov2016
VIP Member
Posts: 73
Joined: 19 Nov 2016 7:58

Unread post by mdosnov2016 »

----------------------------------------
Internal API function call failed

Predicate name = writeFile
SourceCursor = pfc\windowsApi\fileSystem_api\fileSystem_api.pro(455,13)
userMessage = The handle is invalid.

ErrorDescription = The handle is invalid.

ErrorCode = 6
ErrorCodeHex = 00000006
API function name = writeFile
ErrorDescription = The handle is invalid.

Handle = 00000190
nativeCallException (exception) in fileSystem_api::writeFile

----------------------------------------
PrologUser
User avatar
Thomas Linder Puls
VIP Member
Posts: 1398
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls »

And there is no stack trace? Or didn't you include it?

If it is there did you then try to use shift+F2 (Go to -> Go to Position on Clipboard Shift+F2) to see where in the code things goes wrong?

And what about debugging several times; even "unstable" things will usually happen some of the times you debug.

Notice the setting: Debug -> Break On Exception; it should be on because then you can simply run the program over and over in the debugger; once and exception happen the program will break and you can then inspect the run stack, etc.

One more thing. Sometimes file operations fails because some other program has exclusive access to a file (that will however normally result in another kind of exception). Furthermore the program that have the exclusive access is another version of "your own" program that didn't quite terminate completely.

Such "zombie" processes can be found using the task manager (in detailed view; on the detail tab).
Regards Thomas Linder Puls
PDC
Post Reply