Fixed the async packets (packets that need to be sent to the GDB server
while the inferior is running) to be fast. The previous code would always
cause the sender to timeout, yet still return success due to the way we
were waiting for a value (incorrect value) to change. Now the ProcessGDBRemote
plug-in has a public and private "is running" predicate. This allows things
that need to send async packets to interrupt and wait for the private "is running"
state to be flipped to false, and then resume quickly with no timeout.
git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@123903 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp b/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
index 1a7b27b..92e33b2 100644
--- a/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
+++ b/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
@@ -37,7 +37,8 @@
m_thread_suffix_supported (false),
m_rx_packet_listener ("gdbremote.rx_packet"),
m_sequence_mutex (Mutex::eMutexTypeRecursive),
- m_is_running (false),
+ m_public_is_running (false),
+ m_private_is_running (false),
m_async_mutex (Mutex::eMutexTypeRecursive),
m_async_packet_predicate (false),
m_async_packet (),
@@ -206,7 +207,8 @@
state = eStateInvalid;
BroadcastEvent(eBroadcastBitRunPacketSent, NULL);
- m_is_running.SetValue (true, eBroadcastNever);
+ m_public_is_running.SetValue (true, eBroadcastNever);
+ m_private_is_running.SetValue (true, eBroadcastNever);
while (state == eStateRunning)
{
@@ -229,6 +231,11 @@
{
case 'T':
case 'S':
+ // Privately notify any internal threads that we have stopped
+ // in case we wanted to interrupt our process, yet we might
+ // send a packet and continue without returning control to the
+ // user.
+ m_private_is_running.SetValue (false, eBroadcastAlways);
if (m_async_signal != -1)
{
if (async_log)
@@ -272,11 +279,14 @@
if (async_log)
async_log->Printf ("async: error: failed to resume with %s",
Host::GetSignalAsCString (async_signal));
- state = eStateInvalid;
+ state = eStateExited;
break;
}
else
+ {
+ m_private_is_running.SetValue (true, eBroadcastNever);
continue;
+ }
}
}
else if (m_async_packet_predicate.GetValue())
@@ -307,11 +317,15 @@
// Continue again
if (SendPacket("c", 1) == 0)
{
- state = eStateInvalid;
+ // Failed to send the continue packet
+ state = eStateExited;
break;
}
else
+ {
+ m_private_is_running.SetValue (true, eBroadcastNever);
continue;
+ }
}
// Stop with signal and thread info
state = eStateStopped;
@@ -358,7 +372,8 @@
if (log)
log->Printf ("GDBRemoteCommunication::%s () => %s", __FUNCTION__, StateAsCString(state));
response.SetFilePos(0);
- m_is_running.SetValue (false, eBroadcastAlways);
+ m_private_is_running.SetValue (false, eBroadcastAlways);
+ m_public_is_running.SetValue (false, eBroadcastAlways);
return state;
}
@@ -470,7 +485,7 @@
if (Write (&ctrl_c, 1, status, NULL) > 0)
{
if (seconds_to_wait_for_stop)
- m_is_running.WaitForValueEqualTo (false, &timeout, timed_out);
+ m_private_is_running.WaitForValueEqualTo (false, &timeout, timed_out);
return true;
}
}
@@ -481,6 +496,7 @@
size_t
GDBRemoteCommunication::WaitForPacket (StringExtractorGDBRemote &response, uint32_t timeout_seconds)
{
+ Mutex::Locker locker(m_sequence_mutex);
TimeValue timeout_time;
timeout_time = TimeValue::Now();
timeout_time.OffsetWithSeconds (timeout_seconds);
diff --git a/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h b/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h
index c0d8685..ab9384f 100644
--- a/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h
+++ b/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h
@@ -215,7 +215,7 @@
bool
IsRunning() const
{
- return m_is_running.GetValue();
+ return m_public_is_running.GetValue();
}
bool
@@ -260,7 +260,8 @@
m_thread_suffix_supported:1;
lldb_private::Listener m_rx_packet_listener;
lldb_private::Mutex m_sequence_mutex; // Restrict access to sending/receiving packets to a single thread at a time
- lldb_private::Predicate<bool> m_is_running;
+ lldb_private::Predicate<bool> m_public_is_running;
+ lldb_private::Predicate<bool> m_private_is_running;
// If we need to send a packet while the target is running, the m_async_XXX
// member variables take care of making this happen.