[Lldb-commits] [lldb] r215273 - Implement some common file operations on Windows.
Zachary Turner
zturner at google.com
Fri Aug 8 18:29:08 PDT 2014
Author: zturner
Date: Fri Aug 8 20:29:07 2014
New Revision: 215273
URL: http://llvm.org/viewvc/llvm-project?rev=215273&view=rev
Log:
Implement some common file operations on Windows.
Modified:
lldb/trunk/include/lldb/Core/Error.h
lldb/trunk/include/lldb/lldb-enumerations.h
lldb/trunk/source/Host/common/Host.cpp
lldb/trunk/source/Host/windows/Host.cpp
Modified: lldb/trunk/include/lldb/Core/Error.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/Error.h?rev=215273&r1=215272&r2=215273&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/Error.h (original)
+++ lldb/trunk/include/lldb/Core/Error.h Fri Aug 8 20:29:07 2014
@@ -308,7 +308,7 @@ protected:
/// Member variables
//------------------------------------------------------------------
ValueType m_code; ///< Error code as an integer value.
- lldb::ErrorType m_type; ///< The type of the above error code.
+ lldb::ErrorType m_type; ///< The type of the above error code.
mutable std::string m_string; ///< A string representation of the error code.
};
Modified: lldb/trunk/include/lldb/lldb-enumerations.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-enumerations.h?rev=215273&r1=215272&r2=215273&view=diff
==============================================================================
--- lldb/trunk/include/lldb/lldb-enumerations.h (original)
+++ lldb/trunk/include/lldb/lldb-enumerations.h Fri Aug 8 20:29:07 2014
@@ -237,7 +237,8 @@ namespace lldb {
eErrorTypeGeneric, ///< Generic errors that can be any value.
eErrorTypeMachKernel, ///< Mach kernel error codes.
eErrorTypePOSIX, ///< POSIX error codes.
- eErrorTypeExpression ///< These are from the ExpressionResults enum.
+ eErrorTypeExpression, ///< These are from the ExpressionResults enum.
+ eErrorTypeWin32 ///< Standard Win32 error codes.
} ErrorType;
Modified: lldb/trunk/source/Host/common/Host.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/Host.cpp?rev=215273&r1=215272&r2=215273&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/Host.cpp (original)
+++ lldb/trunk/source/Host/common/Host.cpp Fri Aug 8 20:29:07 2014
@@ -2202,66 +2202,7 @@ Host::LaunchApplication (const FileSpec
#endif
-#ifdef LLDB_DISABLE_POSIX
-
-Error
-Host::MakeDirectory (const char* path, uint32_t mode)
-{
- Error error;
- error.SetErrorStringWithFormat("%s in not implemented on this host", __PRETTY_FUNCTION__);
- return error;
-}
-
-Error
-Host::GetFilePermissions (const char* path, uint32_t &file_permissions)
-{
- Error error;
- error.SetErrorStringWithFormat("%s is not supported on this host", __PRETTY_FUNCTION__);
- return error;
-}
-
-Error
-Host::SetFilePermissions (const char* path, uint32_t file_permissions)
-{
- Error error;
- error.SetErrorStringWithFormat("%s is not supported on this host", __PRETTY_FUNCTION__);
- return error;
-}
-
-Error
-Host::Symlink (const char *src, const char *dst)
-{
- Error error;
- error.SetErrorStringWithFormat("%s is not supported on this host", __PRETTY_FUNCTION__);
- return error;
-}
-
-Error
-Host::Readlink (const char *path, char *buf, size_t buf_len)
-{
- Error error;
- error.SetErrorStringWithFormat("%s is not supported on this host", __PRETTY_FUNCTION__);
- return error;
-}
-
-Error
-Host::Unlink (const char *path)
-{
- Error error;
- error.SetErrorStringWithFormat("%s is not supported on this host", __PRETTY_FUNCTION__);
- return error;
-}
-
-Error
-Host::RemoveDirectory (const char* path, bool recurse)
-{
- Error error;
- error.SetErrorStringWithFormat("%s is not supported on this host", __PRETTY_FUNCTION__);
- return error;
-}
-
-#else
-
+#if !defined(_WIN32)
Error
Host::MakeDirectory (const char* path, uint32_t file_permissions)
{
Modified: lldb/trunk/source/Host/windows/Host.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/windows/Host.cpp?rev=215273&r1=215272&r2=215273&view=diff
==============================================================================
--- lldb/trunk/source/Host/windows/Host.cpp (original)
+++ lldb/trunk/source/Host/windows/Host.cpp Fri Aug 8 20:29:07 2014
@@ -25,6 +25,7 @@
#include "lldb/Core/StreamFile.h"
// Windows includes
+#include <shellapi.h>
#include <TlHelp32.h>
using namespace lldb;
@@ -123,6 +124,115 @@ Host::GetOSVersion(uint32_t &major,
}
Error
+Host::MakeDirectory (const char* path, uint32_t mode)
+{
+ // On Win32, the mode parameter is ignored, as Windows files and directories support a
+ // different permission model than POSIX.
+ Error error;
+ if (!::CreateDirectory(path, NULL))
+ error.SetError(::GetLastError(), lldb::eErrorTypeWin32);
+ return error;
+}
+
+Error
+Host::GetFilePermissions (const char* path, uint32_t &file_permissions)
+{
+ Error error;
+ file_permissions = 0;
+ DWORD attrib = ::GetFileAttributes(path);
+ if (attrib == INVALID_FILE_ATTRIBUTES)
+ error.SetError(::GetLastError(), lldb::eErrorTypeWin32);
+ return error;
+}
+
+Error
+Host::SetFilePermissions (const char* path, uint32_t file_permissions)
+{
+ Error error;
+ error.SetErrorStringWithFormat("%s is not supported on this host", __PRETTY_FUNCTION__);
+ return error;
+}
+
+Error
+Host::Symlink (const char *linkname, const char *target)
+{
+ Error error;
+ DWORD attrib = ::GetFileAttributes(target);
+ if (attrib == INVALID_FILE_ATTRIBUTES)
+ {
+ error.SetError(::GetLastError(), lldb::eErrorTypeWin32);
+ return error;
+ }
+ bool is_directory = !!(attrib & FILE_ATTRIBUTE_DIRECTORY);
+ DWORD flag = is_directory ? SYMBOLIC_LINK_FLAG_DIRECTORY : 0;
+ BOOL result = ::CreateSymbolicLink(linkname, target, flag);
+ if (!result)
+ error.SetError(::GetLastError(), lldb::eErrorTypeWin32);
+ return error;
+}
+
+Error
+Host::Readlink (const char *path, char *buf, size_t buf_len)
+{
+ Error error;
+ HANDLE h = ::CreateFile(path, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_OPEN_REPARSE_POINT, NULL);
+ if (h == INVALID_HANDLE_VALUE)
+ {
+ error.SetError(::GetLastError(), lldb::eErrorTypeWin32);
+ return error;
+ }
+
+ // Subtract 1 from the path length since this function does not add a null terminator.
+ DWORD result = ::GetFinalPathNameByHandle(h, buf, buf_len-1, FILE_NAME_NORMALIZED | VOLUME_NAME_DOS);
+ if (result == 0)
+ error.SetError(::GetLastError(), lldb::eErrorTypeWin32);
+
+ ::CloseHandle(h);
+ return error;
+}
+
+Error
+Host::Unlink (const char *path)
+{
+ Error error;
+ BOOL result = ::DeleteFile(path);
+ if (!result)
+ error.SetError(::GetLastError(), lldb::eErrorTypeWin32);
+ return error;
+}
+
+Error
+Host::RemoveDirectory (const char* path, bool recurse)
+{
+ Error error;
+ if (!recurse)
+ {
+ BOOL result = ::RemoveDirectory(path);
+ 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.
+ std::string path_buffer(path);
+ path_buffer.push_back(0);
+
+ SHFILEOPSTRUCT shfos = {0};
+ shfos.wFunc = FO_DELETE;
+ shfos.pFrom = path_buffer.c_str();
+ shfos.fFlags = FOF_NO_UI;
+
+ int result = ::SHFileOperation(&shfos);
+ // TODO(zturner): Correctly handle the intricacies of SHFileOperation return values.
+ if (result != 0)
+ error.SetErrorStringWithFormat("SHFileOperation failed");
+ }
+ return error;
+}
+
+
+Error
Host::LaunchProcess (ProcessLaunchInfo &launch_info)
{
Error error;
More information about the lldb-commits
mailing list