summaryrefslogtreecommitdiffstats
path: root/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
diff options
context:
space:
mode:
authorPavel Labath <labath@google.com>2015-06-30 17:04:49 +0000
committerPavel Labath <labath@google.com>2015-06-30 17:04:49 +0000
commit4a9babb26e91ecc27d95da7ad129941e8aa33b0e (patch)
tree0f2ef49ed3c3d95605dc2f058b936c4dc03b33d9 /lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
parent6c6c46e4dfa9e3e16a7b40bffd90438ce5d38095 (diff)
downloadbcm5719-llvm-4a9babb26e91ecc27d95da7ad129941e8aa33b0e.tar.gz
bcm5719-llvm-4a9babb26e91ecc27d95da7ad129941e8aa33b0e.zip
[NativeProcessLinux] Refactor PtraceWrapper
Summary: This changes PtraceWrapper to return an Error, while the actual result is in an pointer parameter (instead of the other way around). Also made a couple of PtraceWrapper arguments default to zero. This arrangement makes a lot of the code much simpler. Test Plan: Tests pass on linux. It compiles on android arm64/mips64. Reviewers: chaoren, mohit.bhakkad Subscribers: tberghammer, aemerson, lldb-commits Differential Revision: http://reviews.llvm.org/D10808 llvm-svn: 241079
Diffstat (limited to 'lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp')
-rw-r--r--lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp65
1 files changed, 23 insertions, 42 deletions
diff --git a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
index e47cb52e8cc..b956b88ce45 100644
--- a/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
+++ b/lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp
@@ -250,8 +250,7 @@ namespace
assert(sizeof(data) >= word_size);
for (bytes_read = 0; bytes_read < size; bytes_read += remainder)
{
- Error error;
- data = NativeProcessLinux::PtraceWrapper(PTRACE_PEEKDATA, pid, (void*)vm_addr, nullptr, 0, error);
+ Error error = NativeProcessLinux::PtraceWrapper(PTRACE_PEEKDATA, pid, (void*)vm_addr, nullptr, 0, &data);
if (error.Fail())
{
if (log)
@@ -327,7 +326,8 @@ namespace
log->Printf ("NativeProcessLinux::%s() [%p]:0x%lx (0x%lx)", __FUNCTION__,
(void*)vm_addr, *(const unsigned long*)src, data);
- if (NativeProcessLinux::PtraceWrapper(PTRACE_POKEDATA, pid, (void*)vm_addr, (void*)data, 0, error))
+ error = NativeProcessLinux::PtraceWrapper(PTRACE_POKEDATA, pid, (void*)vm_addr, (void*)data);
+ if (error.Fail())
{
if (log)
ProcessPOSIXLog::DecNestLevel();
@@ -1115,7 +1115,7 @@ NativeProcessLinux::Launch(LaunchArgs *args, Error &error)
// send log info to parent re: launch status, in place of the log lines removed here.
// Start tracing this child that is about to exec.
- NativeProcessLinux::PtraceWrapper(PTRACE_TRACEME, 0, nullptr, nullptr, 0, error);
+ error = PtraceWrapper(PTRACE_TRACEME, 0);
if (error.Fail())
exit(ePtraceFailed);
@@ -1351,7 +1351,7 @@ NativeProcessLinux::Attach(lldb::pid_t pid, Error &error)
// Attach to the requested process.
// An attach will cause the thread to stop with a SIGSTOP.
- NativeProcessLinux::PtraceWrapper(PTRACE_ATTACH, tid, nullptr, nullptr, 0, error);
+ error = PtraceWrapper(PTRACE_ATTACH, tid);
if (error.Fail())
{
// No such thread. The thread may have exited.
@@ -1442,9 +1442,7 @@ NativeProcessLinux::SetDefaultPtraceOpts(lldb::pid_t pid)
// (needed to disable legacy SIGTRAP generation)
ptrace_opts |= PTRACE_O_TRACEEXEC;
- Error error;
- NativeProcessLinux::PtraceWrapper(PTRACE_SETOPTIONS, pid, nullptr, (void*)ptrace_opts, 0, error);
- return error;
+ return PtraceWrapper(PTRACE_SETOPTIONS, pid, nullptr, (void*)ptrace_opts);
}
static ExitType convert_pid_status_to_exit_type (int status)
@@ -3173,11 +3171,7 @@ NativeProcessLinux::Resume (lldb::tid_t tid, uint32_t signo)
if (signo != LLDB_INVALID_SIGNAL_NUMBER)
data = signo;
- Error error = DoOperation([&] {
- Error error;
- NativeProcessLinux::PtraceWrapper(PTRACE_CONT, tid, nullptr, (void*)data, 0, error);
- return error;
- });
+ Error error = DoOperation([&] { return PtraceWrapper(PTRACE_CONT, tid, nullptr, (void*)data); });
if (log)
log->Printf ("NativeProcessLinux::%s() resuming thread = %" PRIu64 " result = %s", __FUNCTION__, tid, error.Success() ? "true" : "false");
@@ -3192,31 +3186,19 @@ NativeProcessLinux::SingleStep(lldb::tid_t tid, uint32_t signo)
if (signo != LLDB_INVALID_SIGNAL_NUMBER)
data = signo;
- return DoOperation([&] {
- Error error;
- NativeProcessLinux::PtraceWrapper(PTRACE_SINGLESTEP, tid, nullptr, (void*)data, 0, error);
- return error;
- });
+ return DoOperation([&] { return PtraceWrapper(PTRACE_SINGLESTEP, tid, nullptr, (void*)data); });
}
Error
NativeProcessLinux::GetSignalInfo(lldb::tid_t tid, void *siginfo)
{
- return DoOperation([&] {
- Error error;
- NativeProcessLinux::PtraceWrapper(PTRACE_GETSIGINFO, tid, nullptr, siginfo, 0, error);
- return error;
- });
+ return DoOperation([&] { return PtraceWrapper(PTRACE_GETSIGINFO, tid, nullptr, siginfo); });
}
Error
NativeProcessLinux::GetEventMessage(lldb::tid_t tid, unsigned long *message)
{
- return DoOperation([&] {
- Error error;
- NativeProcessLinux::PtraceWrapper(PTRACE_GETEVENTMSG, tid, nullptr, message, 0, error);
- return error;
- });
+ return DoOperation([&] { return PtraceWrapper(PTRACE_GETEVENTMSG, tid, nullptr, message); });
}
Error
@@ -3225,11 +3207,7 @@ NativeProcessLinux::Detach(lldb::tid_t tid)
if (tid == LLDB_INVALID_THREAD_ID)
return Error();
- return DoOperation([&] {
- Error error;
- NativeProcessLinux::PtraceWrapper(PTRACE_DETACH, tid, nullptr, 0, 0, error);
- return error;
- });
+ return DoOperation([&] { return PtraceWrapper(PTRACE_DETACH, tid); });
}
bool
@@ -3732,27 +3710,30 @@ NativeProcessLinux::DoOperation(const Operation &op)
// Wrapper for ptrace to catch errors and log calls.
// Note that ptrace sets errno on error because -1 can be a valid result (i.e. for PTRACE_PEEK*)
-long
-NativeProcessLinux::PtraceWrapper(int req, lldb::pid_t pid, void *addr, void *data, size_t data_size, Error& error)
+Error
+NativeProcessLinux::PtraceWrapper(int req, lldb::pid_t pid, void *addr, void *data, size_t data_size, long *result)
{
- long int result;
+ Error error;
+ long int ret;
Log *log (ProcessPOSIXLog::GetLogIfAllCategoriesSet (POSIX_LOG_PTRACE));
PtraceDisplayBytes(req, data, data_size);
- error.Clear();
errno = 0;
if (req == PTRACE_GETREGSET || req == PTRACE_SETREGSET)
- result = ptrace(static_cast<__ptrace_request>(req), static_cast< ::pid_t>(pid), *(unsigned int *)addr, data);
+ ret = ptrace(static_cast<__ptrace_request>(req), static_cast< ::pid_t>(pid), *(unsigned int *)addr, data);
else
- result = ptrace(static_cast<__ptrace_request>(req), static_cast< ::pid_t>(pid), addr, data);
+ ret = ptrace(static_cast<__ptrace_request>(req), static_cast< ::pid_t>(pid), addr, data);
- if (result == -1)
+ if (ret == -1)
error.SetErrorToErrno();
+ if (result)
+ *result = ret;
+
if (log)
- log->Printf("ptrace(%d, %" PRIu64 ", %p, %p, %zu)=%lX", req, pid, addr, data, data_size, result);
+ log->Printf("ptrace(%d, %" PRIu64 ", %p, %p, %zu)=%lX", req, pid, addr, data, data_size, ret);
PtraceDisplayBytes(req, data, data_size);
@@ -3770,5 +3751,5 @@ NativeProcessLinux::PtraceWrapper(int req, lldb::pid_t pid, void *addr, void *da
log->Printf("ptrace() failed; errno=%d (%s)", error.GetError(), str);
}
- return result;
+ return error;
}
OpenPOWER on IntegriCloud