Hi abidh,

This patch includes:
# Fix invalid thread id in =thread-exited message
# Remove invalid threads from cache

All tests pass on OS X.

http://reviews.llvm.org/D8603

Files:
  source/Target/Process.cpp
  tools/lldb-mi/MICmdCmdMiscellanous.cpp
  tools/lldb-mi/MICmnLLDBDebuggerHandleEvents.cpp

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
Index: source/Target/Process.cpp
===================================================================
--- source/Target/Process.cpp
+++ source/Target/Process.cpp
@@ -822,32 +822,8 @@
 void
 Process::Finalize()
 {
-    switch (GetPrivateState())
-    {
-        case eStateConnected:
-        case eStateAttaching:
-        case eStateLaunching:
-        case eStateStopped:
-        case eStateRunning:
-        case eStateStepping:
-        case eStateCrashed:
-        case eStateSuspended:
-            if (GetShouldDetach())
-            {
-                // FIXME: This will have to be a process setting:
-                bool keep_stopped = false;
-                Detach(keep_stopped);
-            }
-            else
-                Destroy();
-            break;
-            
-        case eStateInvalid:
-        case eStateUnloaded:
-        case eStateDetached:
-        case eStateExited:
-            break;
-    }
+    // Destroy this process first
+    Destroy();
 
     // Clear our broadcaster before we proceed with destroying
     Broadcaster::Clear();
@@ -3952,6 +3928,13 @@
     // that might hinder the destruction.  Remember to set this back to false when we are done.  That way if the attempt
     // failed and the process stays around for some reason it won't be in a confused state.
     
+    if (GetShouldDetach())
+    {
+        // FIXME: This will have to be a process setting:
+        bool keep_stopped = false;
+        Detach(keep_stopped);
+    }
+
     m_destroy_in_process = true;
 
     Error error (WillDestroy());
Index: tools/lldb-mi/MICmdCmdMiscellanous.cpp
===================================================================
--- tools/lldb-mi/MICmdCmdMiscellanous.cpp
+++ tools/lldb-mi/MICmdCmdMiscellanous.cpp
@@ -74,7 +74,7 @@
 CMICmdCmdGdbExit::Execute(void)
 {
     CMICmnLLDBDebugger::Instance().GetDriver().SetExitApplicationFlag(true);
-    const lldb::SBError sbErr = m_rLLDBDebugSessionInfo.GetProcess().Detach();
+    const lldb::SBError sbErr = m_rLLDBDebugSessionInfo.GetProcess().Destroy();
     // Do not check for sbErr.Fail() here, m_lldbProcess is likely !IsValid()
 
     return MIstatus::success;
Index: tools/lldb-mi/MICmnLLDBDebuggerHandleEvents.cpp
===================================================================
--- tools/lldb-mi/MICmnLLDBDebuggerHandleEvents.cpp
+++ tools/lldb-mi/MICmnLLDBDebuggerHandleEvents.cpp
@@ -1612,14 +1612,10 @@
 bool
 CMICmnLLDBDebuggerHandleEvents::ChkForStateChanges(void)
 {
-    lldb::SBProcess sbProcess = CMICmnLLDBDebugSessionInfo::Instance().GetProcess();
+    CMICmnLLDBDebugSessionInfo &rSessionInfo(CMICmnLLDBDebugSessionInfo::Instance());
+    lldb::SBProcess sbProcess = rSessionInfo.GetProcess();
     if (!sbProcess.IsValid())
         return MIstatus::success;
-    lldb::SBTarget sbTarget = CMICmnLLDBDebugSessionInfo::Instance().GetTarget();
-    if (!sbTarget.IsValid())
-        return MIstatus::success;
-
-    bool bOk = MIstatus::success;
 
     // Check for created threads
     const MIuint nThread = sbProcess.GetNumThreads();
@@ -1631,33 +1627,20 @@
         if (!thread.IsValid())
             continue;
 
-        CMICmnLLDBDebugSessionInfo::VecActiveThreadId_t::const_iterator it =
-            CMICmnLLDBDebugSessionInfo::Instance().m_vecActiveThreadId.begin();
-        bool bFound = false;
-        while (it != CMICmnLLDBDebugSessionInfo::Instance().m_vecActiveThreadId.end())
-        {
-            const MIuint nThreadId = *it;
-            if (nThreadId == i)
-            {
-                bFound = true;
-                break;
-            }
-
-            // Next
-            ++it;
-        }
+        const MIuint threadIndexID = thread.GetIndexID();
+        const bool bFound = std::find(rSessionInfo.m_vecActiveThreadId.begin(), rSessionInfo.m_vecActiveThreadId.end(), threadIndexID) != rSessionInfo.m_vecActiveThreadId.end();
         if (!bFound)
         {
-            CMICmnLLDBDebugSessionInfo::Instance().m_vecActiveThreadId.push_back(i);
+            rSessionInfo.m_vecActiveThreadId.push_back(threadIndexID);
 
             // Form MI "=thread-created,id=\"%d\",group-id=\"i1\""
-            const CMIUtilString strValue(CMIUtilString::Format("%d", thread.GetIndexID()));
+            const CMIUtilString strValue(CMIUtilString::Format("%d", threadIndexID));
             const CMICmnMIValueConst miValueConst(strValue);
             const CMICmnMIValueResult miValueResult("id", miValueConst);
             CMICmnMIOutOfBandRecord miOutOfBand(CMICmnMIOutOfBandRecord::eOutOfBand_ThreadCreated, miValueResult);
             const CMICmnMIValueConst miValueConst2("i1");
             const CMICmnMIValueResult miValueResult2("group-id", miValueConst2);
-            bOk = miOutOfBand.Add(miValueResult2);
+            bool bOk = miOutOfBand.Add(miValueResult2);
             bOk = bOk && MiOutOfBandRecordToStdout(miOutOfBand);
             if (!bOk)
                 return MIstatus::failure;
@@ -1667,13 +1650,13 @@
     lldb::SBThread currentThread = sbProcess.GetSelectedThread();
     if (currentThread.IsValid())
     {
-        const MIuint threadId = currentThread.GetIndexID();
-        if (CMICmnLLDBDebugSessionInfo::Instance().m_currentSelectedThread != threadId)
+        const MIuint currentThreadIndexID = currentThread.GetIndexID();
+        if (rSessionInfo.m_currentSelectedThread != currentThreadIndexID)
         {
-            CMICmnLLDBDebugSessionInfo::Instance().m_currentSelectedThread = threadId;
+            rSessionInfo.m_currentSelectedThread = currentThreadIndexID;
 
             // Form MI "=thread-selected,id=\"%d\""
-            const CMIUtilString strValue(CMIUtilString::Format("%d", currentThread.GetIndexID()));
+            const CMIUtilString strValue(CMIUtilString::Format("%d", currentThreadIndexID));
             const CMICmnMIValueConst miValueConst(strValue);
             const CMICmnMIValueResult miValueResult("id", miValueConst);
             CMICmnMIOutOfBandRecord miOutOfBand(CMICmnMIOutOfBandRecord::eOutOfBand_ThreadSelected, miValueResult);
@@ -1683,28 +1666,31 @@
     }
 
     // Check for invalid (removed) threads
-    CMICmnLLDBDebugSessionInfo::VecActiveThreadId_t::const_iterator it = CMICmnLLDBDebugSessionInfo::Instance().m_vecActiveThreadId.begin();
-    while (it != CMICmnLLDBDebugSessionInfo::Instance().m_vecActiveThreadId.end())
+    CMICmnLLDBDebugSessionInfo::VecActiveThreadId_t::const_iterator it = rSessionInfo.m_vecActiveThreadId.begin();
+    while (it != rSessionInfo.m_vecActiveThreadId.end())
     {
-        const MIuint nThreadId = *it;
-        lldb::SBThread thread = sbProcess.GetThreadAtIndex(nThreadId);
+        const MIuint threadIndexID = *it;
+        lldb::SBThread thread = sbProcess.GetThreadByIndexID(threadIndexID);
         if (!thread.IsValid())
         {
             // Form MI "=thread-exited,id=\"%ld\",group-id=\"i1\""
-            const CMIUtilString strValue(CMIUtilString::Format("%ld", thread.GetIndexID()));
+            const CMIUtilString strValue(CMIUtilString::Format("%ld", threadIndexID));
             const CMICmnMIValueConst miValueConst(strValue);
             const CMICmnMIValueResult miValueResult("id", miValueConst);
             CMICmnMIOutOfBandRecord miOutOfBand(CMICmnMIOutOfBandRecord::eOutOfBand_ThreadExited, miValueResult);
             const CMICmnMIValueConst miValueConst2("i1");
             const CMICmnMIValueResult miValueResult2("group-id", miValueConst2);
-            bOk = miOutOfBand.Add(miValueResult2);
+            bool bOk = miOutOfBand.Add(miValueResult2);
             bOk = bOk && MiOutOfBandRecordToStdout(miOutOfBand);
             if (!bOk)
                 return MIstatus::failure;
-        }
 
-        // Next
-        ++it;
+            // Remove current thread from cache and get next
+            it = rSessionInfo.m_vecActiveThreadId.erase(it);
+        }
+        else
+            // Next
+            ++it;
     }
 
     return TextToStdout("(gdb)");
_______________________________________________
lldb-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits

Reply via email to