71 wchar_t pipe_name[MAX_PATH];
72 swprintf(pipe_name, MAX_PATH, L
"\\\\.\\pipe\\conpty-lldb-%d-%p",
73 GetCurrentProcessId(),
this);
75 CreateNamedPipeW(pipe_name, PIPE_ACCESS_INBOUND | FILE_FLAG_OVERLAPPED,
76 PIPE_TYPE_BYTE | PIPE_WAIT, 1, 4096, 4096, 0,
nullptr);
77 if (out_read == INVALID_HANDLE_VALUE)
78 return llvm::errorCodeToError(
79 std::error_code(GetLastError(), std::system_category()));
80 SECURITY_ATTRIBUTES write_sa = {
sizeof(SECURITY_ATTRIBUTES),
nullptr, TRUE};
81 out_write = CreateFileW(pipe_name, GENERIC_WRITE, 0,
82 inheritable ? &write_sa :
nullptr, OPEN_EXISTING,
83 FILE_ATTRIBUTE_NORMAL,
nullptr);
84 if (out_write == INVALID_HANDLE_VALUE) {
85 CloseHandle(out_read);
86 out_read = INVALID_HANDLE_VALUE;
87 return llvm::errorCodeToError(
88 std::error_code(GetLastError(), std::system_category()));
91 return llvm::Error::success();
101 return llvm::make_error<llvm::StringError>(
"ConPTY is not available",
102 llvm::errc::io_error);
105 wchar_t pipe_name[MAX_PATH];
106 swprintf(pipe_name, MAX_PATH, L
"\\\\.\\pipe\\conpty-lldb-%d-%p",
107 GetCurrentProcessId(),
this);
108 HANDLE hOutputRead = INVALID_HANDLE_VALUE;
109 HANDLE hOutputWrite = INVALID_HANDLE_VALUE;
113 HANDLE hInputRead = INVALID_HANDLE_VALUE;
114 HANDLE hInputWrite = INVALID_HANDLE_VALUE;
115 if (!CreatePipe(&hInputRead, &hInputWrite,
nullptr, 0)) {
116 CloseHandle(hOutputRead);
117 CloseHandle(hOutputWrite);
118 return llvm::errorCodeToError(
119 std::error_code(GetLastError(), std::system_category()));
122 COORD consoleSize{80, 25};
126 int cursorRow = consoleSize.Y;
128 if (req_cols != 0 && req_rows != 0) {
129 consoleSize = {
static_cast<SHORT
>(req_cols),
static_cast<SHORT
>(req_rows)};
130 cursorRow = consoleSize.Y;
133 CONSOLE_SCREEN_BUFFER_INFO csbi;
134 if (GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi)) {
136 static_cast<SHORT
>(csbi.srWindow.Right - csbi.srWindow.Left + 1),
137 static_cast<SHORT
>(csbi.srWindow.Bottom - csbi.srWindow.Top + 1)};
138 cursorRow = csbi.dwCursorPosition.Y - csbi.srWindow.Top + 1;
139 cursorCol = csbi.dwCursorPosition.X + 1;
142 HPCON hPC = INVALID_HANDLE_VALUE;
144 kernel32.CreatePseudoConsole(consoleSize, hInputRead, hOutputWrite,
146 CloseHandle(hInputRead);
147 CloseHandle(hOutputWrite);
150 CloseHandle(hInputWrite);
151 CloseHandle(hOutputRead);
152 return llvm::make_error<llvm::StringError>(
153 "Failed to create Windows ConPTY pseudo terminal",
154 llvm::errc::io_error);
167 llvm::SmallString<32> response =
168 llvm::formatv(
"\x1b[{0};{1}R", cursorRow, cursorCol).sstr<32>();
170 WriteFile(
m_conpty_input, response.data(), response.size(), &nwritten,
174 return llvm::Error::success();
228 SECURITY_ATTRIBUTES sa = {
sizeof(SECURITY_ATTRIBUTES),
nullptr, TRUE};
229 HANDLE hStdinRead = INVALID_HANDLE_VALUE;
230 HANDLE hStdinWrite = INVALID_HANDLE_VALUE;
231 if (!CreatePipe(&hStdinRead, &hStdinWrite, &sa, 0))
232 return llvm::errorCodeToError(
233 std::error_code(GetLastError(), std::system_category()));
235 SetHandleInformation(hStdinWrite, HANDLE_FLAG_INHERIT, 0);
237 HANDLE hStdoutRead = INVALID_HANDLE_VALUE;
238 HANDLE hStdoutWrite = INVALID_HANDLE_VALUE;
240 CloseHandle(hStdinRead);
241 CloseHandle(hStdinWrite);
250 return llvm::Error::success();