Trying to solve our disappearing thread issues by making thread list updates safer.
The current ProcessGDBRemote function that updates the threads could end up with an empty list if any other thread had the sequence mutex. We now don't clear the thread list when we can't access it, and we also have changed how lldb_private::Process handles the return code from the:
virtual bool
Process::UpdateThreadList (lldb_private::ThreadList &old_thread_list,
lldb_private::ThreadList &new_thread_list) = 0;
A bool is now returned to indicate if the list was actually updated or not and the lldb_private::Process class will only update the stop ID of the validity of the thread list if "true" is returned.
The ProcessGDBRemote also got an extra assertion that will hopefully assert when running debug builds so we can find the source of this issue.
git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@154365 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp b/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
index 5b589dc..caa7025 100644
--- a/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
+++ b/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
@@ -201,10 +201,7 @@
// logs all of the packet will set a boolean so that we don't dump this more
// than once
if (!m_history.DidDumpToLog ())
- {
- DumpHistory("/tmp/foo.txt");
m_history.Dump (log.get());
- }
log->Printf ("<%4zu> send packet: %.*s", bytes_written, (int)packet.GetSize(), packet.GetData());
}
@@ -243,7 +240,7 @@
}
bool
-GDBRemoteCommunication::GetSequenceMutex (Mutex::Locker& locker)
+GDBRemoteCommunication::TryLockSequenceMutex (Mutex::Locker& locker)
{
return locker.TryLock (m_sequence_mutex.GetMutex());
}
diff --git a/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h b/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h
index 0e9ea0d..d7986d5 100644
--- a/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h
+++ b/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h
@@ -74,7 +74,7 @@
size_t payload_length);
bool
- GetSequenceMutex(lldb_private::Mutex::Locker& locker);
+ TryLockSequenceMutex(lldb_private::Mutex::Locker& locker);
bool
CheckForPacket (const uint8_t *src,
diff --git a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
index e308f91..4fbfa98 100644
--- a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
+++ b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
@@ -240,7 +240,7 @@
Mutex::Locker locker;
LogSP log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS));
size_t response_len = 0;
- if (GetSequenceMutex (locker))
+ if (TryLockSequenceMutex (locker))
{
if (SendPacketNoLock (payload, payload_length))
response_len = WaitForPacketWithTimeoutMicroSecondsNoLock (response, GetPacketTimeoutInMicroSeconds ());
@@ -628,7 +628,7 @@
return false;
}
-// This function takes a mutex locker as a parameter in case the GetSequenceMutex
+// This function takes a mutex locker as a parameter in case the TryLockSequenceMutex
// actually succeeds. If it doesn't succeed in acquiring the sequence mutex
// (the expected result), then it will send the halt packet. If it does succeed
// then the caller that requested the interrupt will want to keep the sequence
@@ -653,7 +653,7 @@
if (IsRunning())
{
// Only send an interrupt if our debugserver is running...
- if (GetSequenceMutex (locker) == false)
+ if (TryLockSequenceMutex (locker) == false)
{
// Someone has the mutex locked waiting for a response or for the
// inferior to stop, so send the interrupt on the down low...
@@ -1842,7 +1842,7 @@
Mutex::Locker locker;
thread_ids.clear();
- if (GetSequenceMutex (locker))
+ if (TryLockSequenceMutex (locker))
{
sequence_mutex_unavailable = false;
StringExtractorGDBRemote response;
diff --git a/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp b/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
index 77051ff..120caf3 100644
--- a/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
+++ b/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
@@ -181,7 +181,7 @@
if (!m_reg_valid[reg])
{
Mutex::Locker locker;
- if (gdb_comm.GetSequenceMutex (locker))
+ if (gdb_comm.TryLockSequenceMutex (locker))
{
const bool thread_suffix_supported = gdb_comm.GetThreadSuffixSupported();
ProcessSP process_sp (m_thread.GetProcess());
@@ -331,7 +331,7 @@
m_reg_data.GetByteOrder())) // dst byte order
{
Mutex::Locker locker;
- if (gdb_comm.GetSequenceMutex (locker))
+ if (gdb_comm.TryLockSequenceMutex (locker))
{
const bool thread_suffix_supported = gdb_comm.GetThreadSuffixSupported();
ProcessSP process_sp (m_thread.GetProcess());
@@ -440,7 +440,7 @@
StringExtractorGDBRemote response;
Mutex::Locker locker;
- if (gdb_comm.GetSequenceMutex (locker))
+ if (gdb_comm.TryLockSequenceMutex (locker))
{
char packet[32];
const bool thread_suffix_supported = gdb_comm.GetThreadSuffixSupported();
@@ -496,7 +496,7 @@
StringExtractorGDBRemote response;
Mutex::Locker locker;
- if (gdb_comm.GetSequenceMutex (locker))
+ if (gdb_comm.TryLockSequenceMutex (locker))
{
const bool thread_suffix_supported = gdb_comm.GetThreadSuffixSupported();
ProcessSP process_sp (m_thread.GetProcess());
diff --git a/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
index 8a1f120..8b667df 100644
--- a/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ b/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -1129,7 +1129,7 @@
return error;
}
-uint32_t
+bool
ProcessGDBRemote::UpdateThreadList (ThreadList &old_thread_list, ThreadList &new_thread_list)
{
// locker will keep a mutex locked until it goes out of scope
@@ -1151,11 +1151,17 @@
thread_sp.reset (new ThreadGDBRemote (shared_from_this(), tid));
new_thread_list.AddThread(thread_sp);
}
+ SetThreadStopInfo (m_last_stop_packet);
+ }
+ else if (sequence_mutex_unavailable)
+ {
+#if defined (LLDB_CONFIGURATION_DEBUG)
+ assert(!"ProcessGDBRemote::UpdateThreadList() failed due to not getting the sequence mutex");
+#endif
+ return false; // We just didn't get the list
}
- if (sequence_mutex_unavailable == false)
- SetThreadStopInfo (m_last_stop_packet);
- return new_thread_list.GetSize(false);
+ return true;
}
diff --git a/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h b/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
index 9f3b758..a41957f 100644
--- a/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
+++ b/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
@@ -265,7 +265,7 @@
return m_flags;
}
- uint32_t
+ virtual bool
UpdateThreadList (lldb_private::ThreadList &old_thread_list,
lldb_private::ThreadList &new_thread_list);