summaryrefslogtreecommitdiffstats
path: root/lldb/source/Plugins/Process
diff options
context:
space:
mode:
authorJonas Devlieghere <jonas@devlieghere.com>2019-08-21 04:55:56 +0000
committerJonas Devlieghere <jonas@devlieghere.com>2019-08-21 04:55:56 +0000
commitd35b42f20a48d6fd9c1f8fce095c37794d49806c (patch)
tree393063216884d10d5efef46472ada966725a2e85 /lldb/source/Plugins/Process
parent7483005c59828482aa28e09c7a132628b4054e29 (diff)
downloadbcm5719-llvm-d35b42f20a48d6fd9c1f8fce095c37794d49806c.tar.gz
bcm5719-llvm-d35b42f20a48d6fd9c1f8fce095c37794d49806c.zip
[NFC] Return llvm::StringRef from StringExtractor::GetStringRef.
This patch removes the two variant of StringExtractor::GetStringRef that return (non-)const references to std::string. The non-const one was being abused to reinitialize the StringExtractor and its uses are replaced by calls to the copy asignment operator. The const variant was refactored to return an actual llvm::StringRef. llvm-svn: 369493
Diffstat (limited to 'lldb/source/Plugins/Process')
-rw-r--r--lldb/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.cpp4
-rw-r--r--lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp7
-rw-r--r--lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp13
-rw-r--r--lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp7
-rw-r--r--lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp16
-rw-r--r--lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp22
6 files changed, 32 insertions, 37 deletions
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.cpp
index 140e2433023..064bbde8442 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteClientBase.cpp
@@ -72,7 +72,7 @@ StateType GDBRemoteClientBase::SendContinuePacketAndWaitForResponse(
const char stop_type = response.GetChar();
LLDB_LOGF(log, "GDBRemoteClientBase::%s () got packet: %s", __FUNCTION__,
- response.GetStringRef().c_str());
+ response.GetStringRef().data());
switch (stop_type) {
case 'W':
@@ -214,7 +214,7 @@ GDBRemoteClientBase::SendPacketAndWaitForResponseNoLock(
LLDB_LOGF(
log,
"error: packet with payload \"%.*s\" got invalid response \"%s\": %s",
- int(payload.size()), payload.data(), response.GetStringRef().c_str(),
+ int(payload.size()), payload.data(), response.GetStringRef().data(),
(i == (max_response_retries - 1))
? "using invalid response and giving up"
: "ignoring response and waiting for another");
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
index bb283b7397a..bb467df8bb6 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
@@ -751,7 +751,6 @@ GDBRemoteCommunication::CheckForPacket(const uint8_t *src, size_t src_len,
size_t content_end = content_start + content_length;
bool success = true;
- std::string &packet_str = packet.GetStringRef();
if (log) {
// If logging was just enabled and we have history, then dump out what
// we have to the log so we get the historical context. The Dump() call
@@ -813,11 +812,10 @@ GDBRemoteCommunication::CheckForPacket(const uint8_t *src, size_t src_len,
GDBRemoteCommunicationHistory::ePacketTypeRecv,
total_length);
- // Clear packet_str in case there is some existing data in it.
- packet_str.clear();
// Copy the packet from m_bytes to packet_str expanding the run-length
// encoding in the process. Reserve enough byte for the most common case
// (no RLE used)
+ std ::string packet_str;
packet_str.reserve(m_bytes.length());
for (std::string::const_iterator c = m_bytes.begin() + content_start;
c != m_bytes.begin() + content_end; ++c) {
@@ -840,6 +838,7 @@ GDBRemoteCommunication::CheckForPacket(const uint8_t *src, size_t src_len,
packet_str.push_back(*c);
}
}
+ packet = StringExtractorGDBRemote(packet_str);
if (m_bytes[0] == '$' || m_bytes[0] == '%') {
assert(checksum_idx < m_bytes.size());
@@ -1340,7 +1339,7 @@ void GDBRemoteCommunication::AppendBytesToCache(const uint8_t *bytes,
if (type == PacketType::Notify) {
// put this packet into an event
- const char *pdata = packet.GetStringRef().c_str();
+ const char *pdata = packet.GetStringRef().data();
// as the communication class, we are a broadcaster and the async thread
// is tuned to listen to us
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
index f5ce1374b33..b00ecd7a5f3 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
@@ -351,7 +351,7 @@ void GDBRemoteCommunicationClient::GetRemoteQSupported() {
if (SendPacketAndWaitForResponse(packet.GetString(), response,
/*send_async=*/false) ==
PacketResult::Success) {
- const char *response_cstr = response.GetStringRef().c_str();
+ const char *response_cstr = response.GetStringRef().data();
// Hang on to the qSupported packet, so that platforms can do custom
// configuration of the transport before attaching/launching the process.
@@ -465,7 +465,7 @@ bool GDBRemoteCommunicationClient::GetVContSupported(char flavor) {
m_supports_vCont_S = eLazyBoolNo;
if (SendPacketAndWaitForResponse("vCont?", response, false) ==
PacketResult::Success) {
- const char *response_cstr = response.GetStringRef().c_str();
+ const char *response_cstr = response.GetStringRef().data();
if (::strstr(response_cstr, ";c"))
m_supports_vCont_c = eLazyBoolYes;
@@ -2174,8 +2174,7 @@ uint32_t GDBRemoteCommunicationClient::FindProcesses(
if (!DecodeProcessInfoResponse(response, process_info))
break;
process_infos.Append(process_info);
- response.GetStringRef().clear();
- response.SetFilePos(0);
+ response = StringExtractorGDBRemote();
} while (SendPacketAndWaitForResponse("qsProcessInfo", response, false) ==
PacketResult::Success);
} else {
@@ -3897,7 +3896,7 @@ GDBRemoteCommunicationClient::GetSupportedStructuredDataPlugins() {
"GDBRemoteCommunicationClient::%s(): "
"QSupportedAsyncJSONPackets returned invalid "
"result: %s",
- __FUNCTION__, response.GetStringRef().c_str());
+ __FUNCTION__, response.GetStringRef().data());
m_supported_async_json_packets_sp.reset();
}
} else {
@@ -3975,14 +3974,14 @@ Status GDBRemoteCommunicationClient::ConfigureRemoteStructuredData(
SendPacketAndWaitForResponse(stream.GetString(), response, send_async);
if (result == PacketResult::Success) {
// We failed if the config result comes back other than OK.
- if (strcmp(response.GetStringRef().c_str(), "OK") == 0) {
+ if (strcmp(response.GetStringRef().data(), "OK") == 0) {
// Okay!
error.Clear();
} else {
error.SetErrorStringWithFormat("configuring StructuredData feature "
"%s failed with error %s",
type_name.AsCString(),
- response.GetStringRef().c_str());
+ response.GetStringRef().data());
}
} else {
// Can we get more data here on the failure?
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp
index d137c4c39ec..ac6ecffcf85 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.cpp
@@ -59,14 +59,13 @@ GDBRemoteCommunicationServer::GetPacketAndSendResponse(
break;
case StringExtractorGDBRemote::eServerPacketType_unimplemented:
- packet_result = SendUnimplementedResponse(packet.GetStringRef().c_str());
+ packet_result = SendUnimplementedResponse(packet.GetStringRef().data());
break;
default:
auto handler_it = m_packet_handlers.find(packet_type);
if (handler_it == m_packet_handlers.end())
- packet_result =
- SendUnimplementedResponse(packet.GetStringRef().c_str());
+ packet_result = SendUnimplementedResponse(packet.GetStringRef().data());
else
packet_result = handler_it->second(packet, error, interrupt, quit);
break;
@@ -140,7 +139,7 @@ GDBRemoteCommunicationServer::SendIllFormedResponse(
const StringExtractorGDBRemote &failed_packet, const char *message) {
Log *log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PACKETS));
LLDB_LOGF(log, "GDBRemoteCommunicationServer::%s: ILLFORMED: '%s' (%s)",
- __FUNCTION__, failed_packet.GetStringRef().c_str(),
+ __FUNCTION__, failed_packet.GetStringRef().data(),
message ? message : "");
return SendErrorResponse(0x03);
}
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
index 86ce4ea254b..bf7860ad1a5 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
@@ -218,7 +218,7 @@ Status GDBRemoteCommunicationServerLLGS::LaunchProcess() {
if (should_forward_stdio) {
// Temporarily relax the following for Windows until we can take advantage
- // of the recently added pty support. This doesn't really affect the use of
+ // of the recently added pty support. This doesn't really affect the use of
// lldb-server on Windows.
#if !defined(_WIN32)
if (llvm::Error Err = m_process_launch_info.SetUpPtyRedirection())
@@ -1377,7 +1377,7 @@ GDBRemoteCommunicationServerLLGS::Handle_C(StringExtractorGDBRemote &packet) {
if (packet.GetBytesLeft() > 0) {
// FIXME add continue at address support for $C{signo}[;{continue-address}].
if (*packet.Peek() == ';')
- return SendUnimplementedResponse(packet.GetStringRef().c_str());
+ return SendUnimplementedResponse(packet.GetStringRef().data());
else
return SendIllFormedResponse(
packet, "unexpected content after $C{signal-number}");
@@ -1440,7 +1440,7 @@ GDBRemoteCommunicationServerLLGS::Handle_c(StringExtractorGDBRemote &packet) {
if (has_continue_address) {
LLDB_LOG(log, "not implemented for c[address] variant [{0} remains]",
packet.Peek());
- return SendUnimplementedResponse(packet.GetStringRef().c_str());
+ return SendUnimplementedResponse(packet.GetStringRef().data());
}
// Ensure we have a native process.
@@ -1960,7 +1960,7 @@ GDBRemoteCommunicationServerLLGS::Handle_p(StringExtractorGDBRemote &packet) {
LLDB_LOGF(log,
"GDBRemoteCommunicationServerLLGS::%s failed, could not "
"parse register number from request \"%s\"",
- __FUNCTION__, packet.GetStringRef().c_str());
+ __FUNCTION__, packet.GetStringRef().data());
return SendErrorResponse(0x15);
}
@@ -2040,7 +2040,7 @@ GDBRemoteCommunicationServerLLGS::Handle_P(StringExtractorGDBRemote &packet) {
LLDB_LOGF(log,
"GDBRemoteCommunicationServerLLGS::%s failed, could not "
"parse register number from request \"%s\"",
- __FUNCTION__, packet.GetStringRef().c_str());
+ __FUNCTION__, packet.GetStringRef().data());
return SendErrorResponse(0x29);
}
@@ -3060,7 +3060,7 @@ GDBRemoteCommunicationServerLLGS::Handle_qThreadStopInfo(
LLDB_LOGF(log,
"GDBRemoteCommunicationServerLLGS::%s failed, could not "
"parse thread id from request \"%s\"",
- __FUNCTION__, packet.GetStringRef().c_str());
+ __FUNCTION__, packet.GetStringRef().data());
return SendErrorResponse(0x15);
}
return SendStopReplyPacketForThread(tid);
@@ -3234,7 +3234,7 @@ NativeThreadProtocol *GDBRemoteCommunicationServerLLGS::GetThreadFromSuffix(
"GDBRemoteCommunicationServerLLGS::%s gdb-remote parse "
"error: expected ';' prior to start of thread suffix: packet "
"contents = '%s'",
- __FUNCTION__, packet.GetStringRef().c_str());
+ __FUNCTION__, packet.GetStringRef().data());
return nullptr;
}
@@ -3247,7 +3247,7 @@ NativeThreadProtocol *GDBRemoteCommunicationServerLLGS::GetThreadFromSuffix(
"GDBRemoteCommunicationServerLLGS::%s gdb-remote parse "
"error: expected 'thread:' but not found, packet contents = "
"'%s'",
- __FUNCTION__, packet.GetStringRef().c_str());
+ __FUNCTION__, packet.GetStringRef().data());
return nullptr;
}
packet.SetFilePos(packet.GetFilePos() + strlen("thread:"));
diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
index 098e833d548..69bcd8a21cd 100644
--- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -1828,8 +1828,7 @@ ThreadSP ProcessGDBRemote::SetThreadStopInfo(
}
for (const auto &pair : expedited_register_map) {
- StringExtractor reg_value_extractor;
- reg_value_extractor.GetStringRef() = pair.second;
+ StringExtractor reg_value_extractor(pair.second);
DataBufferSP buffer_sp(new DataBufferHeap(
reg_value_extractor.GetStringRef().size() / 2, 0));
reg_value_extractor.GetHexBytes(buffer_sp->GetData(), '\xcc');
@@ -2646,7 +2645,7 @@ Status ProcessGDBRemote::DoDestroy() {
LLDB_LOGF(log,
"ProcessGDBRemote::DoDestroy - got unexpected response "
"to k packet: %s",
- response.GetStringRef().c_str());
+ response.GetStringRef().data());
exit_string.assign("got unexpected response to k packet: ");
exit_string.append(response.GetStringRef());
}
@@ -2808,7 +2807,7 @@ size_t ProcessGDBRemote::DoReadMemory(addr_t addr, void *buf, size_t size,
else
error.SetErrorStringWithFormat(
"unexpected response to GDB server memory read packet '%s': '%s'",
- packet, response.GetStringRef().c_str());
+ packet, response.GetStringRef().data());
} else {
error.SetErrorStringWithFormat("failed to send packet: '%s'", packet);
}
@@ -2918,7 +2917,7 @@ Status ProcessGDBRemote::FlashErase(lldb::addr_t addr, size_t size) {
else
status.SetErrorStringWithFormat(
"unexpected response to GDB server flash erase packet '%s': '%s'",
- packet.GetData(), response.GetStringRef().c_str());
+ packet.GetData(), response.GetStringRef().data());
}
} else {
status.SetErrorStringWithFormat("failed to send packet: '%s'",
@@ -2946,7 +2945,7 @@ Status ProcessGDBRemote::FlashDone() {
else
status.SetErrorStringWithFormat(
"unexpected response to GDB server flash done packet: '%s'",
- response.GetStringRef().c_str());
+ response.GetStringRef().data());
}
} else {
status.SetErrorStringWithFormat("failed to send flash done packet");
@@ -3009,7 +3008,7 @@ size_t ProcessGDBRemote::DoWriteMemory(addr_t addr, const void *buf,
else
error.SetErrorStringWithFormat(
"unexpected response to GDB server memory write packet '%s': '%s'",
- packet.GetData(), response.GetStringRef().c_str());
+ packet.GetData(), response.GetStringRef().data());
} else {
error.SetErrorStringWithFormat("failed to send packet: '%s'",
packet.GetData());
@@ -4452,14 +4451,13 @@ bool ParseRegisters(XMLNode feature_node, GdbServerTargetInfo &target_info,
} else if (name == "invalidate_regnums") {
SplitCommaSeparatedRegisterNumberString(value, invalidate_regs, 0);
} else if (name == "dynamic_size_dwarf_expr_bytes") {
- StringExtractor opcode_extractor;
std::string opcode_string = value.str();
size_t dwarf_opcode_len = opcode_string.length() / 2;
assert(dwarf_opcode_len > 0);
dwarf_opcode_bytes.resize(dwarf_opcode_len);
reg_info.dynamic_size_dwarf_len = dwarf_opcode_len;
- opcode_extractor.GetStringRef().swap(opcode_string);
+ StringExtractor opcode_extractor(opcode_string);
uint32_t ret_val =
opcode_extractor.GetHexBytesAvail(dwarf_opcode_bytes);
assert(dwarf_opcode_len == ret_val);
@@ -5327,7 +5325,7 @@ public:
result.SetStatus(eReturnStatusSuccessFinishResult);
Stream &output_strm = result.GetOutputStream();
output_strm.Printf(" packet: %s\n", packet_cstr);
- std::string &response_str = response.GetStringRef();
+ std::string response_str = response.GetStringRef();
if (strstr(packet_cstr, "qGetProfileData") != nullptr) {
response_str = process->HarmonizeThreadIdsForProfileData(response);
@@ -5336,7 +5334,7 @@ public:
if (response_str.empty())
output_strm.PutCString("response: \nerror: UNIMPLEMENTED\n");
else
- output_strm.Printf("response: %s\n", response.GetStringRef().c_str());
+ output_strm.Printf("response: %s\n", response.GetStringRef().data());
}
}
return true;
@@ -5385,7 +5383,7 @@ public:
if (response_str.empty())
output_strm.PutCString("response: \nerror: UNIMPLEMENTED\n");
else
- output_strm.Printf("response: %s\n", response.GetStringRef().c_str());
+ output_strm.Printf("response: %s\n", response.GetStringRef().data());
}
return true;
}
OpenPOWER on IntegriCloud