diff --git a/lldb/include/lldb/Utility/UnimplementedError.h b/lldb/include/lldb/Utility/UnimplementedError.h new file mode 100644 --- /dev/null +++ b/lldb/include/lldb/Utility/UnimplementedError.h @@ -0,0 +1,28 @@ +//===-- UnimplementedError.h ------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLDB_UTILITY_UNIMPLEMENTEDERROR_H +#define LLDB_UTILITY_UNIMPLEMENTEDERROR_H + +#include "llvm/Support/Errc.h" +#include "llvm/Support/Error.h" + +namespace lldb_private { +class UnimplementedError : public llvm::ErrorInfo { +public: + static char ID; + + void log(llvm::raw_ostream &OS) const override { OS << "Not implemented"; } + + std::error_code convertToErrorCode() const override { + return llvm::errc::not_supported; + }; +}; +} // namespace lldb_private + +#endif // LLDB_UTILITY_UNIMPLEMENTEDERROR_H diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h @@ -79,18 +79,6 @@ operator=(const GDBRemoteCommunicationServer &) = delete; }; -class PacketUnimplementedError - : public llvm::ErrorInfo { -public: - static char ID; - using llvm::ErrorInfo::ErrorInfo; // inherit constructors - PacketUnimplementedError(const llvm::Twine &S) - : ErrorInfo(S, llvm::errc::not_supported) {} - - PacketUnimplementedError() : ErrorInfo(llvm::errc::not_supported) {} -}; - } // namespace process_gdb_remote } // namespace lldb_private diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp @@ -12,11 +12,11 @@ #include "GDBRemoteCommunicationServer.h" -#include - #include "ProcessGDBRemoteLog.h" #include "lldb/Utility/StreamString.h" #include "lldb/Utility/StringExtractorGDBRemote.h" +#include "lldb/Utility/UnimplementedError.h" +#include using namespace lldb; using namespace lldb_private; @@ -113,18 +113,17 @@ GDBRemoteCommunication::PacketResult GDBRemoteCommunicationServer::SendErrorResponse(llvm::Error error) { + assert(error); std::unique_ptr EIB; - std::unique_ptr PUE; + std::unique_ptr UE; llvm::handleAllErrors( std::move(error), - [&](std::unique_ptr E) { PUE = std::move(E); }, + [&](std::unique_ptr E) { UE = std::move(E); }, [&](std::unique_ptr E) { EIB = std::move(E); }); if (EIB) return SendErrorResponse(Status(llvm::Error(std::move(EIB)))); - if (PUE) - return SendUnimplementedResponse(PUE->message().c_str()); - return SendErrorResponse(Status("Unknown Error")); + return SendUnimplementedResponse(""); } GDBRemoteCommunication::PacketResult @@ -152,5 +151,3 @@ bool GDBRemoteCommunicationServer::HandshakeWithClient() { return GetAck() == PacketResult::Success; } - -char PacketUnimplementedError::ID; diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp @@ -10,13 +10,12 @@ #include "lldb/Host/Config.h" -#include "GDBRemoteCommunicationServerLLGS.h" -#include "lldb/Utility/GDBRemote.h" #include #include #include +#include "GDBRemoteCommunicationServerLLGS.h" #include "lldb/Host/ConnectionFileDescriptor.h" #include "lldb/Host/Debug.h" #include "lldb/Host/File.h" @@ -32,11 +31,13 @@ #include "lldb/Utility/Args.h" #include "lldb/Utility/DataBuffer.h" #include "lldb/Utility/Endian.h" +#include "lldb/Utility/GDBRemote.h" #include "lldb/Utility/LLDBAssert.h" #include "lldb/Utility/Log.h" #include "lldb/Utility/RegisterValue.h" #include "lldb/Utility/State.h" #include "lldb/Utility/StreamString.h" +#include "lldb/Utility/UnimplementedError.h" #include "lldb/Utility/UriParser.h" #include "llvm/ADT/Triple.h" #include "llvm/Support/JSON.h" @@ -2876,8 +2877,7 @@ if (object == "features" && annex == "target.xml") return BuildTargetXml(); - return llvm::make_error( - "Xfer object not supported"); + return llvm::make_error(); } GDBRemoteCommunication::PacketResult diff --git a/lldb/source/Utility/CMakeLists.txt b/lldb/source/Utility/CMakeLists.txt --- a/lldb/source/Utility/CMakeLists.txt +++ b/lldb/source/Utility/CMakeLists.txt @@ -65,6 +65,7 @@ StructuredData.cpp TildeExpressionResolver.cpp Timer.cpp + UnimplementedError.cpp UUID.cpp UriParser.cpp UserID.cpp diff --git a/lldb/source/Utility/UnimplementedError.cpp b/lldb/source/Utility/UnimplementedError.cpp new file mode 100644 --- /dev/null +++ b/lldb/source/Utility/UnimplementedError.cpp @@ -0,0 +1,11 @@ +//===-- UnimplementedError.cpp --------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "lldb/Utility/UnimplementedError.h" + +char lldb_private::UnimplementedError::ID; diff --git a/lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationServerTest.cpp b/lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationServerTest.cpp --- a/lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationServerTest.cpp +++ b/lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationServerTest.cpp @@ -9,9 +9,9 @@ #include "gtest/gtest.h" #include "GDBRemoteTestUtils.h" - #include "Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h" #include "lldb/Utility/Connection.h" +#include "lldb/Utility/UnimplementedError.h" namespace lldb_private { namespace process_gdb_remote { @@ -39,8 +39,7 @@ TEST(GDBRemoteCommunicationServerTest, SendErrorResponse_UnimplementedError) { MockServerWithMockConnection server; - auto error = - llvm::make_error("Test unimplemented error"); + auto error = llvm::make_error(); server.SendErrorResponse(std::move(error)); EXPECT_THAT(server.GetPackets(), testing::ElementsAre("$#00")); @@ -61,8 +60,8 @@ TEST(GDBRemoteCommunicationServerTest, SendErrorResponse_ErrorList) { MockServerWithMockConnection server; - auto error = llvm::joinErrors(llvm::make_error(), - llvm::make_error()); + auto error = llvm::joinErrors(llvm::make_error(), + llvm::make_error()); server.SendErrorResponse(std::move(error)); // Make sure only one packet is sent even when there are multiple errors.