diff options
author | Zachary Turner <zturner@google.com> | 2016-11-16 21:15:24 +0000 |
---|---|---|
committer | Zachary Turner <zturner@google.com> | 2016-11-16 21:15:24 +0000 |
commit | c156427ded1dfa7686c90cc56ad16013a079a742 (patch) | |
tree | f4912beeebd9e7a04e9c20a8e05d64e25bde192d /lldb/source/Plugins/Process/gdb-remote | |
parent | 725dc14bb21da8a01709a6b3370a658d071689dc (diff) | |
download | bcm5719-llvm-c156427ded1dfa7686c90cc56ad16013a079a742.tar.gz bcm5719-llvm-c156427ded1dfa7686c90cc56ad16013a079a742.zip |
Don't allow direct access to StreamString's internal buffer.
This is a large API change that removes the two functions from
StreamString that return a std::string& and a const std::string&,
and instead provide one function which returns a StringRef.
Direct access to the underlying buffer violates the concept of
a "stream" which is intended to provide forward only access,
and makes porting to llvm::raw_ostream more difficult in the
future.
Differential Revision: https://reviews.llvm.org/D26698
llvm-svn: 287152
Diffstat (limited to 'lldb/source/Plugins/Process/gdb-remote')
5 files changed, 31 insertions, 28 deletions
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp index 601942808c5..19fc78d8e6d 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp @@ -200,7 +200,9 @@ GDBRemoteCommunication::SendPacketNoLock(llvm::StringRef payload) { Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PACKETS)); ConnectionStatus status = eConnectionStatusSuccess; - const char *packet_data = packet.GetData(); + // TODO: Don't shimmy through a std::string, just use StringRef. + std::string packet_str = packet.GetString(); + const char *packet_data = packet_str.c_str(); const size_t packet_length = packet.GetSize(); size_t bytes_written = Write(packet_data, packet_length, status, NULL); if (log) { @@ -236,7 +238,7 @@ GDBRemoteCommunication::SendPacketNoLock(llvm::StringRef payload) { strm.Printf("\\x%2.2x", *p); // Print the checksum strm.Printf("%*s", (int)3, p); - log->PutCString(strm.GetString().c_str()); + log->PutString(strm.GetString()); } else log->Printf("<%4" PRIu64 "> send packet: %.*s", (uint64_t)bytes_written, (int)packet_length, packet_data); @@ -867,7 +869,7 @@ GDBRemoteCommunication::CheckForPacket(const uint8_t *src, size_t src_len, // Packet footer... strm.Printf("%c%c%c", m_bytes[total_length - 3], m_bytes[total_length - 2], m_bytes[total_length - 1]); - log->PutCString(strm.GetString().c_str()); + log->PutString(strm.GetString()); } else { if (CompressionIsEnabled()) log->Printf("<%4" PRIu64 ":%" PRIu64 "> read packet: %.*s", @@ -1250,7 +1252,7 @@ Error GDBRemoteCommunication::StartDebugserverProcess( Platform *const platform = nullptr; launch_info.Dump(string_stream, platform); log->Printf("launch info for gdb-remote stub:\n%s", - string_stream.GetString().c_str()); + string_stream.GetData()); } error = Host::LaunchProcess(launch_info); diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp index 49733a5ba75..1e5067aff42 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp @@ -349,7 +349,7 @@ void GDBRemoteCommunicationClient::GetRemoteQSupported() { } StringExtractorGDBRemote response; - if (SendPacketAndWaitForResponse(packet.GetData(), response, + if (SendPacketAndWaitForResponse(packet.GetString(), response, /*send_async=*/false) == PacketResult::Success) { const char *response_cstr = response.GetStringRef().c_str(); @@ -518,7 +518,7 @@ GDBRemoteCommunicationClient::SendThreadSpecificPacketAndWaitForResponse( GDBR_LOG_PROCESS | GDBR_LOG_PACKETS)) log->Printf("GDBRemoteCommunicationClient::%s: Didn't get sequence mutex " "for %s packet.", - __FUNCTION__, payload.GetString().c_str()); + __FUNCTION__, payload.GetData()); return PacketResult::ErrorNoSequenceLock; } @@ -2685,15 +2685,15 @@ Error GDBRemoteCommunicationClient::MakeDirectory(const FileSpec &file_spec, stream.PutHex32(file_permissions); stream.PutChar(','); stream.PutCStringAsRawHex8(path.c_str()); - const char *packet = stream.GetData(); + llvm::StringRef packet = stream.GetString(); StringExtractorGDBRemote response; if (SendPacketAndWaitForResponse(packet, response, false) != PacketResult::Success) - return Error("failed to send '%s' packet", packet); + return Error("failed to send '%s' packet", packet.str().c_str()); if (response.GetChar() != 'F') - return Error("invalid response to '%s' packet", packet); + return Error("invalid response to '%s' packet", packet.str().c_str()); return Error(response.GetU32(UINT32_MAX), eErrorTypePOSIX); } @@ -2706,15 +2706,15 @@ Error GDBRemoteCommunicationClient::SetFilePermissions( stream.PutHex32(file_permissions); stream.PutChar(','); stream.PutCStringAsRawHex8(path.c_str()); - const char *packet = stream.GetData(); + llvm::StringRef packet = stream.GetString(); StringExtractorGDBRemote response; if (SendPacketAndWaitForResponse(packet, response, false) != PacketResult::Success) - return Error("failed to send '%s' packet", packet); + return Error("failed to send '%s' packet", stream.GetData()); if (response.GetChar() != 'F') - return Error("invalid response to '%s' packet", packet); + return Error("invalid response to '%s' packet", stream.GetData()); return Error(response.GetU32(UINT32_MAX), eErrorTypePOSIX); } @@ -2800,7 +2800,7 @@ Error GDBRemoteCommunicationClient::GetFilePermissions( PacketResult::Success) { if (response.GetChar() != 'F') { error.SetErrorStringWithFormat("invalid response to '%s' packet", - stream.GetString().c_str()); + stream.GetData()); } else { const uint32_t mode = response.GetS32(-1); if (static_cast<int32_t>(mode) == -1) { @@ -2818,7 +2818,7 @@ Error GDBRemoteCommunicationClient::GetFilePermissions( } } else { error.SetErrorStringWithFormat("failed to send '%s' packet", - stream.GetString().c_str()); + stream.GetData()); } return error; } @@ -3258,7 +3258,7 @@ GDBRemoteCommunicationClient::GetModulesInfo( unescaped_payload.PutCString("jModulesInfo:"); module_array_sp->Write(unescaped_payload); StreamGDBRemote payload; - payload.PutEscapedBytes(unescaped_payload.GetData(), + payload.PutEscapedBytes(unescaped_payload.GetString().data(), unescaped_payload.GetSize()); StringExtractorGDBRemote response; @@ -3569,7 +3569,7 @@ GDBRemoteCommunicationClient::GetSupportedStructuredDataPlugins() { m_supported_async_json_packets_sp->Dump(stream); log->Printf("GDBRemoteCommunicationClient::%s(): supported async " "JSON packets: %s", - __FUNCTION__, stream.GetString().c_str()); + __FUNCTION__, stream.GetData()); } } @@ -3600,7 +3600,7 @@ Error GDBRemoteCommunicationClient::ConfigureRemoteStructuredData( unescaped_stream.Flush(); // Add it to the stream in escaped fashion. - stream.PutEscapedBytes(unescaped_stream.GetData(), + stream.PutEscapedBytes(unescaped_stream.GetString().data(), unescaped_stream.GetSize()); } stream.Flush(); diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp index 28d94f8949a..e4e6810f665 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp @@ -1174,7 +1174,8 @@ GDBRemoteCommunicationServerCommon::Handle_jModulesInfo( StreamString response; response_array_sp->Write(response); StreamGDBRemote escaped_response; - escaped_response.PutEscapedBytes(response.GetData(), response.GetSize()); + escaped_response.PutEscapedBytes(response.GetString().data(), + response.GetSize()); return SendPacketNoLock(escaped_response.GetString()); } diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp index 33b60b5711d..8bf48e93537 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp @@ -246,7 +246,8 @@ GDBRemoteCommunicationServerPlatform::Handle_qQueryGDBServer( server_list.Write(response); StreamGDBRemote escaped_response; - escaped_response.PutEscapedBytes(response.GetData(), response.GetSize()); + escaped_response.PutEscapedBytes(response.GetString().data(), + response.GetSize()); return SendPacketNoLock(escaped_response.GetString()); } diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp index c0fbccb3e4f..3761f06628a 100644 --- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp @@ -1226,7 +1226,7 @@ Error ProcessGDBRemote::DoAttachToProcessWithName( m_async_broadcaster.BroadcastEvent( eBroadcastBitAsyncContinue, - new EventDataBytes(packet.GetData(), packet.GetSize())); + new EventDataBytes(packet.GetString().data(), packet.GetSize())); } else SetExitStatus(-1, error.AsCString()); @@ -1330,7 +1330,7 @@ Error ProcessGDBRemote::DoResume() { } if (continue_packet_error) - continue_packet.GetString().clear(); + continue_packet.Clear(); } } else continue_packet_error = true; @@ -1455,7 +1455,7 @@ Error ProcessGDBRemote::DoResume() { m_async_broadcaster.BroadcastEvent( eBroadcastBitAsyncContinue, - new EventDataBytes(continue_packet.GetData(), + new EventDataBytes(continue_packet.GetString().data(), continue_packet.GetSize())); if (listener_sp->WaitForEvent(std::chrono::seconds(5), event_sp) == @@ -2812,10 +2812,10 @@ size_t ProcessGDBRemote::DoWriteMemory(addr_t addr, const void *buf, else error.SetErrorStringWithFormat( "unexpected response to GDB server memory write packet '%s': '%s'", - packet.GetString().c_str(), response.GetStringRef().c_str()); + packet.GetData(), response.GetStringRef().c_str()); } else { error.SetErrorStringWithFormat("failed to send packet: '%s'", - packet.GetString().c_str()); + packet.GetData()); } return 0; } @@ -4043,8 +4043,7 @@ bool ProcessGDBRemote::GetModuleSpec(const FileSpec &module_file_spec, module_spec.Dump(stream); log->Printf("ProcessGDBRemote::%s - got module info for (%s:%s) : %s", __FUNCTION__, module_file_spec.GetPath().c_str(), - arch.GetTriple().getTriple().c_str(), - stream.GetString().c_str()); + arch.GetTriple().getTriple().c_str(), stream.GetData()); } m_cached_module_specs[key] = module_spec; @@ -4836,7 +4835,7 @@ ParseStructuredDataPacket(llvm::StringRef packet) { json_str.Flush(); log->Printf("ProcessGDBRemote::%s() " "received Async StructuredData packet: %s", - __FUNCTION__, json_str.GetString().c_str()); + __FUNCTION__, json_str.GetData()); } else { log->Printf("ProcessGDBRemote::%s" "() received StructuredData packet:" @@ -5083,7 +5082,7 @@ public: packet.GetString(), response, send_async); result.SetStatus(eReturnStatusSuccessFinishResult); Stream &output_strm = result.GetOutputStream(); - output_strm.Printf(" packet: %s\n", packet.GetString().c_str()); + output_strm.Printf(" packet: %s\n", packet.GetData()); const std::string &response_str = response.GetStringRef(); if (response_str.empty()) |