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
3726using namespace lldb ;
3827using 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
137126NativeProcessAIX::Extension
138127NativeProcessAIX::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
170156llvm::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}
0 commit comments