Skip to content

Commit 6d2ef7e

Browse files
Addressing comments
1 parent 1284f0b commit 6d2ef7e

File tree

2 files changed

+64
-58
lines changed

2 files changed

+64
-58
lines changed

lldb/source/Plugins/Process/AIX/NativeProcessAIX.cpp

Lines changed: 56 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,21 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "NativeProcessAIX.h"
10-
#include "NativeThreadAIX.h"
11-
#include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
1210
#include "lldb/Host/Host.h"
1311
#include "lldb/Host/HostProcess.h"
1412
#include "lldb/Host/ProcessLaunchInfo.h"
1513
#include "lldb/Symbol/ObjectFile.h"
16-
#include "lldb/Target/Process.h"
17-
#include "lldb/Target/Target.h"
18-
#include "lldb/Utility/LLDBAssert.h"
19-
#include "lldb/Utility/LLDBLog.h"
14+
#include "lldb/Utility/Log.h"
2015
#include "lldb/Utility/State.h"
2116
#include "lldb/Utility/Status.h"
22-
#include "lldb/Utility/StringExtractor.h"
2317
#include "llvm/Support/Errno.h"
2418
#include "llvm/Support/Error.h"
25-
#include "llvm/Support/FileSystem.h"
2619
#include <cerrno>
2720
#include <cstdint>
2821
#include <cstring>
29-
#include <fstream>
30-
#include <mutex>
31-
#include <optional>
3222
#include <sstream>
3323
#include <string>
3424
#include <unistd.h>
35-
#include <unordered_map>
3625

3726
using namespace lldb;
3827
using namespace lldb_private;
@@ -45,17 +34,17 @@ static_assert(sizeof(long) >= k_ptrace_word_size,
4534

4635
// Simple helper function to ensure flags are enabled on the given file
4736
// descriptor.
48-
static Status EnsureFDFlags(int fd, int flags) {
49-
Status error;
37+
static llvm::Error EnsureFDFlags(int fd, int flags) {
38+
Error error;
5039

5140
int status = fcntl(fd, F_GETFL);
5241
if (status == -1) {
53-
error = Status::FromErrno();
42+
error = errorCodeToError(errnoAsErrorCode());
5443
return error;
5544
}
5645

5746
if (fcntl(fd, F_SETFL, status | flags) == -1) {
58-
error = Status::FromErrno();
47+
error = errorCodeToError(errnoAsErrorCode());
5948
return error;
6049
}
6150

@@ -136,10 +125,7 @@ NativeProcessAIX::Manager::Attach(
136125

137126
NativeProcessAIX::Extension
138127
NativeProcessAIX::Manager::GetSupportedExtensions() const {
139-
NativeProcessAIX::Extension supported =
140-
Extension::multiprocess | Extension::fork | Extension::vfork |
141-
Extension::pass_signals | Extension::auxv | Extension::libraries_svr4 |
142-
Extension::siginfo_read;
128+
NativeProcessAIX::Extension supported = {};
143129

144130
return supported;
145131
}
@@ -169,11 +155,18 @@ NativeProcessAIX::NativeProcessAIX(::pid_t pid, int terminal_fd,
169155

170156
llvm::Expected<std::vector<::pid_t>> NativeProcessAIX::Attach(::pid_t pid) {
171157

172-
Status status;
158+
Error status;
173159
if ((status = PtraceWrapper(PT_ATTACH, pid)).Fail()) {
174-
return status.ToError();
160+
return errorCodeToError(errnoAsErrorCode());
175161
}
176162

163+
int wpid = llvm::sys::RetryAfterSignal(-1, ::waitpid, pid, nullptr, WNOHANG);
164+
if (wpid <= 0) {
165+
return llvm::errorCodeToError(
166+
std::error_code(errno, std::generic_category()));
167+
}
168+
LLDB_LOG(log, "adding pid = {0}", pid);
169+
177170
std::vector<::pid_t> tids;
178171
tids.push_back(pid);
179172
return std::move(tids);
@@ -190,37 +183,37 @@ Status NativeProcessAIX::Resume(const ResumeActionList &resume_actions) {
190183
return Status();
191184
}
192185

193-
Status NativeProcessAIX::Halt() {
194-
Status error;
186+
Error NativeProcessAIX::Halt() {
187+
Error error;
195188
return error;
196189
}
197190

198-
Status NativeProcessAIX::Detach() {
199-
Status error;
191+
Error NativeProcessAIX::Detach() {
192+
Error error;
200193
return error;
201194
}
202195

203-
Status NativeProcessAIX::Signal(int signo) {
204-
Status error;
196+
Error NativeProcessAIX::Signal(int signo) {
197+
Error error;
205198
return error;
206199
}
207200

208-
Status NativeProcessAIX::Interrupt() { return Status(); }
201+
Error NativeProcessAIX::Interrupt() { return Status(); }
209202

210-
Status NativeProcessAIX::Kill() {
211-
Status error;
203+
Error NativeProcessAIX::Kill() {
204+
Error error;
212205
return error;
213206
}
214207

215-
Status NativeProcessAIX::SetBreakpoint(lldb::addr_t addr, uint32_t size,
216-
bool hardware) {
208+
Error NativeProcessAIX::SetBreakpoint(lldb::addr_t addr, uint32_t size,
209+
bool hardware) {
217210
if (hardware)
218211
return SetHardwareBreakpoint(addr, size);
219212
else
220213
return SetSoftwareBreakpoint(addr, size);
221214
}
222215

223-
Status NativeProcessAIX::RemoveBreakpoint(lldb::addr_t addr, bool hardware) {
216+
Error NativeProcessAIX::RemoveBreakpoint(lldb::addr_t addr, bool hardware) {
224217
if (hardware)
225218
return RemoveHardwareBreakpoint(addr);
226219
else
@@ -231,7 +224,7 @@ int8_t NativeProcessAIX::GetSignalInfo(WaitStatus wstatus) const {
231224
return wstatus.status;
232225
}
233226

234-
Status NativeProcessAIX::Detach(lldb::tid_t tid) {
227+
Error NativeProcessAIX::Detach(lldb::tid_t tid) {
235228
if (tid == LLDB_INVALID_THREAD_ID)
236229
return Status();
237230

@@ -240,9 +233,33 @@ Status NativeProcessAIX::Detach(lldb::tid_t tid) {
240233

241234
// Wrapper for ptrace to catch errors and log calls. Note that ptrace sets
242235
// errno on error because -1 can be a valid result (i.e. for PTRACE_PEEK*)
243-
Status NativeProcessAIX::PtraceWrapper(int req, lldb::pid_t pid, void *addr,
244-
void *data, size_t data_size,
245-
long *result) {
246-
Status error;
236+
Error NativeProcessAIX::PtraceWrapper(int req, lldb::pid_t pid, void *addr,
237+
void *data, size_t data_size,
238+
long *result) {
239+
Error error;
240+
long int ret;
241+
242+
Log *log = GetLog(POSIXLog::Ptrace);
243+
errno = 0;
244+
if (req < PT_COMMAND_MAX) {
245+
if (req == PT_ATTACH) {
246+
ptrace64(req, pid, 0, 0, nullptr);
247+
} else if (req == PT_DETACH) {
248+
ptrace64(req, pid, 0, 0, nullptr);
249+
}
250+
} else {
251+
assert(0 && "Not supported yet.");
252+
}
253+
254+
if (errno) {
255+
error = errorCodeToError(errnoAsErrorCode());
256+
ret = -1;
257+
}
258+
259+
LLDB_LOG(log, "ptrace({0}, {1}, {2}, {3}, {4})={5:x}", req, pid, addr, data,
260+
data_size, ret);
261+
if (error.Fail())
262+
LLDB_LOG(log, "ptrace() failed: {0}", error);
263+
247264
return error;
248265
}

lldb/source/Plugins/Process/AIX/NativeProcessAIX.h

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,21 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#ifndef liblldb_NativeProcessAIX_H_
10-
#define liblldb_NativeProcessAIX_H_
11-
12-
#include <csignal>
13-
#include <unordered_set>
9+
#ifndef LIBLLDB_NATIVEPROCESSAIX_H_
10+
#define LIBLLDB_NATIVEPROCESSAIX_H_
1411

12+
#include "Plugins/Process/Utility/NativeProcessSoftwareSingleStep.h"
1513
#include "lldb/Host/Debug.h"
16-
#include "lldb/Host/HostThread.h"
14+
#include "lldb/Host/common/NativeProcessProtocol.h"
1715
#include "lldb/Target/MemoryRegionInfo.h"
1816
#include "lldb/Utility/ArchSpec.h"
1917
#include "lldb/Utility/FileSpec.h"
2018
#include "lldb/lldb-types.h"
2119
#include "llvm/ADT/SmallPtrSet.h"
22-
23-
#include "NativeThreadAIX.h"
24-
#include "Plugins/Process/Utility/NativeProcessSoftwareSingleStep.h"
25-
#include "lldb/Host/common/NativeProcessProtocol.h"
20+
#include <csignal>
21+
#include <unordered_set>
2622

2723
namespace lldb_private {
28-
class Status;
29-
class Scalar;
3024

3125
namespace process_aix {
3226
/// \class NativeProcessAIX
@@ -36,8 +30,7 @@ namespace process_aix {
3630
/// for debugging.
3731
///
3832
/// Changes in the inferior process state are broadcasted.
39-
class NativeProcessAIX : public NativeProcessProtocol,
40-
private NativeProcessSoftwareSingleStep {
33+
class NativeProcessAIX : public NativeProcessProtocol {
4134
public:
4235
class Manager : public NativeProcessProtocol::Manager {
4336
public:
@@ -99,13 +92,9 @@ class NativeProcessAIX : public NativeProcessProtocol,
9992
void *data = nullptr, size_t data_size = 0,
10093
long *result = nullptr);
10194

102-
// Wrapper for ptrace to catch errors and log calls. Note that ptrace sets
103-
10495
private:
10596
Manager &m_manager;
106-
/*MainLoop::SignalHandleUP m_sigchld_handle;*/
10797
ArchSpec m_arch;
108-
/*MainLoop& m_main_loop;*/
10998

11099
// Private Instance Methods
111100
NativeProcessAIX(::pid_t pid, int terminal_fd, NativeDelegate &delegate,
@@ -127,4 +116,4 @@ class NativeProcessAIX : public NativeProcessProtocol,
127116
} // namespace process_aix
128117
} // namespace lldb_private
129118

130-
#endif // #ifndef liblldb_NativeProcessAIX_H_
119+
#endif // #ifndef LIBLLDB_NATIVEPROCESSAIX_H_

0 commit comments

Comments
 (0)