Have Stream::PutCStringAsRawHex8 take llvm::StringRef

This enables the function to be called with a StringRef without jumping
through any hoops. I rename the function to "PutStringAsRawHex8" to
honor the extended interface. I also remove ".c_str()" from any calls to
this function I could find.

llvm-svn: 353841
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
index 8a5bbc3..afa8e9c 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
@@ -1746,7 +1746,7 @@
     std::string path{file_spec.GetPath(false)};
     StreamString packet;
     packet.PutCString("QSetSTDIN:");
-    packet.PutCStringAsRawHex8(path.c_str());
+    packet.PutStringAsRawHex8(path);
 
     StringExtractorGDBRemote response;
     if (SendPacketAndWaitForResponse(packet.GetString(), response, false) ==
@@ -1766,7 +1766,7 @@
     std::string path{file_spec.GetPath(false)};
     StreamString packet;
     packet.PutCString("QSetSTDOUT:");
-    packet.PutCStringAsRawHex8(path.c_str());
+    packet.PutStringAsRawHex8(path);
 
     StringExtractorGDBRemote response;
     if (SendPacketAndWaitForResponse(packet.GetString(), response, false) ==
@@ -1786,7 +1786,7 @@
     std::string path{file_spec.GetPath(false)};
     StreamString packet;
     packet.PutCString("QSetSTDERR:");
-    packet.PutCStringAsRawHex8(path.c_str());
+    packet.PutStringAsRawHex8(path);
 
     StringExtractorGDBRemote response;
     if (SendPacketAndWaitForResponse(packet.GetString(), response, false) ==
@@ -1822,7 +1822,7 @@
     std::string path{working_dir.GetPath(false)};
     StreamString packet;
     packet.PutCString("QSetWorkingDir:");
-    packet.PutCStringAsRawHex8(path.c_str());
+    packet.PutStringAsRawHex8(path);
 
     StringExtractorGDBRemote response;
     if (SendPacketAndWaitForResponse(packet.GetString(), response, false) ==
@@ -2792,7 +2792,7 @@
   if (working_dir) {
     std::string path{working_dir.GetPath(false)};
     stream.PutChar(',');
-    stream.PutCStringAsRawHex8(path.c_str());
+    stream.PutStringAsRawHex8(path);
   }
   StringExtractorGDBRemote response;
   if (SendPacketAndWaitForResponse(stream.GetString(), response, false) ==
@@ -2829,7 +2829,7 @@
   stream.PutCString("qPlatform_mkdir:");
   stream.PutHex32(file_permissions);
   stream.PutChar(',');
-  stream.PutCStringAsRawHex8(path.c_str());
+  stream.PutStringAsRawHex8(path);
   llvm::StringRef packet = stream.GetString();
   StringExtractorGDBRemote response;
 
@@ -2851,7 +2851,7 @@
   stream.PutCString("qPlatform_chmod:");
   stream.PutHex32(file_permissions);
   stream.PutChar(',');
-  stream.PutCStringAsRawHex8(path.c_str());
+  stream.PutStringAsRawHex8(path);
   llvm::StringRef packet = stream.GetString();
   StringExtractorGDBRemote response;
 
@@ -2892,7 +2892,7 @@
   stream.PutCString("vFile:open:");
   if (path.empty())
     return UINT64_MAX;
-  stream.PutCStringAsRawHex8(path.c_str());
+  stream.PutStringAsRawHex8(path);
   stream.PutChar(',');
   stream.PutHex32(flags);
   stream.PutChar(',');
@@ -2923,7 +2923,7 @@
   std::string path(file_spec.GetPath(false));
   lldb_private::StreamString stream;
   stream.PutCString("vFile:size:");
-  stream.PutCStringAsRawHex8(path.c_str());
+  stream.PutStringAsRawHex8(path);
   StringExtractorGDBRemote response;
   if (SendPacketAndWaitForResponse(stream.GetString(), response, false) ==
       PacketResult::Success) {
@@ -2942,7 +2942,7 @@
   Status error;
   lldb_private::StreamString stream;
   stream.PutCString("vFile:mode:");
-  stream.PutCStringAsRawHex8(path.c_str());
+  stream.PutStringAsRawHex8(path);
   StringExtractorGDBRemote response;
   if (SendPacketAndWaitForResponse(stream.GetString(), response, false) ==
       PacketResult::Success) {
@@ -3044,9 +3044,9 @@
   stream.PutCString("vFile:symlink:");
   // the unix symlink() command reverses its parameters where the dst if first,
   // so we follow suit here
-  stream.PutCStringAsRawHex8(dst_path.c_str());
+  stream.PutStringAsRawHex8(dst_path);
   stream.PutChar(',');
-  stream.PutCStringAsRawHex8(src_path.c_str());
+  stream.PutStringAsRawHex8(src_path);
   StringExtractorGDBRemote response;
   if (SendPacketAndWaitForResponse(stream.GetString(), response, false) ==
       PacketResult::Success) {
@@ -3077,7 +3077,7 @@
   stream.PutCString("vFile:unlink:");
   // the unix symlink() command reverses its parameters where the dst if first,
   // so we follow suit here
-  stream.PutCStringAsRawHex8(path.c_str());
+  stream.PutStringAsRawHex8(path);
   StringExtractorGDBRemote response;
   if (SendPacketAndWaitForResponse(stream.GetString(), response, false) ==
       PacketResult::Success) {
@@ -3107,7 +3107,7 @@
   std::string path(file_spec.GetPath(false));
   lldb_private::StreamString stream;
   stream.PutCString("vFile:exists:");
-  stream.PutCStringAsRawHex8(path.c_str());
+  stream.PutStringAsRawHex8(path);
   StringExtractorGDBRemote response;
   if (SendPacketAndWaitForResponse(stream.GetString(), response, false) ==
       PacketResult::Success) {
@@ -3126,7 +3126,7 @@
   std::string path(file_spec.GetPath(false));
   lldb_private::StreamString stream;
   stream.PutCString("vFile:MD5:");
-  stream.PutCStringAsRawHex8(path.c_str());
+  stream.PutStringAsRawHex8(path);
   StringExtractorGDBRemote response;
   if (SendPacketAndWaitForResponse(stream.GetString(), response, false) ==
       PacketResult::Success) {
@@ -3507,10 +3507,10 @@
 
   StreamString packet;
   packet.PutCString("qModuleInfo:");
-  packet.PutCStringAsRawHex8(module_path.c_str());
+  packet.PutStringAsRawHex8(module_path);
   packet.PutCString(";");
   const auto &triple = arch_spec.GetTriple().getTriple();
-  packet.PutCStringAsRawHex8(triple.c_str());
+  packet.PutStringAsRawHex8(triple);
 
   StringExtractorGDBRemote response;
   if (SendPacketAndWaitForResponse(packet.GetString(), response, false) !=
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp
index ddcd4cb..f27573a 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp
@@ -106,7 +106,7 @@
   if (m_send_error_strings) {
     lldb_private::StreamString packet;
     packet.Printf("E%2.2x;", static_cast<uint8_t>(error.GetError()));
-    packet.PutCStringAsRawHex8(error.AsCString());
+    packet.PutStringAsRawHex8(error.AsCString());
     return SendPacketNoLock(packet.GetString());
   } else
     return SendErrorResponse(error.GetError());
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
index 13e7748..c7a4127 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
@@ -191,13 +191,13 @@
   ArchSpec host_arch(HostInfo::GetArchitecture());
   const llvm::Triple &host_triple = host_arch.GetTriple();
   response.PutCString("triple:");
-  response.PutCStringAsRawHex8(host_triple.getTriple().c_str());
+  response.PutStringAsRawHex8(host_triple.getTriple());
   response.Printf(";ptrsize:%u;", host_arch.GetAddressByteSize());
 
   const char *distribution_id = host_arch.GetDistributionId().AsCString();
   if (distribution_id) {
     response.PutCString("distribution_id:");
-    response.PutCStringAsRawHex8(distribution_id);
+    response.PutStringAsRawHex8(distribution_id);
     response.PutCString(";");
   }
 
@@ -271,12 +271,12 @@
   std::string s;
   if (HostInfo::GetOSBuildString(s)) {
     response.PutCString("os_build:");
-    response.PutCStringAsRawHex8(s.c_str());
+    response.PutStringAsRawHex8(s);
     response.PutChar(';');
   }
   if (HostInfo::GetOSKernelDescription(s)) {
     response.PutCString("os_kernel:");
-    response.PutCStringAsRawHex8(s.c_str());
+    response.PutStringAsRawHex8(s);
     response.PutChar(';');
   }
 
@@ -287,12 +287,12 @@
   // actually have a hostname as far as the remote lldb that is connecting to
   // this lldb-platform is concerned
   response.PutCString("hostname:");
-  response.PutCStringAsRawHex8("127.0.0.1");
+  response.PutStringAsRawHex8("127.0.0.1");
   response.PutChar(';');
 #else  // #if defined(__arm__) || defined(__arm64__) || defined(__aarch64__)
   if (HostInfo::GetHostname(s)) {
     response.PutCString("hostname:");
-    response.PutCStringAsRawHex8(s.c_str());
+    response.PutStringAsRawHex8(s);
     response.PutChar(';');
   }
 #endif // #if defined(__arm__) || defined(__arm64__) || defined(__aarch64__)
@@ -300,7 +300,7 @@
 #else  // #if defined(__APPLE__)
   if (HostInfo::GetHostname(s)) {
     response.PutCString("hostname:");
-    response.PutCStringAsRawHex8(s.c_str());
+    response.PutStringAsRawHex8(s);
     response.PutChar(';');
   }
 #endif // #if defined(__APPLE__)
@@ -439,7 +439,7 @@
     std::string name;
     if (HostInfo::LookupUserName(uid, name)) {
       StreamString response;
-      response.PutCStringAsRawHex8(name.c_str());
+      response.PutStringAsRawHex8(name);
       return SendPacketNoLock(response.GetString());
     }
   }
@@ -460,7 +460,7 @@
     std::string name;
     if (HostInfo::LookupGroupName(gid, name)) {
       StreamString response;
-      response.PutCStringAsRawHex8(name.c_str());
+      response.PutStringAsRawHex8(name);
       return SendPacketNoLock(response.GetString());
     }
   }
@@ -1084,20 +1084,20 @@
     if (!Result)
       return SendErrorResponse(5);
     response.PutCString("md5:");
-    response.PutCStringAsRawHex8(Result->digest().c_str());
+    response.PutStringAsRawHex8(Result->digest());
   } else {
     response.PutCString("uuid:");
-    response.PutCStringAsRawHex8(uuid_str.c_str());
+    response.PutStringAsRawHex8(uuid_str);
   }
   response.PutChar(';');
 
   const auto &module_arch = matched_module_spec.GetArchitecture();
   response.PutCString("triple:");
-  response.PutCStringAsRawHex8(module_arch.GetTriple().getTriple().c_str());
+  response.PutStringAsRawHex8(module_arch.GetTriple().getTriple());
   response.PutChar(';');
 
   response.PutCString("file_path:");
-  response.PutCStringAsRawHex8(matched_module_spec.GetFileSpec().GetCString());
+  response.PutStringAsRawHex8(matched_module_spec.GetFileSpec().GetCString());
   response.PutChar(';');
   response.PutCString("file_offset:");
   response.PutHex64(file_offset);
@@ -1175,13 +1175,13 @@
       proc_info.GetUserID(), proc_info.GetGroupID(),
       proc_info.GetEffectiveUserID(), proc_info.GetEffectiveGroupID());
   response.PutCString("name:");
-  response.PutCStringAsRawHex8(proc_info.GetExecutableFile().GetCString());
+  response.PutStringAsRawHex8(proc_info.GetExecutableFile().GetCString());
   response.PutChar(';');
   const ArchSpec &proc_arch = proc_info.GetArchitecture();
   if (proc_arch.IsValid()) {
     const llvm::Triple &proc_triple = proc_arch.GetTriple();
     response.PutCString("triple:");
-    response.PutCStringAsRawHex8(proc_triple.getTriple().c_str());
+    response.PutStringAsRawHex8(proc_triple.getTriple());
     response.PutChar(';');
   }
 }
@@ -1215,7 +1215,7 @@
 #else
     // We'll send the triple.
     response.PutCString("triple:");
-    response.PutCStringAsRawHex8(proc_triple.getTriple().c_str());
+    response.PutStringAsRawHex8(proc_triple.getTriple());
     response.PutChar(';');
 #endif
     std::string ostype = proc_triple.getOSName();
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
index 857f428..c4b5c69 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
@@ -622,7 +622,7 @@
     } else {
       // The thread name contains special chars, send as hex bytes.
       response.PutCString("hexname:");
-      response.PutCStringAsRawHex8(thread_name.c_str());
+      response.PutStringAsRawHex8(thread_name);
     }
     response.PutChar(';');
   }
@@ -662,7 +662,7 @@
         response.PutCString("jstopinfo:");
         StreamString unescaped_response;
         threads_info_sp->Write(unescaped_response);
-        response.PutCStringAsRawHex8(unescaped_response.GetData());
+        response.PutStringAsRawHex8(unescaped_response.GetData());
         response.PutChar(';');
       } else
         LLDB_LOG(log, "failed to prepare a jstopinfo field for pid {0}",
@@ -763,7 +763,7 @@
   if (!description.empty()) {
     // Description may contains special chars, send as hex bytes.
     response.PutCString("description:");
-    response.PutCStringAsRawHex8(description.c_str());
+    response.PutStringAsRawHex8(description);
     response.PutChar(';');
   } else if ((tid_stop_info.reason == eStopReasonException) &&
              tid_stop_info.details.exception.type) {
@@ -1340,7 +1340,7 @@
   FileSpec working_dir{m_process_launch_info.GetWorkingDirectory()};
   if (working_dir) {
     StreamString response;
-    response.PutCStringAsRawHex8(working_dir.GetCString());
+    response.PutStringAsRawHex8(working_dir.GetCString());
     return SendPacketNoLock(response.GetString());
   }
 
@@ -2425,7 +2425,7 @@
     // Return the error message.
 
     response.PutCString("error:");
-    response.PutCStringAsRawHex8(error.AsCString());
+    response.PutStringAsRawHex8(error.AsCString());
     response.PutChar(';');
   } else {
     // Range start and size.
@@ -2453,7 +2453,7 @@
     ConstString name = region_info.GetName();
     if (name) {
       response.PutCString("name:");
-      response.PutCStringAsRawHex8(name.AsCString());
+      response.PutStringAsRawHex8(name.AsCString());
       response.PutChar(';');
     }
   }
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
index 08aa015..8082991 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
@@ -206,7 +206,7 @@
                   port + m_port_offset);
   if (!socket_name.empty()) {
     response.PutCString("socket_name:");
-    response.PutCStringAsRawHex8(socket_name.c_str());
+    response.PutStringAsRawHex8(socket_name);
     response.PutChar(';');
   }
 
diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
index 57c28d5..1969d65 100644
--- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -4930,7 +4930,7 @@
 
   StreamString packet;
   packet.PutCString("qFileLoadAddress:");
-  packet.PutCStringAsRawHex8(file_path.c_str());
+  packet.PutStringAsRawHex8(file_path);
 
   StringExtractorGDBRemote response;
   if (m_gdb_comm.SendPacketAndWaitForResponse(packet.GetString(), response,