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
13#include <cstring>
14
15using namespace lldb;
16using namespace lldb_private;
17
18ConnectionConPTY::ConnectionConPTY(std::shared_ptr<PseudoConsole> pty)
19 : ConnectionGenericFile(pty->GetSTDOUTHandle(), false), m_pty(pty) {}
20
22
24 Status *error_ptr) {
25 if (m_pty->IsConnected())
28}
29
34
35size_t ConnectionConPTY::Read(void *dst, size_t dst_len,
36 const Timeout<std::micro> &timeout,
38 Status *error_ptr) {
39 {
40 std::unique_lock<std::mutex> guard(m_pty->GetMutex());
41 if (m_pty->IsStopping())
42 m_pty->GetCV().wait(guard, [this] { return !m_pty->IsStopping(); });
43 if (!m_pty->IsConnected()) {
45 return 0;
46 }
47 }
48
49 char *out = static_cast<char *>(dst);
50 size_t bytes_read =
51 ConnectionGenericFile::Read(out, dst_len, timeout, status, error_ptr);
52
53 if (bytes_read > 0) {
56 }
57
58 return bytes_read;
59}
60
61size_t ConnectionConPTY::Write(const void *src, size_t src_len,
63 Status *error_ptr) {
64 if (!m_pty || !m_pty->IsConnected()) {
66 if (error_ptr)
67 *error_ptr = Status::FromErrorString("ConPTY not connected");
68 return 0;
69 }
70 HANDLE stdin_handle = m_pty->GetSTDINHandle();
71 if (stdin_handle == INVALID_HANDLE_VALUE || stdin_handle == nullptr) {
73 if (error_ptr)
74 *error_ptr = Status::FromErrorString("ConPTY STDIN handle is invalid");
75 return 0;
76 }
77 DWORD written = 0;
78 if (!::WriteFile(stdin_handle, src, static_cast<DWORD>(src_len), &written,
79 nullptr)) {
80 DWORD err = ::GetLastError();
81 status = (err == ERROR_BROKEN_PIPE || err == ERROR_NO_DATA)
84 if (error_ptr)
85 *error_ptr = Status(err, lldb::eErrorTypeWin32);
86 return written;
87 }
89 return written;
90}
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.