diff options
-rw-r--r-- | lldb/include/lldb/Host/HostNativeProcess.h | 27 | ||||
-rw-r--r-- | lldb/include/lldb/Host/HostNativeProcessBase.h | 43 | ||||
-rw-r--r-- | lldb/include/lldb/Host/HostProcess.h | 36 | ||||
-rw-r--r-- | lldb/include/lldb/Host/posix/HostProcessPosix.h | 26 | ||||
-rw-r--r-- | lldb/include/lldb/Host/windows/HostProcessWindows.h | 20 | ||||
-rw-r--r-- | lldb/lldb.xcodeproj/project.pbxproj | 4 | ||||
-rw-r--r-- | lldb/source/Host/CMakeLists.txt | 1 | ||||
-rw-r--r-- | lldb/source/Host/common/HostProcess.cpp | 54 | ||||
-rw-r--r-- | lldb/source/Host/posix/HostProcessPosix.cpp | 34 | ||||
-rw-r--r-- | lldb/source/Host/windows/HostProcessWindows.cpp | 53 |
10 files changed, 197 insertions, 101 deletions
diff --git a/lldb/include/lldb/Host/HostNativeProcess.h b/lldb/include/lldb/Host/HostNativeProcess.h new file mode 100644 index 00000000000..b4895643611 --- /dev/null +++ b/lldb/include/lldb/Host/HostNativeProcess.h @@ -0,0 +1,27 @@ +//===-- HostNativeProcess.h -------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef lldb_Host_HostNativeProcess_h_ +#define lldb_Host_HostNativeProcess_h_ + +#if defined(_WIN32) +#include "lldb/Host/windows/HostProcessWindows.h" +namespace lldb_private +{ +typedef HostProcessWindows HostNativeProcess; +} +#else +#include "lldb/Host/posix/HostProcessPosix.h" +namespace lldb_private +{ +typedef HostProcessPosix HostNativeProcess; +} +#endif + +#endif diff --git a/lldb/include/lldb/Host/HostNativeProcessBase.h b/lldb/include/lldb/Host/HostNativeProcessBase.h new file mode 100644 index 00000000000..f19984dcc10 --- /dev/null +++ b/lldb/include/lldb/Host/HostNativeProcessBase.h @@ -0,0 +1,43 @@ +//===-- HostNativeProcessBase.h ---------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef lldb_Host_HostNativeProcessBase_h_ +#define lldb_Host_HostNativeProcessBase_h_ + +#include "lldb/Core/Error.h" +#include "lldb/lldb-defines.h" +#include "lldb/lldb-types.h" + +namespace lldb_private +{ + +class HostNativeProcessBase +{ + DISALLOW_COPY_AND_ASSIGN(HostNativeProcessBase); + + public: + HostNativeProcessBase() {} + explicit HostNativeProcessBase(lldb::process_t process) + : m_process(process) + {} + virtual ~HostNativeProcessBase() {} + + virtual Error Terminate() = 0; + virtual Error GetMainModule(FileSpec &file_spec) const = 0; + + virtual lldb::pid_t GetProcessId() const = 0; + virtual bool IsRunning() const = 0; + + protected: + lldb::process_t m_process; +}; + +} + +#endif diff --git a/lldb/include/lldb/Host/HostProcess.h b/lldb/include/lldb/Host/HostProcess.h index 2c10709ce94..668dca46cc4 100644 --- a/lldb/include/lldb/Host/HostProcess.h +++ b/lldb/include/lldb/Host/HostProcess.h @@ -10,6 +10,8 @@ #ifndef lldb_Host_HostProcess_h_ #define lldb_Host_HostProcess_h_ +#include "lldb/lldb-types.h" + //---------------------------------------------------------------------- /// @class HostInfo HostInfo.h "lldb/Host/HostProcess.h" /// @brief A class that represents a running process on the host machine. @@ -26,19 +28,31 @@ /// //---------------------------------------------------------------------- -#if defined(_WIN32) -#include "lldb/Host/windows/HostProcessWindows.h" -#define HOST_PROCESS_TYPE HostProcessWindows -#else -#include "lldb/Host/posix/HostProcessPosix.h" -#define HOST_PROCESS_TYPE HostProcessPosix -#endif - namespace lldb_private { - typedef HOST_PROCESS_TYPE HostProcess; -} -#undef HOST_PROCESS_TYPE +class HostNativeProcessBase; + +class HostProcess +{ + public: + HostProcess(); + HostProcess(lldb::process_t process); + ~HostProcess(); + + Error Terminate(); + Error GetMainModule(FileSpec &file_spec) const; + + lldb::pid_t GetProcessId() const; + bool IsRunning() const; + + HostNativeProcessBase &GetNativeProcess(); + const HostNativeProcessBase &GetNativeProcess() const; + + private: + std::shared_ptr<HostNativeProcessBase> m_native_process; +}; + +} #endif diff --git a/lldb/include/lldb/Host/posix/HostProcessPosix.h b/lldb/include/lldb/Host/posix/HostProcessPosix.h index aa003ee4845..f8a6bb09d2b 100644 --- a/lldb/include/lldb/Host/posix/HostProcessPosix.h +++ b/lldb/include/lldb/Host/posix/HostProcessPosix.h @@ -12,34 +12,28 @@ #include "lldb/lldb-types.h" #include "lldb/Core/Error.h" -#include "lldb/Target/ProcessLaunchInfo.h" +#include "lldb/Host/HostNativeProcessBase.h" namespace lldb_private { class FileSpec; -class HostProcessPosix +class HostProcessPosix : public HostNativeProcessBase { public: - static const lldb::pid_t kInvalidProcessId; - HostProcessPosix(); - ~HostProcessPosix(); - - Error Signal(int signo) const; - static Error Signal(lldb::pid_t pid, int signo); - - Error Create(lldb::pid_t pid); - Error Terminate(int signo); - Error GetMainModule(FileSpec &file_spec) const; + HostProcessPosix(lldb::process_t process); + virtual ~HostProcessPosix(); - lldb::pid_t GetProcessId() const; - bool IsRunning() const; + virtual Error Signal(int signo) const; + static Error Signal(lldb::process_t process, int signo); - private: + virtual Error Terminate(); + virtual Error GetMainModule(FileSpec &file_spec) const; - lldb::pid_t m_pid; + virtual lldb::pid_t GetProcessId() const; + virtual bool IsRunning() const; }; } diff --git a/lldb/include/lldb/Host/windows/HostProcessWindows.h b/lldb/include/lldb/Host/windows/HostProcessWindows.h index ca1578cdea1..a970e259465 100644 --- a/lldb/include/lldb/Host/windows/HostProcessWindows.h +++ b/lldb/include/lldb/Host/windows/HostProcessWindows.h @@ -10,34 +10,28 @@ #ifndef lldb_Host_HostProcessWindows_h_ #define lldb_Host_HostProcessWindows_h_ -#include "lldb/lldb-types.h" -#include "lldb/Core/Error.h" -#include "lldb/Target/ProcessLaunchInfo.h" +#include "lldb/Host/HostNativeProcessBase.h" namespace lldb_private { class FileSpec; -class HostProcessWindows +class HostProcessWindows : public HostNativeProcessBase { public: HostProcessWindows(); + explicit HostProcessWindows(lldb::process_t process); ~HostProcessWindows(); - Error Create(lldb::pid_t pid); - Error Create(lldb::process_t process); - Error Terminate(); - Error GetMainModule(FileSpec &file_spec) const; + virtual Error Terminate(); + virtual Error GetMainModule(FileSpec &file_spec) const; - lldb::pid_t GetProcessId() const; - bool IsRunning() const; + virtual lldb::pid_t GetProcessId() const; + virtual bool IsRunning() const; private: void Close(); - - lldb::pid_t m_pid; - lldb::process_t m_process; }; } diff --git a/lldb/lldb.xcodeproj/project.pbxproj b/lldb/lldb.xcodeproj/project.pbxproj index c1eb6a3bb8d..754bf82b763 100644 --- a/lldb/lldb.xcodeproj/project.pbxproj +++ b/lldb/lldb.xcodeproj/project.pbxproj @@ -597,6 +597,7 @@ 3FDFED2719BA6D96009756A7 /* HostNativeThreadBase.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3FDFED2419BA6D96009756A7 /* HostNativeThreadBase.cpp */; }; 3FDFED2819BA6D96009756A7 /* HostThread.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3FDFED2519BA6D96009756A7 /* HostThread.cpp */; }; 3FDFED2919BA6D96009756A7 /* ThreadLauncher.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3FDFED2619BA6D96009756A7 /* ThreadLauncher.cpp */; }; + 3FDFED2D19C257A0009756A7 /* HostProcess.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3FDFED2C19C257A0009756A7 /* HostProcess.cpp */; }; 449ACC98197DEA0B008D175E /* FastDemangle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 449ACC96197DE9EC008D175E /* FastDemangle.cpp */; }; 490A36C0180F0E6F00BA31F8 /* PlatformWindows.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 490A36BD180F0E6F00BA31F8 /* PlatformWindows.cpp */; }; 490A36C2180F0E9300BA31F8 /* PlatformWindows.h in Headers */ = {isa = PBXBuildFile; fileRef = 490A36BE180F0E6F00BA31F8 /* PlatformWindows.h */; }; @@ -1823,6 +1824,7 @@ 3FDFED2419BA6D96009756A7 /* HostNativeThreadBase.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HostNativeThreadBase.cpp; sourceTree = "<group>"; }; 3FDFED2519BA6D96009756A7 /* HostThread.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HostThread.cpp; sourceTree = "<group>"; }; 3FDFED2619BA6D96009756A7 /* ThreadLauncher.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ThreadLauncher.cpp; sourceTree = "<group>"; }; + 3FDFED2C19C257A0009756A7 /* HostProcess.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HostProcess.cpp; sourceTree = "<group>"; }; 449ACC96197DE9EC008D175E /* FastDemangle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = FastDemangle.cpp; path = source/Core/FastDemangle.cpp; sourceTree = "<group>"; }; 4906FD4012F2255300A2A77C /* ASTDumper.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ASTDumper.cpp; path = source/Expression/ASTDumper.cpp; sourceTree = "<group>"; }; 4906FD4412F2257600A2A77C /* ASTDumper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ASTDumper.h; path = include/lldb/Expression/ASTDumper.h; sourceTree = "<group>"; }; @@ -4198,6 +4200,7 @@ 69A01E1C1236C5D400C660B5 /* Host.cpp */, 3FDFE53419A29327009756A7 /* HostInfoBase.cpp */, 3FDFED2419BA6D96009756A7 /* HostNativeThreadBase.cpp */, + 3FDFED2C19C257A0009756A7 /* HostProcess.cpp */, 3FDFED2519BA6D96009756A7 /* HostThread.cpp */, 236124A21986B4E2004EFC37 /* IOObject.cpp */, 69A01E1E1236C5D400C660B5 /* Mutex.cpp */, @@ -5101,6 +5104,7 @@ 268900B013353E5000698AC0 /* RegisterContextLLDB.cpp in Sources */, 3FDFE56C19AF9C44009756A7 /* HostProcessPosix.cpp in Sources */, 268900B413353E5000698AC0 /* RegisterContextMacOSXFrameBackchain.cpp in Sources */, + 3FDFED2D19C257A0009756A7 /* HostProcess.cpp in Sources */, 268900B513353E5000698AC0 /* StopInfoMachException.cpp in Sources */, 268900B613353E5000698AC0 /* UnwindMacOSXFrameBackchain.cpp in Sources */, 268900B713353E5F00698AC0 /* DWARFAbbreviationDeclaration.cpp in Sources */, diff --git a/lldb/source/Host/CMakeLists.txt b/lldb/source/Host/CMakeLists.txt index 0051f902c71..578c9469a06 100644 --- a/lldb/source/Host/CMakeLists.txt +++ b/lldb/source/Host/CMakeLists.txt @@ -12,6 +12,7 @@ add_host_subdirectory(common common/Host.cpp common/HostInfoBase.cpp common/HostNativeThreadBase.cpp + common/HostProcess.cpp common/HostThread.cpp common/IOObject.cpp common/Mutex.cpp diff --git a/lldb/source/Host/common/HostProcess.cpp b/lldb/source/Host/common/HostProcess.cpp new file mode 100644 index 00000000000..97ae6780521 --- /dev/null +++ b/lldb/source/Host/common/HostProcess.cpp @@ -0,0 +1,54 @@ +//===-- HostProcess.cpp -----------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "lldb/Host/HostNativeProcess.h" +#include "lldb/Host/HostProcess.h" + +using namespace lldb; +using namespace lldb_private; + +HostProcess::HostProcess() + : m_native_process(new HostNativeProcess) +{ +} + +HostProcess::HostProcess(lldb::process_t process) + : m_native_process(new HostNativeProcess(process)) +{ +} + +Error HostProcess::Terminate() +{ + return m_native_process->Terminate(); +} + +Error HostProcess::GetMainModule(FileSpec &file_spec) const +{ + return m_native_process->GetMainModule(file_spec); +} + +lldb::pid_t HostProcess::GetProcessId() const +{ + return m_native_process->GetProcessId(); +} + +bool HostProcess::IsRunning() const +{ + return m_native_process->IsRunning(); +} + +HostNativeProcessBase &HostProcess::GetNativeProcess() +{ + return *m_native_process; +} + +const HostNativeProcessBase &HostProcess::GetNativeProcess() const +{ + return *m_native_process; +} diff --git a/lldb/source/Host/posix/HostProcessPosix.cpp b/lldb/source/Host/posix/HostProcessPosix.cpp index 4618de4711d..1f909e55820 100644 --- a/lldb/source/Host/posix/HostProcessPosix.cpp +++ b/lldb/source/Host/posix/HostProcessPosix.cpp @@ -16,10 +16,13 @@ using namespace lldb_private; -const lldb::pid_t HostProcessPosix::kInvalidProcessId = 0; +namespace +{ + const int kInvalidPosixProcess = 0; +} HostProcessPosix::HostProcessPosix() -: m_pid(kInvalidProcessId) + : HostNativeProcessBase(kInvalidPosixProcess) { } @@ -27,38 +30,33 @@ HostProcessPosix::~HostProcessPosix() { } -Error HostProcessPosix::Create(lldb::pid_t pid) -{ - Error error; - if (pid == kInvalidProcessId) - error.SetErrorString("Attempt to create an invalid process"); - - m_pid = pid; - return error; -} - Error HostProcessPosix::Signal(int signo) const { - if (m_pid <= 0) + if (m_process == kInvalidPosixProcess) { Error error; error.SetErrorString("HostProcessPosix refers to an invalid process"); return error; } - return HostProcessPosix::Signal(m_pid, signo); + return HostProcessPosix::Signal(m_process, signo); } -Error HostProcessPosix::Signal(lldb::pid_t pid, int signo) +Error HostProcessPosix::Signal(lldb::process_t process, int signo) { Error error; - if (-1 == ::kill(pid, signo)) + if (-1 == ::kill(process, signo)) error.SetErrorToErrno(); return error; } +Error HostProcessPosix::Terminate() +{ + return Signal(SIGKILL); +} + Error HostProcessPosix::GetMainModule(FileSpec &file_spec) const { Error error; @@ -66,7 +64,7 @@ Error HostProcessPosix::GetMainModule(FileSpec &file_spec) const // Use special code here because proc/[pid]/exe is a symbolic link. char link_path[PATH_MAX]; char exe_path[PATH_MAX] = ""; - if (snprintf (link_path, PATH_MAX, "/proc/%" PRIu64 "/exe", m_pid) <= 0) + if (snprintf (link_path, PATH_MAX, "/proc/%" PRIu64 "/exe", m_process) <= 0) { error.SetErrorString("Unable to build /proc/<pid>/exe string"); return error; @@ -92,7 +90,7 @@ Error HostProcessPosix::GetMainModule(FileSpec &file_spec) const lldb::pid_t HostProcessPosix::GetProcessId() const { - return m_pid; + return m_process; } bool HostProcessPosix::IsRunning() const diff --git a/lldb/source/Host/windows/HostProcessWindows.cpp b/lldb/source/Host/windows/HostProcessWindows.cpp index 7a1ad955e3b..bf54e587912 100644 --- a/lldb/source/Host/windows/HostProcessWindows.cpp +++ b/lldb/source/Host/windows/HostProcessWindows.cpp @@ -7,19 +7,18 @@ // //===----------------------------------------------------------------------===// +#include "lldb/Host/FileSpec.h" #include "lldb/Host/windows/windows.h" - -#include <Psapi.h> - #include "lldb/Host/windows/HostProcessWindows.h" #include "llvm/ADT/STLExtras.h" +#include <Psapi.h> + using namespace lldb_private; -HostProcessWindows::HostProcessWindows() - : m_process(NULL) - , m_pid(0) +HostProcessWindows::HostProcessWindows(lldb::process_t process) + : HostNativeProcessBase(process) { } @@ -28,41 +27,10 @@ HostProcessWindows::~HostProcessWindows() Close(); } -Error HostProcessWindows::Create(lldb::pid_t pid) -{ - Error error; - if (pid == m_pid) - return error; - Close(); - - m_process = ::OpenProcess(PROCESS_TERMINATE | PROCESS_QUERY_LIMITED_INFORMATION, FALSE, pid); - if (m_process == NULL) - { - error.SetError(::GetLastError(), lldb::eErrorTypeWin32); - return error; - } - m_pid = pid; - return error; -} - -Error HostProcessWindows::Create(lldb::process_t process) -{ - Error error; - if (process == m_process) - return error; - Close(); - - m_pid = ::GetProcessId(process); - if (m_pid == 0) - error.SetError(::GetLastError(), lldb::eErrorTypeWin32); - m_process = process; - return error; -} - Error HostProcessWindows::Terminate() { Error error; - if (m_process == NULL) + if (m_process == nullptr) error.SetError(ERROR_INVALID_HANDLE, lldb::eErrorTypeWin32); if (!::TerminateProcess(m_process, 0)) @@ -74,7 +42,7 @@ Error HostProcessWindows::Terminate() Error HostProcessWindows::GetMainModule(FileSpec &file_spec) const { Error error; - if (m_process == NULL) + if (m_process == nullptr) error.SetError(ERROR_INVALID_HANDLE, lldb::eErrorTypeWin32); char path[MAX_PATH] = { 0 }; @@ -88,12 +56,12 @@ Error HostProcessWindows::GetMainModule(FileSpec &file_spec) const lldb::pid_t HostProcessWindows::GetProcessId() const { - return m_pid; + return ::GetProcessId(m_process); } bool HostProcessWindows::IsRunning() const { - if (m_process == NULL) + if (m_process == nullptr) return false; DWORD code = 0; @@ -105,8 +73,7 @@ bool HostProcessWindows::IsRunning() const void HostProcessWindows::Close() { - if (m_process != NULL) + if (m_process != nullptr) ::CloseHandle(m_process); m_process = nullptr; - m_pid = 0; } |