labath created this revision. labath added a reviewer: JDevlieghere. Herald added a subscriber: mgorny. Herald added a project: LLDB. labath requested review of this revision.
This is essentially a replacement for the PacketUnimplementedError previously present in the gdb-remote server code. The reason I am introducing a generic error is because I wanted the native process classes to be able to signal that they do not support some functionality. They could not use PacketUnimplementedError as they are independent of a specific transport protocol. Putting the error class in the the native process code was also not ideal because the gdb-remote code is also used for lldb-server's platform mode, which does not (should not) know how to debug individual processes. I'm putting it under Utility, as I think it can be generally useful for notifying about unsupported/unimplemented functionality (and in particular, for programatically testing whether something is unsupported). Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D89121 Files: lldb/include/lldb/Utility/UnimplementedError.h lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp lldb/source/Utility/CMakeLists.txt lldb/source/Utility/UnimplementedError.cpp lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationServerTest.cpp
Index: lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationServerTest.cpp =================================================================== --- lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationServerTest.cpp +++ 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<PacketUnimplementedError>("Test unimplemented error"); + auto error = llvm::make_error<UnimplementedError>(); 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<PacketUnimplementedError>(), - llvm::make_error<PacketUnimplementedError>()); + auto error = llvm::joinErrors(llvm::make_error<UnimplementedError>(), + llvm::make_error<UnimplementedError>()); server.SendErrorResponse(std::move(error)); // Make sure only one packet is sent even when there are multiple errors. Index: lldb/source/Utility/UnimplementedError.cpp =================================================================== --- /dev/null +++ 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; Index: lldb/source/Utility/CMakeLists.txt =================================================================== --- lldb/source/Utility/CMakeLists.txt +++ lldb/source/Utility/CMakeLists.txt @@ -65,6 +65,7 @@ StructuredData.cpp TildeExpressionResolver.cpp Timer.cpp + UnimplementedError.cpp UUID.cpp UriParser.cpp UserID.cpp Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp =================================================================== --- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp +++ 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 <chrono> #include <cstring> #include <thread> +#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<PacketUnimplementedError>( - "Xfer object not supported"); + return llvm::make_error<UnimplementedError>(); } GDBRemoteCommunication::PacketResult Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h =================================================================== --- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h +++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h @@ -79,18 +79,6 @@ operator=(const GDBRemoteCommunicationServer &) = delete; }; -class PacketUnimplementedError - : public llvm::ErrorInfo<PacketUnimplementedError, llvm::StringError> { -public: - static char ID; - using llvm::ErrorInfo<PacketUnimplementedError, - llvm::StringError>::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 Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp =================================================================== --- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp +++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp @@ -12,11 +12,11 @@ #include "GDBRemoteCommunicationServer.h" -#include <cstring> - #include "ProcessGDBRemoteLog.h" #include "lldb/Utility/StreamString.h" #include "lldb/Utility/StringExtractorGDBRemote.h" +#include "lldb/Utility/UnimplementedError.h" +#include <cstring> using namespace lldb; using namespace lldb_private; @@ -113,18 +113,17 @@ GDBRemoteCommunication::PacketResult GDBRemoteCommunicationServer::SendErrorResponse(llvm::Error error) { + assert(error); std::unique_ptr<llvm::ErrorInfoBase> EIB; - std::unique_ptr<PacketUnimplementedError> PUE; + std::unique_ptr<UnimplementedError> UE; llvm::handleAllErrors( std::move(error), - [&](std::unique_ptr<PacketUnimplementedError> E) { PUE = std::move(E); }, + [&](std::unique_ptr<UnimplementedError> E) { UE = std::move(E); }, [&](std::unique_ptr<llvm::ErrorInfoBase> 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; Index: lldb/include/lldb/Utility/UnimplementedError.h =================================================================== --- /dev/null +++ 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<UnimplementedError> { +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
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits