LLDB mainline
ConnectionConPTYWindows.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
10#include "lldb/Utility/Status.h"
12
13using namespace lldb;
14using namespace lldb_private;
15
16ConnectionConPTY::ConnectionConPTY(std::shared_ptr<PseudoConsole> pty)
17 : ConnectionGenericFile(pty->GetSTDOUTHandle(), false), m_pty(pty) {}
18
20
22 Status *error_ptr) {
23 if (m_pty->IsConnected())
26}
27
32
33size_t ConnectionConPTY::Read(void *dst, size_t dst_len,
34 const Timeout<std::micro> &timeout,
36 Status *error_ptr) {
37 {
38 std::unique_lock<std::mutex> guard(m_pty->GetMutex());
39 if (m_pty->IsStopping())
40 m_pty->GetCV().wait(guard, [this] { return !m_pty->IsStopping(); });
41 if (!m_pty->IsConnected()) {
43 return 0;
44 }
45 }
46
47 char *out = static_cast<char *>(dst);
48 size_t bytes_read =
49 ConnectionGenericFile::Read(out, dst_len, timeout, status, error_ptr);
50
51 if (bytes_read > 0) {
54 }
55
56 return bytes_read;
57}
58
59size_t ConnectionConPTY::Write(const void *src, size_t src_len,
61 Status *error_ptr) {
62 if (!m_pty || !m_pty->IsConnected()) {
64 if (error_ptr)
65 *error_ptr = Status::FromErrorString("ConPTY not connected");
66 return 0;
67 }
68 HANDLE stdin_handle = m_pty->GetSTDINHandle();
69 if (stdin_handle == INVALID_HANDLE_VALUE || stdin_handle == nullptr) {
71 if (error_ptr)
72 *error_ptr = Status::FromErrorString("ConPTY STDIN handle is invalid");
73 return 0;
74 }
75 DWORD written = 0;
76 if (!::WriteFile(stdin_handle, src, static_cast<DWORD>(src_len), &written,
77 nullptr)) {
78 DWORD err = ::GetLastError();
79 status = (err == ERROR_BROKEN_PIPE || err == ERROR_NO_DATA)
82 if (error_ptr)
83 *error_ptr = Status(err, lldb::eErrorTypeWin32);
84 return written;
85 }
87 return written;
88}
void * HANDLE
lldb::ConnectionStatus Disconnect(Status *error_ptr) override
Disconnect the communications connection if one is currently connected.
size_t Write(const void *src, size_t src_len, lldb::ConnectionStatus &status, Status *error_ptr) override
The actual write function that attempts to write to the communications protocol.
ConnectionConPTY(std::shared_ptr< PseudoConsole > pty)
size_t Read(void *dst, size_t dst_len, const Timeout< std::micro > &timeout, lldb::ConnectionStatus &status, Status *error_ptr) override
Read from the ConPTY's pipe.
std::shared_ptr< PseudoConsole > m_pty
lldb::ConnectionStatus Connect(llvm::StringRef s, Status *error_ptr) override
Connect using the connect string url.
size_t Read(void *dst, size_t dst_len, const Timeout< std::micro > &timeout, lldb::ConnectionStatus &status, Status *error_ptr) override
The read function that attempts to read from the connection.
An error handling class.
Definition Status.h:118
static Status FromErrorString(const char *str)
Definition Status.h:141
A class that represents a running process on the host machine.
void StripConPTYSequences(void *data, size_t &len, bool strip_init)
Remove ConPTY management sequences from a buffer in-place.
ConnectionStatus
Connection Status Types.
@ eConnectionStatusError
Check GetError() for details.
@ eConnectionStatusEndOfFile
End-of-file encountered.
@ eConnectionStatusSuccess
Success.
@ eConnectionStatusNoConnection
No connection.
@ eErrorTypeWin32
Standard Win32 error codes.