This is an archive of the discontinued LLVM Phabricator instance.

[lldb/gdb-remote] drop all junk bytes in incoming packet
Needs ReviewPublic

Authored by borneoa on Dec 19 2021, 2:01 PM.

Details

Reviewers
clayborg
Summary

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.

Diff Detail

Event Timeline

borneoa requested review of this revision.Dec 19 2021, 2:01 PM
borneoa created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptDec 19 2021, 2:01 PM

It would be nice to add a test case for this if possible. The solution looks good.

clayborg added inline comments.Dec 19 2021, 6:09 PM
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
689–706

This might be more easily and cleanly done with:

const 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);
}
labath added a subscriber: labath.Dec 20 2021, 12:12 AM

The find_first_of solution does look better. For the test, I /think/ it would be sufficient to add a new case to the test in unittests/Process/gdb-remote/GDBRemoteCommunicationTest.cpp.