summaryrefslogtreecommitdiffstats
path: root/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
diff options
context:
space:
mode:
authorPavel Labath <labath@google.com>2016-11-24 10:54:49 +0000
committerPavel Labath <labath@google.com>2016-11-24 10:54:49 +0000
commit1eff73c3244867e0f4ba379a661da33b27814434 (patch)
treeb7093e2774c867369ddd9715f83e2ef113a83160 /lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
parentb15c8da08979f4ed7e4209a46039af7617bb338a (diff)
downloadbcm5719-llvm-1eff73c3244867e0f4ba379a661da33b27814434.tar.gz
bcm5719-llvm-1eff73c3244867e0f4ba379a661da33b27814434.zip
Introduce chrono to more gdb-remote functions
Summary: This replaces the usage of raw integers with duration classes in the gdb-remote packet management functions. The values are still converted back to integers once they go into the generic Communication class -- that I am leaving to a separate change. The changes are mostly straight-forward (*), the only tricky part was representation of infinite timeouts. Currently, we use UINT32_MAX to denote infinite timeout. This is not well suited for duration classes, as they tend to do arithmetic on the values, and the identity of the MAX value can easily get lost (e.g. microseconds(seconds(UINT32_MAX)).count() != UINT32_MAX). We cannot use zero to represent infinity (as Listener classes do) because we already use it to do non-blocking polling reads. For this reason, I chose to have an explicit value for infinity. The way I achieved that is via llvm::Optional, and I think it reads quite natural. Passing llvm::None as "timeout" means "no timeout", while passing zero means "poll". The only tricky part is this breaks implicit conversions (seconds are implicitly convertible to microseconds, but Optional<seconds> cannot be easily converted into Optional<microseconds>). For this reason I added a special class Timeout, inheriting from Optional, and enabling the necessary conversions one would normally expect. (*) The other tricky part was GDBRemoteCommunication::PopPacketFromQueue, which was needlessly complicated. I've simplified it, but that one is only used in non-stop mode, and so is untested. Reviewers: clayborg, zturner, jingham Subscribers: lldb-commits Differential Revision: https://reviews.llvm.org/D26971 llvm-svn: 287864
Diffstat (limited to 'lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp')
-rw-r--r--lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp26
1 files changed, 11 insertions, 15 deletions
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
index 1e5067aff42..f9bbaef6021 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
@@ -49,6 +49,7 @@
using namespace lldb;
using namespace lldb_private;
using namespace lldb_private::process_gdb_remote;
+using namespace std::chrono;
//----------------------------------------------------------------------
// GDBRemoteCommunicationClient constructor
@@ -122,9 +123,8 @@ bool GDBRemoteCommunicationClient::HandshakeWithServer(Error *error_ptr) {
// GDB server and flush them all
StringExtractorGDBRemote response;
PacketResult packet_result = PacketResult::Success;
- const uint32_t timeout_usec = 10 * 1000; // Wait for 10 ms for a response
while (packet_result == PacketResult::Success)
- packet_result = ReadPacket(response, timeout_usec, false);
+ packet_result = ReadPacket(response, milliseconds(10), false);
// The return value from QueryNoAckModeSupported() is true if the packet
// was sent and _any_ response (including UNIMPLEMENTED) was received),
@@ -202,8 +202,7 @@ bool GDBRemoteCommunicationClient::QueryNoAckModeSupported() {
// longer than normal to receive a reply. Wait at least 6 seconds for a
// reply to this packet.
- ScopedTimeout timeout(
- *this, std::max(GetPacketTimeout(), std::chrono::seconds(6)));
+ ScopedTimeout timeout(*this, std::max(GetPacketTimeout(), seconds(6)));
StringExtractorGDBRemote response;
if (SendPacketAndWaitForResponse("QStartNoAckMode", response, false) ==
@@ -315,7 +314,7 @@ void GDBRemoteCommunicationClient::ResetDiscoverableSettings(bool did_exec) {
m_hostname.clear();
m_gdb_server_name.clear();
m_gdb_server_version = UINT32_MAX;
- m_default_packet_timeout = std::chrono::seconds(0);
+ m_default_packet_timeout = seconds(0);
m_max_packet_size = 0;
m_qSupported_response.clear();
m_supported_async_json_packets_is_valid = false;
@@ -1200,7 +1199,7 @@ bool GDBRemoteCommunicationClient::GetHostInfo(bool force) {
} else if (name.equals("default_packet_timeout")) {
uint32_t timeout_seconds;
if (!value.getAsInteger(0, timeout_seconds)) {
- m_default_packet_timeout = std::chrono::seconds(timeout_seconds);
+ m_default_packet_timeout = seconds(timeout_seconds);
SetPacketTimeout(m_default_packet_timeout);
++num_keys_decoded;
}
@@ -1329,8 +1328,7 @@ GDBRemoteCommunicationClient::GetHostArchitecture() {
return m_host_arch;
}
-std::chrono::seconds
-GDBRemoteCommunicationClient::GetHostDefaultPacketTimeout() {
+seconds GDBRemoteCommunicationClient::GetHostDefaultPacketTimeout() {
if (m_qHostInfo_is_valid == eLazyBoolCalculate)
GetHostInfo();
return m_default_packet_timeout;
@@ -2022,7 +2020,7 @@ uint32_t GDBRemoteCommunicationClient::FindProcesses(
StringExtractorGDBRemote response;
// Increase timeout as the first qfProcessInfo packet takes a long time
// on Android. The value of 1min was arrived at empirically.
- ScopedTimeout timeout(*this, std::chrono::seconds(60));
+ ScopedTimeout timeout(*this, minutes(1));
if (SendPacketAndWaitForResponse(packet.GetString(), response, false) ==
PacketResult::Success) {
do {
@@ -2132,9 +2130,9 @@ static void MakeSpeedTestPacket(StreamString &packet, uint32_t send_size,
}
}
-std::chrono::duration<float> calculate_standard_deviation(
- const std::vector<std::chrono::duration<float>> &v) {
- using Dur = std::chrono::duration<float>;
+duration<float>
+calculate_standard_deviation(const std::vector<duration<float>> &v) {
+ using Dur = duration<float>;
Dur sum = std::accumulate(std::begin(v), std::end(v), Dur());
Dur mean = sum / v.size();
float accum = 0;
@@ -2151,8 +2149,6 @@ void GDBRemoteCommunicationClient::TestPacketSpeed(const uint32_t num_packets,
uint32_t max_recv,
uint64_t recv_amount,
bool json, Stream &strm) {
- using namespace std::chrono;
-
uint32_t i;
if (SendSpeedTestPacket(0, 0)) {
StreamString packet;
@@ -2324,7 +2320,7 @@ bool GDBRemoteCommunicationClient::LaunchGDBServer(
}
}
// give the process a few seconds to startup
- ScopedTimeout timeout(*this, std::chrono::seconds(10));
+ ScopedTimeout timeout(*this, seconds(10));
if (SendPacketAndWaitForResponse(stream.GetString(), response, false) ==
PacketResult::Success) {
OpenPOWER on IntegriCloud