[Lldb-commits] [lldb] r231460 - Fix race condition with -o "process launch" on linux

Pavel Labath labath at google.com
Fri Mar 6 02:52:48 PST 2015

Author: labath
Date: Fri Mar  6 04:52:47 2015
New Revision: 231460

URL: http://llvm.org/viewvc/llvm-project?rev=231460&view=rev
Fix race condition with -o "process launch" on linux

starting a debug session on linux with -o "process launch" lldb parameter was failing since
Target::Launch (in sychronous mode) is expecting to be able to receive public process events.
However, PlatformLinux did not set up event hijacking on process launch, which caused these
events to be processed elsewhere and left Target::Launch hanging. This patch enables event
interception in PlatformLinux (which was commented out).

Upon enabling event interception, I noticed an issue, which I traced back to the inconsistent
state of public run lock, which remained false even though public and private process states were
"stopped". I addressed this by making sure the run lock is "stopped" upon exit from
WaitForProcessToStop (which already had similar provisions for other return paths).

Test Plan: This should fix the intermittent TestFormats failure we have been experiencing on Linux.

Reviewers: jingham, clayborg, vharron

Subscribers: lldb-commits

Differential Revision: http://reviews.llvm.org/D8079


Modified: lldb/trunk/source/Plugins/Platform/Linux/PlatformLinux.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/Linux/PlatformLinux.cpp?rev=231460&r1=231459&r2=231460&view=diff
--- lldb/trunk/source/Plugins/Platform/Linux/PlatformLinux.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/Linux/PlatformLinux.cpp Fri Mar  6 04:52:47 2015
@@ -765,7 +765,6 @@ PlatformLinux::DebugProcess (ProcessLaun
     // Adjust launch for a hijacker.
     ListenerSP listener_sp;
-#if 0
     if (!launch_info.GetHijackListener ())
         if (log)
@@ -775,7 +774,6 @@ PlatformLinux::DebugProcess (ProcessLaun
         launch_info.SetHijackListener (listener_sp);
         process_sp->HijackProcessEvents (listener_sp.get ());
     // Log file actions.
     if (log)
@@ -801,7 +799,6 @@ PlatformLinux::DebugProcess (ProcessLaun
         if (listener_sp)
             const StateType state = process_sp->WaitForProcessToStop (NULL, NULL, false, listener_sp.get());
-            process_sp->RestoreProcessEvents();
             if (state == eStateStopped)

Modified: lldb/trunk/source/Target/Process.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=231460&r1=231459&r2=231460&view=diff
--- lldb/trunk/source/Target/Process.cpp (original)
+++ lldb/trunk/source/Target/Process.cpp Fri Mar  6 04:52:47 2015
@@ -1011,6 +1011,10 @@ Process::WaitForProcessToStop (const Tim
         if (log)
             log->Printf("Process::%s returning without waiting for events; process private and public states are already 'stopped'.",
+        // We need to toggle the run lock as this won't get done in
+        // SetPublicState() if the process is hijacked.
+        if (hijack_listener)
+            m_public_run_lock.SetStopped();
         return state;

More information about the lldb-commits mailing list