[Lldb-commits] [lldb] r124818 - in /lldb/trunk: include/lldb/API/SBListener.h include/lldb/API/SBTarget.h source/API/SBListener.cpp source/API/SBTarget.cpp

Greg Clayton gclayton at apple.com
Thu Feb 3 13:28:34 PST 2011


Author: gclayton
Date: Thu Feb  3 15:28:34 2011
New Revision: 124818

URL: http://llvm.org/viewvc/llvm-project?rev=124818&view=rev
Log:
Added a SBListener parameter to Launch and attach calls to avoid a race
condition that could occur when launching or attaching. What could happen is
you would launch/attach to a process, then you would need to tell a listener
to watch for process state changed events. In this case, if you waited too
long to listen for events, you could miss the initial stop event, requiring
clients to listen, then check the process state. 


Modified:
    lldb/trunk/include/lldb/API/SBListener.h
    lldb/trunk/include/lldb/API/SBTarget.h
    lldb/trunk/source/API/SBListener.cpp
    lldb/trunk/source/API/SBTarget.cpp

Modified: lldb/trunk/include/lldb/API/SBListener.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBListener.h?rev=124818&r1=124817&r2=124818&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBListener.h (original)
+++ lldb/trunk/include/lldb/API/SBListener.h Thu Feb  3 15:28:34 2011
@@ -109,6 +109,9 @@
     get() const;
 
     lldb_private::Listener &
+    ref() const;
+        
+    lldb_private::Listener &
     operator *();
 
     const lldb_private::Listener &

Modified: lldb/trunk/include/lldb/API/SBTarget.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBTarget.h?rev=124818&r1=124817&r2=124818&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBTarget.h (original)
+++ lldb/trunk/include/lldb/API/SBTarget.h Thu Feb  3 15:28:34 2011
@@ -54,8 +54,60 @@
     lldb::SBProcess
     GetProcess ();
 
+    //------------------------------------------------------------------
+    /// Launch a new process.
+    ///
+    /// Launch a new process by spawning a new process using the
+    /// target object's executable module's file as the file to launch.
+    /// Arguments are given in \a argv, and the environment variables
+    /// are in \a envp. Standard input and output files can be
+    /// optionally re-directed to \a stdin_path, \a stdout_path, and
+    /// \a stderr_path.
+    ///
+    /// @param[in] listener
+    ///     An optional listener that will receive all process events.
+    ///     If \a listener is valid then \a listener will listen to all
+    ///     process events. If not valid, then this target's debugger
+    ///     (SBTarget::GetDebugger()) will listen to all process events. 
+    ///
+    /// @param[in] argv
+    ///     The argument array.
+    ///
+    /// @param[in] envp
+    ///     The environment array.
+    ///
+    /// @param[in] launch_flags
+    ///     Flags to modify the launch (@see lldb::LaunchFlags)
+    ///
+    /// @param[in] stdin_path
+    ///     The path to use when re-directing the STDIN of the new
+    ///     process. If all stdXX_path arguments are NULL, a pseudo
+    ///     terminal will be used.
+    ///
+    /// @param[in] stdout_path
+    ///     The path to use when re-directing the STDOUT of the new
+    ///     process. If all stdXX_path arguments are NULL, a pseudo
+    ///     terminal will be used.
+    ///
+    /// @param[in] stderr_path
+    ///     The path to use when re-directing the STDERR of the new
+    ///     process. If all stdXX_path arguments are NULL, a pseudo
+    ///     terminal will be used.
+    ///
+    /// @param[in] working_directory
+    ///     The working directory to have the child process run in
+    ///
+    /// @param[in] launch_flags
+    ///     Some launch options specified by logical OR'ing 
+    ///     lldb::LaunchFlags enumeration values together.
+    ///
+    /// @return
+    ///     An error object. Call GetID() to get the process ID if
+    ///     the error object is success.
+    //------------------------------------------------------------------
     lldb::SBProcess
-    Launch (char const **argv,
+    Launch (SBListener &listener, 
+            char const **argv,
             char const **envp,
             const char *stdin_path,
             const char *stdout_path,
@@ -65,12 +117,65 @@
             bool stop_at_entry,
             lldb::SBError& error);
     
+    //------------------------------------------------------------------
+    /// Launch a new process.
+    ///
+    /// Launch a new process by spawning a new process using the
+    /// target object's executable module's file as the file to launch.
+    /// Arguments are given in \a argv, and the environment variables
+    /// are in \a envp. Standard input and output files can be
+    /// optionally re-directed to \a stdin_path, \a stdout_path, and
+    /// \a stderr_path.
+    ///
+    /// @param[in] listener
+    ///     An optional listener that will receive all process events.
+    ///     If NULL, then the this target's debugger (SBTarget::GetDebugger())
+    ///     will listen to all process events. If non-NULL, \a listener
+    ///     will listen to all process events.
+    ///
+    /// @param[in] argv
+    ///     The argument array.
+    ///
+    /// @param[in] envp
+    ///     The environment array.
+    ///
+    /// @param[in] launch_flags
+    ///     Flags to modify the launch (@see lldb::LaunchFlags)
+    ///
+    /// @param[in] stdin_path
+    ///     The path to use when re-directing the STDIN of the new
+    ///     process. If all stdXX_path arguments are NULL, a pseudo
+    ///     terminal will be used.
+    ///
+    /// @param[in] stdout_path
+    ///     The path to use when re-directing the STDOUT of the new
+    ///     process. If all stdXX_path arguments are NULL, a pseudo
+    ///     terminal will be used.
+    ///
+    /// @param[in] stderr_path
+    ///     The path to use when re-directing the STDERR of the new
+    ///     process. If all stdXX_path arguments are NULL, a pseudo
+    ///     terminal will be used.
+    ///
+    /// @param[in] working_directory
+    ///     The working directory to have the child process run in
+    ///
+    /// @param[in] launch_flags
+    ///     Some launch options specified by logical OR'ing 
+    ///     lldb::LaunchFlags enumeration values together.
+    ///
+    /// @return
+    ///     An error object. Call GetID() to get the process ID if
+    ///     the error object is success.
+    //------------------------------------------------------------------
     lldb::SBProcess
-    AttachToProcessWithID (lldb::pid_t pid, // The process ID to attach to
+    AttachToProcessWithID (SBListener &listener, 
+                           lldb::pid_t pid, // The process ID to attach to
                            lldb::SBError& error); // An error explaining what went wrong if attach fails
 
     lldb::SBProcess
-    AttachToProcessWithName (const char *name,  // basename of process to attach to
+    AttachToProcessWithName (SBListener &listener, 
+                             const char *name,  // basename of process to attach to
                              bool wait_for,     // if true wait for a new instance of "name" to be launched
                              lldb::SBError& error);   // An error explaining what went wrong if attach fails
 

Modified: lldb/trunk/source/API/SBListener.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBListener.cpp?rev=124818&r1=124817&r2=124818&view=diff
==============================================================================
--- lldb/trunk/source/API/SBListener.cpp (original)
+++ lldb/trunk/source/API/SBListener.cpp Thu Feb  3 15:28:34 2011
@@ -386,6 +386,11 @@
     m_opaque_ptr = listener;
 }
 
+Listener &
+SBListener::ref() const
+{
+    return *m_opaque_ptr;    
+}
 
 Listener &
 SBListener::operator *()

Modified: lldb/trunk/source/API/SBTarget.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBTarget.cpp?rev=124818&r1=124817&r2=124818&view=diff
==============================================================================
--- lldb/trunk/source/API/SBTarget.cpp (original)
+++ lldb/trunk/source/API/SBTarget.cpp Thu Feb  3 15:28:34 2011
@@ -121,6 +121,7 @@
 SBProcess
 SBTarget::Launch 
 (
+    SBListener &listener, 
     char const **argv,
     char const **envp,
     const char *stdin_path,
@@ -218,7 +219,7 @@
 
                     if (pid != LLDB_INVALID_PROCESS_ID)
                     {
-                        sb_process = AttachToProcessWithID(pid, error);
+                        sb_process = AttachToProcessWithID(listener, pid, error);
                     }
                     else
                     {
@@ -237,7 +238,10 @@
         }
         else
         {
-            sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener()));
+            if (listener.IsValid())
+                sb_process.SetProcess (m_opaque_sp->CreateProcess (listener.ref()));
+            else
+                sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener()));
 
             if (sb_process.IsValid())
             {
@@ -294,6 +298,7 @@
 lldb::SBProcess
 SBTarget::AttachToProcessWithID 
 (
+    SBListener &listener, 
     lldb::pid_t pid,// The process ID to attach to
     SBError& error  // An error explaining what went wrong if attach fails
 )
@@ -302,7 +307,11 @@
     if (m_opaque_sp)
     {
         Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
-        sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener()));
+        if (listener.IsValid())
+            sb_process.SetProcess (m_opaque_sp->CreateProcess (listener.ref()));
+        else
+            sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener()));
+        
 
         if (sb_process.IsValid())
         {
@@ -324,6 +333,7 @@
 lldb::SBProcess
 SBTarget::AttachToProcessWithName 
 (
+    SBListener &listener, 
     const char *name,   // basename of process to attach to
     bool wait_for,      // if true wait for a new instance of "name" to be launched
     SBError& error      // An error explaining what went wrong if attach fails
@@ -334,7 +344,10 @@
     {
         Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex());
 
-        sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener()));
+        if (listener.IsValid())
+            sb_process.SetProcess (m_opaque_sp->CreateProcess (listener.ref()));
+        else
+            sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener()));
 
         if (sb_process.IsValid())
         {





More information about the lldb-commits mailing list