llvm.org GIT mirror llvm / 93e5ec2
KillTheDoctor: Cleanup error_code usage. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120986 91177308-0d34-0410-b5e6-96231b3b80d8 Michael J. Spencer 9 years ago
1 changed file(s) with 15 addition(s) and 19 deletion(s). Raw diff Collapse all Expand all
163163 typedef ScopedHandle ThreadScopedHandle;
164164 typedef ScopedHandle TokenScopedHandle;
165165 typedef ScopedHandle FileScopedHandle;
166
167 error_code get_windows_last_error() {
168 return make_error_code(windows_error(::GetLastError()));
169 }
170166 }
171167
172168 static error_code GetFileNameFromHandle(HANDLE FileHandle,
180176 Sucess = ::GetFileSizeEx(FileHandle, &FileSize);
181177
182178 if (!Sucess)
183 return get_windows_last_error();
179 return windows_error(::GetLastError());
184180
185181 // Create a file mapping object.
186182 FileMappingScopedHandle FileMapping(
192188 NULL));
193189
194190 if (!FileMapping)
195 return get_windows_last_error();
191 return windows_error(::GetLastError());
196192
197193 // Create a file mapping to get the file name.
198194 MappedViewOfFileScopedHandle MappedFile(
199195 ::MapViewOfFile(FileMapping, FILE_MAP_READ, 0, 0, 1));
200196
201197 if (!MappedFile)
202 return get_windows_last_error();
198 return windows_error(::GetLastError());
203199
204200 Sucess = ::GetMappedFileNameA(::GetCurrentProcess(),
205201 MappedFile,
207203 array_lengthof(Filename) - 1);
208204
209205 if (!Sucess)
210 return get_windows_last_error();
206 return windows_error(::GetLastError());
211207 else {
212208 Name = Filename;
213209 return windows_error::success;
255251 PathName,
256252 NULL);
257253 if (length == 0)
258 ec = get_windows_last_error();
254 ec = windows_error(::GetLastError());
259255 else if (length > array_lengthof(PathName)) {
260256 // This may have been the file, return with error.
261 ec = error_code(windows_error::buffer_overflow);
257 ec = windows_error::buffer_overflow;
262258 break;
263259 } else {
264260 // We found the path! Return it.
278274 TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
279275 &TokenHandle);
280276 if (!success)
281 return error_code(::GetLastError(), system_category());
277 return windows_error(::GetLastError());
282278
283279 TokenScopedHandle Token(TokenHandle);
284280 TOKEN_PRIVILEGES TokenPrivileges;
288284 SE_DEBUG_NAME,
289285 &LocallyUniqueID);
290286 if (!success)
291 return error_code(::GetLastError(), system_category());
287 return windows_error(::GetLastError());
292288
293289 TokenPrivileges.PrivilegeCount = 1;
294290 TokenPrivileges.Privileges[0].Luid = LocallyUniqueID;
302298 NULL);
303299 // The value of success is basically useless. Either way we are just returning
304300 // the value of ::GetLastError().
305 return error_code(::GetLastError(), system_category());
301 return windows_error(::GetLastError());
306302 }
307303
308304 static StringRef ExceptionCodeToString(DWORD ExceptionCode) {
403399 &ProcessInfo);
404400 if (!success) {
405401 errs() << ToolName << ": Failed to run program: '" << ProgramToRun
406 << "': " << error_code(::GetLastError(), system_category()).message()
402 << "': " << error_code(windows_error(::GetLastError())).message()
407403 << '\n';
408404 return -1;
409405 }
431427 &KernelTime,
432428 &UserTime);
433429 if (!success) {
434 ec = error_code(::GetLastError(), system_category());
430 ec = windows_error(::GetLastError());
435431
436432 errs() << ToolName << ": Failed to get process times: "
437433 << ec.message() << '\n';
466462 success = WaitForDebugEvent(&DebugEvent, TimeLeft);
467463
468464 if (!success) {
469 ec = error_code(::GetLastError(), system_category());
470
471 if (ec == error_condition(errc::timed_out)) {
465 ec = windows_error(::GetLastError());
466
467 if (ec == errc::timed_out) {
472468 errs() << ToolName << ": Process timed out.\n";
473469 ::TerminateProcess(ProcessInfo.hProcess, -1);
474470 // Otherwise other stuff starts failing...
585581 DebugEvent.dwThreadId,
586582 dwContinueStatus);
587583 if (!success) {
588 ec = error_code(::GetLastError(), system_category());
584 ec = windows_error(::GetLastError());
589585 errs() << ToolName << ": Failed to continue debugging program: '"
590586 << ProgramToRun << "': " << ec.message() << '\n';
591587 return -1;