From 862432c90e25f0901b77aff92cc6e48acd4b212b Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Tue, 3 Nov 2015 16:05:18 +0000 Subject: [PATCH] Fix race during process detach Summary: The code which was preventing the usage of the OS plugin while detach is in progress also prevented us to update the thread list correctly. This resulted in an empty thread list, which confused the detaching logic. Change the condition do only do what it says (disable the usage of the OS plugin). Reviewers: clayborg, jingham Subscribers: lldb-commits Differential Revision: http://reviews.llvm.org/D14201 llvm-svn: 251932 --- .../attach_resume/TestAttachResume.py | 1 - lldb/source/Target/Process.cpp | 55 +++++++++---------- 2 files changed, 26 insertions(+), 30 deletions(-) diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/attach_resume/TestAttachResume.py b/lldb/packages/Python/lldbsuite/test/functionalities/attach_resume/TestAttachResume.py index 2d4ac2d8d004..84c2e36e28c7 100644 --- a/lldb/packages/Python/lldbsuite/test/functionalities/attach_resume/TestAttachResume.py +++ b/lldb/packages/Python/lldbsuite/test/functionalities/attach_resume/TestAttachResume.py @@ -20,7 +20,6 @@ class AttachResumeTestCase(TestBase): @skipIfRemote @expectedFailureFreeBSD('llvm.org/pr19310') @expectedFailureWindows("llvm.org/pr24778") - @expectedFlakeyLinux('llvm.org/pr19310') def test_attach_continue_interrupt_detach(self): """Test attach/continue/interrupt/detach""" self.build() diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp index 115227384823..b0e0591d552e 100644 --- a/lldb/source/Target/Process.cpp +++ b/lldb/source/Target/Process.cpp @@ -1565,41 +1565,38 @@ Process::UpdateThreadListIfNeeded () // Don't call into the OperatingSystem to update the thread list if we are shutting down, since // that may call back into the SBAPI's, requiring the API lock which is already held by whoever is // shutting us down, causing a deadlock. - if (!m_destroy_in_process) + OperatingSystem *os = GetOperatingSystem (); + if (os && !m_destroy_in_process) { - OperatingSystem *os = GetOperatingSystem (); - if (os) - { - // Clear any old backing threads where memory threads might have been - // backed by actual threads from the lldb_private::Process subclass - size_t num_old_threads = old_thread_list.GetSize(false); - for (size_t i=0; iClearBackingThread(); + // Clear any old backing threads where memory threads might have been + // backed by actual threads from the lldb_private::Process subclass + size_t num_old_threads = old_thread_list.GetSize(false); + for (size_t i=0; iClearBackingThread(); - // Turn off dynamic types to ensure we don't run any expressions. Objective C - // can run an expression to determine if a SBValue is a dynamic type or not - // and we need to avoid this. OperatingSystem plug-ins can't run expressions - // that require running code... + // Turn off dynamic types to ensure we don't run any expressions. Objective C + // can run an expression to determine if a SBValue is a dynamic type or not + // and we need to avoid this. OperatingSystem plug-ins can't run expressions + // that require running code... - Target &target = GetTarget(); - const lldb::DynamicValueType saved_prefer_dynamic = target.GetPreferDynamicValue (); - if (saved_prefer_dynamic != lldb::eNoDynamicValues) - target.SetPreferDynamicValue(lldb::eNoDynamicValues); + Target &target = GetTarget(); + const lldb::DynamicValueType saved_prefer_dynamic = target.GetPreferDynamicValue (); + if (saved_prefer_dynamic != lldb::eNoDynamicValues) + target.SetPreferDynamicValue(lldb::eNoDynamicValues); - // Now let the OperatingSystem plug-in update the thread list + // Now let the OperatingSystem plug-in update the thread list - os->UpdateThreadList (old_thread_list, // Old list full of threads created by OS plug-in - real_thread_list, // The actual thread list full of threads created by each lldb_private::Process subclass - new_thread_list); // The new thread list that we will show to the user that gets filled in + os->UpdateThreadList (old_thread_list, // Old list full of threads created by OS plug-in + real_thread_list, // The actual thread list full of threads created by each lldb_private::Process subclass + new_thread_list); // The new thread list that we will show to the user that gets filled in - if (saved_prefer_dynamic != lldb::eNoDynamicValues) - target.SetPreferDynamicValue(saved_prefer_dynamic); - } - else - { - // No OS plug-in, the new thread list is the same as the real thread list - new_thread_list = real_thread_list; - } + if (saved_prefer_dynamic != lldb::eNoDynamicValues) + target.SetPreferDynamicValue(saved_prefer_dynamic); + } + else + { + // No OS plug-in, the new thread list is the same as the real thread list + new_thread_list = real_thread_list; } m_thread_list_real.Update(real_thread_list);