From 0b57cec536236d46e3dba9bd041533462f33dbb7 Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Fri, 20 Dec 2019 19:53:05 +0000 Subject: Move all sources from the llvm project into contrib/llvm-project. This uses the new layout of the upstream repository, which was recently migrated to GitHub, and converted into a "monorepo". That is, most of the earlier separate sub-projects with their own branches and tags were consolidated into one top-level directory, and are now branched and tagged together. Updating the vendor area to match this layout is next. --- .../gdb-remote/GDBRemoteCommunicationServer.cpp | 158 --------------------- 1 file changed, 158 deletions(-) delete mode 100644 contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp (limited to 'contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp') diff --git a/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp b/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp deleted file mode 100644 index 49cbeb023fd5..000000000000 --- a/contrib/llvm/tools/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp +++ /dev/null @@ -1,158 +0,0 @@ -//===-- GDBRemoteCommunicationServer.cpp ------------------------*- 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 -// -//===----------------------------------------------------------------------===// - -#include - -#include "lldb/Host/Config.h" - -#include "GDBRemoteCommunicationServer.h" - -#include - -#include "ProcessGDBRemoteLog.h" -#include "lldb/Utility/StreamString.h" -#include "lldb/Utility/StringExtractorGDBRemote.h" - -using namespace lldb; -using namespace lldb_private; -using namespace lldb_private::process_gdb_remote; - -GDBRemoteCommunicationServer::GDBRemoteCommunicationServer( - const char *comm_name, const char *listener_name) - : GDBRemoteCommunication(comm_name, listener_name), m_exit_now(false) { - RegisterPacketHandler( - StringExtractorGDBRemote::eServerPacketType_QEnableErrorStrings, - [this](StringExtractorGDBRemote packet, Status &error, bool &interrupt, - bool &quit) { return this->Handle_QErrorStringEnable(packet); }); -} - -GDBRemoteCommunicationServer::~GDBRemoteCommunicationServer() {} - -void GDBRemoteCommunicationServer::RegisterPacketHandler( - StringExtractorGDBRemote::ServerPacketType packet_type, - PacketHandler handler) { - m_packet_handlers[packet_type] = std::move(handler); -} - -GDBRemoteCommunication::PacketResult -GDBRemoteCommunicationServer::GetPacketAndSendResponse( - Timeout timeout, Status &error, bool &interrupt, bool &quit) { - StringExtractorGDBRemote packet; - - PacketResult packet_result = WaitForPacketNoLock(packet, timeout, false); - if (packet_result == PacketResult::Success) { - const StringExtractorGDBRemote::ServerPacketType packet_type = - packet.GetServerPacketType(); - switch (packet_type) { - case StringExtractorGDBRemote::eServerPacketType_nack: - case StringExtractorGDBRemote::eServerPacketType_ack: - break; - - case StringExtractorGDBRemote::eServerPacketType_invalid: - error.SetErrorString("invalid packet"); - quit = true; - break; - - case StringExtractorGDBRemote::eServerPacketType_unimplemented: - packet_result = SendUnimplementedResponse(packet.GetStringRef().c_str()); - break; - - default: - auto handler_it = m_packet_handlers.find(packet_type); - if (handler_it == m_packet_handlers.end()) - packet_result = - SendUnimplementedResponse(packet.GetStringRef().c_str()); - else - packet_result = handler_it->second(packet, error, interrupt, quit); - break; - } - } else { - if (!IsConnected()) { - error.SetErrorString("lost connection"); - quit = true; - } else { - error.SetErrorString("timeout"); - } - } - - // Check if anything occurred that would force us to want to exit. - if (m_exit_now) - quit = true; - - return packet_result; -} - -GDBRemoteCommunication::PacketResult -GDBRemoteCommunicationServer::SendUnimplementedResponse(const char *) { - // TODO: Log the packet we aren't handling... - return SendPacketNoLock(""); -} - -GDBRemoteCommunication::PacketResult -GDBRemoteCommunicationServer::SendErrorResponse(uint8_t err) { - char packet[16]; - int packet_len = ::snprintf(packet, sizeof(packet), "E%2.2x", err); - assert(packet_len < (int)sizeof(packet)); - return SendPacketNoLock(llvm::StringRef(packet, packet_len)); -} - -GDBRemoteCommunication::PacketResult -GDBRemoteCommunicationServer::SendErrorResponse(const Status &error) { - if (m_send_error_strings) { - lldb_private::StreamString packet; - packet.Printf("E%2.2x;", static_cast(error.GetError())); - packet.PutStringAsRawHex8(error.AsCString()); - return SendPacketNoLock(packet.GetString()); - } else - return SendErrorResponse(error.GetError()); -} - -GDBRemoteCommunication::PacketResult -GDBRemoteCommunicationServer::SendErrorResponse(llvm::Error error) { - std::unique_ptr EIB; - std::unique_ptr PUE; - llvm::handleAllErrors( - std::move(error), - [&](std::unique_ptr E) { PUE = 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")); -} - -GDBRemoteCommunication::PacketResult -GDBRemoteCommunicationServer::Handle_QErrorStringEnable( - StringExtractorGDBRemote &packet) { - m_send_error_strings = true; - return SendOKResponse(); -} - -GDBRemoteCommunication::PacketResult -GDBRemoteCommunicationServer::SendIllFormedResponse( - const StringExtractorGDBRemote &failed_packet, const char *message) { - Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PACKETS)); - if (log) - log->Printf("GDBRemoteCommunicationServer::%s: ILLFORMED: '%s' (%s)", - __FUNCTION__, failed_packet.GetStringRef().c_str(), - message ? message : ""); - return SendErrorResponse(0x03); -} - -GDBRemoteCommunication::PacketResult -GDBRemoteCommunicationServer::SendOKResponse() { - return SendPacketNoLock("OK"); -} - -bool GDBRemoteCommunicationServer::HandshakeWithClient() { - return GetAck() == PacketResult::Success; -} - -char PacketUnimplementedError::ID; -- cgit v1.2.3