|
|
Home » U++ TheIDE » U++ TheIDE: Compiling, Linking, Debugging of your packages » I keep getting the same "cannot open exe for writing" error...
|
|
Re: I keep getting the same "cannot open exe for writing" error... [message #50655 is a reply to message #50651] |
Thu, 29 November 2018 13:41   |
 |
peterh
Messages: 108 Registered: November 2018 Location: Germany
|
Experienced Member |
|
|
The question is, if your process needs more time than 3 seconds to terminate.
The other question is can it been terminated with this method at all?
If it hangs in blocking IO in kernel mode, possibly it cannot be terminated.
I do regulary see applications that do serial IO via the .NET and if these crash, then
Windows does not shut down because it waits for the process forever.
This is why I proposed tho give report to the user.
There could be a message box:
"Process termination timeout"
"Wait and retry?" "Ignore and try to Close anyway"
WaitForSingleObject should return these Values:
WAIT_OBJECT_0 means the thread has stopped.
WAIT_TIMEOUT means the thread is running.
Not that I have practical experience with this. This is what I found in MSDN.
Edit:
Just for explanation:
Even if the processhandle is closed and the process detached the file cannot been deleted or modified as long as the process is running.
This is, because windows needs the .exe file for virtual memory paging, when the process is still running.
In this case the file could be renamed and marked for deletion.
[Updated on: Thu, 29 November 2018 16:22] Report message to a moderator
|
|
|
|
Re: I keep getting the same "cannot open exe for writing" error... [message #50659 is a reply to message #50651] |
Fri, 30 November 2018 09:01   |
 |
peterh
Messages: 108 Registered: November 2018 Location: Germany
|
Experienced Member |
|
|
Hi,
I do not know how Windows terminates a process.
I have however done WIN32 programming years ago before, even Kernel debugging. (Debugging a kernel mode driver)
So I have ideas about it.
Windows might inject an ExitProcess call into the code of the process in order to terminate it with the least damage possible.
This would not work, if the process doesnt run (e.g. hangs in blocking IO in kernel mode).
Also this can be delayed, if heavy background activity happens, e.g. swapping and it could be necessary to swap portions of the debugged process in.
In these cases I can imagine, TerminateProcess would need time or might be impossible.
All the best,
Peter
[Updated on: Fri, 30 November 2018 09:04] Report message to a moderator
|
|
|
Re: I keep getting the same "cannot open exe for writing" error... [message #50660 is a reply to message #50659] |
Fri, 30 November 2018 11:48   |
 |
peterh
Messages: 108 Registered: November 2018 Location: Germany
|
Experienced Member |
|
|
I have seen this same error with MinGW on Window7 32 Bit.
(): Linking has failed
(): C:/upp/bin/mingw64/32/bin/../lib/gcc/i686-w64-mingw32/7.1.0/ ../../../../i686-w64-mingw32/bin/ld.exe: cannot open output file C:\up
p\out\reference\MINGW.Debug.Debug_Full.Gui.Mt.Noblitz\CoWork .exe: Permission denied
(): collect2.exe: error: ld returned 1 exit status
It happens reproducibly when I start CoWork.exe in debug mode and terminate it with stop.
The process stays in memory after termination.
In this case the terminated process can be removed with the Windows Taskmanager.
Edit:
I retried this with MingW 32 and 64 on a faster Computer, running Windows 10 64 Bit.
There it doesnt happen.
[Updated on: Sat, 01 December 2018 14:13] Report message to a moderator
|
|
|
Re: I keep getting the same "cannot open exe for writing" error... [message #50688 is a reply to message #50660] |
Wed, 05 December 2018 21:52   |
 |
peterh
Messages: 108 Registered: November 2018 Location: Germany
|
Experienced Member |
|
|
Hi,
I want to add this, because it might help others:
I went back to the 2018.1 stable build, because I had problems with the nightly builds.
With 2018.1 the aforementioned problem occurs frequently to me.
Then I added WaitForSingleObject(hProcess,10000) to Pdb::Stop() as aforementioned.
This did not cure the problem, but did also not cause any additional effects like delays.
Then I did see, the Ide project had the flags "GUI" and no other.
So I recompiled Theide with flags "GUI MT", because I believe, it could be multithreaded.
Apparently this cured the problem for me. It did not happen again since 2 hours now.
All the best,
Peter
[Updated on: Wed, 05 December 2018 21:57] Report message to a moderator
|
|
|
|
|
|
|
|
Re: I keep getting the same "cannot open exe for writing" error... [message #50700 is a reply to message #50697] |
Thu, 06 December 2018 20:53   |
 |
peterh
Messages: 108 Registered: November 2018 Location: Germany
|
Experienced Member |
|
|
I have now changed the code in the following way:
if(hProcess != INVALID_HANDLE_VALUE) {
DebugActiveProcessStop(processid);
TerminateProcess(hProcess, 0);
DWORD retval = MsgWaitForMultipleObjects(
1, //DWORD nCount,
&hProcess, //const HANDLE *pHandles,
true, //BOOL fWaitAll,
10000, //DWORD dwMilliseconds,
0 //DWORD dwWakeMask
);
if (retval == WAIT_TIMEOUT) Exclamation("WAIT_TIMEOUT");
if (retval == WAIT_ABANDONED) Exclamation("WAIT_ABANDONED");
WaitForSingleObject(hProcess,10000);
while(threads.GetCount())
RemoveThread(threads.GetKey(0)); // To CloseHandle
UnloadModuleSymbols();
SymCleanup(hProcess);
CloseHandle(hProcess);
}
I did this because I have read, the WaitForSingleObject() call can return prematurely under some special circumstances.
I cannot explain it, because Microsoft cannot explain it clearly. 
The explanations given are misunderstandable or ambigous and there are subtile typos sometimes. And no examples
I simply try it, if someone understands this perfectly, it will be appreciated.
After I did this, something changed: Stopping the debugee needs about 4 seconds, which is perfectly ok for me.
Edit: I added some debug code
The reason for the 4 seconds delay is not WAIT_TIMEOUT and is not WAIT_ABANDONED.
I will add some code to log the reason tomorrow. (Still I am learning Upp, needs more time than usual)
Ok, I will try this over the next few days and then report again.
So long,
Peter
[Updated on: Thu, 06 December 2018 22:40] Report message to a moderator
|
|
|
|
Re: I keep getting the same "cannot open exe for writing" error... [message #50713 is a reply to message #50712] |
Sat, 08 December 2018 18:33   |
 |
peterh
Messages: 108 Registered: November 2018 Location: Germany
|
Experienced Member |
|
|
Now it happened again.
DebugActiveProcessStop returned false, this means it failed.
Probably the debugger could not detach.
In turn, TerminateProcess failed.
"terminated flag" = terminated flag
terminated = false //This is OK
"DebugActiveProcessStop" = DebugActiveProcessStop
retval = 0x0 //Boolean, Failed
"TerminateProcess" = TerminateProcess
retval = 0x0 //Boolean, Failed
"WaitForSingleObject" = WaitForSingleObject
retval = 0x102 //WAIT_TIMEOUT
"CloseHandle" = CloseHandle
retval = 0x1 //Succeeded
[Updated on: Sat, 08 December 2018 18:47] Report message to a moderator
|
|
|
Re: I keep getting the same "cannot open exe for writing" error... [message #50717 is a reply to message #50712] |
Sat, 08 December 2018 19:27   |
 |
peterh
Messages: 108 Registered: November 2018 Location: Germany
|
Experienced Member |
|
|
New Code:
void Pdb::Stop()
{
DWORD retval;
LOG("---------------------------------------");
LOG("terminated flag");
DUMP(terminated);
if(!terminated) {
terminated = true;
SaveTree();
String fn = ConfigFile("TreeTypes.txt");
FileOut out(fn);
for(int i = 0; i < treetype.GetCount(); i++)
out << treetype.GetKey(i) << "\r\n" << treetype[i] << "\r\n";
StringStream ss;
Store(callback(this, &Pdb::SerializeSession), ss);
WorkspaceConfigData("pdb-debugger") = ss;
if(hProcess == INVALID_HANDLE_VALUE)
{ LOG("hProcess Handle is invalid handle value");};
if(hProcess != INVALID_HANDLE_VALUE) {
LOG("DebugActiveProcessStop");
for(int i=0; i<10; i++){
if (retval = DebugActiveProcessStop(processid)) break;
DUMPHEX(retval);
Sleep(100);
}
DUMPHEX(retval);
retval = TerminateProcess(hProcess, 0);
LOG("TerminateProcess");
DUMPHEX(retval);
retval = WaitForSingleObject(hProcess,10000);
LOG("WaitForSingleObject");
DUMPHEX(retval);
#ifdef NEVEREVER
retval = MsgWaitForMultipleObjects(
1, //DWORD nCount,
&hProcess, //const HANDLE *pHandles,
true, //BOOL fWaitAll,
10000, //DWORD dwMilliseconds,
0 //DWORD dwWakeMask
);
LOG("WaitForMultibleObjects");
DUMPHEX(retval);
#endif
while(threads.GetCount())
RemoveThread(threads.GetKey(0)); // To CloseHandle
UnloadModuleSymbols();
SymCleanup(hProcess);
retval = CloseHandle(hProcess);
LOG("CloseHandle");
DUMPHEX(retval);
}
StoreToGlobal(*this, CONFIGNAME);
IdeRemoveBottom(*this);
IdeRemoveRight(disas);
}
}
[Updated on: Sat, 08 December 2018 19:29] Report message to a moderator
|
|
|
Re: I keep getting the same "cannot open exe for writing" error... [message #50718 is a reply to message #50717] |
Sat, 08 December 2018 19:50   |
 |
peterh
Messages: 108 Registered: November 2018 Location: Germany
|
Experienced Member |
|
|
Apparently it happened again.
This time however, with the new code and it worked as intended.
But not completely, because TerminateProcess failed.
Possibly the process was already terminated, because WaitForSingleObject
succeeded with retval == WAIT_OBJECT_0.
Any way, TheIde had no problem after this.
---------------------------------------
terminated flag
terminated = false
DebugActiveProcessStop
retval = 0x0
retval = 0x1
TerminateProcess
retval = 0x0
WaitForSingleObject
retval = 0x0
CloseHandle
retval = 0x1
[Updated on: Sat, 08 December 2018 19:58] Report message to a moderator
|
|
|
|
|
|
Goto Forum:
Current Time: Fri May 09 18:29:01 CEST 2025
Total time taken to generate the page: 0.01171 seconds
|
|
|