[Lldb-commits] [lldb] r221637 - [ProcessWindows] Notify process plugin when the launch succeeds.

Zachary Turner zturner at google.com
Mon Nov 10 14:32:19 PST 2014


Author: zturner
Date: Mon Nov 10 16:32:18 2014
New Revision: 221637

URL: http://llvm.org/viewvc/llvm-project?rev=221637&view=rev
Log:
[ProcessWindows] Notify process plugin when the launch succeeds.

Modified:
    lldb/trunk/source/Plugins/Process/Windows/DebuggerThread.cpp
    lldb/trunk/source/Plugins/Process/Windows/DebuggerThread.h
    lldb/trunk/source/Plugins/Process/Windows/ForwardDecl.h
    lldb/trunk/source/Plugins/Process/Windows/IDebugDelegate.h
    lldb/trunk/source/Plugins/Process/Windows/LocalDebugDelegate.cpp
    lldb/trunk/source/Plugins/Process/Windows/LocalDebugDelegate.h
    lldb/trunk/source/Plugins/Process/Windows/ProcessMessages.h
    lldb/trunk/source/Plugins/Process/Windows/ProcessWindows.cpp
    lldb/trunk/source/Plugins/Process/Windows/ProcessWindows.h

Modified: lldb/trunk/source/Plugins/Process/Windows/DebuggerThread.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Windows/DebuggerThread.cpp?rev=221637&r1=221636&r2=221637&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Windows/DebuggerThread.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Windows/DebuggerThread.cpp Mon Nov 10 16:32:18 2014
@@ -43,28 +43,22 @@ struct DebugLaunchContext
 DebuggerThread::DebuggerThread(DebugDelegateSP debug_delegate)
     : m_debug_delegate(debug_delegate)
     , m_image_file(nullptr)
-    , m_launched_event(nullptr)
 {
-    m_launched_event = ::CreateEvent(nullptr, TRUE, FALSE, nullptr);
 }
 
 DebuggerThread::~DebuggerThread()
 {
-    if (m_launched_event != nullptr)
-        ::CloseHandle(m_launched_event);
 }
 
-HostProcess
+Error
 DebuggerThread::DebugLaunch(const ProcessLaunchInfo &launch_info)
 {
     Error error;
 
     DebugLaunchContext *context = new DebugLaunchContext(this, launch_info);
     HostThread slave_thread(ThreadLauncher::LaunchThread("lldb.plugin.process-windows.slave[?]", DebuggerThreadRoutine, context, &error));
-    if (error.Success())
-        ::WaitForSingleObject(m_launched_event, INFINITE);
 
-    return m_process;
+    return error;
 }
 
 lldb::thread_result_t
@@ -95,7 +89,10 @@ DebuggerThread::DebuggerThreadRoutine(co
     if (error.Success())
         DebugLoop();
     else
-        SetEvent(m_launched_event);
+    {
+        ProcessMessageDebuggerError message(m_process, error, 0);
+        m_debug_delegate->OnDebuggerError(message);
+    }
 
     return 0;
 }
@@ -175,7 +172,8 @@ DebuggerThread::HandleCreateProcessEvent
     ((HostThreadWindows &)m_main_thread.GetNativeThread()).SetOwnsHandle(false);
     m_image_file = info.hFile;
 
-    SetEvent(m_launched_event);
+    ProcessMessageDebuggerConnected message(m_process);
+    m_debug_delegate->OnDebuggerConnected(message);
 
     return DBG_CONTINUE;
 }

Modified: lldb/trunk/source/Plugins/Process/Windows/DebuggerThread.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Windows/DebuggerThread.h?rev=221637&r1=221636&r2=221637&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Windows/DebuggerThread.h (original)
+++ lldb/trunk/source/Plugins/Process/Windows/DebuggerThread.h Mon Nov 10 16:32:18 2014
@@ -32,7 +32,18 @@ class DebuggerThread : public std::enabl
     DebuggerThread(DebugDelegateSP debug_delegate);
     virtual ~DebuggerThread();
 
-    HostProcess DebugLaunch(const ProcessLaunchInfo &launch_info);
+    Error DebugLaunch(const ProcessLaunchInfo &launch_info);
+
+    HostProcess
+    GetProcess() const
+    {
+        return m_process;
+    }
+    HostThread
+    GetMainThread() const
+    {
+        return m_main_thread;
+    }
 
   private:
     void DebugLoop();
@@ -48,9 +59,6 @@ class DebuggerThread : public std::enabl
 
     DebugDelegateSP m_debug_delegate;
 
-    HANDLE m_launched_event; // Signalled when the process is finished launching, either
-                             // successfully or with an error.
-
     HostProcess m_process;    // The process being debugged.
     HostThread m_main_thread; // The main thread of the inferior.
     HANDLE m_image_file;      // The image file of the process being debugged.

Modified: lldb/trunk/source/Plugins/Process/Windows/ForwardDecl.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Windows/ForwardDecl.h?rev=221637&r1=221636&r2=221637&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Windows/ForwardDecl.h (original)
+++ lldb/trunk/source/Plugins/Process/Windows/ForwardDecl.h Mon Nov 10 16:32:18 2014
@@ -22,7 +22,6 @@ class DebuggerThread;
 
 // Process message forward declarations.
 class ProcessMessageBase;
-class ProcessMessageCreateProcess;
 class ProcessMessageExitProcess;
 class ProcessMessageDebuggerConnected;
 class ProcessMessageException;
@@ -34,7 +33,7 @@ class ProcessMessageDebugString;
 class ProcessMessageDebuggerError;
 
 typedef std::shared_ptr<IDebugDelegate> DebugDelegateSP;
-typedef std::unique_ptr<DebuggerThread> DebuggerThreadUP;
+typedef std::shared_ptr<DebuggerThread> DebuggerThreadSP;
 }
 
 #endif
\ No newline at end of file

Modified: lldb/trunk/source/Plugins/Process/Windows/IDebugDelegate.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Windows/IDebugDelegate.h?rev=221637&r1=221636&r2=221637&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Windows/IDebugDelegate.h (original)
+++ lldb/trunk/source/Plugins/Process/Windows/IDebugDelegate.h Mon Nov 10 16:32:18 2014
@@ -10,20 +10,11 @@
 #ifndef liblldb_Plugins_Process_Windows_IDebugDelegate_H_
 #define liblldb_Plugins_Process_Windows_IDebugDelegate_H_
 
+#include "ForwardDecl.h"
+
 namespace lldb_private
 {
 
-class ProcessMessageCreateProcess;
-class ProcessMessageExitProcess;
-class ProcessMessageDebuggerConnected;
-class ProcessMessageException;
-class ProcessMessageCreateThread;
-class ProcessMessageExitThread;
-class ProcessMessageLoadDll;
-class ProcessMessageUnloadDll;
-class ProcessMessageDebugString;
-class ProcessMessageDebuggerError;
-
 //----------------------------------------------------------------------
 // IDebugDelegate
 //
@@ -35,7 +26,6 @@ class IDebugDelegate
   public:
     virtual ~IDebugDelegate() {}
 
-    virtual void OnProcessLaunched(const ProcessMessageCreateProcess &message) = 0;
     virtual void OnExitProcess(const ProcessMessageExitProcess &message) = 0;
     virtual void OnDebuggerConnected(const ProcessMessageDebuggerConnected &message) = 0;
     virtual void OnDebugException(const ProcessMessageException &message) = 0;

Modified: lldb/trunk/source/Plugins/Process/Windows/LocalDebugDelegate.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Windows/LocalDebugDelegate.cpp?rev=221637&r1=221636&r2=221637&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Windows/LocalDebugDelegate.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Windows/LocalDebugDelegate.cpp Mon Nov 10 16:32:18 2014
@@ -19,12 +19,6 @@ LocalDebugDelegate::LocalDebugDelegate(P
 }
 
 void
-LocalDebugDelegate::OnProcessLaunched(const ProcessMessageCreateProcess &message)
-{
-    ((ProcessWindows &)*m_process).OnProcessLaunched(message);
-}
-
-void
 LocalDebugDelegate::OnExitProcess(const ProcessMessageExitProcess &message)
 {
     ((ProcessWindows &)*m_process).OnExitProcess(message);

Modified: lldb/trunk/source/Plugins/Process/Windows/LocalDebugDelegate.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Windows/LocalDebugDelegate.h?rev=221637&r1=221636&r2=221637&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Windows/LocalDebugDelegate.h (original)
+++ lldb/trunk/source/Plugins/Process/Windows/LocalDebugDelegate.h Mon Nov 10 16:32:18 2014
@@ -42,16 +42,15 @@ class LocalDebugDelegate : public IDebug
   public:
     explicit LocalDebugDelegate::LocalDebugDelegate(lldb::ProcessSP process);
 
-    void OnProcessLaunched(const ProcessMessageCreateProcess &message);
-    void OnExitProcess(const ProcessMessageExitProcess &message);
-    void OnDebuggerConnected(const ProcessMessageDebuggerConnected &message);
-    void OnDebugException(const ProcessMessageException &message);
-    void OnCreateThread(const ProcessMessageCreateThread &message);
-    void OnExitThread(const ProcessMessageExitThread &message);
-    void OnLoadDll(const ProcessMessageLoadDll &message);
-    void OnUnloadDll(const ProcessMessageUnloadDll &message);
-    void OnDebugString(const ProcessMessageDebugString &message);
-    void OnDebuggerError(const ProcessMessageDebuggerError &message);
+    void OnExitProcess(const ProcessMessageExitProcess &message) override;
+    void OnDebuggerConnected(const ProcessMessageDebuggerConnected &message) override;
+    void OnDebugException(const ProcessMessageException &message) override;
+    void OnCreateThread(const ProcessMessageCreateThread &message) override;
+    void OnExitThread(const ProcessMessageExitThread &message) override;
+    void OnLoadDll(const ProcessMessageLoadDll &message) override;
+    void OnUnloadDll(const ProcessMessageUnloadDll &message) override;
+    void OnDebugString(const ProcessMessageDebugString &message) override;
+    void OnDebuggerError(const ProcessMessageDebuggerError &message) override;
 
   private:
     lldb::ProcessSP m_process;

Modified: lldb/trunk/source/Plugins/Process/Windows/ProcessMessages.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Windows/ProcessMessages.h?rev=221637&r1=221636&r2=221637&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Windows/ProcessMessages.h (original)
+++ lldb/trunk/source/Plugins/Process/Windows/ProcessMessages.h Mon Nov 10 16:32:18 2014
@@ -42,6 +42,15 @@ class ProcessMessageBase
     HostProcess m_process;
 };
 
+class ProcessMessageDebuggerConnected : public ProcessMessageBase
+{
+  public:
+    ProcessMessageDebuggerConnected(const HostProcess &process)
+        : ProcessMessageBase(process)
+    {
+    }
+};
+
 class ProcessMessageExitProcess : public ProcessMessageBase
 {
   public:

Modified: lldb/trunk/source/Plugins/Process/Windows/ProcessWindows.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Windows/ProcessWindows.cpp?rev=221637&r1=221636&r2=221637&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Windows/ProcessWindows.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Windows/ProcessWindows.cpp Mon Nov 10 16:32:18 2014
@@ -35,6 +35,24 @@
 using namespace lldb;
 using namespace lldb_private;
 
+namespace lldb_private
+{
+// We store a pointer to this class in the ProcessWindows, so that we don't expose Windows
+// OS specific types and implementation details from a public header file.
+class ProcessWindowsData
+{
+  public:
+    ProcessWindowsData()
+        : m_launched_event(nullptr)
+    {
+        m_launched_event = ::CreateEvent(nullptr, TRUE, FALSE, nullptr);
+    }
+
+    ~ProcessWindowsData() { ::CloseHandle(m_launched_event); }
+
+    HANDLE m_launched_event;
+};
+}
 //------------------------------------------------------------------------------
 // Static functions.
 
@@ -61,8 +79,9 @@ ProcessWindows::Initialize()
 //------------------------------------------------------------------------------
 // Constructors and destructors.
 
-ProcessWindows::ProcessWindows(Target& target, Listener &listener)
+ProcessWindows::ProcessWindows(Target &target, Listener &listener)
     : lldb_private::Process(target, listener)
+    , m_data_up(new ProcessWindowsData())
 {
 }
 
@@ -107,7 +126,15 @@ ProcessWindows::DoLaunch(Module *exe_mod
     {
         DebugDelegateSP delegate(new LocalDebugDelegate(shared_from_this()));
         m_debugger.reset(new DebuggerThread(delegate));
-        process = m_debugger->DebugLaunch(launch_info);
+        // Kick off the DebugLaunch asynchronously and wait for it to complete.
+        result = m_debugger->DebugLaunch(launch_info);
+        if (result.Success())
+        {
+            if (::WaitForSingleObject(m_data_up->m_launched_event, INFINITE) == WAIT_OBJECT_0)
+                process = m_debugger->GetProcess();
+            else
+                result.SetError(::GetLastError(), eErrorTypeWin32);
+        }
     }
     else
         return Host::LaunchProcess(launch_info);
@@ -210,11 +237,6 @@ ProcessWindows::CanDebug(Target &target,
 }
 
 void
-ProcessWindows::OnProcessLaunched(const ProcessMessageCreateProcess &message)
-{
-}
-
-void
 ProcessWindows::OnExitProcess(const ProcessMessageExitProcess &message)
 {
     SetProcessExitStatus(nullptr, GetID(), true, 0, message.GetExitCode());
@@ -223,6 +245,7 @@ ProcessWindows::OnExitProcess(const Proc
 void
 ProcessWindows::OnDebuggerConnected(const ProcessMessageDebuggerConnected &message)
 {
+    ::SetEvent(m_data_up->m_launched_event);
 }
 
 void
@@ -258,4 +281,16 @@ ProcessWindows::OnDebugString(const Proc
 void
 ProcessWindows::OnDebuggerError(const ProcessMessageDebuggerError &message)
 {
+    DWORD result = ::WaitForSingleObject(m_data_up->m_launched_event, 0);
+    if (result == WAIT_TIMEOUT)
+    {
+        // If we haven't actually launched the process yet, this was an error
+        // launching the process.  Set the internal error and signal.
+        m_launch_error = message.GetError();
+        ::SetEvent(m_data_up->m_launched_event);
+        return;
+    }
+
+    // This happened while debugging.
+    // TODO: Implement this.
 }

Modified: lldb/trunk/source/Plugins/Process/Windows/ProcessWindows.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Windows/ProcessWindows.h?rev=221637&r1=221636&r2=221637&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Windows/ProcessWindows.h (original)
+++ lldb/trunk/source/Plugins/Process/Windows/ProcessWindows.h Mon Nov 10 16:32:18 2014
@@ -14,11 +14,13 @@
 
 // C++ Includes
 #include <map>
+#include <memory>
 #include <queue>
 
 // Other libraries and framework includes
 #include "ForwardDecl.h"
 #include "IDebugDelegate.h"
+#include "lldb/Core/Error.h"
 #include "lldb/Host/HostThread.h"
 #include "lldb/Target/Process.h"
 
@@ -27,6 +29,7 @@ class ProcessMonitor;
 namespace lldb_private
 {
 class HostProcess;
+class ProcessWindowsData;
 }
 
 class ProcessWindows : public lldb_private::Process, public lldb_private::IDebugDelegate
@@ -112,7 +115,6 @@ public:
     virtual size_t DoReadMemory(lldb::addr_t vm_addr, void *buf, size_t size, lldb_private::Error &error);
 
     // IDebugDelegate overrides.
-    virtual void OnProcessLaunched(const lldb_private::ProcessMessageCreateProcess &message) override;
     virtual void OnExitProcess(const lldb_private::ProcessMessageExitProcess &message) override;
     virtual void OnDebuggerConnected(const lldb_private::ProcessMessageDebuggerConnected &message) override;
     virtual void OnDebugException(const lldb_private::ProcessMessageException &message) override;
@@ -124,7 +126,9 @@ public:
     virtual void OnDebuggerError(const lldb_private::ProcessMessageDebuggerError &message) override;
 
   private:
-    lldb_private::DebuggerThreadUP m_debugger;
+    std::unique_ptr<lldb_private::ProcessWindowsData> m_data_up;
+    lldb_private::Error m_launch_error;
+    lldb_private::DebuggerThreadSP m_debugger;
 };
 
 #endif  // liblldb_Plugins_Process_Windows_ProcessWindows_H_





More information about the lldb-commits mailing list