20#include "llvm/Support/Errno.h"
21#include "llvm/Support/Error.h"
27#include <sys/ptrace.h>
37 "Size of long must be larger than ptrace word size");
42 int status = fcntl(fd, F_GETFL);
44 return errorCodeToError(errnoAsErrorCode());
45 if (fcntl(fd, F_SETFL, status | flags) == -1)
46 return errorCodeToError(errnoAsErrorCode());
47 return Error::success();
60llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
71 LLDB_LOG(log,
"failed to launch process: {0}", status);
77 ::pid_t wpid = llvm::sys::RetryAfterSignal(-1, ::waitpid, pid, &wstatus, 0);
80 if (!WIFSTOPPED(wstatus)) {
81 LLDB_LOG(log,
"Could not sync with inferior process: wstatus={1}",
83 return llvm::make_error<StringError>(
"Could not sync with inferior process",
84 llvm::inconvertibleErrorCode());
86 LLDB_LOG(log,
"inferior started, now in stopped state");
90 HostInfo::GetArchitecture(HostInfo::eArchKind64), *
this, {pid}));
93llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
101 return tids_or.takeError();
104 pid, -1, native_delegate,
105 HostInfo::GetArchitecture(HostInfo::eArchKind64), *
this, *tids_or));
112static std::optional<std::pair<lldb::pid_t, WaitStatus>>
WaitPid() {
117 llvm::sys::RetryAfterSignal(-1, ::waitpid, -1, &status, WNOHANG);
122 if (wait_pid == -1) {
130 LLDB_LOG(log,
"waitpid(-1, &status, _) = {0}, status = {1}", wait_pid,
132 return std::make_pair(wait_pid, wait_status);
150 llvm::ArrayRef<::pid_t> tids)
165 if (llvm::Error err =
PtraceWrapper(PT_ATTACH, pid).takeError())
168 int wpid = llvm::sys::RetryAfterSignal(-1, ::waitpid, pid,
nullptr, WNOHANG);
170 return llvm::errorCodeToError(errnoAsErrorCode());
171 LLDB_LOG(log,
"adding pid = {0}", pid);
173 return std::vector<::pid_t>{pid};
179 return Status(
"unsupported");
193 size_t &bytes_read) {
194 return Status(
"unsupported");
198 size_t size,
size_t &bytes_written) {
199 return Status(
"unsupported");
211 return Status(
"unsupported");
232 void *addr,
void *data,
240 ret = ptrace64(req, pid, 0, 0,
nullptr);
243 llvm_unreachable(
"PT_ request not supported yet.");
246 LLDB_LOG(log,
"ptrace({0}, {1}, {2}, {3}, {4})={5:x}", req, pid, addr, data,
251 return llvm::errorCodeToError(errnoAsErrorCode());
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
static std::optional< std::pair< lldb::pid_t, WaitStatus > > WaitPid()
static constexpr unsigned k_ptrace_word_size
static llvm::Error SetFDFlags(int fd, int flags)
An architecture specification class.
lldb::pid_t GetProcessId() const
SignalHandleUP RegisterSignal(int signo, const Callback &callback, Status &error)
NativeProcessProtocol(lldb::pid_t pid, int terminal_fd, NativeDelegate &delegate)
Status SetSoftwareBreakpoint(lldb::addr_t addr, uint32_t size_hint)
void SetState(lldb::StateType state, bool notify_delegates=true)
void SetCurrentThreadID(lldb::tid_t tid)
std::vector< std::unique_ptr< NativeThreadProtocol > > m_threads
virtual Status RemoveBreakpoint(lldb::addr_t addr, bool hardware=false)
virtual Status SetHardwareBreakpoint(lldb::addr_t addr, size_t size)
virtual Status RemoveHardwareBreakpoint(lldb::addr_t addr)
PseudoTerminal & GetPTY()
HostProcess LaunchProcess(const ProcessLaunchInfo &launch_info, Status &error) override
int ReleasePrimaryFileDescriptor()
Release the primary file descriptor.
llvm::Error ToError() const
FIXME: Replace all uses with takeError() instead.
bool Fail() const
Test for error condition.
bool Success() const
Test for success condition.
void AddProcess(NativeProcessAIX &process)
llvm::Expected< std::unique_ptr< NativeProcessProtocol > > Launch(ProcessLaunchInfo &launch_info, NativeDelegate &native_delegate) override
Launch a process for debugging.
Manager(MainLoop &mainloop)
llvm::Expected< std::unique_ptr< NativeProcessProtocol > > Attach(lldb::pid_t pid, NativeDelegate &native_delegate) override
Attach to an existing process.
MainLoop::SignalHandleUP m_sigchld_handle
void CollectThread(::pid_t tid)
Status ReadMemory(lldb::addr_t addr, void *buf, size_t size, size_t &bytes_read) override
static llvm::Expected< std::vector<::pid_t > > Attach(::pid_t pid)
Status WriteMemory(lldb::addr_t addr, const void *buf, size_t size, size_t &bytes_written) override
bool SupportHardwareSingleStepping() const
Status RemoveBreakpoint(lldb::addr_t addr, bool hardware=false) override
size_t UpdateThreads() override
static llvm::Expected< int > PtraceWrapper(int req, lldb::pid_t pid, void *addr=nullptr, void *data=nullptr, size_t data_size=0)
Status GetLoadedModuleFileSpec(const char *module_path, FileSpec &file_spec) override
Status Signal(int signo) override
Sends a process a UNIX signal signal.
Status Interrupt() override
Tells a process to interrupt all operations as if by a Ctrl-C.
lldb::addr_t GetSharedLibraryInfoAddress() override
Status Resume(const ResumeActionList &resume_actions) override
NativeProcessAIX(::pid_t pid, int terminal_fd, NativeDelegate &delegate, const ArchSpec &arch, Manager &manager, llvm::ArrayRef<::pid_t > tids)
Status SetBreakpoint(lldb::addr_t addr, uint32_t size, bool hardware) override
#define UNUSED_IF_ASSERT_DISABLED(x)
#define LLDB_INVALID_ADDRESS
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
@ eStateStopped
Process or thread is stopped and can be examined.
@ eErrorTypePOSIX
POSIX error codes.
static WaitStatus Decode(int wstatus)