[Lldb-commits] [PATCH] D116009: [lldb/gdb-remote] drop all junk bytes in incoming packet

Antonio Borneo via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Sun Dec 19 14:01:04 PST 2021


borneoa created this revision.
borneoa added a reviewer: clayborg.
borneoa requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

The loop that detects the junk bytes exits:
a) when it reaches the last byte in m_bytes, or
b) when it finds a valid 'first byte'.
The current code drops the first 'idx-1' bytes. This is consistent
with case b), but it left one junk byte in case a).

Let the code dropping all the junk bytes in both the cases above.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D116009

Files:
  lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp


Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
===================================================================
--- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
+++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
@@ -689,7 +689,7 @@
       const size_t bytes_len = m_bytes.size();
       bool done = false;
       uint32_t idx;
-      for (idx = 1; !done && idx < bytes_len; ++idx) {
+      for (idx = 1; !done && idx < bytes_len;) {
         switch (m_bytes[idx]) {
         case '+':
         case '-':
@@ -700,12 +700,13 @@
           break;
 
         default:
+           ++idx;
           break;
         }
       }
       LLDB_LOGF(log, "GDBRemoteCommunication::%s tossing %u junk bytes: '%.*s'",
-                __FUNCTION__, idx - 1, idx - 1, m_bytes.c_str());
-      m_bytes.erase(0, idx - 1);
+                __FUNCTION__, idx, idx, m_bytes.c_str());
+      m_bytes.erase(0, idx);
     } break;
     }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D116009.395357.patch
Type: text/x-patch
Size: 985 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20211219/63731e7b/attachment.bin>


More information about the lldb-commits mailing list