[OCaml] Llvm_linker: do not use external in module interface
[oota-llvm.git] / utils / KillTheDoctor / KillTheDoctor.cpp
index a623d6af8d9ca6094e72681ea9dda4036031a45a..feba2e54f6a5fb20f8c7367e07e06eb137a80593 100644 (file)
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/PrettyStackTrace.h"
-#include "llvm/Support/raw_ostream.h"
-#include "llvm/Support/type_traits.h"
 #include "llvm/Support/Signals.h"
+#include "llvm/Support/raw_ostream.h"
 #include "llvm/Support/system_error.h"
+#include "llvm/Support/type_traits.h"
 #include <algorithm>
 #include <cerrno>
 #include <cstdlib>
 #include <map>
 #include <string>
+
+// These includes must be last.
 #include <Windows.h>
 #include <WinError.h>
 #include <Dbghelp.h>
 #include <psapi.h>
+
 using namespace llvm;
 
 #undef max
@@ -169,14 +172,14 @@ namespace {
 static 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,12 +201,12 @@ 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;
@@ -211,19 +214,6 @@ static error_code GetFileNameFromHandle(HANDLE FileHandle,
   }
 }
 
-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;
-  }
-}
-
 /// @brief Find program using shell lookup rules.
 /// @param Program This is either an absolute path, relative path, or simple a
 ///        program name. Look in PATH for any programs that match. If no
@@ -269,39 +259,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";
@@ -523,7 +480,7 @@ int main(int argc, char **argv) {
           errs().indent(ToolName.size()) << ": DLL Name : " << DLLName << '\n';
         }
 
-        if (NoUser32 && sys::Path(DLLName).getBasename() == "user32") {
+        if (NoUser32 && sys::path::stem(DLLName) == "user32") {
           // Program is loading user32.dll, in the applications we are testing,
           // this only happens if an assert has fired. By now the message has
           // already been printed, so simply close the program.