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 bool open = m_pty->GetMode() == PseudoConsole::Mode::ConPTY
38 ? m_pty->GetSTDOUTHandle() != INVALID_HANDLE_VALUE
39 : m_pty->IsConnected();
40 if (!open) {
42 return 0;
43 }
44
45 char *out = static_cast<char *>(dst);
46 size_t bytes_read =
47 ConnectionGenericFile::Read(out, dst_len, timeout, status, error_ptr);
48
49 if (bytes_read > 0) {
52 }
53
54 return bytes_read;
55}
56
57size_t ConnectionConPTY::Write(const void *src, size_t src_len,
59 Status *error_ptr) {
60 if (!m_pty || !m_pty->IsConnected()) {
62 if (error_ptr)
63 *error_ptr = Status::FromErrorString("ConPTY not connected");
64 return 0;
65 }
66 HANDLE stdin_handle = m_pty->GetSTDINHandle();
67 if (stdin_handle == INVALID_HANDLE_VALUE || stdin_handle == nullptr) {
69 if (error_ptr)
70 *error_ptr = Status::FromErrorString("ConPTY STDIN handle is invalid");
71 return 0;
72 }
73 DWORD written = 0;
74 if (!::WriteFile(stdin_handle, src, static_cast<DWORD>(src_len), &written,
75 nullptr)) {
76 DWORD err = ::GetLastError();
77 status = (err == ERROR_BROKEN_PIPE || err == ERROR_NO_DATA)
80 if (error_ptr)
81 *error_ptr = Status(err, lldb::eErrorTypeWin32);
82 return written;
83 }
85 return written;
86}
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.