diff options
author | Paul Maybee <paulmay@microsoft.com> | 2023-07-29 17:23:43 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2023-08-17 14:11:33 (GMT) |
commit | 8b1257e7bf821461e6e0d92bf57e1c4ed885ddf9 (patch) | |
tree | 9ce28af2bff1b6c1d6f97f3e105849d3fe7829f4 /Source/cmDebuggerWindowsPipeConnection.h | |
parent | b0054dd65c1d69a437abe85d27e704326884a9c2 (diff) | |
download | CMake-8b1257e7bf821461e6e0d92bf57e1c4ed885ddf9.zip CMake-8b1257e7bf821461e6e0d92bf57e1c4ed885ddf9.tar.gz CMake-8b1257e7bf821461e6e0d92bf57e1c4ed885ddf9.tar.bz2 |
Debugger: Replace libuv with platform-specific connection code
Remove libuv usage from CMake debugger. Libuv has an async io model
and cppdap uses a sync model, so an extra thread and a buffer copy
were necessary to match semantics. In order to eliminate those
costs this commit implements the IO using platform specific APIs.
Diffstat (limited to 'Source/cmDebuggerWindowsPipeConnection.h')
-rw-r--r-- | Source/cmDebuggerWindowsPipeConnection.h | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/Source/cmDebuggerWindowsPipeConnection.h b/Source/cmDebuggerWindowsPipeConnection.h new file mode 100644 index 0000000..88ed1de --- /dev/null +++ b/Source/cmDebuggerWindowsPipeConnection.h @@ -0,0 +1,101 @@ +/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying + file Copyright.txt or https://cmake.org/licensing for details. */ +#pragma once + +#include "cmConfigure.h" // IWYU pragma: keep + +#include <condition_variable> +#include <cstddef> +#include <future> +#include <memory> +#include <mutex> +#include <string> +#include <thread> + +#include <windows.h> + +#include <cm3p/cppdap/io.h> + +#include "cmDebuggerAdapter.h" + +namespace cmDebugger { + +#ifdef _WIN32 + +class DuplexPipe_WIN32 +{ +public: + DuplexPipe_WIN32(HANDLE read); + ~DuplexPipe_WIN32(); + + void close(); + size_t read(void* buffer, size_t n); + bool write(void const* buffer, size_t n); + + bool WaitForConnection(); + +private: + HANDLE hPipe; + OVERLAPPED readOp; + OVERLAPPED writeOp; +}; + +class cmDebuggerPipeConnection_WIN32 + : public dap::ReaderWriter + , public cmDebuggerConnection + , public std::enable_shared_from_this<cmDebuggerPipeConnection_WIN32> +{ +public: + cmDebuggerPipeConnection_WIN32(std::string name); + ~cmDebuggerPipeConnection_WIN32() override; + + void WaitForConnection() override; + + bool StartListening(std::string& errorMessage) override; + std::shared_ptr<dap::Reader> GetReader() override; + std::shared_ptr<dap::Writer> GetWriter() override; + + // dap::ReaderWriter implementation + + bool isOpen() override; + void close() override; + size_t read(void* buffer, size_t n) override; + bool write(void const* buffer, size_t n) override; + + // Used for unit test synchronization + std::promise<void> StartedListening; + +private: + void CloseConnection(); + std::string GetErrorMessage(DWORD errorCode); + + std::string const PipeName; + std::unique_ptr<DuplexPipe_WIN32> pipes; +}; + +using cmDebuggerPipeConnection = cmDebuggerPipeConnection_WIN32; + +class cmDebuggerPipeClient_WIN32 + : public dap::ReaderWriter + , public std::enable_shared_from_this<cmDebuggerPipeClient_WIN32> +{ +public: + cmDebuggerPipeClient_WIN32(std::string name); + ~cmDebuggerPipeClient_WIN32(); + void WaitForConnection(); + + bool isOpen() override; + void close() override; + size_t read(void* buffer, size_t n) override; + bool write(void const* buffer, size_t n) override; + +private: + std::string const PipeName; + std::unique_ptr<DuplexPipe_WIN32> pipes; +}; + +using cmDebuggerPipeClient = cmDebuggerPipeClient_WIN32; + +#endif // _WIN32 + +} // namespace cmDebugger |