[Lldb-commits] [lldb] r247908 - Fix LLDB RSP client to decode '$O' packets incorrectly

Dawn Perchik via lldb-commits lldb-commits at lists.llvm.org
Thu Sep 17 10:55:32 PDT 2015


Author: dperchik
Date: Thu Sep 17 12:55:32 2015
New Revision: 247908

URL: http://llvm.org/viewvc/llvm-project?rev=247908&view=rev
Log:
Fix LLDB RSP client to decode '$O' packets incorrectly

Character with ASCII code 0 is incorrectly treated by LLDB as the end of
RSP packet. The left of the debugger server output is silently ignored.

Patch from evgeny.leviant at gmail.com
Reviewed by: clayborg
Subscribers: lldb-commits
Differential Revision: http://reviews.llvm.org/D12523

Modified:
    lldb/trunk/include/lldb/Utility/StringExtractor.h
    lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
    lldb/trunk/source/Utility/StringExtractor.cpp

Modified: lldb/trunk/include/lldb/Utility/StringExtractor.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Utility/StringExtractor.h?rev=247908&r1=247907&r2=247908&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Utility/StringExtractor.h (original)
+++ lldb/trunk/include/lldb/Utility/StringExtractor.h Thu Sep 17 12:55:32 2015
@@ -115,6 +115,9 @@ public:
     GetHexU8 (uint8_t fail_value = 0, bool set_eof_on_fail = true);
 
     bool
+    GetHexU8Ex (uint8_t& ch, bool set_eof_on_fail = true);
+
+    bool
     GetNameColonValue (std::string &name, std::string &value);
 
     int32_t

Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp?rev=247908&r1=247907&r2=247908&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp Thu Sep 17 12:55:32 2015
@@ -1262,9 +1262,13 @@ GDBRemoteCommunicationClient::SendContin
                         got_async_packet = true;
                         std::string inferior_stdout;
                         inferior_stdout.reserve(response.GetBytesLeft () / 2);
-                        char ch;
-                        while ((ch = response.GetHexU8()) != '\0')
-                            inferior_stdout.append(1, ch);
+
+                        uint8_t ch;
+                        while (response.GetHexU8Ex(ch))
+                        {
+                            if (ch != 0)
+                                inferior_stdout.append(1, (char)ch);
+                        }
                         process->AppendSTDOUT (inferior_stdout.c_str(), inferior_stdout.size());
                     }
                     break;

Modified: lldb/trunk/source/Utility/StringExtractor.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Utility/StringExtractor.cpp?rev=247908&r1=247907&r2=247908&view=diff
==============================================================================
--- lldb/trunk/source/Utility/StringExtractor.cpp (original)
+++ lldb/trunk/source/Utility/StringExtractor.cpp Thu Sep 17 12:55:32 2015
@@ -125,14 +125,23 @@ StringExtractor::DecodeHexU8()
 uint8_t
 StringExtractor::GetHexU8 (uint8_t fail_value, bool set_eof_on_fail)
 {
+    GetHexU8Ex(fail_value, set_eof_on_fail);
+    return fail_value;
+}
+
+bool
+StringExtractor::GetHexU8Ex (uint8_t& ch, bool set_eof_on_fail)
+{
     int byte = DecodeHexU8();
     if (byte == -1)
     {
         if (set_eof_on_fail || m_index >= m_packet.size())
             m_index = UINT64_MAX;
-        return fail_value;
+        // ch should not be changed in case of failure
+        return false;
     }
-    return (uint8_t)byte;
+    ch = (uint8_t)byte;
+    return true;
 }
 
 uint32_t




More information about the lldb-commits mailing list