[Lldb-commits] [lldb] [lldb][windows] add a Windows FifoFile implementation (PR #185894)
Charles Zablit via lldb-commits
lldb-commits at lists.llvm.org
Wed Mar 11 10:37:30 PDT 2026
================
@@ -24,17 +28,83 @@ using namespace llvm;
namespace lldb_dap {
-FifoFile::FifoFile(StringRef path) : m_path(path) {}
+FifoFile::FifoFile(StringRef path, lldb::pipe_t pipe) : m_path(path) {
+#ifdef _WIN32
+ if (pipe == INVALID_HANDLE_VALUE)
+ pipe = CreateFileA(m_path.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL,
+ OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);
+#endif
+ m_pipe = pipe;
+}
FifoFile::~FifoFile() {
-#if !defined(_WIN32)
+#ifdef _WIN32
+ if (m_pipe != INVALID_HANDLE_VALUE) {
+ DisconnectNamedPipe(m_pipe);
+ CloseHandle(m_pipe);
+ }
+#else
unlink(m_path.c_str());
#endif
}
+void FifoFile::WriteLine(std::string line) {
+#ifdef _WIN32
+ DWORD written;
+ line += "\n";
+ WriteFile(m_pipe, line.c_str(), static_cast<DWORD>(line.size()), &written,
+ NULL);
+ FlushFileBuffers(m_pipe);
+#else
+ std::ofstream writer(m_path, std::ofstream::out);
+ writer << line << std::endl;
+#endif
+}
+
+void FifoFile::Connect() {
+#ifdef _WIN32
+ ConnectNamedPipe(m_pipe, NULL);
+#endif
+}
+
+std::string FifoFile::ReadLine() {
+#ifdef _WIN32
+ std::string buffer;
+ char read_buffer[4096];
+ DWORD bytes_read;
+
+ if (ReadFile(m_pipe, read_buffer, sizeof(read_buffer) - 1, &bytes_read,
+ NULL) &&
+ bytes_read > 0) {
+ read_buffer[bytes_read] = '\0';
+ buffer = read_buffer;
+ }
----------------
charles-zablit wrote:
For our usage in https://github.com/llvm/llvm-project/pull/174635 this will never be a problem given the size of the json data (100 chars at most).
I have added a read loop in case this ends up being used by something else later.
https://github.com/llvm/llvm-project/pull/185894
More information about the lldb-commits
mailing list