[Lldb-commits] [lldb] r160187 - in /lldb/trunk: include/lldb/API/SBProcess.h scripts/Python/interface/SBProcess.i scripts/Python/interface/SBThread.i source/API/SBProcess.cpp

Jim Ingham jingham at apple.com
Fri Jul 13 13:18:18 PDT 2012


Author: jingham
Date: Fri Jul 13 15:18:18 2012
New Revision: 160187

URL: http://llvm.org/viewvc/llvm-project?rev=160187&view=rev
Log:
Add accessors on process to get & set the selected thread by IndexID (useful since that's the one that "thread list" shows and it won't get reused even if the underlying system thread ID gets reused.

Modified:
    lldb/trunk/include/lldb/API/SBProcess.h
    lldb/trunk/scripts/Python/interface/SBProcess.i
    lldb/trunk/scripts/Python/interface/SBThread.i
    lldb/trunk/source/API/SBProcess.cpp

Modified: lldb/trunk/include/lldb/API/SBProcess.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBProcess.h?rev=160187&r1=160186&r2=160187&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBProcess.h (original)
+++ lldb/trunk/include/lldb/API/SBProcess.h Fri Jul 13 15:18:18 2012
@@ -105,6 +105,9 @@
     GetThreadByID (lldb::tid_t sb_thread_id);
 
     lldb::SBThread
+    GetThreadByIndexID (uint32_t index_id);
+
+    lldb::SBThread
     GetSelectedThread () const;
 
     bool
@@ -112,6 +115,9 @@
 
     bool
     SetSelectedThreadByID (uint32_t tid);
+    
+    bool
+    SetSelectedThreadByIndexID (uint32_t index_id);
 
     //------------------------------------------------------------------
     // Stepping related functions

Modified: lldb/trunk/scripts/Python/interface/SBProcess.i
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBProcess.i?rev=160187&r1=160186&r2=160187&view=diff
==============================================================================
--- lldb/trunk/scripts/Python/interface/SBProcess.i (original)
+++ lldb/trunk/scripts/Python/interface/SBProcess.i Fri Jul 13 15:18:18 2012
@@ -127,12 +127,30 @@
     uint32_t
     GetNumThreads ();
 
+    %feature("autodoc", "
+    Returns the INDEX'th thread from the list of current threads.  The index
+    of a thread is only valid for the current stop.  For a persistent thread
+    identifier use either the thread ID or the IndexID.  See help on SBThread
+    for more details.
+    ") GetThreadAtIndex;
     lldb::SBThread
     GetThreadAtIndex (size_t index);
 
+    %feature("autodoc", "
+    Returns the thread with the given thread ID.
+    ") GetThreadByID;
     lldb::SBThread
     GetThreadByID (lldb::tid_t sb_thread_id);
+    
+    %feature("autodoc", "
+    Returns the thread with the given thread IndexID.
+    ") GetThreadByIndexID;
+    lldb::SBThread
+    GetThreadByIndexID (uint32_t index_id);
 
+    %feature("autodoc", "
+    Returns the currently selected thread.
+    ") GetSelectedThread;
     lldb::SBThread
     GetSelectedThread () const;
 
@@ -142,6 +160,9 @@
     bool
     SetSelectedThreadByID (uint32_t tid);
 
+    bool
+    SetSelectedThreadByIndexID (uint32_t index_id);
+    
     //------------------------------------------------------------------
     // Stepping related functions
     //------------------------------------------------------------------

Modified: lldb/trunk/scripts/Python/interface/SBThread.i
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/interface/SBThread.i?rev=160187&r1=160186&r2=160187&view=diff
==============================================================================
--- lldb/trunk/scripts/Python/interface/SBThread.i (original)
+++ lldb/trunk/scripts/Python/interface/SBThread.i Fri Jul 13 15:18:18 2012
@@ -12,6 +12,12 @@
 %feature("docstring",
 "Represents a thread of execution. SBProcess contains SBThread(s).
 
+SBThreads can be referred to by their ID, which maps to the system specific thread
+identifier, or by IndexID.  The ID may or may not be unique depending on whether the
+system reuses its thread identifiers.  The IndexID is a monotonically increasing identifier
+that will always uniquely reference a particular thread, and when that thread goes
+away it will not be reused.
+
 SBThread supports frame iteration. For example (from test/python_api/
 lldbutil/iter/TestLLDBIterator.py),
 

Modified: lldb/trunk/source/API/SBProcess.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBProcess.cpp?rev=160187&r1=160186&r2=160187&view=diff
==============================================================================
--- lldb/trunk/source/API/SBProcess.cpp (original)
+++ lldb/trunk/source/API/SBProcess.cpp Fri Jul 13 15:18:18 2012
@@ -405,6 +405,26 @@
     return ret_val;
 }
 
+bool
+SBProcess::SetSelectedThreadByIndexID (uint32_t index_id)
+{
+    LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
+
+    bool ret_val = false;
+    ProcessSP process_sp(GetSP());
+    if (process_sp)
+    {
+        Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
+        ret_val = process_sp->GetThreadList().SetSelectedThreadByIndexID (index_id);
+    }
+
+    if (log)
+        log->Printf ("SBProcess(%p)::SetSelectedThreadByID (tid=0x%x) => %s", 
+                     process_sp.get(), index_id, (ret_val ? "true" : "false"));
+
+    return ret_val;
+}
+
 SBThread
 SBProcess::GetThreadAtIndex (size_t index)
 {
@@ -725,6 +745,33 @@
     return sb_thread;
 }
 
+SBThread
+SBProcess::GetThreadByIndexID (uint32_t index_id)
+{
+    SBThread sb_thread;
+    ThreadSP thread_sp;
+    ProcessSP process_sp(GetSP());
+    if (process_sp)
+    {
+        Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
+        Process::StopLocker stop_locker;
+        const bool can_update = stop_locker.TryLock(&process_sp->GetRunLock());
+        thread_sp = process_sp->GetThreadList().FindThreadByIndexID (index_id, can_update);
+        sb_thread.SetThread (thread_sp);
+    }
+
+    LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
+    if (log)
+    {
+        log->Printf ("SBProcess(%p)::GetThreadByID (tid=0x%x) => SBThread (%p)", 
+                     process_sp.get(), 
+                     index_id,
+                     thread_sp.get());
+    }
+
+    return sb_thread;
+}
+
 StateType
 SBProcess::GetStateFromEvent (const SBEvent &event)
 {





More information about the lldb-commits mailing list