X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;ds=sidebyside;f=utils%2FKillTheDoctor%2FKillTheDoctor.cpp;h=fae3b1a8b9d84bda4a92b6437fd908faea13337f;hb=813f44a29fd0fd140127023222d0633e23783bcc;hp=7a89dd379b70f5cd9c7e42a51845013d9f04ec79;hpb=b9c767cce502f016a5bdb07884625a3fffbe048c;p=oota-llvm.git diff --git a/utils/KillTheDoctor/KillTheDoctor.cpp b/utils/KillTheDoctor/KillTheDoctor.cpp index 7a89dd379b7..fae3b1a8b9d 100644 --- a/utils/KillTheDoctor/KillTheDoctor.cpp +++ b/utils/KillTheDoctor/KillTheDoctor.cpp @@ -38,20 +38,25 @@ #include "llvm/ADT/Twine.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/ManagedStatic.h" +#include "llvm/Support/Path.h" #include "llvm/Support/PrettyStackTrace.h" +#include "llvm/Support/Signals.h" +#include "llvm/Support/WindowsError.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Support/type_traits.h" -#include "llvm/Support/Signals.h" -#include "llvm/Support/system_error.h" #include #include #include #include #include +#include + +// These includes must be last. #include #include #include #include + using namespace llvm; #undef max @@ -166,17 +171,19 @@ namespace { typedef ScopedHandle FileScopedHandle; } -static error_code GetFileNameFromHandle(HANDLE FileHandle, - std::string& Name) { +static std::error_code windows_error(DWORD E) { return mapWindowsError(E); } + +static std::error_code GetFileNameFromHandle(HANDLE FileHandle, + std::string &Name) { char Filename[MAX_PATH+1]; - bool Sucess = false; + bool Success = false; Name.clear(); // Get the file size. LARGE_INTEGER FileSize; - Sucess = ::GetFileSizeEx(FileHandle, &FileSize); + Success = ::GetFileSizeEx(FileHandle, &FileSize); - if (!Sucess) + if (!Success) return windows_error(::GetLastError()); // Create a file mapping object. @@ -198,29 +205,16 @@ static error_code GetFileNameFromHandle(HANDLE FileHandle, if (!MappedFile) return windows_error(::GetLastError()); - Sucess = ::GetMappedFileNameA(::GetCurrentProcess(), + Success = ::GetMappedFileNameA(::GetCurrentProcess(), MappedFile, Filename, array_lengthof(Filename) - 1); - if (!Sucess) + if (!Success) return windows_error(::GetLastError()); else { Name = Filename; - return windows_error::success; - } -} - -static std::string QuoteProgramPathIfNeeded(StringRef Command) { - if (Command.find_first_of(' ') == StringRef::npos) - return Command; - else { - std::string ret; - ret.reserve(Command.size() + 3); - ret.push_back('"'); - ret.append(Command.begin(), Command.end()); - ret.push_back('"'); - return ret; + return std::error_code(); } } @@ -230,7 +224,8 @@ static std::string QuoteProgramPathIfNeeded(StringRef Command) { /// extension is present, try all extensions in PATHEXT. /// @return If ec == errc::success, The absolute path to the program. Otherwise /// the return value is undefined. -static std::string FindProgram(const std::string &Program, error_code &ec) { +static std::string FindProgram(const std::string &Program, + std::error_code &ec) { char PathName[MAX_PATH + 1]; typedef SmallVector pathext_t; pathext_t pathext; @@ -255,11 +250,11 @@ static std::string FindProgram(const std::string &Program, error_code &ec) { ec = windows_error(::GetLastError()); else if (length > array_lengthof(PathName)) { // This may have been the file, return with error. - ec = windows_error::buffer_overflow; + ec = windows_error(ERROR_BUFFER_OVERFLOW); break; } else { // We found the path! Return it. - ec = windows_error::success; + ec = std::error_code(); break; } } @@ -269,39 +264,6 @@ static std::string FindProgram(const std::string &Program, error_code &ec) { return PathName; } -static error_code EnableDebugPrivileges() { - HANDLE TokenHandle; - BOOL success = ::OpenProcessToken(::GetCurrentProcess(), - TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, - &TokenHandle); - if (!success) - return windows_error(::GetLastError()); - - TokenScopedHandle Token(TokenHandle); - TOKEN_PRIVILEGES TokenPrivileges; - LUID LocallyUniqueID; - - success = ::LookupPrivilegeValueA(NULL, - SE_DEBUG_NAME, - &LocallyUniqueID); - if (!success) - return windows_error(::GetLastError()); - - TokenPrivileges.PrivilegeCount = 1; - TokenPrivileges.Privileges[0].Luid = LocallyUniqueID; - TokenPrivileges.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; - - success = ::AdjustTokenPrivileges(Token, - FALSE, - &TokenPrivileges, - sizeof(TOKEN_PRIVILEGES), - NULL, - NULL); - // The value of success is basically useless. Either way we are just returning - // the value of ::GetLastError(). - return windows_error(::GetLastError()); -} - static StringRef ExceptionCodeToString(DWORD ExceptionCode) { switch(ExceptionCode) { case EXCEPTION_ACCESS_VIOLATION: return "EXCEPTION_ACCESS_VIOLATION"; @@ -355,7 +317,7 @@ int main(int argc, char **argv) { std::string CommandLine(ProgramToRun); - error_code ec; + std::error_code ec; ProgramToRun = FindProgram(ProgramToRun, ec); if (ec) { errs() << ToolName << ": Failed to find program: '" << CommandLine @@ -399,8 +361,8 @@ int main(int argc, char **argv) { &StartupInfo, &ProcessInfo); if (!success) { - errs() << ToolName << ": Failed to run program: '" << ProgramToRun - << "': " << error_code(windows_error(::GetLastError())).message() + errs() << ToolName << ": Failed to run program: '" << ProgramToRun << "': " + << std::error_code(windows_error(::GetLastError())).message() << '\n'; return -1; } @@ -463,9 +425,10 @@ int main(int argc, char **argv) { success = WaitForDebugEvent(&DebugEvent, TimeLeft); if (!success) { - ec = windows_error(::GetLastError()); + DWORD LastError = ::GetLastError(); + ec = windows_error(LastError); - if (ec == errc::timed_out) { + if (LastError == ERROR_SEM_TIMEOUT || LastError == WSAETIMEDOUT) { errs() << ToolName << ": Process timed out.\n"; ::TerminateProcess(ProcessInfo.hProcess, -1); // Otherwise other stuff starts failing...