Skip to content

Commit

Permalink
[lldb] Update Host/windows to new Status API
Browse files Browse the repository at this point in the history
  • Loading branch information
adrian-prantl committed Aug 27, 2024
1 parent 1022323 commit de687ea
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
14 changes: 7 additions & 7 deletions lldb/source/Host/common/Socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ Status SharedSocket::CompleteSending(lldb::pid_t child_pid) {
if (error.Fail())
return error;
if (num_bytes != sizeof(protocol_info))
return Status::FromErrorStringWithFormat(
"WriteWithTimeout(WSAPROTOCOL_INFO) failed: %d bytes", num_bytes);
return Status::FromErrorStringWithFormatv(
"WriteWithTimeout(WSAPROTOCOL_INFO) failed: {0} bytes", num_bytes);
#endif
return Status();
}
Expand All @@ -129,16 +129,16 @@ Status SharedSocket::GetNativeSocket(shared_fd_t fd, NativeSocket &socket) {
if (error.Fail())
return error;
if (num_bytes != sizeof(protocol_info)) {
return Status(
"socket_pipe.ReadWithTimeout(WSAPROTOCOL_INFO) failed: % d bytes",
return Status::FromErrorStringWithFormatv(
"socket_pipe.ReadWithTimeout(WSAPROTOCOL_INFO) failed: {0} bytes",
num_bytes);
}
}
socket = ::WSASocket(FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO,
FROM_PROTOCOL_INFO, &protocol_info, 0, 0);
if (socket == INVALID_SOCKET) {
return Status::FromErrorStringWithFormat(
"WSASocket(FROM_PROTOCOL_INFO) failed: error %d", ::WSAGetLastError());
return Status::FromErrorStringWithFormatv(
"WSASocket(FROM_PROTOCOL_INFO) failed: error {0}", ::WSAGetLastError());
}
return Status();
#else
Expand Down Expand Up @@ -421,7 +421,7 @@ size_t Socket::Send(const void *buf, const size_t num_bytes) {

void Socket::SetLastError(Status &error) {
#if defined(_WIN32)
error.SetError(::WSAGetLastError(), lldb::eErrorTypeWin32);
error = Status(::WSAGetLastError(), lldb::eErrorTypeWin32);
#else
error = Status::FromErrno();
#endif
Expand Down
10 changes: 5 additions & 5 deletions lldb/source/Host/windows/ConnectionGenericFileWindows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace {
class ReturnInfo {
public:
void Set(size_t bytes, ConnectionStatus status, DWORD error_code) {
m_error.SetError(error_code, eErrorTypeWin32);
m_error = Status(error_code, eErrorTypeWin32);
m_bytes = bytes;
m_status = status;
}
Expand Down Expand Up @@ -97,8 +97,8 @@ lldb::ConnectionStatus ConnectionGenericFile::Connect(llvm::StringRef path,

if (!path.consume_front("file://")) {
if (error_ptr)
error_ptr->SetErrorStringWithFormat("unsupported connection URL: '%s'",
path.str().c_str());
*error_ptr = Status::FromErrorStringWithFormat(
"unsupported connection URL: '%s'", path.str().c_str());
return eConnectionStatusError;
}

Expand All @@ -115,15 +115,15 @@ lldb::ConnectionStatus ConnectionGenericFile::Connect(llvm::StringRef path,
std::wstring wpath;
if (!llvm::ConvertUTF8toWide(path, wpath)) {
if (error_ptr)
error_ptr->SetError(1, eErrorTypeGeneric);
*error_ptr = Status(1, eErrorTypeGeneric);
return eConnectionStatusError;
}
m_file = ::CreateFileW(wpath.c_str(), GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ, NULL, OPEN_ALWAYS,
FILE_FLAG_OVERLAPPED, NULL);
if (m_file == INVALID_HANDLE_VALUE) {
if (error_ptr)
error_ptr->SetError(::GetLastError(), eErrorTypeWin32);
*error_ptr = Status(::GetLastError(), eErrorTypeWin32);
return eConnectionStatusError;
}

Expand Down
8 changes: 4 additions & 4 deletions lldb/source/Host/windows/FileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ Status FileSystem::Symlink(const FileSpec &src, const FileSpec &dst) {
return error;
DWORD attrib = ::GetFileAttributesW(wdst.c_str());
if (attrib == INVALID_FILE_ATTRIBUTES) {
error.SetError(::GetLastError(), lldb::eErrorTypeWin32);
error = Status(::GetLastError(), lldb::eErrorTypeWin32);
return error;
}
bool is_directory = !!(attrib & FILE_ATTRIBUTE_DIRECTORY);
DWORD flag = is_directory ? SYMBOLIC_LINK_FLAG_DIRECTORY : 0;
BOOL result = ::CreateSymbolicLinkW(wsrc.c_str(), wdst.c_str(), flag);
if (!result)
error.SetError(::GetLastError(), lldb::eErrorTypeWin32);
error = Status(::GetLastError(), lldb::eErrorTypeWin32);
return error;
}

Expand All @@ -60,7 +60,7 @@ Status FileSystem::Readlink(const FileSpec &src, FileSpec &dst) {
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);
error = Status(::GetLastError(), lldb::eErrorTypeWin32);
return error;
}

Expand All @@ -71,7 +71,7 @@ Status FileSystem::Readlink(const FileSpec &src, FileSpec &dst) {
h, buf.data(), buf.size() - 1, FILE_NAME_NORMALIZED | VOLUME_NAME_DOS);
std::string path;
if (result == 0)
error.SetError(::GetLastError(), lldb::eErrorTypeWin32);
error = Status(::GetLastError(), lldb::eErrorTypeWin32);
else if (!llvm::convertWideToUTF8(buf.data(), path))
error = Status::FromErrorString(PATH_CONVERSION_ERROR);
else
Expand Down
4 changes: 2 additions & 2 deletions lldb/source/Host/windows/HostProcessWindows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ void HostProcessWindows::SetOwnsHandle(bool owns) { m_owns_handle = owns; }
Status HostProcessWindows::Terminate() {
Status error;
if (m_process == nullptr)
error.SetError(ERROR_INVALID_HANDLE, lldb::eErrorTypeWin32);
error = Status(ERROR_INVALID_HANDLE, lldb::eErrorTypeWin32);

if (!::TerminateProcess(m_process, 0))
error.SetError(::GetLastError(), lldb::eErrorTypeWin32);
error = Status(::GetLastError(), lldb::eErrorTypeWin32);

return error;
}
Expand Down
6 changes: 3 additions & 3 deletions lldb/source/Host/windows/HostThreadWindows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ Status HostThreadWindows::Join(lldb::thread_result_t *result) {
*result = 0;
*result = exit_code;
} else if (WAIT_OBJECT_0 != wait_result)
error.SetError(::GetLastError(), eErrorTypeWin32);
error = Status(::GetLastError(), eErrorTypeWin32);
} else
error.SetError(ERROR_INVALID_HANDLE, eErrorTypeWin32);
error = Status(ERROR_INVALID_HANDLE, eErrorTypeWin32);

Reset();
return error;
Expand All @@ -52,7 +52,7 @@ Status HostThreadWindows::Cancel() {
Status error;

DWORD result = ::QueueUserAPC(::ExitThreadProxy, m_thread, 0);
error.SetError(result, eErrorTypeWin32);
error = Status(result, eErrorTypeWin32);
return error;
}

Expand Down

0 comments on commit de687ea

Please sign in to comment.