@@ -113,14 +113,30 @@ ProcessLauncherWindows::LaunchProcess(const ProcessLaunchInfo &launch_info,
113
113
// command line is not empty, its contents may be modified by CreateProcessW.
114
114
WCHAR *pwcommandLine = wcommandLine.empty () ? nullptr : &wcommandLine[0 ];
115
115
116
- BOOL result = ::CreateProcessW (
117
- wexecutable.c_str (), pwcommandLine, NULL , NULL , TRUE , flags, env_block,
118
- wworkingDirectory.size () == 0 ? NULL : wworkingDirectory.c_str (),
119
- &startupinfo, &pi );
116
+ BOOL result;
117
+ DWORD last_error = 0 ;
118
+ // This is the workaround for the error "The process cannot access the file
119
+ // because it is being used by another process". Note the executable file is
120
+ // installed to the target by the process `lldb-server platform`, but launched
121
+ // by the process `lldb-server gdbserver`. Sometimes system may block the file
122
+ // for some time after copying.
123
+ for (int i = 0 ; i < 50 ; ++i) {
124
+ result = ::CreateProcessW (
125
+ wexecutable.c_str (), pwcommandLine, NULL , NULL , TRUE , flags, env_block,
126
+ wworkingDirectory.size () == 0 ? NULL : wworkingDirectory.c_str (),
127
+ &startupinfo, &pi );
128
+ if (!result) {
129
+ last_error = ::GetLastError ();
130
+ if (last_error != ERROR_SHARING_VIOLATION)
131
+ break ;
132
+ ::Sleep (100 );
133
+ } else
134
+ break ;
135
+ }
120
136
121
137
if (!result) {
122
138
// Call GetLastError before we make any other system calls.
123
- error.SetError (:: GetLastError () , eErrorTypeWin32);
139
+ error.SetError (last_error , eErrorTypeWin32);
124
140
// Note that error 50 ("The request is not supported") will occur if you
125
141
// try debug a 64-bit inferior from a 32-bit LLDB.
126
142
}
0 commit comments