[Lldb-commits] [PATCH] D116006: [lldb/gdb-remote] remove junk bytes, then decode the packet
Antonio Borneo via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Sun Dec 19 10:40:22 PST 2021
borneoa updated this revision to Diff 395347.
borneoa added a comment.
resend it on top of its dependency
[lldb/gdb-remote] drop all junk bytes in incoming packet
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D116006/new/
https://reviews.llvm.org/D116006
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
@@ -647,6 +647,34 @@
}
}
+ // 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;
+ for (idx = 0; !done && idx < bytes_len;) {
+ switch (m_bytes[idx]) {
+ case '+':
+ case '-':
+ case '\x03':
+ case '%':
+ case '$':
+ done = true;
+ break;
+
+ default:
+ ++idx;
+ break;
+ }
+ }
+ if (idx) {
+ LLDB_LOGF(log, "GDBRemoteCommunication::%s tossing %u junk bytes: '%.*s'",
+ __FUNCTION__, idx, idx, m_bytes.c_str());
+ m_bytes.erase(0, idx);
+ }
+
switch (m_bytes[0]) {
case '+': // Look for ack
case '-': // Look for cancel
@@ -681,32 +709,9 @@
}
break;
- default: {
- // 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;
- for (idx = 1; !done && idx < bytes_len; ++idx) {
- switch (m_bytes[idx]) {
- case '+':
- case '-':
- case '\x03':
- case '%':
- case '$':
- done = true;
- break;
-
- default:
- 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);
- } break;
+ default:
+ // no more bytes after junk
+ break;
}
if (content_length == std::string::npos) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D116006.395347.patch
Type: text/x-patch
Size: 2390 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20211219/a035a351/attachment-0001.bin>
More information about the lldb-commits
mailing list