[Lldb-commits] [lldb] 225f241 - [lldb/Reproducers] Move connection logic into replay server (NFC)

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Tue May 19 10:55:42 PDT 2020


Author: Jonas Devlieghere
Date: 2020-05-19T10:55:35-07:00
New Revision: 225f241c84469d7d29c9ef626558c302134c48ff

URL: https://github.com/llvm/llvm-project/commit/225f241c84469d7d29c9ef626558c302134c48ff
DIFF: https://github.com/llvm/llvm-project/commit/225f241c84469d7d29c9ef626558c302134c48ff.diff

LOG: [lldb/Reproducers] Move connection logic into replay server (NFC)

Move the logic for connecting to the replay server into the replay
server itself, so it can be reused outside of ProcessGDBRemote.

Added: 
    

Modified: 
    lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationReplayServer.cpp
    lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationReplayServer.h
    lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
    lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h

Removed: 
    


################################################################################
diff  --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationReplayServer.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationReplayServer.cpp
index 910dcf2cf589..920327e7d0ab 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationReplayServer.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationReplayServer.cpp
@@ -287,3 +287,28 @@ thread_result_t GDBRemoteCommunicationReplayServer::AsyncThread(void *arg) {
 
   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
index 1263b3c0a09f..65587293667f 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationReplayServer.h
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationReplayServer.h
@@ -11,6 +11,7 @@
 
 // Other libraries and framework includes
 #include "GDBRemoteCommunication.h"
+#include "GDBRemoteCommunicationClient.h"
 #include "GDBRemoteCommunicationHistory.h"
 
 // Project includes
@@ -51,6 +52,8 @@ class GDBRemoteCommunicationReplayServer : public GDBRemoteCommunication {
   bool StartAsyncThread();
   void StopAsyncThread();
 
+  Status Connect(process_gdb_remote::GDBRemoteCommunicationClient &client);
+
 protected:
   enum {
     eBroadcastBitAsyncContinue = (1 << 0),

diff  --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
index dbad49d62097..58e9712b570b 100644
--- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -649,8 +649,8 @@ Status ProcessGDBRemote::DoConnectRemote(Stream *strm,
   if (error.Fail())
     return error;
 
-  if (repro::Loader *loader = repro::Reproducer::Instance().GetLoader())
-    error = ConnectToReplayServer(loader);
+  if (repro::Reproducer::Instance().IsReplaying())
+    error = ConnectToReplayServer();
   else
     error = ConnectToDebugserver(remote_url);
 
@@ -3355,30 +3355,10 @@ Status ProcessGDBRemote::DoSignal(int signo) {
   return error;
 }
 
-Status ProcessGDBRemote::ConnectToReplayServer(repro::Loader *loader) {
-  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.");
-
-  // Load replay history.
-  if (auto error =
-          m_gdb_replay_server.LoadReplayHistory(FileSpec(*history_file)))
-    return Status("Unable to load replay history");
-
-  // Make a local connection.
-  if (auto error = GDBRemoteCommunication::ConnectLocally(m_gdb_comm,
-                                                          m_gdb_replay_server))
-    return Status("Unable to connect to replay server");
+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;
@@ -3403,8 +3383,8 @@ ProcessGDBRemote::EstablishConnectionIfNeeded(const ProcessInfo &process_info) {
   if (platform_sp && !platform_sp->IsHost())
     return Status("Lost debug server connection");
 
-  if (repro::Loader *loader = repro::Reproducer::Instance().GetLoader())
-    return ConnectToReplayServer(loader);
+  if (repro::Reproducer::Instance().IsReplaying())
+    return ConnectToReplayServer();
 
   auto error = LaunchAndConnectToDebugserver(process_info);
   if (error.Fail()) {

diff  --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
index 9063fcb00622..6ed75dd03f63 100644
--- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
+++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
@@ -312,7 +312,7 @@ class ProcessGDBRemote : public Process,
   bool UpdateThreadList(ThreadList &old_thread_list,
                         ThreadList &new_thread_list) override;
 
-  Status ConnectToReplayServer(repro::Loader *loader);
+  Status ConnectToReplayServer();
 
   Status EstablishConnectionIfNeeded(const ProcessInfo &process_info);
 
@@ -387,7 +387,7 @@ class ProcessGDBRemote : public Process,
   DynamicLoader *GetDynamicLoader() override;
 
   bool GetGDBServerRegisterInfoXMLAndProcess(ArchSpec &arch_to_use,
-                                             std::string xml_filename, 
+                                             std::string xml_filename,
                                              uint32_t &cur_reg_num,
                                              uint32_t &reg_offset);
 


        


More information about the lldb-commits mailing list