aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2016-08-27 15:52:29 +0000
committerZachary Turner <zturner@google.com>2016-08-27 15:52:29 +0000
commit26709df81deda2ef4ea143ba51caf9c3bb9b9398 (patch)
tree8bb811ce94d4a3fbf48204cf95496cc8dc530cdf /lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
parent56658af2cb2329f5691b4e837b6c06aa3833f81e (diff)
downloadllvm-26709df81deda2ef4ea143ba51caf9c3bb9b9398.zip
llvm-26709df81deda2ef4ea143ba51caf9c3bb9b9398.tar.gz
llvm-26709df81deda2ef4ea143ba51caf9c3bb9b9398.tar.bz2
Convert some functions to use StringRef instead of c_str, len
This started as an effort to change StringExtractor to store a StringRef internally instead of a std::string. I got that working locally with just 1 test failure which I was unable to figure out the cause of. But it was also a massive changelist due to a trickle down effect of changes. So I'm starting over, using what I learned from the first time to tackle smaller, more isolated changes hopefully leading up to a full conversion by the end. At first the changes (such as in this CL) will seem mostly a matter of preference and pointless otherwise. However, there are some places in my larger CL where using StringRef turned 20+ lines of code into 2, drastically simplifying logic. Hopefully once these go in they will illustrate some of the benefits of thinking in terms of StringRef. llvm-svn: 279917
Diffstat (limited to 'lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp')
-rw-r--r--lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp20
1 files changed, 10 insertions, 10 deletions
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
index efc7cad..f3892d2 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
@@ -187,12 +187,12 @@ GDBRemoteCommunication::~GDBRemoteCommunication()
}
char
-GDBRemoteCommunication::CalculcateChecksum (const char *payload, size_t payload_length)
+GDBRemoteCommunication::CalculcateChecksum (llvm::StringRef payload)
{
int checksum = 0;
- for (size_t i = 0; i < payload_length; ++i)
- checksum += payload[i];
+ for (char c : payload)
+ checksum += c;
return checksum & 255;
}
@@ -224,16 +224,16 @@ GDBRemoteCommunication::SendNack ()
}
GDBRemoteCommunication::PacketResult
-GDBRemoteCommunication::SendPacketNoLock (const char *payload, size_t payload_length)
+GDBRemoteCommunication::SendPacketNoLock (llvm::StringRef payload)
{
if (IsConnected())
{
StreamString packet(0, 4, eByteOrderBig);
packet.PutChar('$');
- packet.Write (payload, payload_length);
+ packet.Write (payload.data(), payload.size());
packet.PutChar('#');
- packet.PutHex8(CalculcateChecksum (payload, payload_length));
+ packet.PutHex8(CalculcateChecksum (payload));
Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PACKETS));
ConnectionStatus status = eConnectionStatusSuccess;
@@ -455,7 +455,7 @@ GDBRemoteCommunication::WaitForPacketWithTimeoutMicroSecondsNoLock (StringExtrac
response_regex.Compile("^QC[0-9A-Fa-f]+$");
}
- PacketResult echo_packet_result = SendPacketNoLock (echo_packet, echo_packet_len);
+ PacketResult echo_packet_result = SendPacketNoLock (llvm::StringRef(echo_packet, echo_packet_len));
if (echo_packet_result == PacketResult::Success)
{
const uint32_t max_retries = 3;
@@ -603,7 +603,7 @@ GDBRemoteCommunication::DecompressPacket ()
packet_checksum_cstr[2] = '\0';
long packet_checksum = strtol (packet_checksum_cstr, NULL, 16);
- long actual_checksum = CalculcateChecksum (m_bytes.data() + 1, hash_mark_idx - 1);
+ long actual_checksum = CalculcateChecksum (llvm::StringRef(m_bytes).substr(1, hash_mark_idx - 1));
bool success = packet_checksum == actual_checksum;
if (!success)
{
@@ -747,7 +747,7 @@ GDBRemoteCommunication::DecompressPacket ()
new_packet.push_back ('#');
if (GetSendAcks ())
{
- uint8_t decompressed_checksum = CalculcateChecksum ((const char *) decompressed_buffer, decompressed_bytes);
+ uint8_t decompressed_checksum = CalculcateChecksum (llvm::StringRef((const char *) decompressed_buffer, decompressed_bytes));
char decompressed_checksum_str[3];
snprintf (decompressed_checksum_str, 3, "%02x", decompressed_checksum);
new_packet.append (decompressed_checksum_str);
@@ -1001,7 +1001,7 @@ GDBRemoteCommunication::CheckForPacket (const uint8_t *src, size_t src_len, Stri
{
const char *packet_checksum_cstr = &m_bytes[checksum_idx];
char packet_checksum = strtol (packet_checksum_cstr, NULL, 16);
- char actual_checksum = CalculcateChecksum (packet_str.c_str(), packet_str.size());
+ char actual_checksum = CalculcateChecksum (packet_str);
success = packet_checksum == actual_checksum;
if (!success)
{