[Lldb-commits] [lldb] r229875 - Prevent LLGS from crashing when exiting - make NativeProcessLinux to wait until ThreadStateCoordinator is fully stopped before entering ~NativeProcessLinux.

Oleksiy Vyalov ovyalov at google.com
Thu Feb 19 09:58:04 PST 2015


Author: ovyalov
Date: Thu Feb 19 11:58:04 2015
New Revision: 229875

URL: http://llvm.org/viewvc/llvm-project?rev=229875&view=rev
Log:
 Prevent LLGS from crashing when exiting - make NativeProcessLinux to wait until ThreadStateCoordinator is fully stopped before entering ~NativeProcessLinux.

http://reviews.llvm.org/D7692


Modified:
    lldb/trunk/include/lldb/Host/common/NativeProcessProtocol.h
    lldb/trunk/source/Host/common/NativeProcessProtocol.cpp
    lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp
    lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.h
    lldb/trunk/source/Plugins/Process/Linux/NativeThreadLinux.cpp
    lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp

Modified: lldb/trunk/include/lldb/Host/common/NativeProcessProtocol.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/common/NativeProcessProtocol.h?rev=229875&r1=229874&r2=229875&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/common/NativeProcessProtocol.h (original)
+++ lldb/trunk/include/lldb/Host/common/NativeProcessProtocol.h Thu Feb 19 11:58:04 2015
@@ -283,6 +283,10 @@ namespace lldb_private
         bool
         UnregisterNativeDelegate (NativeDelegate &native_delegate);
 
+        // Called before termination of NativeProcessProtocol's instance.
+        virtual void
+        Terminate ();
+
     protected:
         lldb::pid_t m_pid;
 

Modified: lldb/trunk/source/Host/common/NativeProcessProtocol.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/NativeProcessProtocol.cpp?rev=229875&r1=229874&r2=229875&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/NativeProcessProtocol.cpp (original)
+++ lldb/trunk/source/Host/common/NativeProcessProtocol.cpp Thu Feb 19 11:58:04 2015
@@ -435,3 +435,9 @@ NativeProcessProtocol::DoStopIDBumped (u
 {
     // Default implementation does nothing.
 }
+
+void
+NativeProcessProtocol::Terminate ()
+{
+    // Default implementation does nothing.
+}

Modified: lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp?rev=229875&r1=229874&r2=229875&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp Thu Feb 19 11:58:04 2015
@@ -1453,7 +1453,8 @@ WAIT_AGAIN:
     }
 }
 
-NativeProcessLinux::~NativeProcessLinux()
+void
+NativeProcessLinux::Terminate ()
 {
     StopMonitor();
 }
@@ -3637,6 +3638,7 @@ NativeProcessLinux::StopCoordinatorThrea
     // Tell the coordinator we're done.  This will cause the coordinator
     // run loop thread to exit when the processing queue hits this message.
     m_coordinator_up->StopCoordinator ();
+    m_coordinator_thread.Join (nullptr);
 }
 
 bool

Modified: lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.h?rev=229875&r1=229874&r2=229875&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.h (original)
+++ lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.h Thu Feb 19 11:58:04 2015
@@ -62,12 +62,6 @@ namespace lldb_private
             NativeProcessProtocolSP &native_process_sp);
 
         // ---------------------------------------------------------------------
-        // Public Instance Methods
-        // ---------------------------------------------------------------------
-
-        ~NativeProcessLinux() override;
-
-        // ---------------------------------------------------------------------
         // NativeProcessProtocol Interface
         // ---------------------------------------------------------------------
         Error
@@ -118,6 +112,9 @@ namespace lldb_private
         void
         DoStopIDBumped (uint32_t newBumpId) override;
 
+        void
+        Terminate () override;
+
         // ---------------------------------------------------------------------
         // Interface used by NativeRegisterContext-derived classes.
         // ---------------------------------------------------------------------

Modified: lldb/trunk/source/Plugins/Process/Linux/NativeThreadLinux.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/NativeThreadLinux.cpp?rev=229875&r1=229874&r2=229875&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Linux/NativeThreadLinux.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Linux/NativeThreadLinux.cpp Thu Feb 19 11:58:04 2015
@@ -270,13 +270,17 @@ NativeThreadLinux::SetRunning ()
     // then this is a new thread. So set all existing watchpoints.
     if (m_watchpoint_index_map.empty())
     {
-        const auto &watchpoint_map = GetProcess()->GetWatchpointMap();
-        if (watchpoint_map.empty()) return;
-        GetRegisterContext()->ClearAllHardwareWatchpoints();
-        for (const auto &pair : watchpoint_map)
+        const auto process_sp = GetProcess();
+        if (process_sp)
         {
-            const auto& wp = pair.second;
-            SetWatchpoint(wp.m_addr, wp.m_size, wp.m_watch_flags, wp.m_hardware);
+            const auto &watchpoint_map = process_sp->GetWatchpointMap();
+            if (watchpoint_map.empty()) return;
+            GetRegisterContext()->ClearAllHardwareWatchpoints();
+            for (const auto &pair : watchpoint_map)
+            {
+                const auto& wp = pair.second;
+                SetWatchpoint(wp.m_addr, wp.m_size, wp.m_watch_flags, wp.m_hardware);
+            }
         }
     }
 }

Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp?rev=229875&r1=229874&r2=229875&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp Thu Feb 19 11:58:04 2015
@@ -99,6 +99,13 @@ GDBRemoteCommunicationServerLLGS::GDBRem
 //----------------------------------------------------------------------
 GDBRemoteCommunicationServerLLGS::~GDBRemoteCommunicationServerLLGS()
 {
+    Mutex::Locker locker (m_debugged_process_mutex);
+
+    if (m_debugged_process_sp)
+    {
+        m_debugged_process_sp->Terminate ();
+        m_debugged_process_sp.reset ();
+    }
 }
 
 void





More information about the lldb-commits mailing list