diff options
author | Brad King <brad.king@kitware.com> | 2023-09-11 12:12:10 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2023-09-11 12:12:29 (GMT) |
commit | b1cb23a011a8ffbcbb648abed36dc73491767ea5 (patch) | |
tree | 4beb7fa0462c3e1054fd6e22bedb578c0533ea90 /Source | |
parent | 4bd020d952a47f74785ed9d3dc13b66fc7c613d2 (diff) | |
parent | cd46ecad1910fae22c93f02b108e70c4e0a2a8ea (diff) | |
download | CMake-b1cb23a011a8ffbcbb648abed36dc73491767ea5.zip CMake-b1cb23a011a8ffbcbb648abed36dc73491767ea5.tar.gz CMake-b1cb23a011a8ffbcbb648abed36dc73491767ea5.tar.bz2 |
Merge topic 'fix-win-dbg-msg'
cd46ecad19 Debugger: Fix pipe connection error message construction on Windows
Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Merge-request: !8785
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmDebuggerWindowsPipeConnection.cxx | 17 | ||||
-rw-r--r-- | Source/cmDebuggerWindowsPipeConnection.h | 2 |
2 files changed, 18 insertions, 1 deletions
diff --git a/Source/cmDebuggerWindowsPipeConnection.cxx b/Source/cmDebuggerWindowsPipeConnection.cxx index 1c6a2a7..5f6f848 100644 --- a/Source/cmDebuggerWindowsPipeConnection.cxx +++ b/Source/cmDebuggerWindowsPipeConnection.cxx @@ -221,13 +221,28 @@ void cmDebuggerPipeClient_WIN32::WaitForConnection() NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL); if (hPipe == INVALID_HANDLE_VALUE) { auto err = GetLastError(); - throw std::runtime_error("CreateFile failed with " + err); + throw std::runtime_error(std::string("CreateFile failed for pipe ") + + GetErrorMessage(err)); } pipes = std::make_unique<DuplexPipe_WIN32>(hPipe); } } +std::string cmDebuggerPipeClient_WIN32::GetErrorMessage(DWORD errorCode) +{ + LPSTR message = nullptr; + DWORD size = FormatMessageA( + FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + nullptr, errorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPSTR)&message, 0, nullptr); + std::string errorMessage = + this->PipeName + ": " + std::string(message, size); + LocalFree(message); + return errorMessage; +} + bool cmDebuggerPipeClient_WIN32::isOpen() { return pipes != nullptr; diff --git a/Source/cmDebuggerWindowsPipeConnection.h b/Source/cmDebuggerWindowsPipeConnection.h index 88ed1de..6a57435 100644 --- a/Source/cmDebuggerWindowsPipeConnection.h +++ b/Source/cmDebuggerWindowsPipeConnection.h @@ -90,6 +90,8 @@ public: bool write(void const* buffer, size_t n) override; private: + std::string GetErrorMessage(DWORD errorCode); + std::string const PipeName; std::unique_ptr<DuplexPipe_WIN32> pipes; }; |