Deleted Added
full compact
HostProcessPosix.cpp (276479) HostProcessPosix.cpp (280031)
1//===-- HostProcessWindows.cpp ----------------------------------*- C++ -*-===//
1//===-- HostProcessPosix.cpp ------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "lldb/Host/Host.h"
10#include "lldb/Host/posix/HostProcessPosix.h"
11#include "lldb/Host/FileSystem.h"
12
13#include "llvm/ADT/STLExtras.h"
14
15#include <limits.h>
16
17using namespace lldb_private;
18
11#include "lldb/Host/posix/HostProcessPosix.h"
12#include "lldb/Host/FileSystem.h"
13
14#include "llvm/ADT/STLExtras.h"
15
16#include <limits.h>
17
18using namespace lldb_private;
19
19const lldb::pid_t HostProcessPosix::kInvalidProcessId = 0;
20namespace
21{
22 const int kInvalidPosixProcess = 0;
23}
20
21HostProcessPosix::HostProcessPosix()
24
25HostProcessPosix::HostProcessPosix()
22: m_pid(kInvalidProcessId)
26 : HostNativeProcessBase(kInvalidPosixProcess)
23{
24}
25
27{
28}
29
26HostProcessPosix::~HostProcessPosix()
30HostProcessPosix::HostProcessPosix(lldb::process_t process)
31 : HostNativeProcessBase(process)
27{
28}
29
32{
33}
34
30Error HostProcessPosix::Create(lldb::pid_t pid)
35HostProcessPosix::~HostProcessPosix()
31{
36{
32 Error error;
33 if (pid == kInvalidProcessId)
34 error.SetErrorString("Attempt to create an invalid process");
35
36 m_pid = pid;
37 return error;
38}
39
40Error HostProcessPosix::Signal(int signo) const
41{
37}
38
39Error HostProcessPosix::Signal(int signo) const
40{
42 if (m_pid <= 0)
41 if (m_process == kInvalidPosixProcess)
43 {
44 Error error;
45 error.SetErrorString("HostProcessPosix refers to an invalid process");
46 return error;
47 }
48
42 {
43 Error error;
44 error.SetErrorString("HostProcessPosix refers to an invalid process");
45 return error;
46 }
47
49 return HostProcessPosix::Signal(m_pid, signo);
48 return HostProcessPosix::Signal(m_process, signo);
50}
51
49}
50
52Error HostProcessPosix::Signal(lldb::pid_t pid, int signo)
51Error HostProcessPosix::Signal(lldb::process_t process, int signo)
53{
54 Error error;
55
52{
53 Error error;
54
56 if (-1 == ::kill(pid, signo))
55 if (-1 == ::kill(process, signo))
57 error.SetErrorToErrno();
58
59 return error;
60}
61
56 error.SetErrorToErrno();
57
58 return error;
59}
60
61Error HostProcessPosix::Terminate()
62{
63 return Signal(SIGKILL);
64}
65
62Error HostProcessPosix::GetMainModule(FileSpec &file_spec) const
63{
64 Error error;
65
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] = "";
66Error HostProcessPosix::GetMainModule(FileSpec &file_spec) const
67{
68 Error error;
69
70 // Use special code here because proc/[pid]/exe is a symbolic link.
71 char link_path[PATH_MAX];
72 char exe_path[PATH_MAX] = "";
69 if (snprintf (link_path, PATH_MAX, "/proc/%" PRIu64 "/exe", m_pid) <= 0)
73 if (snprintf (link_path, PATH_MAX, "/proc/%" PRIu64 "/exe", m_process) <= 0)
70 {
71 error.SetErrorString("Unable to build /proc/<pid>/exe string");
72 return error;
73 }
74
75 error = FileSystem::Readlink(link_path, exe_path, llvm::array_lengthof(exe_path));
76 if (!error.Success())
77 return error;

--- 9 unchanged lines hidden (view full) ---

87 }
88
89 file_spec.SetFile(exe_path, false);
90 return error;
91}
92
93lldb::pid_t HostProcessPosix::GetProcessId() const
94{
74 {
75 error.SetErrorString("Unable to build /proc/<pid>/exe string");
76 return error;
77 }
78
79 error = FileSystem::Readlink(link_path, exe_path, llvm::array_lengthof(exe_path));
80 if (!error.Success())
81 return error;

--- 9 unchanged lines hidden (view full) ---

91 }
92
93 file_spec.SetFile(exe_path, false);
94 return error;
95}
96
97lldb::pid_t HostProcessPosix::GetProcessId() const
98{
95 return m_pid;
99 return m_process;
96}
97
98bool HostProcessPosix::IsRunning() const
99{
100}
101
102bool HostProcessPosix::IsRunning() const
103{
104 if (m_process == kInvalidPosixProcess)
105 return false;
106
100 // Send this process the null signal. If it succeeds the process is running.
101 Error error = Signal(0);
102 return error.Success();
103}
107 // Send this process the null signal. If it succeeds the process is running.
108 Error error = Signal(0);
109 return error.Success();
110}
111
112HostThread
113HostProcessPosix::StartMonitoring(HostProcess::MonitorCallback callback, void *callback_baton, bool monitor_signals)
114{
115 return Host::StartMonitoringChildProcess(callback, callback_baton, m_process, monitor_signals);
116}