[Lldb-commits] [PATCH] D11449: Handle old style 'S' packet correctly

Bhushan Attarde bhushan.attarde at imgtec.com
Wed Jul 22 23:16:32 PDT 2015


bhushan created this revision.
bhushan added a reviewer: clayborg.
bhushan added subscribers: lldb-commits, jaydeep, sagar, mohit.bhakkad, nitesh.jain.
bhushan set the repository for this revision to rL LLVM.

This patch fixes couple of issues described below:

1. A thread tries to lock a mutex which is already locked. This happens in ProcessGDBRemote.cpp
 
ProcessGDBRemote::RefreshStateAfterStop ()
    - locks  m_last_stop_packet_mutex
    - access packet stack to get the stop info and 
    - call SetThreadStopInfo(stop_info)
		- calls UpdateThreadIDList() to get the thread list if the response is old style 'S' packet which does not provide the thread information.
		  This causes a problem because UpdateThreadIDList() again tries to aquire a lock on m_last_stop_packet_mutex (which is already locked).
		  
This patch fixes this issue by changing the Type of m_last_stop_packet_mutex to eMutexTypeRecursive so that the same thread can enter the mutex recursively.

2. The old style 'S' packet isn't handled correctly.
This patch fixes this issue by updating a thread list before the stop packet is parsed so that it can get a valid thread id and allows to set the stop info correctly.

Repository:
  rL LLVM

http://reviews.llvm.org/D11449

Files:
  source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp

Index: source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
===================================================================
--- source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -371,7 +371,7 @@
     m_flags (0),
     m_gdb_comm (),
     m_debugserver_pid (LLDB_INVALID_PROCESS_ID),
-    m_last_stop_packet_mutex (Mutex::eMutexTypeNormal),
+    m_last_stop_packet_mutex (Mutex::eMutexTypeRecursive),
     m_register_info (),
     m_async_broadcaster (NULL, "lldb.process.gdb-remote.async-broadcaster"),
     m_async_thread_state_mutex(Mutex::eMutexTypeRecursive),
@@ -2485,6 +2485,15 @@
                 }
             }
 
+            if (tid == LLDB_INVALID_THREAD_ID)
+            {
+                // A thread id may be invalid if the response is old style 'S' packet which does not provide the 
+                // thread information. So update the thread list and choose the first one.
+                UpdateThreadIDList ();
+
+                tid = m_thread_ids.front ();
+            }
+
             ThreadSP thread_sp = SetThreadStopInfo (tid,
                                                     expedited_register_map,
                                                     signo,
@@ -2499,19 +2508,6 @@
                                                     queue_kind,
                                                     queue_serial);
 
-            // If the response is old style 'S' packet which does not provide us with thread information
-            // then update the thread list and choose the first one.
-            if (!thread_sp)
-            {
-                UpdateThreadIDList ();
-
-                if (!m_thread_ids.empty ())
-                {
-                    Mutex::Locker locker (m_thread_list_real.GetMutex ());
-                    thread_sp = m_thread_list_real.FindThreadByProtocolID (m_thread_ids.front (), false);
-                }
-            }
-
             return eStateStopped;
         }
         break;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D11449.30450.patch
Type: text/x-patch
Size: 2031 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20150723/08f01048/attachment.bin>


More information about the lldb-commits mailing list