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, NULL);
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), NULL, TRUE};
82 CreateFileW(pipe_name, GENERIC_WRITE, 0, inheritable ? &write_sa : NULL,
83 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
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();
102 "Attempted to open a PseudoConsole in a different mode than None");
105 return llvm::make_error<llvm::StringError>(
"ConPTY is not available",
106 llvm::errc::io_error);
109 "ConPTY has already been opened");
113 wchar_t pipe_name[MAX_PATH];
114 swprintf(pipe_name, MAX_PATH, L
"\\\\.\\pipe\\conpty-lldb-%d-%p",
115 GetCurrentProcessId(),
this);
116 HANDLE hOutputRead = INVALID_HANDLE_VALUE;
117 HANDLE hOutputWrite = INVALID_HANDLE_VALUE;
121 HANDLE hInputRead = INVALID_HANDLE_VALUE;
122 HANDLE hInputWrite = INVALID_HANDLE_VALUE;
123 if (!CreatePipe(&hInputRead, &hInputWrite, NULL, 0)) {
124 CloseHandle(hOutputRead);
125 CloseHandle(hOutputWrite);
126 return llvm::errorCodeToError(
127 std::error_code(GetLastError(), std::system_category()));
130 COORD consoleSize{80, 25};
134 int cursorRow = consoleSize.Y;
136 CONSOLE_SCREEN_BUFFER_INFO csbi;
137 if (GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi)) {
139 static_cast<SHORT
>(csbi.srWindow.Right - csbi.srWindow.Left + 1),
140 static_cast<SHORT
>(csbi.srWindow.Bottom - csbi.srWindow.Top + 1)};
141 cursorRow = csbi.dwCursorPosition.Y - csbi.srWindow.Top + 1;
142 cursorCol = csbi.dwCursorPosition.X + 1;
144 HPCON hPC = INVALID_HANDLE_VALUE;
146 kernel32.CreatePseudoConsole(consoleSize, hInputRead, hOutputWrite,
148 CloseHandle(hInputRead);
149 CloseHandle(hOutputWrite);
152 CloseHandle(hInputWrite);
153 CloseHandle(hOutputRead);
154 return llvm::make_error<llvm::StringError>(
155 "Failed to create Windows ConPTY pseudo terminal",
156 llvm::errc::io_error);
169 llvm::SmallString<32> response =
170 llvm::formatv(
"\x1b[{0};{1}R", cursorRow, cursorCol).sstr<32>();
172 WriteFile(
m_conpty_input, response.data(), response.size(), &nwritten,
176 return llvm::Error::success();
220 "Attempted to open a AnonymousPipes in a different mode than None");
222 SECURITY_ATTRIBUTES sa = {
sizeof(SECURITY_ATTRIBUTES), NULL, TRUE};
223 HANDLE hStdinRead = INVALID_HANDLE_VALUE;
224 HANDLE hStdinWrite = INVALID_HANDLE_VALUE;
225 if (!CreatePipe(&hStdinRead, &hStdinWrite, &sa, 0))
226 return llvm::errorCodeToError(
227 std::error_code(GetLastError(), std::system_category()));
229 SetHandleInformation(hStdinWrite, HANDLE_FLAG_INHERIT, 0);
231 HANDLE hStdoutRead = INVALID_HANDLE_VALUE;
232 HANDLE hStdoutWrite = INVALID_HANDLE_VALUE;
234 CloseHandle(hStdinRead);
235 CloseHandle(hStdinWrite);
244 return llvm::Error::success();