[Lldb-commits] [lldb] r124018 - in /lldb/trunk: include/lldb/Target/Process.h source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp source/Plugins/Process/gdb-remote/ProcessGDBRemote.h source/Target/ThreadList.cpp

Jim Ingham jingham at apple.com
Fri Jan 21 17:33:44 PST 2011


Author: jingham
Date: Fri Jan 21 19:33:44 2011
New Revision: 124018

URL: http://llvm.org/viewvc/llvm-project?rev=124018&view=rev
Log:
Added an interface for noticing new thread creation.  At this point, I only turn it on when 
we are requesting a single thread to run.  May seem like a silly thing to do, but the kernel 
on MacOS X will inject new threads into a program willy-nilly, and I would like to keep them
from running if I can.

Modified:
    lldb/trunk/include/lldb/Target/Process.h
    lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
    lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
    lldb/trunk/source/Target/ThreadList.cpp

Modified: lldb/trunk/include/lldb/Target/Process.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Process.h?rev=124018&r1=124017&r2=124018&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Process.h (original)
+++ lldb/trunk/include/lldb/Target/Process.h Fri Jan 21 19:33:44 2011
@@ -1753,6 +1753,18 @@
         m_dynamic_checkers_ap.reset(dynamic_checkers);
     }
 
+    virtual bool
+    StartNoticingNewThreads()
+    {   
+        return true;
+    }
+    
+    virtual bool
+    StopNoticingNewThreads()
+    {   
+        return true;
+    }
+    
     //------------------------------------------------------------------
     // lldb::ExecutionContextScope pure virtual functions
     //------------------------------------------------------------------

Modified: lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp?rev=124018&r1=124017&r2=124018&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp Fri Jan 21 19:33:44 2011
@@ -119,7 +119,8 @@
     m_packet_timeout (1),
     m_max_memory_size (512),
     m_waiting_for_attach (false),
-    m_local_debugserver (true)
+    m_local_debugserver (true),
+    m_thread_observation_bps()
 {
 }
 
@@ -2279,3 +2280,91 @@
     }
 
 }
+
+bool
+ProcessGDBRemote::NewThreadNotifyBreakpointHit (void *baton,
+                             lldb_private::StoppointCallbackContext *context,
+                             lldb::user_id_t break_id,
+                             lldb::user_id_t break_loc_id)
+{
+    // I don't think I have to do anything here, just make sure I notice the new thread when it starts to 
+    // run so I can stop it if that's what I want to do.
+    LogSP log (lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
+    if (log)
+        log->Printf("Hit New Thread Notification breakpoint.");
+    return false;
+}
+
+
+bool
+ProcessGDBRemote::StartNoticingNewThreads()
+{
+    static const char *bp_names[] =
+    {
+        "start_wqthread",
+        "_pthread_start",
+        NULL
+    };
+    
+    LogSP log (lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
+    size_t num_bps = m_thread_observation_bps.size();
+    if (num_bps != 0)
+    {
+        for (int i = 0; i < num_bps; i++)
+        {
+            lldb::BreakpointSP break_sp = m_target.GetBreakpointByID(m_thread_observation_bps[i]);
+            if (break_sp)
+            {
+                if (log)
+                    log->Printf("Enabled noticing new thread breakpoint.");
+                break_sp->SetEnabled(true);
+            }
+        }
+    }
+    else 
+    {
+        for (int i = 0; bp_names[i] != NULL; i++)
+        {
+            Breakpoint *breakpoint = m_target.CreateBreakpoint (NULL, bp_names[i], eFunctionNameTypeFull, true).get();
+            if (breakpoint)
+            {
+                if (log)
+                     log->Printf("Successfully created new thread notification breakpoint at \"%s\".", bp_names[i]);
+                m_thread_observation_bps.push_back(breakpoint->GetID());
+                breakpoint->SetCallback (ProcessGDBRemote::NewThreadNotifyBreakpointHit, this, true);
+            }
+            else
+            {
+                if (log)
+                    log->Printf("Failed to create new thread notification breakpoint.");
+                return false;
+            }
+        }
+    }
+
+    return true;
+}
+
+bool
+ProcessGDBRemote::StopNoticingNewThreads()
+{   
+    size_t num_bps = m_thread_observation_bps.size();
+    if (num_bps != 0)
+    {
+        for (int i = 0; i < num_bps; i++)
+        {
+            LogSP log (lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
+            
+            lldb::BreakpointSP break_sp = m_target.GetBreakpointByID(m_thread_observation_bps[i]);
+            if (break_sp)
+            {
+                if (log)
+                    log->Printf ("Disabling new thread notification breakpoint.");
+                break_sp->SetEnabled(false);
+            }
+        }
+    }
+    return true;
+}
+    
+

Modified: lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h?rev=124018&r1=124017&r2=124018&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h Fri Jan 21 19:33:44 2011
@@ -216,6 +216,12 @@
 
     virtual lldb_private::DynamicLoader *
     GetDynamicLoader ();
+    
+    virtual bool
+    StartNoticingNewThreads();    
+
+    virtual bool
+    StopNoticingNewThreads();    
 
 protected:
     friend class ThreadGDBRemote;
@@ -336,6 +342,7 @@
     size_t m_max_memory_size;       // The maximum number of bytes to read/write when reading and writing memory
     bool m_waiting_for_attach;
     bool m_local_debugserver;  // Is the debugserver process we are talking to local or on another machine.
+    std::vector<lldb::user_id_t>  m_thread_observation_bps;
 
     void
     ResetGDBRemoteState ();
@@ -379,6 +386,12 @@
     //------------------------------------------------------------------
     // For ProcessGDBRemote only
     //------------------------------------------------------------------
+    static bool
+    NewThreadNotifyBreakpointHit (void *baton,
+                         lldb_private::StoppointCallbackContext *context,
+                         lldb::user_id_t break_id,
+                         lldb::user_id_t break_loc_id);
+
     DISALLOW_COPY_AND_ASSIGN (ProcessGDBRemote);
 
 };

Modified: lldb/trunk/source/Target/ThreadList.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/ThreadList.cpp?rev=124018&r1=124017&r2=124018&view=diff
==============================================================================
--- lldb/trunk/source/Target/ThreadList.cpp (original)
+++ lldb/trunk/source/Target/ThreadList.cpp Fri Jan 21 19:33:44 2011
@@ -352,6 +352,10 @@
     Mutex::Locker locker(m_threads_mutex);
 
     m_process->UpdateThreadListIfNeeded();
+    
+    LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
+    if (log)
+        log->Printf ("Turning off notification of new threads while single stepping a thread.");
 
     collection::iterator pos, end = m_threads.end();
     for (pos = m_threads.begin(); pos != end; ++pos)
@@ -403,6 +407,20 @@
         }
     }   
 
+    if (wants_solo_run)
+    {
+        LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
+        if (log)
+            log->Printf ("Turning on notification of new threads while single stepping a thread.");
+        m_process->StartNoticingNewThreads();
+    }
+    else
+    {
+        LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
+        if (log)
+            log->Printf ("Turning off notification of new threads while single stepping a thread.");
+        m_process->StopNoticingNewThreads();
+    }
     
     // Give all the threads that are likely to run a last chance to set up their state before we
     // negotiate who is actually going to get a chance to run...





More information about the lldb-commits mailing list