[Lldb-commits] [PATCH] D116006: [lldb/gdb-remote] remove junk bytes, then decode the packet

Greg Clayton via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Sun Dec 19 18:10:24 PST 2021


clayborg added inline comments.


================
Comment at: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp:650-676
+    // Check if we have an unexpected byte and we need to flush all bad data
+    // that is in m_bytes, so we need to find the first byte that is a '+'
+    // (ACK), '-' (NACK), \x03 (CTRL+C interrupt), or '$' character (start of
+    // packet header) or of course, the end of the data in m_bytes...
+    const size_t bytes_len = m_bytes.size();
+    bool done = false;
+    uint32_t idx;
----------------
Might be easier to use std::string methods to do this:
```
const size_t idx = m_bytes.find_first_of("+-\x03%$");
if (idx != 0) {
      LLDB_LOGF(log, "GDBRemoteCommunication::%s tossing %u junk bytes: '%.*s'",
                __FUNCTION__, idx, idx, m_bytes.c_str());
      m_bytes.erase(0, idx);
}
```


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D116006/new/

https://reviews.llvm.org/D116006



More information about the lldb-commits mailing list