[Lldb-commits] [lldb] r123053 - in /lldb/trunk: source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp source/Utility/StringExtractor.cpp source/Utility/StringExtractor.h tools/debugserver/source/RNBRemote.cpp

Greg Clayton gclayton at apple.com
Fri Jan 7 19:17:57 PST 2011


Author: gclayton
Date: Fri Jan  7 21:17:57 2011
New Revision: 123053

URL: http://llvm.org/viewvc/llvm-project?rev=123053&view=rev
Log:
Modified the stop reply packet to be able to send the thread name using the
new "hexname" key for the "key:value;" duple that is part of the packet. This
allows for thread names to contain special characters such as $ # : ; + -

Debugserver now detects if the thread name contains special characters and
sends the chars in hex format if needed.


Modified:
    lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
    lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
    lldb/trunk/source/Utility/StringExtractor.cpp
    lldb/trunk/source/Utility/StringExtractor.h
    lldb/trunk/tools/debugserver/source/RNBRemote.cpp

Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp?rev=123053&r1=123052&r2=123053&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp Fri Jan  7 21:17:57 2011
@@ -517,18 +517,25 @@
                     std::string &response_str = response.GetStringRef();
                     if (packet_data[0] == '$')
                     {
-                        assert (packet_size >= 4);  // Must have at least '$#CC' where CC is checksum
-                        assert (packet_data[packet_size-3] == '#');
-                        assert (::isxdigit (packet_data[packet_size-2]));  // Must be checksum hex byte
-                        assert (::isxdigit (packet_data[packet_size-1]));  // Must be checksum hex byte
-                        response_str.assign (packet_data + 1, packet_size - 4);
+                        bool success = false;
+                        if (packet_size < 4)
+                            ::fprintf (stderr, "Packet that starts with $ is too short: '%s'\n", packet_data);
+                        else if (packet_data[packet_size-3] != '#' || 
+                                 !::isxdigit (packet_data[packet_size-2]) || 
+                                 !::isxdigit (packet_data[packet_size-1]))
+                            ::fprintf (stderr, "Invalid checksum footer for packet: '%s'\n", packet_data);
+                        else
+                            success = true;
+                        
+                        if (success)
+                            response_str.assign (packet_data + 1, packet_size - 4);
                         if (m_send_acks)
                         {
                             char packet_checksum = strtol (&packet_data[packet_size-2], NULL, 16);
                             char actual_checksum = CalculcateChecksum (&response_str[0], response_str.size());
                             checksum_error = packet_checksum != actual_checksum;
                             // Send the ack or nack if needed
-                            if (checksum_error)
+                            if (checksum_error || !success)
                                 SendAck('-');
                             else
                                 SendAck('+');

Modified: lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp?rev=123053&r1=123052&r2=123053&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp Fri Jan  7 21:17:57 2011
@@ -1036,6 +1036,15 @@
                     // thread in big endian hex
                     tid = Args::StringToUInt32 (value.c_str(), 0, 16);
                 }
+                else if (name.compare("hexname") == 0)
+                {
+                    StringExtractor name_extractor;
+                    // Swap "value" over into "name_extractor"
+                    name_extractor.GetStringRef().swap(value);
+                    // Now convert the HEX bytes into a string value
+                    name_extractor.GetHexByteString (value);
+                    thread_name.swap (value);
+                }
                 else if (name.compare("name") == 0)
                 {
                     thread_name.swap (value);

Modified: lldb/trunk/source/Utility/StringExtractor.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Utility/StringExtractor.cpp?rev=123053&r1=123052&r2=123053&view=diff
==============================================================================
--- lldb/trunk/source/Utility/StringExtractor.cpp (original)
+++ lldb/trunk/source/Utility/StringExtractor.cpp Fri Jan  7 21:17:57 2011
@@ -336,6 +336,16 @@
     return fail_value;
 }
 
+size_t
+StringExtractor::GetHexByteString (std::string &str)
+{
+    str.clear();
+    char ch;
+    while ((ch = GetHexU8()) != '\0')
+        str.append(1, ch);
+    return str.size();
+}
+
 bool
 StringExtractor::GetNameColonValue (std::string &name, std::string &value)
 {

Modified: lldb/trunk/source/Utility/StringExtractor.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Utility/StringExtractor.h?rev=123053&r1=123052&r2=123053&view=diff
==============================================================================
--- lldb/trunk/source/Utility/StringExtractor.h (original)
+++ lldb/trunk/source/Utility/StringExtractor.h Fri Jan  7 21:17:57 2011
@@ -110,6 +110,9 @@
     uint64_t
     GetHexWithFixedSize (uint32_t byte_size, bool little_endian, uint64_t fail_value);
 
+    size_t
+    GetHexByteString (std::string &str);
+
 protected:
     //------------------------------------------------------------------
     // For StringExtractor only

Modified: lldb/trunk/tools/debugserver/source/RNBRemote.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/RNBRemote.cpp?rev=123053&r1=123052&r2=123053&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/RNBRemote.cpp (original)
+++ lldb/trunk/tools/debugserver/source/RNBRemote.cpp Fri Jan  7 21:17:57 2011
@@ -1922,7 +1922,21 @@
 
         const char *thread_name = DNBThreadGetName (pid, tid);
         if (thread_name && thread_name[0])
-            ostrm << std::hex << "name:" << thread_name << ';';
+        {
+            size_t thread_name_len = strlen(thread_name);
+            
+            if (::strcspn (thread_name, "$#+-;:") == thread_name_len)
+                ostrm << std::hex << "name:" << thread_name << ';';
+            else
+            {
+                // the thread name contains special chars, send as hex bytes
+                ostrm << std::hex << "hexname:";
+                uint8_t *u_thread_name = (uint8_t *)thread_name;
+                for (int i = 0; i < thread_name_len; i++)
+                    ostrm << RAWHEX8(u_thread_name[i]);
+                ostrm << ';';
+            }
+        }
 
         thread_identifier_info_data_t thread_ident_info;
         if (DNBThreadGetIdentifierInfo (pid, tid, &thread_ident_info))





More information about the lldb-commits mailing list