diff options
Diffstat (limited to 'source/Host/windows')
| -rw-r--r-- | source/Host/windows/ConnectionGenericFileWindows.cpp | 5 | ||||
| -rw-r--r-- | source/Host/windows/FileSystem.cpp | 165 | ||||
| -rw-r--r-- | source/Host/windows/Host.cpp | 16 | ||||
| -rw-r--r-- | source/Host/windows/HostInfoWindows.cpp | 6 | ||||
| -rw-r--r-- | source/Host/windows/HostProcessWindows.cpp | 2 | ||||
| -rw-r--r-- | source/Host/windows/HostThreadWindows.cpp | 2 | ||||
| -rw-r--r-- | source/Host/windows/ThisThread.cpp | 63 | ||||
| -rw-r--r-- | source/Host/windows/Windows.cpp | 32 |
8 files changed, 14 insertions, 277 deletions
diff --git a/source/Host/windows/ConnectionGenericFileWindows.cpp b/source/Host/windows/ConnectionGenericFileWindows.cpp index 5d48a1c867ad..8fc038f3f9b6 100644 --- a/source/Host/windows/ConnectionGenericFileWindows.cpp +++ b/source/Host/windows/ConnectionGenericFileWindows.cpp @@ -8,8 +8,9 @@ //===----------------------------------------------------------------------===// #include "lldb/Host/windows/ConnectionGenericFileWindows.h" -#include "lldb/Core/Error.h" -#include "lldb/Core/Log.h" +#include "lldb/Utility/Error.h" +#include "lldb/Utility/Log.h" +#include "lldb/Utility/Timeout.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringRef.h" diff --git a/source/Host/windows/FileSystem.cpp b/source/Host/windows/FileSystem.cpp index f0ba7376876d..092b70b1f4dc 100644 --- a/source/Host/windows/FileSystem.cpp +++ b/source/Host/windows/FileSystem.cpp @@ -15,6 +15,7 @@ #include "lldb/Host/FileSystem.h" #include "lldb/Host/windows/AutoHandle.h" +#include "lldb/Host/windows/PosixApi.h" #include "llvm/Support/ConvertUTF.h" #include "llvm/Support/FileSystem.h" @@ -26,126 +27,6 @@ const char *FileSystem::DEV_NULL = "nul"; const char *FileSystem::PATH_CONVERSION_ERROR = "Error converting path between UTF-8 and native encoding"; -FileSpec::PathSyntax FileSystem::GetNativePathSyntax() { - return FileSpec::ePathSyntaxWindows; -} - -Error FileSystem::MakeDirectory(const FileSpec &file_spec, - uint32_t file_permissions) { - // On Win32, the mode parameter is ignored, as Windows files and directories - // support a - // different permission model than POSIX. - Error error; - const auto err_code = - llvm::sys::fs::create_directories(file_spec.GetPath(), true); - if (err_code) { - error.SetErrorString(err_code.message().c_str()); - } - - return error; -} - -Error FileSystem::DeleteDirectory(const FileSpec &file_spec, bool recurse) { - Error error; - std::wstring path_buffer; - if (!llvm::ConvertUTF8toWide(file_spec.GetPath(), path_buffer)) { - error.SetErrorString(PATH_CONVERSION_ERROR); - return error; - } - if (!recurse) { - BOOL result = ::RemoveDirectoryW(path_buffer.c_str()); - if (!result) - error.SetError(::GetLastError(), lldb::eErrorTypeWin32); - } else { - // SHFileOperation() accepts a list of paths, and so must be - // double-null-terminated to - // indicate the end of the list. The first null terminator is there only in - // the backing - // store but not the actual vector contents, and so we need to push twice. - path_buffer.push_back(0); - path_buffer.push_back(0); - - SHFILEOPSTRUCTW shfos = {}; - shfos.wFunc = FO_DELETE; - shfos.pFrom = (LPCWSTR)path_buffer.data(); - shfos.fFlags = FOF_NO_UI; - - int result = ::SHFileOperationW(&shfos); - // TODO(zturner): Correctly handle the intricacies of SHFileOperation return - // values. - if (result != 0) - error.SetErrorStringWithFormat("SHFileOperation failed"); - } - return error; -} - -Error FileSystem::GetFilePermissions(const FileSpec &file_spec, - uint32_t &file_permissions) { - Error error; - // Beware that Windows's permission model is different from Unix's, and it's - // not clear if this API is supposed to check ACLs. To match the caller's - // expectations as closely as possible, we'll use Microsoft's _stat, which - // attempts to emulate POSIX stat. This should be good enough for basic - // checks like FileSpec::Readable. - struct _stat file_stats; - if (::_stat(file_spec.GetCString(), &file_stats) == 0) { - // The owner permission bits in "st_mode" currently match the definitions - // for the owner file mode bits. - file_permissions = file_stats.st_mode & (_S_IREAD | _S_IWRITE | _S_IEXEC); - } else { - error.SetErrorToErrno(); - } - - return error; -} - -Error FileSystem::SetFilePermissions(const FileSpec &file_spec, - uint32_t file_permissions) { - Error error; - error.SetErrorStringWithFormat("%s is not supported on this host", - LLVM_PRETTY_FUNCTION); - return error; -} - -lldb::user_id_t FileSystem::GetFileSize(const FileSpec &file_spec) { - return file_spec.GetByteSize(); -} - -bool FileSystem::GetFileExists(const FileSpec &file_spec) { - return file_spec.Exists(); -} - -Error FileSystem::Hardlink(const FileSpec &src, const FileSpec &dst) { - Error error; - std::wstring wsrc, wdst; - if (!llvm::ConvertUTF8toWide(src.GetCString(), wsrc) || - !llvm::ConvertUTF8toWide(dst.GetCString(), wdst)) - error.SetErrorString(PATH_CONVERSION_ERROR); - else if (!::CreateHardLinkW(wsrc.c_str(), wdst.c_str(), nullptr)) - error.SetError(::GetLastError(), lldb::eErrorTypeWin32); - return error; -} - -int FileSystem::GetHardlinkCount(const FileSpec &file_spec) { - std::wstring path; - if (!llvm::ConvertUTF8toWide(file_spec.GetCString(), path)) - return -1; - - HANDLE file_handle = - ::CreateFileW(path.c_str(), FILE_READ_ATTRIBUTES, FILE_SHARE_READ, - nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); - - if (file_handle == INVALID_HANDLE_VALUE) - return -1; - - AutoHandle auto_file_handle(file_handle); - BY_HANDLE_FILE_INFORMATION file_info; - if (::GetFileInformationByHandle(file_handle, &file_info)) - return file_info.nNumberOfLinks; - - return -1; -} - Error FileSystem::Symlink(const FileSpec &src, const FileSpec &dst) { Error error; std::wstring wsrc, wdst; @@ -167,19 +48,6 @@ Error FileSystem::Symlink(const FileSpec &src, const FileSpec &dst) { return error; } -Error FileSystem::Unlink(const FileSpec &file_spec) { - Error error; - std::wstring path; - if (!llvm::ConvertUTF8toWide(file_spec.GetCString(), path)) { - error.SetErrorString(PATH_CONVERSION_ERROR); - return error; - } - BOOL result = ::DeleteFileW(path.c_str()); - if (!result) - error.SetError(::GetLastError(), lldb::eErrorTypeWin32); - return error; -} - Error FileSystem::Readlink(const FileSpec &src, FileSpec &dst) { Error error; std::wstring wsrc; @@ -217,15 +85,6 @@ Error FileSystem::ResolveSymbolicLink(const FileSpec &src, FileSpec &dst) { return Error("ResolveSymbolicLink() isn't implemented on Windows"); } -bool FileSystem::IsLocal(const FileSpec &spec) { - if (spec) { - // TODO: return true if the file is on a locally mounted file system - return true; - } - - return false; -} - FILE *FileSystem::Fopen(const char *path, const char *mode) { std::wstring wpath, wmode; if (!llvm::ConvertUTF8toWide(path, wpath)) @@ -237,25 +96,3 @@ FILE *FileSystem::Fopen(const char *path, const char *mode) { return nullptr; return file; } - -int FileSystem::Stat(const char *path, struct stat *stats) { - std::wstring wpath; - if (!llvm::ConvertUTF8toWide(path, wpath)) { - errno = EINVAL; - return -EINVAL; - } - int stat_result; -#ifdef _USE_32BIT_TIME_T - struct _stat32 file_stats; - stat_result = ::_wstat32(wpath.c_str(), &file_stats); -#else - struct _stat64i32 file_stats; - stat_result = ::_wstat64i32(wpath.c_str(), &file_stats); -#endif - if (stat_result == 0) { - static_assert(sizeof(struct stat) == sizeof(file_stats), - "stat and _stat32/_stat64i32 must have the same layout"); - *stats = *reinterpret_cast<struct stat *>(&file_stats); - } - return stat_result; -} diff --git a/source/Host/windows/Host.cpp b/source/Host/windows/Host.cpp index 3da073605dcb..9a6957b2a1ff 100644 --- a/source/Host/windows/Host.cpp +++ b/source/Host/windows/Host.cpp @@ -15,16 +15,16 @@ // C++ Includes // Other libraries and framework includes // Project includes -#include "lldb/Core/Error.h" -#include "lldb/Core/Log.h" #include "lldb/Target/Process.h" +#include "lldb/Utility/Error.h" +#include "lldb/Utility/Log.h" -#include "lldb/Core/DataBufferHeap.h" -#include "lldb/Core/DataExtractor.h" #include "lldb/Core/StreamFile.h" #include "lldb/Core/StructuredData.h" #include "lldb/Host/Host.h" #include "lldb/Host/HostInfo.h" +#include "lldb/Utility/DataBufferHeap.h" +#include "lldb/Utility/DataExtractor.h" #include "llvm/Support/ConvertUTF.h" @@ -97,14 +97,6 @@ void GetProcessExecutableAndTriple(const AutoHandle &handle, } } -lldb::DataBufferSP Host::GetAuxvData(lldb_private::Process *process) { - return 0; -} - -lldb::tid_t Host::GetCurrentThreadID() { - return lldb::tid_t(::GetCurrentThreadId()); -} - lldb::thread_t Host::GetCurrentThread() { return lldb::thread_t(::GetCurrentThread()); } diff --git a/source/Host/windows/HostInfoWindows.cpp b/source/Host/windows/HostInfoWindows.cpp index a965ec0ea4e2..53a24ad1893e 100644 --- a/source/Host/windows/HostInfoWindows.cpp +++ b/source/Host/windows/HostInfoWindows.cpp @@ -14,10 +14,12 @@ #include <mutex> // std::once #include "lldb/Host/windows/HostInfoWindows.h" +#include "lldb/Host/windows/PosixApi.h" #include "llvm/ADT/SmallString.h" #include "llvm/Support/ConvertUTF.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" +#include "llvm/Support/Threading.h" #include "llvm/Support/raw_ostream.h" using namespace lldb_private; @@ -90,8 +92,8 @@ bool HostInfoWindows::GetHostname(std::string &s) { } FileSpec HostInfoWindows::GetProgramFileSpec() { - static std::once_flag g_once_flag; - std::call_once(g_once_flag, []() { + static llvm::once_flag g_once_flag; + llvm::call_once(g_once_flag, []() { std::vector<wchar_t> buffer(PATH_MAX); ::GetModuleFileNameW(NULL, buffer.data(), buffer.size()); std::string path; diff --git a/source/Host/windows/HostProcessWindows.cpp b/source/Host/windows/HostProcessWindows.cpp index 8201d53bd27c..3bbc84a4ca59 100644 --- a/source/Host/windows/HostProcessWindows.cpp +++ b/source/Host/windows/HostProcessWindows.cpp @@ -8,10 +8,10 @@ //===----------------------------------------------------------------------===// #include "lldb/Host/windows/HostProcessWindows.h" -#include "lldb/Host/FileSpec.h" #include "lldb/Host/HostThread.h" #include "lldb/Host/ThreadLauncher.h" #include "lldb/Host/windows/windows.h" +#include "lldb/Utility/FileSpec.h" #include "llvm/ADT/STLExtras.h" #include "llvm/Support/ConvertUTF.h" diff --git a/source/Host/windows/HostThreadWindows.cpp b/source/Host/windows/HostThreadWindows.cpp index 41be21bfa304..aa791714c338 100644 --- a/source/Host/windows/HostThreadWindows.cpp +++ b/source/Host/windows/HostThreadWindows.cpp @@ -7,7 +7,7 @@ // //===----------------------------------------------------------------------===// -#include "lldb/Core/Error.h" +#include "lldb/Utility/Error.h" #include "lldb/Host/windows/HostThreadWindows.h" #include "lldb/Host/windows/windows.h" diff --git a/source/Host/windows/ThisThread.cpp b/source/Host/windows/ThisThread.cpp deleted file mode 100644 index 8db12f05b0ba..000000000000 --- a/source/Host/windows/ThisThread.cpp +++ /dev/null @@ -1,63 +0,0 @@ -//===-- ThisThread.cpp ------------------------------------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#include "lldb/Core/Error.h" - -#include "lldb/Host/ThisThread.h" -#include "lldb/Host/windows/windows.h" - -#include "llvm/ADT/STLExtras.h" -#include "llvm/ADT/SmallVector.h" - -using namespace lldb; -using namespace lldb_private; - -#if defined(_MSC_VER) && !defined(__clang__) - -namespace { -static const DWORD MS_VC_EXCEPTION = 0x406D1388; - -#pragma pack(push, 8) -struct THREADNAME_INFO { - DWORD dwType; // Must be 0x1000. - LPCSTR szName; // Pointer to thread name - DWORD dwThreadId; // Thread ID (-1 == current thread) - DWORD dwFlags; // Reserved. Do not use. -}; -#pragma pack(pop) -} - -#endif - -void ThisThread::SetName(llvm::StringRef name) { -// Other compilers don't yet support SEH, so we can only set the thread if -// compiling with MSVC. -// TODO(zturner): Once clang-cl supports SEH, relax this conditional. -#if defined(_MSC_VER) && !defined(__clang__) - THREADNAME_INFO info; - info.dwType = 0x1000; - info.szName = name.data(); - info.dwThreadId = ::GetCurrentThreadId(); - info.dwFlags = 0; - - __try { - ::RaiseException(MS_VC_EXCEPTION, 0, sizeof(info) / sizeof(ULONG_PTR), - (ULONG_PTR *)&info); - } __except (EXCEPTION_EXECUTE_HANDLER) { - } -#endif -} - -void ThisThread::GetName(llvm::SmallVectorImpl<char> &name) { - // Getting the thread name is not supported on Windows. - // TODO(zturner): In SetName(), make a TLS entry that contains the thread's - // name, and in this function - // try to extract that TLS entry. - name.clear(); -} diff --git a/source/Host/windows/Windows.cpp b/source/Host/windows/Windows.cpp index 21afc6d85da5..9d0e70e6d126 100644 --- a/source/Host/windows/Windows.cpp +++ b/source/Host/windows/Windows.cpp @@ -23,13 +23,6 @@ #include <stdlib.h> #include <string.h> -// These prototypes are defined in <direct.h>, but it also defines chdir() and -// getcwd(), giving multiply defined errors -extern "C" { -char *_getcwd(char *buffer, int maxlen); -int _chdir(const char *path); -} - namespace { bool utf8ToWide(const char *utf8, wchar_t *buf, size_t bufSize) { const llvm::UTF8 *sourceStart = reinterpret_cast<const llvm::UTF8 *>(utf8); @@ -190,31 +183,6 @@ char *basename(char *path) { return &l1[1]; } -// use _getcwd() instead of GetCurrentDirectory() because it updates errno -char *getcwd(char *path, int max) { - assert(path == NULL || max <= PATH_MAX); - wchar_t wpath[PATH_MAX]; - if (wchar_t *wresult = _wgetcwd(wpath, PATH_MAX)) { - // Caller is allowed to pass in NULL for `path`. - // In that case, we're supposed to allocate a - // buffer on the caller's behalf. - if (path == NULL) { - max = UNI_MAX_UTF8_BYTES_PER_CODE_POINT * wcslen(wresult) + 1; - path = (char *)malloc(max); - if (path == NULL) { - errno = ENOMEM; - return NULL; - } - } - if (wideToUtf8(wresult, path, max)) - return path; - } - return NULL; -} - -// use _chdir() instead of SetCurrentDirectory() because it updates errno -int chdir(const char *path) { return _chdir(path); } - char *dirname(char *path) { char *l1 = strrchr(path, '\\'); char *l2 = strrchr(path, '/'); |
