1 //===-- HostProcessWindows.cpp ----------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/Host/posix/HostProcessPosix.h"
11 #include "lldb/Host/FileSystem.h"
13 #include "llvm/ADT/STLExtras.h"
17 using namespace lldb_private;
19 const lldb::pid_t HostProcessPosix::kInvalidProcessId = 0;
21 HostProcessPosix::HostProcessPosix()
22 : m_pid(kInvalidProcessId)
26 HostProcessPosix::~HostProcessPosix()
30 Error HostProcessPosix::Create(lldb::pid_t pid)
33 if (pid == kInvalidProcessId)
34 error.SetErrorString("Attempt to create an invalid process");
40 Error HostProcessPosix::Signal(int signo) const
45 error.SetErrorString("HostProcessPosix refers to an invalid process");
49 return HostProcessPosix::Signal(m_pid, signo);
52 Error HostProcessPosix::Signal(lldb::pid_t pid, int signo)
56 if (-1 == ::kill(pid, signo))
57 error.SetErrorToErrno();
62 Error HostProcessPosix::GetMainModule(FileSpec &file_spec) const
66 // Use special code here because proc/[pid]/exe is a symbolic link.
67 char link_path[PATH_MAX];
68 char exe_path[PATH_MAX] = "";
69 if (snprintf (link_path, PATH_MAX, "/proc/%" PRIu64 "/exe", m_pid) <= 0)
71 error.SetErrorString("Unable to build /proc/<pid>/exe string");
75 error = FileSystem::Readlink(link_path, exe_path, llvm::array_lengthof(exe_path));
79 const ssize_t len = strlen(exe_path);
80 // If the binary has been deleted, the link name has " (deleted)" appended.
82 static const ssize_t deleted_len = strlen(" (deleted)");
83 if (len > deleted_len &&
84 !strcmp(exe_path + len - deleted_len, " (deleted)"))
86 exe_path[len - deleted_len] = 0;
89 file_spec.SetFile(exe_path, false);
93 lldb::pid_t HostProcessPosix::GetProcessId() const
98 bool HostProcessPosix::IsRunning() const
100 // Send this process the null signal. If it succeeds the process is running.
101 Error error = Signal(0);
102 return error.Success();