[Lldb-commits] [lldb] r353841 - Have Stream::PutCStringAsRawHex8 take llvm::StringRef
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Tue Feb 12 06:28:56 PST 2019
Author: labath
Date: Tue Feb 12 06:28:55 2019
New Revision: 353841
URL: http://llvm.org/viewvc/llvm-project?rev=353841&view=rev
Log:
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.
Modified:
lldb/trunk/include/lldb/Utility/Stream.h
lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp
lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
lldb/trunk/source/Utility/Stream.cpp
lldb/trunk/unittests/Utility/StreamTest.cpp
Modified: lldb/trunk/include/lldb/Utility/Stream.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Utility/Stream.h?rev=353841&r1=353840&r2=353841&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Utility/Stream.h (original)
+++ lldb/trunk/include/lldb/Utility/Stream.h Tue Feb 12 06:28:55 2019
@@ -203,7 +203,7 @@ public:
lldb::ByteOrder src_byte_order = lldb::eByteOrderInvalid,
lldb::ByteOrder dst_byte_order = lldb::eByteOrderInvalid);
- size_t PutCStringAsRawHex8(const char *s);
+ size_t PutStringAsRawHex8(llvm::StringRef s);
//------------------------------------------------------------------
/// Output a NULL terminated C string \a cstr to the stream \a s.
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=353841&r1=353840&r2=353841&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp Tue Feb 12 06:28:55 2019
@@ -1746,7 +1746,7 @@ int GDBRemoteCommunicationClient::SetSTD
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 @@ int GDBRemoteCommunicationClient::SetSTD
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 @@ int GDBRemoteCommunicationClient::SetSTD
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 @@ int GDBRemoteCommunicationClient::SetWor
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 @@ lldb_private::Status GDBRemoteCommunicat
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 @@ Status GDBRemoteCommunicationClient::Mak
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 @@ GDBRemoteCommunicationClient::SetFilePer
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 @@ GDBRemoteCommunicationClient::OpenFile(c
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 @@ lldb::user_id_t GDBRemoteCommunicationCl
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 @@ GDBRemoteCommunicationClient::GetFilePer
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 @@ Status GDBRemoteCommunicationClient::Cre
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 @@ Status GDBRemoteCommunicationClient::Unl
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 @@ bool GDBRemoteCommunicationClient::GetFi
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 @@ bool GDBRemoteCommunicationClient::Calcu
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 @@ bool GDBRemoteCommunicationClient::GetMo
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) !=
Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp?rev=353841&r1=353840&r2=353841&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp Tue Feb 12 06:28:55 2019
@@ -106,7 +106,7 @@ GDBRemoteCommunicationServer::SendErrorR
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());
Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp?rev=353841&r1=353840&r2=353841&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp Tue Feb 12 06:28:55 2019
@@ -191,13 +191,13 @@ GDBRemoteCommunicationServerCommon::Hand
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 @@ GDBRemoteCommunicationServerCommon::Hand
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 @@ GDBRemoteCommunicationServerCommon::Hand
// 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 @@ GDBRemoteCommunicationServerCommon::Hand
#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 @@ GDBRemoteCommunicationServerCommon::Hand
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 @@ GDBRemoteCommunicationServerCommon::Hand
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 @@ GDBRemoteCommunicationServerCommon::Hand
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 @@ void GDBRemoteCommunicationServerCommon:
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 @@ void GDBRemoteCommunicationServerCommon:
#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();
Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp?rev=353841&r1=353840&r2=353841&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp Tue Feb 12 06:28:55 2019
@@ -622,7 +622,7 @@ GDBRemoteCommunicationServerLLGS::SendSt
} 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 @@ GDBRemoteCommunicationServerLLGS::SendSt
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 @@ GDBRemoteCommunicationServerLLGS::SendSt
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 @@ GDBRemoteCommunicationServerLLGS::Handle
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 @@ GDBRemoteCommunicationServerLLGS::Handle
// 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 @@ GDBRemoteCommunicationServerLLGS::Handle
ConstString name = region_info.GetName();
if (name) {
response.PutCString("name:");
- response.PutCStringAsRawHex8(name.AsCString());
+ response.PutStringAsRawHex8(name.AsCString());
response.PutChar(';');
}
}
Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp?rev=353841&r1=353840&r2=353841&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp Tue Feb 12 06:28:55 2019
@@ -206,7 +206,7 @@ GDBRemoteCommunicationServerPlatform::Ha
port + m_port_offset);
if (!socket_name.empty()) {
response.PutCString("socket_name:");
- response.PutCStringAsRawHex8(socket_name.c_str());
+ response.PutStringAsRawHex8(socket_name);
response.PutChar(';');
}
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=353841&r1=353840&r2=353841&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp Tue Feb 12 06:28:55 2019
@@ -4930,7 +4930,7 @@ Status ProcessGDBRemote::GetFileLoadAddr
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,
Modified: lldb/trunk/source/Utility/Stream.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Utility/Stream.cpp?rev=353841&r1=353840&r2=353841&view=diff
==============================================================================
--- lldb/trunk/source/Utility/Stream.cpp (original)
+++ lldb/trunk/source/Utility/Stream.cpp Tue Feb 12 06:28:55 2019
@@ -493,14 +493,12 @@ size_t Stream::PutBytesAsRawHex8(const v
return *delta;
}
-size_t Stream::PutCStringAsRawHex8(const char *s) {
+size_t Stream::PutStringAsRawHex8(llvm::StringRef s) {
ByteDelta delta(*this);
bool binary_is_set = m_flags.Test(eBinary);
m_flags.Clear(eBinary);
- while(*s) {
- _PutHex8(*s, false);
- ++s;
- }
+ for (char c : s)
+ _PutHex8(c, false);
if (binary_is_set)
m_flags.Set(eBinary);
return *delta;
Modified: lldb/trunk/unittests/Utility/StreamTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Utility/StreamTest.cpp?rev=353841&r1=353840&r2=353841&view=diff
==============================================================================
--- lldb/trunk/unittests/Utility/StreamTest.cpp (original)
+++ lldb/trunk/unittests/Utility/StreamTest.cpp Tue Feb 12 06:28:55 2019
@@ -121,16 +121,16 @@ TEST_F(StreamTest, PutCharNull) {
EXPECT_EQ(std::string("a", 1), TakeValue());
}
-TEST_F(StreamTest, PutCStringAsRawHex8) {
- s.PutCStringAsRawHex8("");
+TEST_F(StreamTest, PutStringAsRawHex8) {
+ s.PutStringAsRawHex8("");
EXPECT_EQ(0U, s.GetWrittenBytes());
EXPECT_EQ("", TakeValue());
- s.PutCStringAsRawHex8("foobar");
+ s.PutStringAsRawHex8("foobar");
EXPECT_EQ(12U, s.GetWrittenBytes());
EXPECT_EQ("666f6f626172", TakeValue());
- s.PutCStringAsRawHex8(" ");
+ s.PutStringAsRawHex8(" ");
EXPECT_EQ(2U, s.GetWrittenBytes());
EXPECT_EQ("20", TakeValue());
}
More information about the lldb-commits
mailing list