[Lldb-commits] [lldb] r249361 - SBTarget::Attach(SBAttachInfo &) was changed to not be asynchronous back in February and this affected Xcode's abililty to cancel an attach to process by name.

Greg Clayton via lldb-commits lldb-commits at lists.llvm.org
Mon Oct 5 15:58:37 PDT 2015


Author: gclayton
Date: Mon Oct  5 17:58:37 2015
New Revision: 249361

URL: http://llvm.org/viewvc/llvm-project?rev=249361&view=rev
Log:
SBTarget::Attach(SBAttachInfo &) was changed to not be asynchronous back in February and this affected Xcode's abililty to cancel an attach to process by name.

Added the ability to specify if an attach by name should be synchronous or not in SBAttachInfo and ProcessAttachInfo.

<rdar://problem/22821480>


Modified:
    lldb/trunk/include/lldb/API/SBAttachInfo.h
    lldb/trunk/include/lldb/Target/Process.h
    lldb/trunk/scripts/interface/SBAttachInfo.i
    lldb/trunk/source/API/SBAttachInfo.cpp
    lldb/trunk/source/Target/Target.cpp

Modified: lldb/trunk/include/lldb/API/SBAttachInfo.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBAttachInfo.h?rev=249361&r1=249360&r2=249361&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBAttachInfo.h (original)
+++ lldb/trunk/include/lldb/API/SBAttachInfo.h Mon Oct  5 17:58:37 2015
@@ -23,8 +23,47 @@ public:
 
     SBAttachInfo (lldb::pid_t pid);
 
+    //------------------------------------------------------------------
+    /// Attach to a process by name.
+    ///
+    /// This function implies that a future call to SBTarget::Attach(...)
+    /// will be synchronous.
+    ///
+    /// @param[in] path
+    ///     A full or partial name for the process to attach to.
+    ///
+    /// @param[in] wait_for
+    ///     If \b false, attach to an existing process whose name matches.
+    ///     If \b true, then wait for the next process whose name matches.
+    //------------------------------------------------------------------
     SBAttachInfo (const char *path, bool wait_for);
 
+    //------------------------------------------------------------------
+    /// Attach to a process by name.
+    ///
+    /// Future calls to SBTarget::Attach(...) will be synchronous or
+    /// asynchronous depending on the \a async argument.
+    ///
+    /// @param[in] path
+    ///     A full or partial name for the process to attach to.
+    ///
+    /// @param[in] wait_for
+    ///     If \b false, attach to an existing process whose name matches.
+    ///     If \b true, then wait for the next process whose name matches.
+    ///
+    /// @param[in] async
+    ///     If \b false, then the SBTarget::Attach(...) call will be a
+    ///     synchronous call with no way to cancel the attach in
+    ///     progress.
+    ///     If \b true, then the SBTarget::Attach(...) function will
+    ///     return immediately and clients are expected to wait for a
+    ///     process eStateStopped event if a suitable process is
+    ///     eventually found. If the client wants to cancel the event,
+    ///     SBProcess::Stop() can be called and an eStateExited process
+    ///     event will be delivered.
+    //------------------------------------------------------------------
+    SBAttachInfo (const char *path, bool wait_for, bool async);
+
     SBAttachInfo (const SBAttachInfo &rhs);
 
     ~SBAttachInfo();
@@ -47,9 +86,45 @@ public:
     bool
     GetWaitForLaunch ();
 
+    //------------------------------------------------------------------
+    /// Set attach by process name settings.
+    ///
+    /// Designed to be used after a call to SBAttachInfo::SetExecutable().
+    /// This function implies that a call to SBTarget::Attach(...) will
+    /// be synchronous.
+    ///
+    /// @param[in] wait_for
+    ///     If \b false, attach to an existing process whose name matches.
+    ///     If \b true, then wait for the next process whose name matches.
+    //------------------------------------------------------------------
     void
     SetWaitForLaunch (bool b);
 
+    //------------------------------------------------------------------
+    /// Set attach by process name settings.
+    ///
+    /// Designed to be used after a call to SBAttachInfo::SetExecutable().
+    /// Future calls to SBTarget::Attach(...) will be synchronous or
+    /// asynchronous depending on the \a async argument.
+    ///
+    /// @param[in] wait_for
+    ///     If \b false, attach to an existing process whose name matches.
+    ///     If \b true, then wait for the next process whose name matches.
+    ///
+    /// @param[in] async
+    ///     If \b false, then the SBTarget::Attach(...) call will be a
+    ///     synchronous call with no way to cancel the attach in
+    ///     progress.
+    ///     If \b true, then the SBTarget::Attach(...) function will
+    ///     return immediately and clients are expected to wait for a
+    ///     process eStateStopped event if a suitable process is
+    ///     eventually found. If the client wants to cancel the event,
+    ///     SBProcess::Stop() can be called and an eStateExited process
+    ///     event will be delivered.
+    //------------------------------------------------------------------
+    void
+    SetWaitForLaunch (bool b, bool async);
+
     bool
     GetIgnoreExisting ();
 

Modified: lldb/trunk/include/lldb/Target/Process.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Process.h?rev=249361&r1=249360&r2=249361&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Process.h (original)
+++ lldb/trunk/include/lldb/Target/Process.h Mon Oct  5 17:58:37 2015
@@ -239,7 +239,8 @@ public:
         m_wait_for_launch (false),
         m_ignore_existing (true),
         m_continue_once_attached (false),
-        m_detach_on_error (true)
+        m_detach_on_error (true),
+        m_async (false)
     {
     }
 
@@ -252,7 +253,8 @@ public:
         m_wait_for_launch (false),
         m_ignore_existing (true),
         m_continue_once_attached (false),
-        m_detach_on_error(true)
+        m_detach_on_error (true),
+        m_async (false)
     {
         ProcessInfo::operator= (launch_info);
         SetProcessPluginName (launch_info.GetProcessPluginName());
@@ -275,6 +277,18 @@ public:
     }
 
     bool
+    GetAsync () const
+    {
+        return m_async;
+    }
+
+    void
+    SetAsync (bool b)
+    {
+        m_async = b;
+    }
+
+    bool
     GetIgnoreExisting () const
     {
         return m_ignore_existing;
@@ -400,6 +414,7 @@ protected:
     bool m_ignore_existing;
     bool m_continue_once_attached; // Supports the use-case scenario of immediately continuing the process once attached.
     bool m_detach_on_error;  // If we are debugging remotely, instruct the stub to detach rather than killing the target on error.
+    bool m_async; // Use an async attach where we start the attach and return immediately (used by GUI programs with --waitfor so they can call SBProcess::Stop() to cancel attach)
 };
 
 class ProcessLaunchCommandOptions : public Options

Modified: lldb/trunk/scripts/interface/SBAttachInfo.i
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/interface/SBAttachInfo.i?rev=249361&r1=249360&r2=249361&view=diff
==============================================================================
--- lldb/trunk/scripts/interface/SBAttachInfo.i (original)
+++ lldb/trunk/scripts/interface/SBAttachInfo.i Mon Oct  5 17:58:37 2015
@@ -18,6 +18,8 @@ public:
 
     SBAttachInfo (const char *path, bool wait_for);
 
+    SBAttachInfo (const char *path, bool wait_for, bool async);
+
     SBAttachInfo (const lldb::SBAttachInfo &rhs);
 
     lldb::pid_t
@@ -38,6 +40,9 @@ public:
     void
     SetWaitForLaunch (bool b);
 
+    void
+    SetWaitForLaunch (bool b, bool async);
+
     bool
     GetIgnoreExisting ();
 

Modified: lldb/trunk/source/API/SBAttachInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBAttachInfo.cpp?rev=249361&r1=249360&r2=249361&view=diff
==============================================================================
--- lldb/trunk/source/API/SBAttachInfo.cpp (original)
+++ lldb/trunk/source/API/SBAttachInfo.cpp Mon Oct  5 17:58:37 2015
@@ -36,6 +36,15 @@ SBAttachInfo::SBAttachInfo (const char *
     m_opaque_sp->SetWaitForLaunch (wait_for);
 }
 
+SBAttachInfo::SBAttachInfo (const char *path, bool wait_for, bool async) :
+    m_opaque_sp (new ProcessAttachInfo())
+{
+    if (path && path[0])
+        m_opaque_sp->GetExecutableFile().SetFile(path, false);
+    m_opaque_sp->SetWaitForLaunch (wait_for);
+    m_opaque_sp->SetAsync(async);
+}
+
 SBAttachInfo::SBAttachInfo (const SBAttachInfo &rhs) :
     m_opaque_sp (new ProcessAttachInfo())
 {
@@ -127,6 +136,13 @@ SBAttachInfo::SetWaitForLaunch (bool b)
     m_opaque_sp->SetWaitForLaunch (b);
 }
 
+void
+SBAttachInfo::SetWaitForLaunch (bool b, bool async)
+{
+    m_opaque_sp->SetWaitForLaunch (b);
+    m_opaque_sp->SetAsync(async);
+}
+
 bool
 SBAttachInfo::GetIgnoreExisting ()
 {

Modified: lldb/trunk/source/Target/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Target.cpp?rev=249361&r1=249360&r2=249361&view=diff
==============================================================================
--- lldb/trunk/source/Target/Target.cpp (original)
+++ lldb/trunk/source/Target/Target.cpp Mon Oct  5 17:58:37 2015
@@ -3124,9 +3124,6 @@ Target::Attach (ProcessAttachInfo &attac
         }
     }
 
-    ListenerSP hijack_listener_sp (new Listener ("lldb.Target.Attach.attach.hijack"));
-    attach_info.SetHijackListener (hijack_listener_sp);
-
     const ModuleSP old_exec_module_sp = GetExecutableModule ();
 
     // If no process info was specified, then use the target executable
@@ -3143,6 +3140,13 @@ Target::Attach (ProcessAttachInfo &attac
     }
 
     const auto platform_sp = GetDebugger ().GetPlatformList ().GetSelectedPlatform ();
+    ListenerSP hijack_listener_sp;
+    const bool async = attach_info.GetAsync();
+    if (async == false)
+    {
+        hijack_listener_sp.reset (new Listener ("lldb.Target.Attach.attach.hijack"));
+        attach_info.SetHijackListener (hijack_listener_sp);
+    }
 
     Error error;
     if (state != eStateConnected && platform_sp != nullptr && platform_sp->CanDebugProcess ())
@@ -3162,11 +3166,12 @@ Target::Attach (ProcessAttachInfo &attac
                 return error;
             }
         }
-        process_sp->HijackProcessEvents (hijack_listener_sp.get ());
+        if (hijack_listener_sp)
+            process_sp->HijackProcessEvents (hijack_listener_sp.get ());
         error = process_sp->Attach (attach_info);
     }
 
-    if (error.Success () && process_sp)
+    if (error.Success () && process_sp && async == false)
     {
         state = process_sp->WaitForProcessToStop (nullptr, nullptr, false, attach_info.GetHijackListener ().get (), stream);
         process_sp->RestoreProcessEvents ();
@@ -3175,9 +3180,9 @@ Target::Attach (ProcessAttachInfo &attac
         {
             const char *exit_desc = process_sp->GetExitDescription ();
             if (exit_desc)
-                error.SetErrorStringWithFormat ("attach failed: %s", exit_desc);
+                error.SetErrorStringWithFormat ("%s", exit_desc);
             else
-                error.SetErrorString ("attach failed: process did not stop (no such process or permission problem?)");
+                error.SetErrorString ("process did not stop (no such process or permission problem?)");
             process_sp->Destroy (false);
         }
     }




More information about the lldb-commits mailing list