[Lldb-commits] [lldb] a8ae682 - [lldb] Delete GDBRemoteCommunicationReplayServer
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Mon Jan 3 07:14:39 PST 2022
Author: Pavel Labath
Date: 2022-01-03T16:13:57+01:00
New Revision: a8ae6828a98dcd5ea083eb07be8ad6db77b688a2
URL: https://github.com/llvm/llvm-project/commit/a8ae6828a98dcd5ea083eb07be8ad6db77b688a2
DIFF: https://github.com/llvm/llvm-project/commit/a8ae6828a98dcd5ea083eb07be8ad6db77b688a2.diff
LOG: [lldb] Delete GDBRemoteCommunicationReplayServer
This survived the reproducer deletion.
Added:
Modified:
lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h
lldb/source/Plugins/Process/gdb-remote/CMakeLists.txt
lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
Removed:
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationReplayServer.cpp
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationReplayServer.h
################################################################################
diff --git a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h
index f594f43b3f136..425839c883a44 100644
--- a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h
+++ b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.h
@@ -14,7 +14,6 @@
#include "Plugins/Process/Utility/GDBRemoteSignals.h"
#include "Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h"
-#include "Plugins/Process/gdb-remote/GDBRemoteCommunicationReplayServer.h"
#include "lldb/Target/Platform.h"
namespace lldb_private {
@@ -155,7 +154,6 @@ class PlatformRemoteGDBServer : public Platform, private UserIDResolver {
protected:
process_gdb_remote::GDBRemoteCommunicationClient m_gdb_client;
- process_gdb_remote::GDBRemoteCommunicationReplayServer m_gdb_replay_server;
std::string m_platform_description; // After we connect we can get a more
// complete description of what we are
// connected to
diff --git a/lldb/source/Plugins/Process/gdb-remote/CMakeLists.txt b/lldb/source/Plugins/Process/gdb-remote/CMakeLists.txt
index 448d032b381f1..d578033e1c414 100644
--- a/lldb/source/Plugins/Process/gdb-remote/CMakeLists.txt
+++ b/lldb/source/Plugins/Process/gdb-remote/CMakeLists.txt
@@ -20,7 +20,6 @@ add_lldb_library(lldbPluginProcessGDBRemote PLUGIN
GDBRemoteCommunication.cpp
GDBRemoteCommunicationClient.cpp
GDBRemoteCommunicationHistory.cpp
- GDBRemoteCommunicationReplayServer.cpp
GDBRemoteCommunicationServer.cpp
GDBRemoteCommunicationServerCommon.cpp
GDBRemoteCommunicationServerLLGS.cpp
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationReplayServer.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationReplayServer.cpp
deleted file mode 100644
index c91d7cb5ac30f..0000000000000
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationReplayServer.cpp
+++ /dev/null
@@ -1,314 +0,0 @@
-//===-- GDBRemoteCommunicationReplayServer.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 <cerrno>
-
-#include "lldb/Host/Config.h"
-#include "llvm/ADT/ScopeExit.h"
-
-#include "GDBRemoteCommunicationReplayServer.h"
-#include "ProcessGDBRemoteLog.h"
-
-// C Includes
-// C++ Includes
-#include <cstring>
-
-// Project includes
-#include "lldb/Host/ThreadLauncher.h"
-#include "lldb/Utility/ConstString.h"
-#include "lldb/Utility/Event.h"
-#include "lldb/Utility/FileSpec.h"
-#include "lldb/Utility/StreamString.h"
-#include "lldb/Utility/StringExtractorGDBRemote.h"
-
-using namespace llvm;
-using namespace lldb;
-using namespace lldb_private;
-using namespace lldb_private::process_gdb_remote;
-
-/// Check if the given expected packet matches the actual packet.
-static bool unexpected(llvm::StringRef expected, llvm::StringRef actual) {
- // The 'expected' string contains the raw data, including the leading $ and
- // trailing checksum. The 'actual' string contains only the packet's content.
- if (expected.contains(actual))
- return false;
- // Contains a PID which might be
diff erent.
- if (expected.contains("vAttach"))
- return false;
- // Contains a ascii-hex-path.
- if (expected.contains("QSetSTD"))
- return false;
- // Contains environment values.
- if (expected.contains("QEnvironment"))
- return false;
-
- return true;
-}
-
-/// Check if we should reply to the given packet.
-static bool skip(llvm::StringRef data) {
- assert(!data.empty() && "Empty packet?");
-
- // We've already acknowledge the '+' packet so we're done here.
- if (data == "+")
- return true;
-
- /// Don't 't reply to ^C. We need this because of stop reply packets, which
- /// are only returned when the target halts. Reproducers synchronize these
- /// 'asynchronous' replies, by recording them as a regular replies to the
- /// previous packet (e.g. vCont). As a result, we should ignore real
- /// asynchronous requests.
- if (data.data()[0] == 0x03)
- return true;
-
- return false;
-}
-
-GDBRemoteCommunicationReplayServer::GDBRemoteCommunicationReplayServer()
- : GDBRemoteCommunication("gdb-replay", "gdb-replay.rx_packet"),
- m_async_broadcaster(nullptr, "lldb.gdb-replay.async-broadcaster"),
- m_async_listener_sp(
- Listener::MakeListener("lldb.gdb-replay.async-listener")),
- m_async_thread_state_mutex() {
- m_async_broadcaster.SetEventName(eBroadcastBitAsyncContinue,
- "async thread continue");
- m_async_broadcaster.SetEventName(eBroadcastBitAsyncThreadShouldExit,
- "async thread should exit");
-
- const uint32_t async_event_mask =
- eBroadcastBitAsyncContinue | eBroadcastBitAsyncThreadShouldExit;
- m_async_listener_sp->StartListeningForEvents(&m_async_broadcaster,
- async_event_mask);
-}
-
-GDBRemoteCommunicationReplayServer::~GDBRemoteCommunicationReplayServer() {
- StopAsyncThread();
-}
-
-GDBRemoteCommunication::PacketResult
-GDBRemoteCommunicationReplayServer::GetPacketAndSendResponse(
- Timeout<std::micro> timeout, Status &error, bool &interrupt, bool &quit) {
- std::lock_guard<std::recursive_mutex> guard(m_async_thread_state_mutex);
-
- StringExtractorGDBRemote packet;
- PacketResult packet_result = WaitForPacketNoLock(packet, timeout, false);
-
- if (packet_result != PacketResult::Success) {
- if (!IsConnected()) {
- error.SetErrorString("lost connection");
- quit = true;
- } else {
- error.SetErrorString("timeout");
- }
- return packet_result;
- }
-
- m_async_broadcaster.BroadcastEvent(eBroadcastBitAsyncContinue);
-
- // Check if we should reply to this packet.
- if (skip(packet.GetStringRef()))
- return PacketResult::Success;
-
- // This completes the handshake. Since m_send_acks was true, we can unset it
- // already.
- if (packet.GetStringRef() == "QStartNoAckMode")
- m_send_acks = false;
-
- // A QEnvironment packet is sent for every environment variable. If the
- // number of environment variables is
diff erent during replay, the replies
- // become out of sync.
- if (packet.GetStringRef().find("QEnvironment") == 0)
- return SendRawPacketNoLock("$OK#9a");
-
- Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
- while (!m_packet_history.empty()) {
- // Pop last packet from the history.
- GDBRemotePacket entry = m_packet_history.back();
- m_packet_history.pop_back();
-
- // Decode run-length encoding.
- const std::string expanded_data =
- GDBRemoteCommunication::ExpandRLE(entry.packet.data);
-
- // We've handled the handshake implicitly before. Skip the packet and move
- // on.
- if (entry.packet.data == "+")
- continue;
-
- if (entry.type == GDBRemotePacket::ePacketTypeSend) {
- if (unexpected(expanded_data, packet.GetStringRef())) {
- LLDB_LOG(log,
- "GDBRemoteCommunicationReplayServer expected packet: '{0}'",
- expanded_data);
- LLDB_LOG(log, "GDBRemoteCommunicationReplayServer actual packet: '{0}'",
- packet.GetStringRef());
-#ifndef NDEBUG
- // This behaves like a regular assert, but prints the expected and
- // received packet before aborting.
- printf("Reproducer expected packet: '%s'\n", expanded_data.c_str());
- printf("Reproducer received packet: '%s'\n",
- packet.GetStringRef().data());
- llvm::report_fatal_error("Encountered unexpected packet during replay");
-#endif
- return PacketResult::ErrorSendFailed;
- }
-
- // Ignore QEnvironment packets as they're handled earlier.
- if (expanded_data.find("QEnvironment") == 1) {
- assert(m_packet_history.back().type ==
- GDBRemotePacket::ePacketTypeRecv);
- m_packet_history.pop_back();
- }
-
- continue;
- }
-
- if (entry.type == GDBRemotePacket::ePacketTypeInvalid) {
- LLDB_LOG(
- log,
- "GDBRemoteCommunicationReplayServer skipped invalid packet: '{0}'",
- packet.GetStringRef());
- continue;
- }
-
- LLDB_LOG(log,
- "GDBRemoteCommunicationReplayServer replied to '{0}' with '{1}'",
- packet.GetStringRef(), entry.packet.data);
- return SendRawPacketNoLock(entry.packet.data);
- }
-
- quit = true;
-
- return packet_result;
-}
-
-llvm::Error
-GDBRemoteCommunicationReplayServer::LoadReplayHistory(const FileSpec &path) {
- auto error_or_file = MemoryBuffer::getFile(path.GetPath());
- if (auto err = error_or_file.getError())
- return errorCodeToError(err);
-
- yaml::Input yin((*error_or_file)->getBuffer());
- yin >> m_packet_history;
-
- if (auto err = yin.error())
- return errorCodeToError(err);
-
- // We want to manipulate the vector like a stack so we need to reverse the
- // order of the packets to have the oldest on at the back.
- std::reverse(m_packet_history.begin(), m_packet_history.end());
-
- return Error::success();
-}
-
-bool GDBRemoteCommunicationReplayServer::StartAsyncThread() {
- std::lock_guard<std::recursive_mutex> guard(m_async_thread_state_mutex);
- if (!m_async_thread.IsJoinable()) {
- // Create a thread that watches our internal state and controls which
- // events make it to clients (into the DCProcess event queue).
- llvm::Expected<HostThread> async_thread = ThreadLauncher::LaunchThread(
- "<lldb.gdb-replay.async>",
- GDBRemoteCommunicationReplayServer::AsyncThread, this);
- if (!async_thread) {
- LLDB_LOG_ERROR(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_HOST),
- async_thread.takeError(),
- "failed to launch host thread: {}");
- return false;
- }
- m_async_thread = *async_thread;
- }
-
- // Wait for handshake.
- m_async_broadcaster.BroadcastEvent(eBroadcastBitAsyncContinue);
-
- return m_async_thread.IsJoinable();
-}
-
-void GDBRemoteCommunicationReplayServer::StopAsyncThread() {
- std::lock_guard<std::recursive_mutex> guard(m_async_thread_state_mutex);
-
- if (!m_async_thread.IsJoinable())
- return;
-
- // Request thread to stop.
- m_async_broadcaster.BroadcastEvent(eBroadcastBitAsyncThreadShouldExit);
-
- // Disconnect client.
- Disconnect();
-
- // Stop the thread.
- m_async_thread.Join(nullptr);
- m_async_thread.Reset();
-}
-
-void GDBRemoteCommunicationReplayServer::ReceivePacket(
- GDBRemoteCommunicationReplayServer &server, bool &done) {
- Status error;
- bool interrupt;
- auto packet_result = server.GetPacketAndSendResponse(std::chrono::seconds(1),
- error, interrupt, done);
- if (packet_result != GDBRemoteCommunication::PacketResult::Success &&
- packet_result !=
- GDBRemoteCommunication::PacketResult::ErrorReplyTimeout) {
- done = true;
- } else {
- server.m_async_broadcaster.BroadcastEvent(eBroadcastBitAsyncContinue);
- }
-}
-
-thread_result_t GDBRemoteCommunicationReplayServer::AsyncThread(void *arg) {
- GDBRemoteCommunicationReplayServer *server =
- (GDBRemoteCommunicationReplayServer *)arg;
- auto D = make_scope_exit([&]() { server->Disconnect(); });
- EventSP event_sp;
- bool done = false;
- while (!done) {
- if (server->m_async_listener_sp->GetEvent(event_sp, llvm::None)) {
- const uint32_t event_type = event_sp->GetType();
- if (event_sp->BroadcasterIs(&server->m_async_broadcaster)) {
- switch (event_type) {
- case eBroadcastBitAsyncContinue:
- ReceivePacket(*server, done);
- if (done)
- return {};
- break;
- case eBroadcastBitAsyncThreadShouldExit:
- default:
- return {};
- }
- }
- }
- }
-
- return {};
-}
-
-Status GDBRemoteCommunicationReplayServer::Connect(
- process_gdb_remote::GDBRemoteCommunicationClient &client) {
- repro::Loader *loader = repro::Reproducer::Instance().GetLoader();
- if (!loader)
- return Status("No loader provided.");
-
- static std::unique_ptr<repro::MultiLoader<repro::GDBRemoteProvider>>
- multi_loader = repro::MultiLoader<repro::GDBRemoteProvider>::Create(
- repro::Reproducer::Instance().GetLoader());
- if (!multi_loader)
- return Status("No gdb remote provider found.");
-
- llvm::Optional<std::string> history_file = multi_loader->GetNextFile();
- if (!history_file)
- return Status("No gdb remote packet log found.");
-
- if (auto error = LoadReplayHistory(FileSpec(*history_file)))
- return Status("Unable to load replay history");
-
- if (auto error = GDBRemoteCommunication::ConnectLocally(client, *this))
- return Status("Unable to connect to replay server");
-
- return {};
-}
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationReplayServer.h b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationReplayServer.h
deleted file mode 100644
index 2f8770d0accfc..0000000000000
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationReplayServer.h
+++ /dev/null
@@ -1,88 +0,0 @@
-//===-- GDBRemoteCommunicationReplayServer.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_SOURCE_PLUGINS_PROCESS_GDB_REMOTE_GDBREMOTECOMMUNICATIONREPLAYSERVER_H
-#define LLDB_SOURCE_PLUGINS_PROCESS_GDB_REMOTE_GDBREMOTECOMMUNICATIONREPLAYSERVER_H
-
-// Other libraries and framework includes
-#include "GDBRemoteCommunication.h"
-#include "GDBRemoteCommunicationClient.h"
-#include "GDBRemoteCommunicationHistory.h"
-
-// Project includes
-#include "lldb/Host/HostThread.h"
-#include "lldb/Utility/Broadcaster.h"
-#include "lldb/lldb-private-forward.h"
-#include "llvm/Support/Error.h"
-
-// C Includes
-// C++ Includes
-#include <functional>
-#include <map>
-#include <thread>
-
-class StringExtractorGDBRemote;
-
-namespace lldb_private {
-namespace process_gdb_remote {
-
-class ProcessGDBRemote;
-
-/// Dummy GDB server that replays packets from the GDB Remote Communication
-/// history. This is used to replay GDB packets.
-class GDBRemoteCommunicationReplayServer : public GDBRemoteCommunication {
-public:
- GDBRemoteCommunicationReplayServer();
-
- ~GDBRemoteCommunicationReplayServer() override;
-
- PacketResult GetPacketAndSendResponse(Timeout<std::micro> timeout,
- Status &error, bool &interrupt,
- bool &quit);
-
- bool HandshakeWithClient() { return GetAck() == PacketResult::Success; }
-
- llvm::Error LoadReplayHistory(const FileSpec &path);
-
- bool StartAsyncThread();
- void StopAsyncThread();
-
- Status Connect(process_gdb_remote::GDBRemoteCommunicationClient &client);
-
-protected:
- enum {
- eBroadcastBitAsyncContinue = (1 << 0),
- eBroadcastBitAsyncThreadShouldExit = (1 << 1),
- };
-
- static void ReceivePacket(GDBRemoteCommunicationReplayServer &server,
- bool &done);
- static lldb::thread_result_t AsyncThread(void *arg);
-
- /// Replay history with the oldest packet at the end.
- std::vector<GDBRemotePacket> m_packet_history;
-
- /// Server thread.
- Broadcaster m_async_broadcaster;
- lldb::ListenerSP m_async_listener_sp;
- HostThread m_async_thread;
- std::recursive_mutex m_async_thread_state_mutex;
-
- bool m_skip_acks = false;
-
-private:
- GDBRemoteCommunicationReplayServer(
- const GDBRemoteCommunicationReplayServer &) = delete;
- const GDBRemoteCommunicationReplayServer &
- operator=(const GDBRemoteCommunicationReplayServer &) = delete;
-};
-
-} // namespace process_gdb_remote
-} // namespace lldb_private
-
-#endif // LLDB_SOURCE_PLUGINS_PROCESS_GDB_REMOTE_GDBREMOTECOMMUNICATIONREPLAYSERVER_H
diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
index 93fe36c0d9d69..cb5ec7f18d190 100644
--- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -23,13 +23,6 @@
#include <ctime>
#include <sys/types.h>
-#include <algorithm>
-#include <csignal>
-#include <map>
-#include <memory>
-#include <mutex>
-#include <sstream>
-
#include "lldb/Breakpoint/Watchpoint.h"
#include "lldb/Core/Debugger.h"
#include "lldb/Core/Module.h"
@@ -70,6 +63,13 @@
#include "lldb/Utility/State.h"
#include "lldb/Utility/StreamString.h"
#include "lldb/Utility/Timer.h"
+#include <algorithm>
+#include <csignal>
+#include <map>
+#include <memory>
+#include <mutex>
+#include <sstream>
+#include <thread>
#include "GDBRemoteRegisterContext.h"
#include "Plugins/Platform/MacOSX/PlatformRemoteiOS.h"
@@ -253,9 +253,8 @@ ProcessGDBRemote::ProcessGDBRemote(lldb::TargetSP target_sp,
m_addr_to_mmap_size(), m_thread_create_bp_sp(),
m_waiting_for_attach(false), m_destroy_tried_resuming(false),
m_command_sp(), m_breakpoint_pc_offset(0),
- m_initial_tid(LLDB_INVALID_THREAD_ID), m_replay_mode(false),
- m_allow_flash_writes(false), m_erased_flash_ranges(),
- m_vfork_in_progress(false) {
+ m_initial_tid(LLDB_INVALID_THREAD_ID), m_allow_flash_writes(false),
+ m_erased_flash_ranges(), m_vfork_in_progress(false) {
m_async_broadcaster.SetEventName(eBroadcastBitAsyncThreadShouldExit,
"async thread should exit");
m_async_broadcaster.SetEventName(eBroadcastBitAsyncContinue,
@@ -3316,24 +3315,6 @@ Status ProcessGDBRemote::DoSignal(int signo) {
return error;
}
-Status ProcessGDBRemote::ConnectToReplayServer() {
- Status status = m_gdb_replay_server.Connect(m_gdb_comm);
- if (status.Fail())
- return status;
-
- // Enable replay mode.
- m_replay_mode = true;
-
- // Start server thread.
- m_gdb_replay_server.StartAsyncThread();
-
- // Start client thread.
- StartAsyncThread();
-
- // Do the usual setup.
- return ConnectToDebugserver("");
-}
-
Status
ProcessGDBRemote::EstablishConnectionIfNeeded(const ProcessInfo &process_info) {
// Make sure we aren't already connected?
diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
index 488336b8c1b85..bdf130e3ec110 100644
--- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
+++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
@@ -34,7 +34,6 @@
#include "lldb/lldb-private-forward.h"
#include "GDBRemoteCommunicationClient.h"
-#include "GDBRemoteCommunicationReplayServer.h"
#include "GDBRemoteRegisterContext.h"
#include "llvm/ADT/DenseMap.h"
@@ -251,7 +250,6 @@ class ProcessGDBRemote : public Process,
};
GDBRemoteCommunicationClient m_gdb_comm;
- GDBRemoteCommunicationReplayServer m_gdb_replay_server;
std::atomic<lldb::pid_t> m_debugserver_pid;
llvm::Optional<StringExtractorGDBRemote> m_last_stop_packet;
@@ -292,7 +290,6 @@ class ProcessGDBRemote : public Process,
lldb::tid_t m_initial_tid; // The initial thread ID, given by stub on attach
bool m_use_g_packet_for_reading;
- bool m_replay_mode;
bool m_allow_flash_writes;
using FlashRangeVector = lldb_private::RangeVector<lldb::addr_t, size_t>;
using FlashRange = FlashRangeVector::Entry;
@@ -320,8 +317,6 @@ class ProcessGDBRemote : public Process,
bool DoUpdateThreadList(ThreadList &old_thread_list,
ThreadList &new_thread_list) override;
- Status ConnectToReplayServer();
-
Status EstablishConnectionIfNeeded(const ProcessInfo &process_info);
Status LaunchAndConnectToDebugserver(const ProcessInfo &process_info);
More information about the lldb-commits
mailing list