Index: source/Plugins/Process/Linux/NativeProcessLinux.h =================================================================== --- source/Plugins/Process/Linux/NativeProcessLinux.h +++ source/Plugins/Process/Linux/NativeProcessLinux.h @@ -141,8 +141,13 @@ Error DoOperation(const Operation &op); - static long - PtraceWrapper(int req, lldb::pid_t pid, void *addr, void *data, size_t data_size, Error& error); + static Error + PtraceWrapper(int req, + lldb::pid_t pid, + void *addr = nullptr, + void *data = nullptr, + size_t data_size = 0, + long *result = nullptr); protected: // --------------------------------------------------------------------- Index: source/Plugins/Process/Linux/NativeProcessLinux.cpp =================================================================== --- source/Plugins/Process/Linux/NativeProcessLinux.cpp +++ source/Plugins/Process/Linux/NativeProcessLinux.cpp @@ -250,8 +250,7 @@ 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 @@ 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 @@ // 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 @@ // 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 @@ // (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 @@ 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 @@ 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 @@ 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 @@ // 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 @@ log->Printf("ptrace() failed; errno=%d (%s)", error.GetError(), str); } - return result; + return error; } Index: source/Plugins/Process/Linux/NativeRegisterContextLinux.cpp =================================================================== --- source/Plugins/Process/Linux/NativeRegisterContextLinux.cpp +++ source/Plugins/Process/Linux/NativeRegisterContextLinux.cpp @@ -196,10 +196,8 @@ NativeProcessLinux* process_p = static_cast(process_sp.get()); return process_p->DoOperation([&] { - Error error; - NativeProcessLinux::PtraceWrapper(PTRACE_GETREGSET, m_thread.GetID(), - static_cast(®set), buf, buf_size, error); - return error; + return NativeProcessLinux::PtraceWrapper(PTRACE_GETREGSET, m_thread.GetID(), + static_cast(®set), buf, buf_size); }); } @@ -212,10 +210,8 @@ NativeProcessLinux* process_p = static_cast(process_sp.get()); return process_p->DoOperation([&] { - Error error; - NativeProcessLinux::PtraceWrapper(PTRACE_SETREGSET, m_thread.GetID(), - static_cast(®set), buf, buf_size, error); - return error; + return NativeProcessLinux::PtraceWrapper(PTRACE_SETREGSET, m_thread.GetID(), + static_cast(®set), buf, buf_size); }); } @@ -226,13 +222,13 @@ RegisterValue &value) { Log *log (ProcessPOSIXLog::GetLogIfAllCategoriesSet (POSIX_LOG_REGISTERS)); - Error error; - lldb::addr_t data = NativeProcessLinux::PtraceWrapper( - PTRACE_PEEKUSER, m_thread.GetID(), reinterpret_cast(offset), nullptr, 0, error); + long data; + Error error = NativeProcessLinux::PtraceWrapper( + PTRACE_PEEKUSER, m_thread.GetID(), reinterpret_cast(offset), nullptr, 0, &data); if (error.Success()) - value = data; + value = static_cast(data); if (log) log->Printf ("NativeRegisterContextLinux::%s() reg %s: 0x%" PRIx64, __FUNCTION__, reg_name, data); @@ -252,41 +248,30 @@ if (log) log->Printf ("NativeRegisterContextLinux::%s() reg %s: %p", __FUNCTION__, reg_name, buf); - Error error; - NativeProcessLinux::PtraceWrapper( - PTRACE_POKEUSER, m_thread.GetID(), reinterpret_cast(offset), buf, 0, error); - - return error; + return NativeProcessLinux::PtraceWrapper( + PTRACE_POKEUSER, m_thread.GetID(), reinterpret_cast(offset), buf); } Error NativeRegisterContextLinux::DoReadGPR(void *buf, size_t buf_size) { - Error error; - NativeProcessLinux::PtraceWrapper(PTRACE_GETREGS, m_thread.GetID(), nullptr, buf, buf_size, error); - return error; + return NativeProcessLinux::PtraceWrapper(PTRACE_GETREGS, m_thread.GetID(), nullptr, buf, buf_size); } Error NativeRegisterContextLinux::DoWriteGPR(void *buf, size_t buf_size) { - Error error; - NativeProcessLinux::PtraceWrapper(PTRACE_SETREGS, m_thread.GetID(), nullptr, buf, buf_size, error); - return error; + return NativeProcessLinux::PtraceWrapper(PTRACE_SETREGS, m_thread.GetID(), nullptr, buf, buf_size); } Error NativeRegisterContextLinux::DoReadFPR(void *buf, size_t buf_size) { - Error error; - NativeProcessLinux::PtraceWrapper(PTRACE_GETFPREGS, m_thread.GetID(), nullptr, buf, buf_size, error); - return error; + return NativeProcessLinux::PtraceWrapper(PTRACE_GETFPREGS, m_thread.GetID(), nullptr, buf, buf_size); } Error NativeRegisterContextLinux::DoWriteFPR(void *buf, size_t buf_size) { - Error error; - NativeProcessLinux::PtraceWrapper(PTRACE_SETFPREGS, m_thread.GetID(), nullptr, buf, buf_size, error); - return error; + return NativeProcessLinux::PtraceWrapper(PTRACE_SETFPREGS, m_thread.GetID(), nullptr, buf, buf_size); } Index: source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp =================================================================== --- source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp +++ source/Plugins/Process/Linux/NativeRegisterContextLinux_arm64.cpp @@ -735,11 +735,11 @@ ioVec.iov_base = &dreg_state; ioVec.iov_len = sizeof (dreg_state); - NativeProcessLinux::PtraceWrapper(PTRACE_GETREGSET, tid, ®set, &ioVec, ioVec.iov_len, error); + error = NativeProcessLinux::PtraceWrapper(PTRACE_GETREGSET, tid, ®set, &ioVec, ioVec.iov_len); watch_count = dreg_state.dbg_info & 0xff; regset = NT_ARM_HW_BREAK; - NativeProcessLinux::PtraceWrapper(PTRACE_GETREGSET, tid, ®set, &ioVec, ioVec.iov_len, error); + error = NativeProcessLinux::PtraceWrapper(PTRACE_GETREGSET, tid, ®set, &ioVec, ioVec.iov_len); break_count = dreg_state.dbg_info & 0xff; return error; @@ -777,8 +777,7 @@ dreg_state.dbg_regs[i].ctrl = cntrl_buf[i]; } - NativeProcessLinux::PtraceWrapper(PTRACE_SETREGSET, m_thread.GetID(), &type, &ioVec, ioVec.iov_len, error); - return error; + return NativeProcessLinux::PtraceWrapper(PTRACE_SETREGSET, m_thread.GetID(), &type, &ioVec, ioVec.iov_len); }); } @@ -803,8 +802,8 @@ ioVec.iov_base = ®s; ioVec.iov_len = sizeof regs; - NativeProcessLinux::PtraceWrapper( - PTRACE_GETREGSET, m_thread.GetID(), ®set, &ioVec, sizeof regs, error); + error = NativeProcessLinux::PtraceWrapper( + PTRACE_GETREGSET, m_thread.GetID(), ®set, &ioVec, sizeof regs); if (error.Success()) { ArchSpec arch; @@ -822,8 +821,8 @@ ioVec.iov_base = ®s; ioVec.iov_len = sizeof regs; - NativeProcessLinux::PtraceWrapper( - PTRACE_GETREGSET, m_thread.GetID(), ®set, &ioVec, sizeof regs, error); + error = NativeProcessLinux::PtraceWrapper( + PTRACE_GETREGSET, m_thread.GetID(), ®set, &ioVec, sizeof regs); if (error.Success()) { ArchSpec arch; @@ -857,12 +856,12 @@ ioVec.iov_base = ®s; ioVec.iov_len = sizeof regs; - NativeProcessLinux::PtraceWrapper( PTRACE_GETREGSET, tid, ®set, &ioVec, sizeof regs, error); + error = NativeProcessLinux::PtraceWrapper( PTRACE_GETREGSET, tid, ®set, &ioVec, sizeof regs); if (error.Success()) { ::memcpy((void *)(((unsigned char *)(®s)) + offset), value.GetBytes(), 16); - NativeProcessLinux::PtraceWrapper(PTRACE_SETREGSET, tid, ®set, &ioVec, sizeof regs, error); + error = NativeProcessLinux::PtraceWrapper(PTRACE_SETREGSET, tid, ®set, &ioVec, sizeof regs); } } else @@ -873,11 +872,11 @@ ioVec.iov_base = ®s; ioVec.iov_len = sizeof regs; - NativeProcessLinux::PtraceWrapper(PTRACE_GETREGSET, tid, ®set, &ioVec, sizeof regs, error); + error = NativeProcessLinux::PtraceWrapper(PTRACE_GETREGSET, tid, ®set, &ioVec, sizeof regs); if (error.Success()) { ::memcpy((void *)(((unsigned char *)(®s)) + offset), value.GetBytes(), 8); - NativeProcessLinux::PtraceWrapper(PTRACE_SETREGSET, tid, ®set, &ioVec, sizeof regs, error); + error = NativeProcessLinux::PtraceWrapper(PTRACE_SETREGSET, tid, ®set, &ioVec, sizeof regs); } } return error; @@ -892,8 +891,7 @@ ioVec.iov_base = buf; ioVec.iov_len = buf_size; - NativeProcessLinux::PtraceWrapper(PTRACE_GETREGSET, m_thread.GetID(), ®set, &ioVec, buf_size, error); - return error; + return NativeProcessLinux::PtraceWrapper(PTRACE_GETREGSET, m_thread.GetID(), ®set, &ioVec, buf_size); } Error @@ -905,8 +903,7 @@ ioVec.iov_base = buf; ioVec.iov_len = buf_size; - NativeProcessLinux::PtraceWrapper(PTRACE_SETREGSET, m_thread.GetID(), ®set, &ioVec, buf_size, error); - return error; + return NativeProcessLinux::PtraceWrapper(PTRACE_SETREGSET, m_thread.GetID(), ®set, &ioVec, buf_size); } Error @@ -918,8 +915,7 @@ ioVec.iov_base = buf; ioVec.iov_len = buf_size; - NativeProcessLinux::PtraceWrapper(PTRACE_GETREGSET, m_thread.GetID(), ®set, &ioVec, buf_size, error); - return error; + return NativeProcessLinux::PtraceWrapper(PTRACE_GETREGSET, m_thread.GetID(), ®set, &ioVec, buf_size); } Error @@ -931,8 +927,7 @@ ioVec.iov_base = buf; ioVec.iov_len = buf_size; - NativeProcessLinux::PtraceWrapper(PTRACE_SETREGSET, m_thread.GetID(), ®set, &ioVec, buf_size, error); - return error; + return NativeProcessLinux::PtraceWrapper(PTRACE_SETREGSET, m_thread.GetID(), ®set, &ioVec, buf_size); } #endif // defined (__arm64__) || defined (__aarch64__) Index: source/Plugins/Process/Linux/NativeRegisterContextLinux_mips64.cpp =================================================================== --- source/Plugins/Process/Linux/NativeRegisterContextLinux_mips64.cpp +++ source/Plugins/Process/Linux/NativeRegisterContextLinux_mips64.cpp @@ -1060,9 +1060,8 @@ uint32_t size, RegisterValue &value) { - Error error; elf_gregset_t regs; - NativeProcessLinux::PtraceWrapper(PTRACE_GETREGS, m_thread.GetID(), NULL, ®s, sizeof regs, error); + Error error = NativeProcessLinux::PtraceWrapper(PTRACE_GETREGS, m_thread.GetID(), NULL, ®s, sizeof regs); if (error.Success()) { lldb_private::ArchSpec arch; @@ -1079,13 +1078,12 @@ const char* reg_name, const RegisterValue &value) { - Error error; elf_gregset_t regs; - NativeProcessLinux::PtraceWrapper(PTRACE_GETREGS, m_thread.GetID(), NULL, ®s, sizeof regs, error); + Error error = NativeProcessLinux::PtraceWrapper(PTRACE_GETREGS, m_thread.GetID(), NULL, ®s, sizeof regs); if (error.Success()) { ::memcpy((void *)(((unsigned char *)(®s)) + offset), value.GetBytes(), 8); - NativeProcessLinux::PtraceWrapper(PTRACE_SETREGS, m_thread.GetID(), NULL, ®s, sizeof regs, error); + error = NativeProcessLinux::PtraceWrapper(PTRACE_SETREGS, m_thread.GetID(), NULL, ®s, sizeof regs); } return error; } @@ -1093,19 +1091,13 @@ Error NativeRegisterContextLinux_mips64::DoReadWatchPointRegisterValue(lldb::tid_t tid, void* watch_readback) { - Error error; - NativeProcessLinux::PtraceWrapper( - PTRACE_GET_WATCH_REGS, m_thread.GetID(), watch_readback, NULL, 0, error); - return error; + return NativeProcessLinux::PtraceWrapper( PTRACE_GET_WATCH_REGS, m_thread.GetID(), watch_readback); } Error NativeRegisterContextLinux_mips64::DoWriteWatchPointRegisterValue(lldb::tid_t tid, void* watch_reg_value) { - Error error; - NativeProcessLinux::PtraceWrapper(PTRACE_SET_WATCH_REGS, - m_thread.GetID(), watch_reg_value, NULL, 0, error); - return error; + return NativeProcessLinux::PtraceWrapper(PTRACE_SET_WATCH_REGS, m_thread.GetID(), watch_reg_value); } #endif // defined (__mips__)