summaryrefslogtreecommitdiffstats
path: root/lldb/source/Plugins/Process/gdb-remote
diff options
context:
space:
mode:
authorGreg Clayton <gclayton@apple.com>2010-12-03 06:02:24 +0000
committerGreg Clayton <gclayton@apple.com>2010-12-03 06:02:24 +0000
commite5219660542e7126c7de8f2bd945f05d238760a4 (patch)
treeecc0d3c75273eeba285fbcbbefde043e1eea6325 /lldb/source/Plugins/Process/gdb-remote
parente0c4560b50b1b89649a8b06c1b138bf1d3bb8c99 (diff)
downloadbcm5719-llvm-e5219660542e7126c7de8f2bd945f05d238760a4.tar.gz
bcm5719-llvm-e5219660542e7126c7de8f2bd945f05d238760a4.zip
Fixed a race condition that could cause ProcessGDBRemote::DoResume() to return
an error saying the resume timed out. Previously the thread that was trying to resume the process would eventually call ProcessGDBRemote::DoResume() which would broadcast an event over to the async GDB remote thread which would sent the continue packet to the remote gdb server. Right after this was sent, it would set a predicate boolean value (protected by a mutex and condition) and then the thread that issued the ProcessGDBRemote::DoResume() would then wait for that condition variable to be set. If the async gdb thread was too quick though, the predicate boolean value could have been set to true and back to false by the time the thread that issued the ProcessGDBRemote::DoResume() checks the boolean value. So we can't use the predicate value as a handshake. I have changed the code over to using a Event by having the GDB remote communication object post an event: GDBRemoteCommunication::eBroadcastBitRunPacketSent This allows reliable handshaking between the two threads and avoids the erroneous ProcessGDBRemote::DoResume() errors. Added a host backtrace service to allow in process backtraces when trying to track down tricky issues. I need to see if LLVM has any backtracing abilities abstracted in it already, and if so, use that, but I needed something ASAP for the current issue I was working on. The static function is: void Host::Backtrace (Stream &strm, uint32_t max_frames); And it will backtrace at most "max_frames" frames for the current thread and can be used with any of the Stream subclasses for logging. llvm-svn: 120793
Diffstat (limited to 'lldb/source/Plugins/Process/gdb-remote')
-rw-r--r--lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp19
-rw-r--r--lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h7
-rw-r--r--lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp20
3 files changed, 22 insertions, 24 deletions
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
index 89b723849fc..394b55231a8 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
@@ -199,13 +199,13 @@ GDBRemoteCommunication::SendContinuePacketAndWaitForResponse
log->Printf ("GDBRemoteCommunication::%s ()", __FUNCTION__);
Mutex::Locker locker(m_sequence_mutex);
-// ScopedValueChanger<bool> restore_running_to_false (m_is_running, false);
StateType state = eStateRunning;
if (SendPacket(payload, packet_length) == 0)
state = eStateInvalid;
- m_is_running.SetValue (true, eBroadcastAlways);
+ BroadcastEvent(eBroadcastBitRunPacketSent, NULL);
+ m_is_running.SetValue (true, eBroadcastNever);
while (state == eStateRunning)
{
@@ -357,7 +357,7 @@ GDBRemoteCommunication::SendContinuePacketAndWaitForResponse
if (log)
log->Printf ("GDBRemoteCommunication::%s () => %s", __FUNCTION__, StateAsCString(state));
response.SetFilePos(0);
- m_is_running.SetValue (false, eBroadcastOnChange);
+ m_is_running.SetValue (false, eBroadcastAlways);
return state;
}
@@ -858,16 +858,3 @@ GDBRemoteCommunication::DeallocateMemory (addr_t addr, uint32_t timeout_seconds)
return false;
}
-bool
-GDBRemoteCommunication::WaitForIsRunning (uint32_t timeout_sec)
-{
- TimeValue timeout;
- if (timeout_sec)
- {
- timeout = TimeValue::Now();
- timeout.OffsetWithSeconds (timeout_sec);
- }
- return m_is_running.WaitForValueEqualTo (true, &timeout, NULL);
-}
-
-
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h
index e7ef38ab1e0..0434d8fb736 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h
@@ -34,6 +34,10 @@ class GDBRemoteCommunication :
public lldb_private::Communication
{
public:
+ enum
+ {
+ eBroadcastBitRunPacketSent = kLoUserBroadcastBit
+ };
//------------------------------------------------------------------
// Constructors and Destructors
//------------------------------------------------------------------
@@ -203,9 +207,6 @@ public:
}
bool
- WaitForIsRunning (uint32_t timeout_sec);
-
- bool
GetHostInfo (uint32_t timeout_seconds);
bool
diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
index e7a879bd5a5..083ef95a1f6 100644
--- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -878,10 +878,20 @@ ProcessGDBRemote::DoResume ()
{
Error error;
ProcessGDBRemoteLog::LogIf (GDBR_LOG_PROCESS, "ProcessGDBRemote::Resume()");
- m_async_broadcaster.BroadcastEvent (eBroadcastBitAsyncContinue, new EventDataBytes (m_continue_packet.GetData(), m_continue_packet.GetSize()));
- const uint32_t timedout_sec = 1;
- if (m_gdb_comm.WaitForIsRunning (timedout_sec) == false)
- error.SetErrorString("Resume timed out.");
+
+ Listener listener ("gdb-remote.resume-packet-sent");
+ if (listener.StartListeningForEvents (&m_gdb_comm, GDBRemoteCommunication::eBroadcastBitRunPacketSent))
+ {
+ EventSP event_sp;
+ TimeValue timeout;
+ timeout = TimeValue::Now();
+ timeout.OffsetWithSeconds (5);
+ m_async_broadcaster.BroadcastEvent (eBroadcastBitAsyncContinue, new EventDataBytes (m_continue_packet.GetData(), m_continue_packet.GetSize()));
+
+ if (listener.WaitForEvent (&timeout, event_sp) == false)
+ error.SetErrorString("Resume timed out.");
+ }
+
return error;
}
@@ -1206,7 +1216,7 @@ ProcessGDBRemote::DoDestroy ()
SetExitStatus(-1, "process killed");
StringExtractorGDBRemote response;
- if (m_gdb_comm.SendPacketAndWaitForResponse("k", response, 2, false))
+ if (m_gdb_comm.SendPacketAndWaitForResponse("k", response, 1, false))
{
log = ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS);
if (log)
OpenPOWER on IntegriCloud