[Lldb-commits] [lldb] 6f82264 - [lldb/gdb-remote] Remove more non-stop mode remnants

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Wed Nov 24 01:02:31 PST 2021


Author: Pavel Labath
Date: 2021-11-24T10:00:43+01:00
New Revision: 6f82264dbb02028d4ec4940aeb6d716dded6e879

URL: https://github.com/llvm/llvm-project/commit/6f82264dbb02028d4ec4940aeb6d716dded6e879
DIFF: https://github.com/llvm/llvm-project/commit/6f82264dbb02028d4ec4940aeb6d716dded6e879.diff

LOG: [lldb/gdb-remote] Remove more non-stop mode remnants

The read thread handling is completely dead code now that non-stop mode
no longer exists.

Added: 
    

Modified: 
    lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
    lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.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/GDBRemoteCommunication.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
index 4ce79da48f073..5c8dd03daf1c6 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
@@ -81,11 +81,6 @@ GDBRemoteCommunication::~GDBRemoteCommunication() {
   if (m_decompression_scratch)
     free (m_decompression_scratch);
 #endif
-
-  // Stop the communications read thread which is used to parse all incoming
-  // packets.  This function will block until the read thread returns.
-  if (m_read_thread_enabled)
-    StopReadThread();
 }
 
 char GDBRemoteCommunication::CalculcateChecksum(llvm::StringRef payload) {
@@ -225,40 +220,7 @@ GDBRemoteCommunication::PacketResult
 GDBRemoteCommunication::ReadPacket(StringExtractorGDBRemote &response,
                                    Timeout<std::micro> timeout,
                                    bool sync_on_timeout) {
-  if (m_read_thread_enabled)
-    return PopPacketFromQueue(response, timeout);
-  else
-    return WaitForPacketNoLock(response, timeout, sync_on_timeout);
-}
-
-// This function is called when a packet is requested.
-// A whole packet is popped from the packet queue and returned to the caller.
-// Packets are placed into this queue from the communication read thread. See
-// GDBRemoteCommunication::AppendBytesToCache.
-GDBRemoteCommunication::PacketResult
-GDBRemoteCommunication::PopPacketFromQueue(StringExtractorGDBRemote &response,
-                                           Timeout<std::micro> timeout) {
-  auto pred = [&] { return !m_packet_queue.empty() && IsConnected(); };
-  // lock down the packet queue
-  std::unique_lock<std::mutex> lock(m_packet_queue_mutex);
-
-  if (!timeout)
-    m_condition_queue_not_empty.wait(lock, pred);
-  else {
-    if (!m_condition_queue_not_empty.wait_for(lock, *timeout, pred))
-      return PacketResult::ErrorReplyTimeout;
-    if (!IsConnected())
-      return PacketResult::ErrorDisconnected;
-  }
-
-  // get the front element of the queue
-  response = m_packet_queue.front();
-
-  // remove the front element
-  m_packet_queue.pop();
-
-  // we got a packet
-  return PacketResult::Success;
+  return WaitForPacketNoLock(response, timeout, sync_on_timeout);
 }
 
 GDBRemoteCommunication::PacketResult
@@ -1287,53 +1249,6 @@ GDBRemoteCommunication::ScopedTimeout::~ScopedTimeout() {
     m_gdb_comm.SetPacketTimeout(m_saved_timeout);
 }
 
-// This function is called via the Communications class read thread when bytes
-// become available for this connection. This function will consume all
-// incoming bytes and try to parse whole packets as they become available. Full
-// packets are placed in a queue, so that all packet requests can simply pop
-// from this queue. Async notification packets will be dispatched immediately
-// to the ProcessGDBRemote Async thread via an event.
-void GDBRemoteCommunication::AppendBytesToCache(const uint8_t *bytes,
-                                                size_t len, bool broadcast,
-                                                lldb::ConnectionStatus status) {
-  StringExtractorGDBRemote packet;
-
-  while (true) {
-    PacketType type = CheckForPacket(bytes, len, packet);
-
-    // scrub the data so we do not pass it back to CheckForPacket on future
-    // passes of the loop
-    bytes = nullptr;
-    len = 0;
-
-    // we may have received no packet so lets bail out
-    if (type == PacketType::Invalid)
-      break;
-
-    if (type == PacketType::Standard) {
-      // scope for the mutex
-      {
-        // lock down the packet queue
-        std::lock_guard<std::mutex> guard(m_packet_queue_mutex);
-        // push a new packet into the queue
-        m_packet_queue.push(packet);
-        // Signal condition variable that we have a packet
-        m_condition_queue_not_empty.notify_one();
-      }
-    }
-
-    if (type == PacketType::Notify) {
-      // put this packet into an event
-      const char *pdata = packet.GetStringRef().data();
-
-      // as the communication class, we are a broadcaster and the async thread
-      // is tuned to listen to us
-      BroadcastEvent(eBroadcastBitGdbReadThreadGotNotify,
-                     new EventDataBytes(pdata));
-    }
-  }
-}
-
 void llvm::format_provider<GDBRemoteCommunication::PacketResult>::format(
     const GDBRemoteCommunication::PacketResult &result, raw_ostream &Stream,
     StringRef Style) {

diff  --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h
index 5da568e9b4d4c..afc7e740d4c96 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h
@@ -84,8 +84,6 @@ class GDBRemoteCommunication : public Communication {
 public:
   enum {
     eBroadcastBitRunPacketSent = kLoUserBroadcastBit,
-    eBroadcastBitGdbReadThreadGotNotify =
-        kLoUserBroadcastBit << 1 // Sent when we received a notify packet.
   };
 
   enum class PacketType { Invalid = 0, Standard, Notify };
@@ -196,10 +194,6 @@ class GDBRemoteCommunication : public Communication {
       bool sync_on_timeout,
       llvm::function_ref<void(llvm::StringRef)> output_callback);
 
-  // Pop a packet from the queue in a thread safe manner
-  PacketResult PopPacketFromQueue(StringExtractorGDBRemote &response,
-                                  Timeout<std::micro> timeout);
-
   PacketResult WaitForPacketNoLock(StringExtractorGDBRemote &response,
                                    Timeout<std::micro> timeout,
                                    bool sync_on_timeout);
@@ -226,24 +220,7 @@ class GDBRemoteCommunication : public Communication {
 
   static lldb::thread_result_t ListenThread(lldb::thread_arg_t arg);
 
-  // GDB-Remote read thread
-  //  . this thread constantly tries to read from the communication
-  //    class and stores all packets received in a queue.  The usual
-  //    threads read requests simply pop packets off the queue in the
-  //    usual order.
-  //    This setup allows us to intercept and handle async packets, such
-  //    as the notify packet.
-
-  // This method is defined as part of communication.h
-  // when the read thread gets any bytes it will pass them on to this function
-  void AppendBytesToCache(const uint8_t *bytes, size_t len, bool broadcast,
-                          lldb::ConnectionStatus status) override;
-
 private:
-  std::queue<StringExtractorGDBRemote> m_packet_queue; // The packet queue
-  std::mutex m_packet_queue_mutex; // Mutex for accessing queue
-  std::condition_variable
-      m_condition_queue_not_empty; // Condition variable to wait for packets
   // Promise used to grab the port number from listening thread
   std::promise<uint16_t> m_port_promise;
 

diff  --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
index 2233bf6758190..3e6cf495cf031 100644
--- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -282,9 +282,7 @@ ProcessGDBRemote::ProcessGDBRemote(lldb::TargetSP target_sp,
               __FUNCTION__);
   }
 
-  const uint32_t gdb_event_mask =
-      Communication::eBroadcastBitReadThreadDidExit |
-      GDBRemoteCommunication::eBroadcastBitGdbReadThreadGotNotify;
+  const uint32_t gdb_event_mask = Communication::eBroadcastBitReadThreadDidExit;
   if (m_async_listener_sp->StartListeningForEvents(
           &m_gdb_comm, gdb_event_mask) != gdb_event_mask) {
     LLDB_LOGF(log,
@@ -1324,24 +1322,6 @@ Status ProcessGDBRemote::DoResume() {
   return error;
 }
 
-void ProcessGDBRemote::HandleStopReplySequence() {
-  while (true) {
-    // Send vStopped
-    StringExtractorGDBRemote response;
-    m_gdb_comm.SendPacketAndWaitForResponse("vStopped", response);
-
-    // OK represents end of signal list
-    if (response.IsOKResponse())
-      break;
-
-    // If not OK or a normal packet we have a problem
-    if (!response.IsNormalResponse())
-      break;
-
-    SetLastStopPacket(response);
-  }
-}
-
 void ProcessGDBRemote::ClearThreadIDList() {
   std::lock_guard<std::recursive_mutex> guard(m_thread_list_real.GetMutex());
   m_thread_ids.clear();
@@ -3539,31 +3519,6 @@ void ProcessGDBRemote::StopAsyncThread() {
         __FUNCTION__);
 }
 
-bool ProcessGDBRemote::HandleNotifyPacket(StringExtractorGDBRemote &packet) {
-  // get the packet at a string
-  const std::string &pkt = std::string(packet.GetStringRef());
-  // skip %stop:
-  StringExtractorGDBRemote stop_info(pkt.c_str() + 5);
-
-  // pass as a thread stop info packet
-  SetLastStopPacket(stop_info);
-
-  // check for more stop reasons
-  HandleStopReplySequence();
-
-  // if the process is stopped then we need to fake a resume so that we can
-  // stop properly with the new break. This is possible due to
-  // SetPrivateState() broadcasting the state change as a side effect.
-  if (GetPrivateState() == lldb::StateType::eStateStopped) {
-    SetPrivateState(lldb::StateType::eStateRunning);
-  }
-
-  // since we have some stopped packets we can halt the process
-  SetPrivateState(lldb::StateType::eStateStopped);
-
-  return true;
-}
-
 thread_result_t ProcessGDBRemote::AsyncThread(void *arg) {
   ProcessGDBRemote *process = (ProcessGDBRemote *)arg;
 
@@ -3712,17 +3667,6 @@ thread_result_t ProcessGDBRemote::AsyncThread(void *arg) {
           done = true;
           break;
 
-        case GDBRemoteCommunication::eBroadcastBitGdbReadThreadGotNotify: {
-          lldb_private::Event *event = event_sp.get();
-          const EventDataBytes *continue_packet =
-              EventDataBytes::GetEventDataFromEvent(event);
-          StringExtractorGDBRemote notify(
-              (const char *)continue_packet->GetBytes());
-          // Hand this over to the process to handle
-          process->HandleNotifyPacket(notify);
-          break;
-        }
-
         default:
           LLDB_LOGF(log,
                     "ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64

diff  --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
index 8134bc6b530d6..9b0ae6507b6e7 100644
--- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
+++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
@@ -343,8 +343,6 @@ class ProcessGDBRemote : public Process,
 
   size_t UpdateThreadIDsFromStopReplyThreadsValue(llvm::StringRef value);
 
-  bool HandleNotifyPacket(StringExtractorGDBRemote &packet);
-
   bool StartAsyncThread();
 
   void StopAsyncThread();
@@ -375,8 +373,6 @@ class ProcessGDBRemote : public Process,
                     lldb::addr_t dispatch_queue_t, std::string &queue_name,
                     lldb::QueueKind queue_kind, uint64_t queue_serial);
 
-  void HandleStopReplySequence();
-
   void ClearThreadIDList();
 
   bool UpdateThreadIDList();


        


More information about the lldb-commits mailing list