[Lldb-commits] [lldb] r214094 - Teach LLDB about Windows processes.

Zachary Turner zturner at google.com
Mon Jul 28 09:45:18 PDT 2014


Author: zturner
Date: Mon Jul 28 11:45:18 2014
New Revision: 214094

URL: http://llvm.org/viewvc/llvm-project?rev=214094&view=rev
Log:
Teach LLDB about Windows processes.

This patch creates a simple ProcessWindows process plugin.
The only thing it knows how to do currently is create processes.

Differential Revision: http://reviews.llvm.org/D4681

Added:
    lldb/trunk/source/Plugins/Process/Windows/
    lldb/trunk/source/Plugins/Process/Windows/CMakeLists.txt
    lldb/trunk/source/Plugins/Process/Windows/ProcessWindows.cpp
    lldb/trunk/source/Plugins/Process/Windows/ProcessWindows.h
Modified:
    lldb/trunk/source/CMakeLists.txt
    lldb/trunk/source/Plugins/Process/CMakeLists.txt
    lldb/trunk/source/lldb.cpp

Modified: lldb/trunk/source/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/CMakeLists.txt?rev=214094&r1=214093&r2=214094&view=diff
==============================================================================
--- lldb/trunk/source/CMakeLists.txt (original)
+++ lldb/trunk/source/CMakeLists.txt Mon Jul 28 11:45:18 2014
@@ -98,6 +98,7 @@ endif ()
 if ( CMAKE_SYSTEM_NAME MATCHES "Windows" )
   list(APPEND LLDB_USED_LIBS
     lldbHostWindows
+    lldbPluginProcessWindows
     lldbPluginProcessElfCore
     lldbPluginJITLoaderGDB
     Ws2_32

Modified: lldb/trunk/source/Plugins/Process/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/CMakeLists.txt?rev=214094&r1=214093&r2=214094&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/CMakeLists.txt (original)
+++ lldb/trunk/source/Plugins/Process/CMakeLists.txt Mon Jul 28 11:45:18 2014
@@ -5,6 +5,7 @@ elseif (CMAKE_SYSTEM_NAME MATCHES "FreeB
   add_subdirectory(FreeBSD)
   add_subdirectory(POSIX)
 elseif (CMAKE_SYSTEM_NAME MATCHES "Windows")
+  add_subdirectory(Windows)
 elseif (CMAKE_SYSTEM_NAME MATCHES "Darwin")
   add_subdirectory(POSIX)
   add_subdirectory(MacOSX-Kernel)

Added: lldb/trunk/source/Plugins/Process/Windows/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Windows/CMakeLists.txt?rev=214094&view=auto
==============================================================================
--- lldb/trunk/source/Plugins/Process/Windows/CMakeLists.txt (added)
+++ lldb/trunk/source/Plugins/Process/Windows/CMakeLists.txt Mon Jul 28 11:45:18 2014
@@ -0,0 +1,9 @@
+set(LLVM_NO_RTTI 1)
+
+include_directories(.)
+include_directories(../Utility)
+
+add_lldb_library(lldbPluginProcessWindows
+  ProcessWindows.cpp
+  )
+

Added: lldb/trunk/source/Plugins/Process/Windows/ProcessWindows.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Windows/ProcessWindows.cpp?rev=214094&view=auto
==============================================================================
--- lldb/trunk/source/Plugins/Process/Windows/ProcessWindows.cpp (added)
+++ lldb/trunk/source/Plugins/Process/Windows/ProcessWindows.cpp Mon Jul 28 11:45:18 2014
@@ -0,0 +1,203 @@
+//===-- ProcessWindows.cpp --------------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// Windows includes
+#include "lldb/Host/windows/windows.h"
+
+// C++ Includes
+// Other libraries and framework includes
+#include "lldb/Core/Module.h"
+#include "lldb/Core/PluginManager.h"
+#include "lldb/Core/State.h"
+#include "lldb/Host/Host.h"
+#include "lldb/Symbol/ObjectFile.h"
+#include "lldb/Target/DynamicLoader.h"
+#include "lldb/Target/Target.h"
+
+#include "ProcessWindows.h"
+
+using namespace lldb;
+using namespace lldb_private;
+
+//------------------------------------------------------------------------------
+// Static functions.
+
+ProcessSP
+ProcessWindows::CreateInstance(Target &target, Listener &listener, const FileSpec *)
+{
+    return ProcessSP(new ProcessWindows(target, listener));
+}
+
+void
+ProcessWindows::Initialize()
+{
+    static bool g_initialized = false;
+
+    if (!g_initialized)
+    {
+        g_initialized = true;
+        PluginManager::RegisterPlugin(GetPluginNameStatic(),
+                                      GetPluginDescriptionStatic(),
+                                      CreateInstance);
+    }
+}
+
+//------------------------------------------------------------------------------
+// Constructors and destructors.
+
+ProcessWindows::ProcessWindows(Target& target, Listener &listener)
+    : lldb_private::Process(target, listener)
+{
+}
+
+void
+ProcessWindows::Terminate()
+{
+}
+
+lldb_private::ConstString
+ProcessWindows::GetPluginNameStatic()
+{
+    static ConstString g_name("windows");
+    return g_name;
+}
+
+const char *
+ProcessWindows::GetPluginDescriptionStatic()
+{
+    return "Process plugin for Windows";
+}
+
+
+bool
+ProcessWindows::UpdateThreadList(ThreadList &old_thread_list, ThreadList &new_thread_list)
+{
+    new_thread_list = old_thread_list;
+    return new_thread_list.GetSize(false) > 0;
+}
+
+Error
+ProcessWindows::DoLaunch(Module *exe_module,
+                         ProcessLaunchInfo &launch_info)
+{
+    std::string executable;
+    std::string commandLine;
+    std::vector<char> environment;
+    STARTUPINFO startupinfo = {0};
+    PROCESS_INFORMATION pi = {0};
+    startupinfo.cb = sizeof(startupinfo);
+    
+    executable = launch_info.GetExecutableFile().GetPath();
+    launch_info.GetArguments().GetQuotedCommandString(commandLine);
+    BOOL result = ::CreateProcessA(executable.c_str(),
+                                   const_cast<char*>(commandLine.c_str()),
+                                   NULL,
+                                   NULL,
+                                   FALSE,
+                                   CREATE_NEW_CONSOLE,
+                                   NULL,
+                                   launch_info.GetWorkingDirectory(),
+                                   &startupinfo,
+                                   &pi);
+    Error error;
+    if (!result)
+        error.SetErrorToErrno();
+    return error;
+}
+
+Error
+ProcessWindows::DoResume()
+{
+    Error error;
+    return error;
+}
+
+
+//------------------------------------------------------------------------------
+// ProcessInterface protocol.
+
+lldb_private::ConstString
+ProcessWindows::GetPluginName()
+{
+    return GetPluginNameStatic();
+}
+
+uint32_t
+ProcessWindows::GetPluginVersion()
+{
+    return 1;
+}
+
+void
+ProcessWindows::GetPluginCommandHelp(const char *command, Stream *strm)
+{
+}
+
+Error
+ProcessWindows::ExecutePluginCommand(Args &command, Stream *strm)
+{
+    return Error(1, eErrorTypeGeneric);
+}
+
+Log *
+ProcessWindows::EnablePluginLogging(Stream *strm, Args &command)
+{
+    return NULL;
+}
+
+Error
+ProcessWindows::DoDetach(bool keep_stopped)
+{
+    Error error;
+    error.SetErrorString("Detaching from processes is not currently supported on Windows.");
+    return error;
+}
+
+Error
+ProcessWindows::DoDestroy()
+{
+    Error error;
+    error.SetErrorString("Destroying processes is not currently supported on Windows.");
+    return error;
+}
+
+void
+ProcessWindows::RefreshStateAfterStop()
+{
+}
+
+bool
+ProcessWindows::IsAlive()
+{
+    return false;
+}
+
+size_t
+ProcessWindows::DoReadMemory(lldb::addr_t vm_addr,
+                             void *buf,
+                             size_t size,
+                             Error &error)
+{
+    return 0;
+}
+
+
+bool
+ProcessWindows::CanDebug(Target &target, bool plugin_specified_by_name)
+{
+    if (plugin_specified_by_name)
+        return true;
+
+    // For now we are just making sure the file exists for a given module
+    ModuleSP exe_module_sp(target.GetExecutableModule());
+    if (exe_module_sp.get())
+        return exe_module_sp->GetFileSpec().Exists();
+    return false;
+}
+

Added: lldb/trunk/source/Plugins/Process/Windows/ProcessWindows.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Windows/ProcessWindows.h?rev=214094&view=auto
==============================================================================
--- lldb/trunk/source/Plugins/Process/Windows/ProcessWindows.h (added)
+++ lldb/trunk/source/Plugins/Process/Windows/ProcessWindows.h Mon Jul 28 11:45:18 2014
@@ -0,0 +1,109 @@
+//===-- ProcessWindows.h ----------------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef liblldb_Plugins_Process_Windows_ProcessWindows_H_
+#define liblldb_Plugins_Process_Windows_ProcessWindows_H_
+
+// C Includes
+
+// C++ Includes
+#include <queue>
+
+// Other libraries and framework includes
+#include "lldb/Target/Process.h"
+
+class ProcessMonitor;
+
+class ProcessWindows :
+    public lldb_private::Process
+{
+public:
+    //------------------------------------------------------------------
+    // Static functions.
+    //------------------------------------------------------------------
+    static lldb::ProcessSP
+    CreateInstance(lldb_private::Target& target,
+                   lldb_private::Listener &listener,
+                   const lldb_private::FileSpec *);
+
+    static void
+    Initialize();
+
+    static void
+    Terminate();
+
+    static lldb_private::ConstString
+    GetPluginNameStatic();
+
+    static const char *
+    GetPluginDescriptionStatic();
+
+    //------------------------------------------------------------------
+    // Constructors and destructors
+    //------------------------------------------------------------------
+    ProcessWindows(lldb_private::Target& target,
+                   lldb_private::Listener &listener);
+
+    virtual lldb_private::Error
+    DoDetach(bool keep_stopped);
+
+    virtual bool
+    DetachRequiresHalt() { return true; }
+
+    virtual bool
+    UpdateThreadList(lldb_private::ThreadList &old_thread_list, lldb_private::ThreadList &new_thread_list);
+
+    virtual lldb_private::Error
+    DoLaunch (lldb_private::Module *exe_module,
+              lldb_private::ProcessLaunchInfo &launch_info);
+
+    virtual lldb_private::Error
+    DoResume ();
+
+    //------------------------------------------------------------------
+    // PluginInterface protocol
+    //------------------------------------------------------------------
+    virtual lldb_private::ConstString
+    GetPluginName();
+
+    virtual uint32_t
+    GetPluginVersion();
+
+    virtual void
+    GetPluginCommandHelp(const char *command, lldb_private::Stream *strm);
+
+    virtual lldb_private::Error
+    ExecutePluginCommand(lldb_private::Args &command,
+                         lldb_private::Stream *strm);
+
+    virtual lldb_private::Log *
+    EnablePluginLogging(lldb_private::Stream *strm,
+                        lldb_private::Args &command);
+
+
+    virtual bool
+    CanDebug(lldb_private::Target &target, bool plugin_specified_by_name);
+
+    virtual lldb_private::Error
+    DoDestroy ();
+
+    virtual void
+    RefreshStateAfterStop ();
+
+    virtual bool
+    IsAlive ();
+
+    virtual size_t
+    DoReadMemory (lldb::addr_t vm_addr, 
+                  void *buf, 
+                  size_t size,
+                  lldb_private::Error &error);
+};
+
+#endif  // liblldb_Plugins_Process_Windows_ProcessWindows_H_

Modified: lldb/trunk/source/lldb.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/lldb.cpp?rev=214094&r1=214093&r2=214094&view=diff
==============================================================================
--- lldb/trunk/source/lldb.cpp (original)
+++ lldb/trunk/source/lldb.cpp Mon Jul 28 11:45:18 2014
@@ -78,6 +78,10 @@
 #include "Plugins/Process/Linux/ProcessLinux.h"
 #endif
 
+#if defined (_WIN32)
+#include "Plugins/Process/Windows/ProcessWindows.h"
+#endif
+
 #if defined (__FreeBSD__)
 #include "Plugins/Process/POSIX/ProcessPOSIX.h"
 #include "Plugins/Process/FreeBSD/ProcessFreeBSD.h"
@@ -159,6 +163,9 @@ lldb_private::Initialize ()
         //----------------------------------------------------------------------
         ProcessLinux::Initialize();
 #endif
+#if defined(_WIN32)
+        ProcessWindows::Initialize();
+#endif
 #if defined (__FreeBSD__)
         ProcessFreeBSD::Initialize();
 #endif





More information about the lldb-commits mailing list