#include <sys/ptrace.h>
#include <sys/socket.h>
#include <sys/types.h>
-#include <sys/user.h>
#include <sys/wait.h>
// C++ Includes
}
}
-static void PtraceDisplayBytes(__ptrace_request &req, void *data)
+static void PtraceDisplayBytes(__ptrace_request &req, void *data, size_t data_size)
{
StreamString buf;
LogSP verbose_log (ProcessPOSIXLog::GetLogIfAllCategoriesSet (
}
case PTRACE_SETREGS:
{
- DisplayBytes(buf, data, sizeof(user_regs_struct));
+ DisplayBytes(buf, data, data_size);
verbose_log->Printf("PTRACE_SETREGS %s", buf.GetData());
break;
}
case PTRACE_SETFPREGS:
{
- DisplayBytes(buf, data, sizeof(user_fpregs_struct));
+ DisplayBytes(buf, data, data_size);
verbose_log->Printf("PTRACE_SETFPREGS %s", buf.GetData());
break;
}
}
// Wrapper for ptrace to catch errors and log calls.
+// Note that ptrace sets errno on error because -1 is a valid result for PTRACE_PEEK*
extern long
-PtraceWrapper(__ptrace_request req, pid_t pid, void *addr, void *data,
+PtraceWrapper(__ptrace_request req, pid_t pid, void *addr, void *data, size_t data_size,
const char* reqName, const char* file, int line)
{
long int result;
LogSP log (ProcessPOSIXLog::GetLogIfAllCategoriesSet (POSIX_LOG_PTRACE));
if (log)
- log->Printf("ptrace(%s, %u, %p, %p) called from file %s line %d",
- reqName, pid, addr, data, file, line);
+ log->Printf("ptrace(%s, %u, %p, %p, %zu) called from file %s line %d",
+ reqName, pid, addr, data, data_size, file, line);
- PtraceDisplayBytes(req, data);
+ PtraceDisplayBytes(req, data, data_size);
errno = 0;
result = ptrace(req, pid, addr, data);
- PtraceDisplayBytes(req, data);
+ PtraceDisplayBytes(req, data, data_size);
- if (log && (result == -1 || errno != 0))
+ if (log && errno != 0)
{
const char* str;
switch (errno)
return result;
}
-#define PTRACE(req, pid, addr, data) \
- PtraceWrapper((req), (pid), (addr), (data), #req, __FILE__, __LINE__)
+// Wrapper for ptrace when logging is not required.
+// Sets errno to 0 prior to calling ptrace.
+extern long
+PtraceWrapper(__ptrace_request req, pid_t pid, void *addr, void *data, size_t data_size)
+{
+ errno = 0;
+ long result = ptrace(req, pid, addr, data);
+ return result;
+}
+
+#define PTRACE(req, pid, addr, data, data_size) \
+ PtraceWrapper((req), (pid), (addr), (data), (data_size), #req, __FILE__, __LINE__)
#else
-#define PTRACE ptrace
+ PtraceWrapper((req), (pid), (addr), (data), (data_size))
#endif
//------------------------------------------------------------------------------
for (bytes_read = 0; bytes_read < size; bytes_read += remainder)
{
errno = 0;
- data = PTRACE(PTRACE_PEEKDATA, pid, (void*)vm_addr, NULL);
- if (data == -1L && errno)
+ data = PTRACE(PTRACE_PEEKDATA, pid, (void*)vm_addr, NULL, 0);
+ if (errno)
{
error.SetErrorToErrno();
if (log)
log->Printf ("ProcessMonitor::%s() [%p]:0x%lx (0x%lx)", __FUNCTION__,
(void*)vm_addr, *(unsigned long*)src, data);
- if (PTRACE(PTRACE_POKEDATA, pid, (void*)vm_addr, (void*)data))
+ if (PTRACE(PTRACE_POKEDATA, pid, (void*)vm_addr, (void*)data, 0))
{
error.SetErrorToErrno();
if (log)
// Set errno to zero so that we can detect a failed peek.
errno = 0;
- lldb::addr_t data = PTRACE(PTRACE_PEEKUSER, m_tid, (void*)m_offset, NULL);
- if (data == -1UL && errno)
+ lldb::addr_t data = PTRACE(PTRACE_PEEKUSER, m_tid, (void*)m_offset, NULL, 0);
+ if (errno)
m_result = false;
else
{
if (log)
log->Printf ("ProcessMonitor::%s() reg %s: %p", __FUNCTION__,
POSIXThread::GetRegisterNameFromOffset(m_offset), buf);
- if (PTRACE(PTRACE_POKEUSER, m_tid, (void*)m_offset, buf))
+ if (PTRACE(PTRACE_POKEUSER, m_tid, (void*)m_offset, buf, 0))
m_result = false;
else
m_result = true;
class ReadGPROperation : public Operation
{
public:
- ReadGPROperation(lldb::tid_t tid, void *buf, bool &result)
- : m_tid(tid), m_buf(buf), m_result(result)
+ ReadGPROperation(lldb::tid_t tid, void *buf, size_t buf_size, bool &result)
+ : m_tid(tid), m_buf(buf), m_buf_size(buf_size), m_result(result)
{ }
void Execute(ProcessMonitor *monitor);
private:
lldb::tid_t m_tid;
void *m_buf;
+ size_t m_buf_size;
bool &m_result;
};
void
ReadGPROperation::Execute(ProcessMonitor *monitor)
{
- if (PTRACE(PTRACE_GETREGS, m_tid, NULL, m_buf) < 0)
+ if (PTRACE(PTRACE_GETREGS, m_tid, NULL, m_buf, m_buf_size) < 0)
m_result = false;
else
m_result = true;
class ReadFPROperation : public Operation
{
public:
- ReadFPROperation(lldb::tid_t tid, void *buf, bool &result)
- : m_tid(tid), m_buf(buf), m_result(result)
+ ReadFPROperation(lldb::tid_t tid, void *buf, size_t buf_size, bool &result)
+ : m_tid(tid), m_buf(buf), m_buf_size(buf_size), m_result(result)
{ }
void Execute(ProcessMonitor *monitor);
private:
lldb::tid_t m_tid;
void *m_buf;
+ size_t m_buf_size;
bool &m_result;
};
void
ReadFPROperation::Execute(ProcessMonitor *monitor)
{
- if (PTRACE(PTRACE_GETFPREGS, m_tid, NULL, m_buf) < 0)
+ if (PTRACE(PTRACE_GETFPREGS, m_tid, NULL, m_buf, m_buf_size) < 0)
m_result = false;
else
m_result = true;
class WriteGPROperation : public Operation
{
public:
- WriteGPROperation(lldb::tid_t tid, void *buf, bool &result)
- : m_tid(tid), m_buf(buf), m_result(result)
+ WriteGPROperation(lldb::tid_t tid, void *buf, size_t buf_size, bool &result)
+ : m_tid(tid), m_buf(buf), m_buf_size(buf_size), m_result(result)
{ }
void Execute(ProcessMonitor *monitor);
private:
lldb::tid_t m_tid;
void *m_buf;
+ size_t m_buf_size;
bool &m_result;
};
void
WriteGPROperation::Execute(ProcessMonitor *monitor)
{
- if (PTRACE(PTRACE_SETREGS, m_tid, NULL, m_buf) < 0)
+ if (PTRACE(PTRACE_SETREGS, m_tid, NULL, m_buf, m_buf_size) < 0)
m_result = false;
else
m_result = true;
class WriteFPROperation : public Operation
{
public:
- WriteFPROperation(lldb::tid_t tid, void *buf, bool &result)
- : m_tid(tid), m_buf(buf), m_result(result)
+ WriteFPROperation(lldb::tid_t tid, void *buf, size_t buf_size, bool &result)
+ : m_tid(tid), m_buf(buf), m_buf_size(buf_size), m_result(result)
{ }
void Execute(ProcessMonitor *monitor);
private:
lldb::tid_t m_tid;
void *m_buf;
+ size_t m_buf_size;
bool &m_result;
};
void
WriteFPROperation::Execute(ProcessMonitor *monitor)
{
- if (PTRACE(PTRACE_SETFPREGS, m_tid, NULL, m_buf) < 0)
+ if (PTRACE(PTRACE_SETFPREGS, m_tid, NULL, m_buf, m_buf_size) < 0)
m_result = false;
else
m_result = true;
if (m_signo != LLDB_INVALID_SIGNAL_NUMBER)
data = m_signo;
- if (PTRACE(PTRACE_CONT, m_tid, NULL, (void*)data))
+ if (PTRACE(PTRACE_CONT, m_tid, NULL, (void*)data, 0))
m_result = false;
else
m_result = true;
if (m_signo != LLDB_INVALID_SIGNAL_NUMBER)
data = m_signo;
- if (PTRACE(PTRACE_SINGLESTEP, m_tid, NULL, (void*)data))
+ if (PTRACE(PTRACE_SINGLESTEP, m_tid, NULL, (void*)data, 0))
m_result = false;
else
m_result = true;
void
SiginfoOperation::Execute(ProcessMonitor *monitor)
{
- if (PTRACE(PTRACE_GETSIGINFO, m_tid, NULL, m_info)) {
+ if (PTRACE(PTRACE_GETSIGINFO, m_tid, NULL, m_info, 0)) {
m_result = false;
m_err = errno;
}
void
EventMessageOperation::Execute(ProcessMonitor *monitor)
{
- if (PTRACE(PTRACE_GETEVENTMSG, m_tid, NULL, m_message))
+ if (PTRACE(PTRACE_GETEVENTMSG, m_tid, NULL, m_message, 0))
m_result = false;
else
m_result = true;
{
lldb::pid_t pid = monitor->GetPID();
- if (PTRACE(PTRACE_KILL, pid, NULL, NULL))
+ if (PTRACE(PTRACE_KILL, pid, NULL, NULL, 0))
m_result = false;
else
m_result = true;
lldb_private::Error &error)
: m_process(static_cast<ProcessLinux *>(process)),
m_operation_thread(LLDB_INVALID_HOST_THREAD),
+ m_monitor_thread(LLDB_INVALID_HOST_THREAD),
m_pid(LLDB_INVALID_PROCESS_ID),
m_terminal_fd(-1),
- m_monitor_thread(LLDB_INVALID_HOST_THREAD),
m_client_fd(-1),
m_server_fd(-1)
{
lldb_private::Error &error)
: m_process(static_cast<ProcessLinux *>(process)),
m_operation_thread(LLDB_INVALID_HOST_THREAD),
+ m_monitor_thread(LLDB_INVALID_HOST_THREAD),
m_pid(LLDB_INVALID_PROCESS_ID),
m_terminal_fd(-1),
- m_monitor_thread(LLDB_INVALID_HOST_THREAD),
+
m_client_fd(-1),
m_server_fd(-1)
{
if (pid == 0)
{
// Trace this process.
- if (PTRACE(PTRACE_TRACEME, 0, NULL, NULL) < 0)
+ if (PTRACE(PTRACE_TRACEME, 0, NULL, NULL, 0) < 0)
exit(ePtraceFailed);
// Do not inherit setgid powers.
// Have the tracer trace threads which spawn in the inferior process.
ptrace_opts |= PTRACE_O_TRACEFORK | PTRACE_O_TRACEVFORK | PTRACE_O_TRACECLONE;
- if (PTRACE(PTRACE_SETOPTIONS, pid, NULL, (void*)ptrace_opts) < 0)
+ if (PTRACE(PTRACE_SETOPTIONS, pid, NULL, (void*)ptrace_opts, 0) < 0)
{
args->m_error.SetErrorToErrno();
goto FINISH;
}
// Attach to the requested process.
- if (PTRACE(PTRACE_ATTACH, pid, NULL, NULL) < 0)
+ if (PTRACE(PTRACE_ATTACH, pid, NULL, NULL, 0) < 0)
{
args->m_error.SetErrorToErrno();
goto FINISH;
}
bool
-ProcessMonitor::ReadRegisterValue(lldb::tid_t tid, unsigned offset, unsigned size, RegisterValue &value)
+ProcessMonitor::ReadRegisterValue(lldb::tid_t tid, unsigned offset,
+ unsigned size, RegisterValue &value)
{
bool result;
ReadRegOperation op(tid, offset, value, result);
}
bool
-ProcessMonitor::WriteRegisterValue(lldb::tid_t tid, unsigned offset, const RegisterValue &value)
+ProcessMonitor::WriteRegisterValue(lldb::tid_t tid, unsigned offset,
+ const RegisterValue &value)
{
bool result;
WriteRegOperation op(tid, offset, value, result);
}
bool
-ProcessMonitor::ReadGPR(lldb::tid_t tid, void *buf)
+ProcessMonitor::ReadGPR(lldb::tid_t tid, void *buf, size_t buf_size)
{
bool result;
- ReadGPROperation op(tid, buf, result);
+ ReadGPROperation op(tid, buf, buf_size, result);
DoOperation(&op);
return result;
}
bool
-ProcessMonitor::ReadFPR(lldb::tid_t tid, void *buf)
+ProcessMonitor::ReadFPR(lldb::tid_t tid, void *buf, size_t buf_size)
{
bool result;
- ReadFPROperation op(tid, buf, result);
+ ReadFPROperation op(tid, buf, buf_size, result);
DoOperation(&op);
return result;
}
bool
-ProcessMonitor::WriteGPR(lldb::tid_t tid, void *buf)
+ProcessMonitor::WriteGPR(lldb::tid_t tid, void *buf, size_t buf_size)
{
bool result;
- WriteGPROperation op(tid, buf, result);
+ WriteGPROperation op(tid, buf, buf_size, result);
DoOperation(&op);
return result;
}
bool
-ProcessMonitor::WriteFPR(lldb::tid_t tid, void *buf)
+ProcessMonitor::WriteFPR(lldb::tid_t tid, void *buf, size_t buf_size)
{
bool result;
- WriteFPROperation op(tid, buf, result);
+ WriteFPROperation op(tid, buf, buf_size, result);
DoOperation(&op);
return result;
}