Broadcast an event when the selected thread is changed.
authorJim Ingham <jingham@apple.com>
Tue, 11 Dec 2012 02:31:48 +0000 (02:31 +0000)
committerJim Ingham <jingham@apple.com>
Tue, 11 Dec 2012 02:31:48 +0000 (02:31 +0000)
<rdar://problem/10976636>

llvm-svn: 169810

lldb/include/lldb/API/SBThread.h
lldb/include/lldb/Target/Thread.h
lldb/include/lldb/Target/ThreadList.h
lldb/source/Commands/CommandObjectThread.cpp
lldb/source/Target/ThreadList.cpp
lldb/tools/driver/Driver.cpp

index a77bd5b..62abed1 100644 (file)
@@ -26,7 +26,8 @@ public:
         eBroadcastBitStackChanged           = (1 << 0),
         eBroadcastBitThreadSuspended        = (1 << 1),
         eBroadcastBitThreadResumed          = (1 << 2),
-        eBroadcastBitSelectedFrameChanged  = (1 << 3)
+        eBroadcastBitSelectedFrameChanged   = (1 << 3),
+        eBroadcastBitThreadSelected         = (1 << 4)
     };
 
     static const char *
index d02d070..8eb3202 100644 (file)
@@ -57,6 +57,7 @@ class Thread :
     public Broadcaster
 {
 friend class ThreadEventData;
+friend class ThreadList;
 
 public:
     //------------------------------------------------------------------
@@ -67,7 +68,8 @@ public:
         eBroadcastBitStackChanged           = (1 << 0),
         eBroadcastBitThreadSuspended        = (1 << 1),
         eBroadcastBitThreadResumed          = (1 << 2),
-        eBroadcastBitSelectedFrameChanged  = (1 << 3)
+        eBroadcastBitSelectedFrameChanged   = (1 << 3),
+        eBroadcastBitThreadSelected         = (1 << 4)
     };
 
     static ConstString &GetStaticBroadcasterClass ();
index 609cb51..85c6863 100644 (file)
@@ -51,10 +51,10 @@ public:
     GetSelectedThread ();
 
     bool
-    SetSelectedThreadByID (lldb::tid_t tid);
+    SetSelectedThreadByID (lldb::tid_t tid, bool notify = false);
 
     bool
-    SetSelectedThreadByIndexID (uint32_t index_id);
+    SetSelectedThreadByIndexID (uint32_t index_id, bool notify = false);
 
     void
     Clear();
@@ -131,6 +131,9 @@ public:
     
 protected:
 
+    void
+    NotifySelectedThreadChanged (lldb::tid_t tid);
+
     typedef std::vector<lldb::ThreadSP> collection;
     //------------------------------------------------------------------
     // Classes that inherit from Process can see and modify these
index 7098ca2..b5fa519 100644 (file)
@@ -1185,17 +1185,9 @@ protected:
             return false;
         }
 
-        process->GetThreadList().SetSelectedThreadByID(new_thread->GetID());
+        process->GetThreadList().SetSelectedThreadByID(new_thread->GetID(), true);
         result.SetStatus (eReturnStatusSuccessFinishNoResult);
         
-        const uint32_t start_frame = 0;
-        const uint32_t num_frames = 1;
-        const uint32_t num_frames_with_source = 1;
-        new_thread->GetStatus (result.GetOutputStream(), 
-                               start_frame,
-                               num_frames,
-                               num_frames_with_source);
-
         return result.Succeeded();
     }
 
index fe38b57..9ce772e 100644 (file)
@@ -555,7 +555,7 @@ ThreadList::GetSelectedThread ()
 }
 
 bool
-ThreadList::SetSelectedThreadByID (lldb::tid_t tid)
+ThreadList::SetSelectedThreadByID (lldb::tid_t tid, bool notify)
 {
     Mutex::Locker locker(m_threads_mutex);
     ThreadSP selected_thread_sp(FindThreadByID(tid));
@@ -567,11 +567,14 @@ ThreadList::SetSelectedThreadByID (lldb::tid_t tid)
     else
         m_selected_tid = LLDB_INVALID_THREAD_ID;
 
+    if (notify)
+        NotifySelectedThreadChanged(m_selected_tid);
+    
     return m_selected_tid != LLDB_INVALID_THREAD_ID;
 }
 
 bool
-ThreadList::SetSelectedThreadByIndexID (uint32_t index_id)
+ThreadList::SetSelectedThreadByIndexID (uint32_t index_id, bool notify)
 {
     Mutex::Locker locker(m_threads_mutex);
     ThreadSP selected_thread_sp (FindThreadByIndexID(index_id));
@@ -583,10 +586,22 @@ ThreadList::SetSelectedThreadByIndexID (uint32_t index_id)
     else
         m_selected_tid = LLDB_INVALID_THREAD_ID;
 
+    if (notify)
+        NotifySelectedThreadChanged(m_selected_tid);
+    
     return m_selected_tid != LLDB_INVALID_THREAD_ID;
 }
 
 void
+ThreadList::NotifySelectedThreadChanged (lldb::tid_t tid)
+{
+    ThreadSP selected_thread_sp (FindThreadByID(tid));
+    if (selected_thread_sp->EventTypeHasListeners(Thread::eBroadcastBitThreadSelected))
+        selected_thread_sp->BroadcastEvent(Thread::eBroadcastBitThreadSelected,
+                                           new Thread::ThreadEventData(selected_thread_sp));
+}
+
+void
 ThreadList::Update (ThreadList &rhs)
 {
     if (this != &rhs)
index 2fbaf4e..38f2a34 100644 (file)
@@ -986,7 +986,8 @@ Driver::HandleThreadEvent (const SBEvent &event)
     // reprint the thread status for that thread.
     using namespace lldb;
     const uint32_t event_type = event.GetType();
-    if (event_type == SBThread::eBroadcastBitStackChanged)
+    if (event_type == SBThread::eBroadcastBitStackChanged
+        || event_type == SBThread::eBroadcastBitThreadSelected)
     {
         SBThread thread = SBThread::GetThreadFromEvent (event);
         if (thread.IsValid())
@@ -1302,7 +1303,8 @@ Driver::MainLoop ()
                                          SBTarget::eBroadcastBitBreakpointChanged);
         listener.StartListeningForEventClass(m_debugger, 
                                          SBThread::GetBroadcasterClassName(),
-                                         SBThread::eBroadcastBitStackChanged);
+                                         SBThread::eBroadcastBitStackChanged |
+                                         SBThread::eBroadcastBitThreadSelected);
         listener.StartListeningForEvents (*m_io_channel_ap,
                                           IOChannel::eBroadcastBitHasUserInput |
                                           IOChannel::eBroadcastBitUserInterrupt |