summaryrefslogtreecommitdiff
path: root/source/Plugins/Process/NetBSD
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2019-08-20 20:51:52 +0000
committerDimitry Andric <dim@FreeBSD.org>2019-08-20 20:51:52 +0000
commit5f29bb8a675e8f96452b632e7129113f7dec850e (patch)
tree3d3f2a0d3ad10872a4dcaba8ec8d1d20c87ab147 /source/Plugins/Process/NetBSD
parent88c643b6fec27eec436c8d138fee6346e92337d6 (diff)
Notes
Diffstat (limited to 'source/Plugins/Process/NetBSD')
-rw-r--r--source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp53
-rw-r--r--source/Plugins/Process/NetBSD/NativeProcessNetBSD.h15
-rw-r--r--source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD.cpp84
-rw-r--r--source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD.h37
-rw-r--r--source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD_x86_64.cpp233
-rw-r--r--source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD_x86_64.h26
-rw-r--r--source/Plugins/Process/NetBSD/NativeThreadNetBSD.cpp7
-rw-r--r--source/Plugins/Process/NetBSD/NativeThreadNetBSD.h13
8 files changed, 178 insertions, 290 deletions
diff --git a/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp b/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp
index a1b7d7df4553..32d20d2b1215 100644
--- a/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp
+++ b/source/Plugins/Process/NetBSD/NativeProcessNetBSD.cpp
@@ -1,9 +1,8 @@
//===-- NativeProcessNetBSD.cpp ------------------------------- -*- C++ -*-===//
//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
@@ -55,9 +54,7 @@ static Status EnsureFDFlags(int fd, int flags) {
return error;
}
-// -----------------------------------------------------------------------------
// Public Static Methods
-// -----------------------------------------------------------------------------
llvm::Expected<std::unique_ptr<NativeProcessProtocol>>
NativeProcessNetBSD::Factory::Launch(ProcessLaunchInfo &launch_info,
@@ -137,9 +134,7 @@ NativeProcessNetBSD::Factory::Attach(
return std::move(process_up);
}
-// -----------------------------------------------------------------------------
// Public Instance Methods
-// -----------------------------------------------------------------------------
NativeProcessNetBSD::NativeProcessNetBSD(::pid_t pid, int terminal_fd,
NativeDelegate &delegate,
@@ -243,12 +238,25 @@ void NativeProcessNetBSD::MonitorSIGTRAP(lldb::pid_t pid) {
SetState(StateType::eStateStopped, true);
} break;
case TRAP_DBREG: {
+ // Find the thread.
+ NativeThreadNetBSD* thread = nullptr;
+ for (const auto &t : m_threads) {
+ if (t->GetID() == info.psi_lwpid) {
+ thread = static_cast<NativeThreadNetBSD *>(t.get());
+ break;
+ }
+ }
+ if (!thread) {
+ LLDB_LOG(log,
+ "thread not found in m_threads, pid = {0}, LWP = {1}",
+ GetID(), info.psi_lwpid);
+ break;
+ }
+
// If a watchpoint was hit, report it
- uint32_t wp_index;
- Status error = static_cast<NativeThreadNetBSD &>(*m_threads[info.psi_lwpid])
- .GetRegisterContext()
- .GetWatchpointHitIndex(
- wp_index, (uintptr_t)info.psi_siginfo.si_addr);
+ uint32_t wp_index = LLDB_INVALID_INDEX32;
+ Status error = thread->GetRegisterContext().GetWatchpointHitIndex(
+ wp_index, (uintptr_t)info.psi_siginfo.si_addr);
if (error.Fail())
LLDB_LOG(log,
"received error while checking for watchpoint hits, pid = "
@@ -263,11 +271,9 @@ void NativeProcessNetBSD::MonitorSIGTRAP(lldb::pid_t pid) {
}
// If a breakpoint was hit, report it
- uint32_t bp_index;
- error = static_cast<NativeThreadNetBSD &>(*m_threads[info.psi_lwpid])
- .GetRegisterContext()
- .GetHardwareBreakHitIndex(bp_index,
- (uintptr_t)info.psi_siginfo.si_addr);
+ uint32_t bp_index = LLDB_INVALID_INDEX32;
+ error = thread->GetRegisterContext().GetHardwareBreakHitIndex(
+ bp_index, (uintptr_t)info.psi_siginfo.si_addr);
if (error.Fail())
LLDB_LOG(log,
"received error while checking for hardware "
@@ -666,7 +672,8 @@ Status NativeProcessNetBSD::Attach() {
int wstatus;
// Need to use WALLSIG otherwise we receive an error with errno=ECHLD At this
// point we should have a thread stopped if waitpid succeeds.
- if ((wstatus = waitpid(m_pid, NULL, WALLSIG)) < 0)
+ if ((wstatus = llvm::sys::RetryAfterSignal(-1, waitpid,
+ m_pid, nullptr, WALLSIG)) < 0)
return Status(errno, eErrorTypePOSIX);
/* Initialize threads */
@@ -699,10 +706,10 @@ Status NativeProcessNetBSD::ReadMemory(lldb::addr_t addr, void *buf,
io.piod_addr = dst + bytes_read;
Status error = NativeProcessNetBSD::PtraceWrapper(PT_IO, GetID(), &io);
- if (error.Fail())
+ if (error.Fail() || io.piod_len == 0)
return error;
- bytes_read = io.piod_len;
+ bytes_read += io.piod_len;
io.piod_len = size - bytes_read;
} while (bytes_read < size);
@@ -727,10 +734,10 @@ Status NativeProcessNetBSD::WriteMemory(lldb::addr_t addr, const void *buf,
io.piod_offs = (void *)(addr + bytes_written);
Status error = NativeProcessNetBSD::PtraceWrapper(PT_IO, GetID(), &io);
- if (error.Fail())
+ if (error.Fail() || io.piod_len == 0)
return error;
- bytes_written = io.piod_len;
+ bytes_written += io.piod_len;
io.piod_len = size - bytes_written;
} while (bytes_written < size);
diff --git a/source/Plugins/Process/NetBSD/NativeProcessNetBSD.h b/source/Plugins/Process/NetBSD/NativeProcessNetBSD.h
index a3f1c4c6a06a..e85ca3b7a925 100644
--- a/source/Plugins/Process/NetBSD/NativeProcessNetBSD.h
+++ b/source/Plugins/Process/NetBSD/NativeProcessNetBSD.h
@@ -1,9 +1,8 @@
//===-- NativeProcessNetBSD.h --------------------------------- -*- C++ -*-===//
//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
@@ -19,7 +18,7 @@
namespace lldb_private {
namespace process_netbsd {
-/// @class NativeProcessNetBSD
+/// \class NativeProcessNetBSD
/// Manages communication with the inferior (debugee) process.
///
/// Upon construction, this class prepares and launches an inferior process
@@ -39,9 +38,7 @@ public:
MainLoop &mainloop) const override;
};
- // ---------------------------------------------------------------------
// NativeProcessProtocol Interface
- // ---------------------------------------------------------------------
Status Resume(const ResumeActionList &resume_actions) override;
Status Halt() override;
@@ -84,9 +81,7 @@ public:
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
GetAuxvData() const override;
- // ---------------------------------------------------------------------
// Interface used by NativeRegisterContext-derived classes.
- // ---------------------------------------------------------------------
static Status PtraceWrapper(int req, lldb::pid_t pid, void *addr = nullptr,
int data = 0, int *result = nullptr);
@@ -96,9 +91,7 @@ private:
LazyBool m_supports_mem_region = eLazyBoolCalculate;
std::vector<std::pair<MemoryRegionInfo, FileSpec>> m_mem_region_cache;
- // ---------------------------------------------------------------------
// Private Instance Methods
- // ---------------------------------------------------------------------
NativeProcessNetBSD(::pid_t pid, int terminal_fd, NativeDelegate &delegate,
const ArchSpec &arch, MainLoop &mainloop);
diff --git a/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD.cpp b/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD.cpp
index d4fef6342439..3a9caaad74c8 100644
--- a/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD.cpp
+++ b/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD.cpp
@@ -1,9 +1,8 @@
//===-- NativeRegisterContextNetBSD.cpp -------------------------*- C++ -*-===//
//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
@@ -25,81 +24,8 @@ NativeRegisterContextNetBSD::NativeRegisterContextNetBSD(
: NativeRegisterContextRegisterInfo(native_thread,
reg_info_interface_p) {}
-Status NativeRegisterContextNetBSD::ReadGPR() {
- void *buf = GetGPRBuffer();
- if (!buf)
- return Status("GPR buffer is NULL");
-
- return DoReadGPR(buf);
-}
-
-Status NativeRegisterContextNetBSD::WriteGPR() {
- void *buf = GetGPRBuffer();
- if (!buf)
- return Status("GPR buffer is NULL");
-
- return DoWriteGPR(buf);
-}
-
-Status NativeRegisterContextNetBSD::ReadFPR() {
- void *buf = GetFPRBuffer();
- if (!buf)
- return Status("FPR buffer is NULL");
-
- return DoReadFPR(buf);
-}
-
-Status NativeRegisterContextNetBSD::WriteFPR() {
- void *buf = GetFPRBuffer();
- if (!buf)
- return Status("FPR buffer is NULL");
-
- return DoWriteFPR(buf);
-}
-
-Status NativeRegisterContextNetBSD::ReadDBR() {
- void *buf = GetDBRBuffer();
- if (!buf)
- return Status("DBR buffer is NULL");
-
- return DoReadDBR(buf);
-}
-
-Status NativeRegisterContextNetBSD::WriteDBR() {
- void *buf = GetDBRBuffer();
- if (!buf)
- return Status("DBR buffer is NULL");
-
- return DoWriteDBR(buf);
-}
-
-Status NativeRegisterContextNetBSD::DoReadGPR(void *buf) {
- return NativeProcessNetBSD::PtraceWrapper(PT_GETREGS, GetProcessPid(), buf,
- m_thread.GetID());
-}
-
-Status NativeRegisterContextNetBSD::DoWriteGPR(void *buf) {
- return NativeProcessNetBSD::PtraceWrapper(PT_SETREGS, GetProcessPid(), buf,
- m_thread.GetID());
-}
-
-Status NativeRegisterContextNetBSD::DoReadFPR(void *buf) {
- return NativeProcessNetBSD::PtraceWrapper(PT_GETFPREGS, GetProcessPid(), buf,
- m_thread.GetID());
-}
-
-Status NativeRegisterContextNetBSD::DoWriteFPR(void *buf) {
- return NativeProcessNetBSD::PtraceWrapper(PT_SETFPREGS, GetProcessPid(), buf,
- m_thread.GetID());
-}
-
-Status NativeRegisterContextNetBSD::DoReadDBR(void *buf) {
- return NativeProcessNetBSD::PtraceWrapper(PT_GETDBREGS, GetProcessPid(), buf,
- m_thread.GetID());
-}
-
-Status NativeRegisterContextNetBSD::DoWriteDBR(void *buf) {
- return NativeProcessNetBSD::PtraceWrapper(PT_SETDBREGS, GetProcessPid(), buf,
+Status NativeRegisterContextNetBSD::DoRegisterSet(int ptrace_req, void *buf) {
+ return NativeProcessNetBSD::PtraceWrapper(ptrace_req, GetProcessPid(), buf,
m_thread.GetID());
}
diff --git a/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD.h b/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD.h
index b81430e7f5ac..f5dd0c33b677 100644
--- a/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD.h
+++ b/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD.h
@@ -1,9 +1,8 @@
//===-- NativeRegisterContextNetBSD.h ---------------------------*- C++ -*-===//
//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
@@ -33,35 +32,7 @@ public:
NativeThreadProtocol &native_thread);
protected:
- virtual Status ReadGPR();
- virtual Status WriteGPR();
-
- virtual Status ReadFPR();
- virtual Status WriteFPR();
-
- virtual Status ReadDBR();
- virtual Status WriteDBR();
-
- virtual void *GetGPRBuffer() { return nullptr; }
- virtual size_t GetGPRSize() {
- return GetRegisterInfoInterface().GetGPRSize();
- }
-
- virtual void *GetFPRBuffer() { return nullptr; }
- virtual size_t GetFPRSize() { return 0; }
-
- virtual void *GetDBRBuffer() { return nullptr; }
- virtual size_t GetDBRSize() { return 0; }
-
- virtual Status DoReadGPR(void *buf);
- virtual Status DoWriteGPR(void *buf);
-
- virtual Status DoReadFPR(void *buf);
- virtual Status DoWriteFPR(void *buf);
-
- virtual Status DoReadDBR(void *buf);
- virtual Status DoWriteDBR(void *buf);
-
+ Status DoRegisterSet(int req, void *buf);
virtual NativeProcessNetBSD &GetProcess();
virtual ::pid_t GetProcessPid();
};
diff --git a/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD_x86_64.cpp b/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD_x86_64.cpp
index 78da3527122f..a7cd637bf826 100644
--- a/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD_x86_64.cpp
+++ b/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD_x86_64.cpp
@@ -1,9 +1,8 @@
//===-- NativeRegisterContextNetBSD_x86_64.cpp ---------------*- C++ -*-===//
//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
@@ -21,8 +20,12 @@
// clang-format off
#include <sys/types.h>
+#include <sys/ptrace.h>
#include <sys/sysctl.h>
+#include <sys/uio.h>
#include <x86/cpu.h>
+#include <x86/cpu_extended_state.h>
+#include <x86/specialreg.h>
#include <elf.h>
#include <err.h>
#include <stdint.h>
@@ -32,9 +35,7 @@
using namespace lldb_private;
using namespace lldb_private::process_netbsd;
-// ----------------------------------------------------------------------------
// Private namespace.
-// ----------------------------------------------------------------------------
namespace {
// x86 64-bit general purpose registers.
@@ -93,58 +94,6 @@ static const RegisterSet g_reg_sets_x86_64[k_num_register_sets] = {
};
#define REG_CONTEXT_SIZE (GetRegisterInfoInterface().GetGPRSize())
-
-const int fpu_present = []() -> int {
- int mib[2];
- int error;
- size_t len;
- int val;
-
- len = sizeof(val);
- mib[0] = CTL_MACHDEP;
- mib[1] = CPU_FPU_PRESENT;
-
- error = sysctl(mib, __arraycount(mib), &val, &len, NULL, 0);
- if (error)
- errx(EXIT_FAILURE, "sysctl");
-
- return val;
-}();
-
-const int osfxsr = []() -> int {
- int mib[2];
- int error;
- size_t len;
- int val;
-
- len = sizeof(val);
- mib[0] = CTL_MACHDEP;
- mib[1] = CPU_OSFXSR;
-
- error = sysctl(mib, __arraycount(mib), &val, &len, NULL, 0);
- if (error)
- errx(EXIT_FAILURE, "sysctl");
-
- return val;
-}();
-
-const int fpu_save = []() -> int {
- int mib[2];
- int error;
- size_t len;
- int val;
-
- len = sizeof(val);
- mib[0] = CTL_MACHDEP;
- mib[1] = CPU_FPU_SAVE;
-
- error = sysctl(mib, __arraycount(mib), &val, &len, NULL, 0);
- if (error)
- errx(EXIT_FAILURE, "sysctl");
-
- return val;
-}();
-
} // namespace
NativeRegisterContextNetBSD *
@@ -153,9 +102,7 @@ NativeRegisterContextNetBSD::CreateHostNativeRegisterContextNetBSD(
return new NativeRegisterContextNetBSD_x86_64(target_arch, native_thread);
}
-// ----------------------------------------------------------------------------
// NativeRegisterContextNetBSD_x86_64 members.
-// ----------------------------------------------------------------------------
static RegisterInfoInterface *
CreateRegisterInfoInterface(const ArchSpec &target_arch) {
@@ -202,9 +149,9 @@ int NativeRegisterContextNetBSD_x86_64::GetSetForNativeRegNum(
if (reg_num <= k_last_gpr_x86_64)
return GPRegSet;
else if (reg_num <= k_last_fpr_x86_64)
- return (fpu_present == 1 && osfxsr == 1 && fpu_save >= 1) ? FPRegSet : -1;
+ return FPRegSet;
else if (reg_num <= k_last_avx_x86_64)
- return -1; // AVX
+ return XStateRegSet; // AVX
else if (reg_num <= k_last_mpxr_x86_64)
return -1; // MPXR
else if (reg_num <= k_last_mpxc_x86_64)
@@ -215,37 +162,46 @@ int NativeRegisterContextNetBSD_x86_64::GetSetForNativeRegNum(
return -1;
}
-int NativeRegisterContextNetBSD_x86_64::ReadRegisterSet(uint32_t set) {
+Status NativeRegisterContextNetBSD_x86_64::ReadRegisterSet(uint32_t set) {
switch (set) {
case GPRegSet:
- ReadGPR();
- return 0;
+ return DoRegisterSet(PT_GETREGS, &m_gpr_x86_64);
case FPRegSet:
- ReadFPR();
- return 0;
+ return DoRegisterSet(PT_GETFPREGS, &m_fpr_x86_64);
case DBRegSet:
- ReadDBR();
- return 0;
- default:
- break;
+ return DoRegisterSet(PT_GETDBREGS, &m_dbr_x86_64);
+ case XStateRegSet:
+#ifdef HAVE_XSTATE
+ {
+ struct iovec iov = {&m_xstate_x86_64, sizeof(m_xstate_x86_64)};
+ return DoRegisterSet(PT_GETXSTATE, &iov);
+ }
+#else
+ return Status("XState is not supported by the kernel");
+#endif
}
- return -1;
+ llvm_unreachable("NativeRegisterContextNetBSD_x86_64::ReadRegisterSet");
}
-int NativeRegisterContextNetBSD_x86_64::WriteRegisterSet(uint32_t set) {
+
+Status NativeRegisterContextNetBSD_x86_64::WriteRegisterSet(uint32_t set) {
switch (set) {
case GPRegSet:
- WriteGPR();
- return 0;
+ return DoRegisterSet(PT_SETREGS, &m_gpr_x86_64);
case FPRegSet:
- WriteFPR();
- return 0;
+ return DoRegisterSet(PT_SETFPREGS, &m_fpr_x86_64);
case DBRegSet:
- WriteDBR();
- return 0;
- default:
- break;
+ return DoRegisterSet(PT_SETDBREGS, &m_dbr_x86_64);
+ case XStateRegSet:
+#ifdef HAVE_XSTATE
+ {
+ struct iovec iov = {&m_xstate_x86_64, sizeof(m_xstate_x86_64)};
+ return DoRegisterSet(PT_SETXSTATE, &iov);
+ }
+#else
+ return Status("XState is not supported by the kernel");
+#endif
}
- return -1;
+ llvm_unreachable("NativeRegisterContextNetBSD_x86_64::WriteRegisterSet");
}
Status
@@ -277,13 +233,9 @@ NativeRegisterContextNetBSD_x86_64::ReadRegister(const RegisterInfo *reg_info,
return error;
}
- if (ReadRegisterSet(set) != 0) {
- // This is likely an internal register for lldb use only and should not be
- // directly queried.
- error.SetErrorStringWithFormat(
- "reading register set for register \"%s\" failed", reg_info->name);
+ error = ReadRegisterSet(set);
+ if (error.Fail())
return error;
- }
switch (reg) {
case lldb_rax_x86_64:
@@ -407,7 +359,7 @@ NativeRegisterContextNetBSD_x86_64::ReadRegister(const RegisterInfo *reg_info,
case lldb_mm5_x86_64:
case lldb_mm6_x86_64:
case lldb_mm7_x86_64:
- reg_value.SetBytes(&m_fpr_x86_64.fxstate.fx_xmm[reg - lldb_mm0_x86_64],
+ reg_value.SetBytes(&m_fpr_x86_64.fxstate.fx_87_ac[reg - lldb_mm0_x86_64],
reg_info->byte_size, endian::InlHostByteOrder());
break;
case lldb_xmm0_x86_64:
@@ -429,6 +381,39 @@ NativeRegisterContextNetBSD_x86_64::ReadRegister(const RegisterInfo *reg_info,
reg_value.SetBytes(&m_fpr_x86_64.fxstate.fx_xmm[reg - lldb_xmm0_x86_64],
reg_info->byte_size, endian::InlHostByteOrder());
break;
+ case lldb_ymm0_x86_64:
+ case lldb_ymm1_x86_64:
+ case lldb_ymm2_x86_64:
+ case lldb_ymm3_x86_64:
+ case lldb_ymm4_x86_64:
+ case lldb_ymm5_x86_64:
+ case lldb_ymm6_x86_64:
+ case lldb_ymm7_x86_64:
+ case lldb_ymm8_x86_64:
+ case lldb_ymm9_x86_64:
+ case lldb_ymm10_x86_64:
+ case lldb_ymm11_x86_64:
+ case lldb_ymm12_x86_64:
+ case lldb_ymm13_x86_64:
+ case lldb_ymm14_x86_64:
+ case lldb_ymm15_x86_64:
+#ifdef HAVE_XSTATE
+ if (!(m_xstate_x86_64.xs_rfbm & XCR0_SSE) ||
+ !(m_xstate_x86_64.xs_rfbm & XCR0_YMM_Hi128)) {
+ error.SetErrorStringWithFormat("register \"%s\" not supported by CPU/kernel",
+ reg_info->name);
+ } else {
+ uint32_t reg_index = reg - lldb_ymm0_x86_64;
+ YMMReg ymm = XStateToYMM(
+ m_xstate_x86_64.xs_fxsave.fx_xmm[reg_index].xmm_bytes,
+ m_xstate_x86_64.xs_ymm_hi128.xs_ymm[reg_index].ymm_bytes);
+ reg_value.SetBytes(ymm.bytes, reg_info->byte_size,
+ endian::InlHostByteOrder());
+ }
+#else
+ error.SetErrorString("XState queries not supported by the kernel");
+#endif
+ break;
case lldb_dr0_x86_64:
case lldb_dr1_x86_64:
case lldb_dr2_x86_64:
@@ -473,13 +458,9 @@ Status NativeRegisterContextNetBSD_x86_64::WriteRegister(
return error;
}
- if (ReadRegisterSet(set) != 0) {
- // This is likely an internal register for lldb use only and should not be
- // directly queried.
- error.SetErrorStringWithFormat(
- "reading register set for register \"%s\" failed", reg_info->name);
+ error = ReadRegisterSet(set);
+ if (error.Fail())
return error;
- }
switch (reg) {
case lldb_rax_x86_64:
@@ -603,7 +584,7 @@ Status NativeRegisterContextNetBSD_x86_64::WriteRegister(
case lldb_mm5_x86_64:
case lldb_mm6_x86_64:
case lldb_mm7_x86_64:
- ::memcpy(&m_fpr_x86_64.fxstate.fx_xmm[reg - lldb_mm0_x86_64],
+ ::memcpy(&m_fpr_x86_64.fxstate.fx_87_ac[reg - lldb_mm0_x86_64],
reg_value.GetBytes(), reg_value.GetByteSize());
break;
case lldb_xmm0_x86_64:
@@ -625,6 +606,39 @@ Status NativeRegisterContextNetBSD_x86_64::WriteRegister(
::memcpy(&m_fpr_x86_64.fxstate.fx_xmm[reg - lldb_xmm0_x86_64],
reg_value.GetBytes(), reg_value.GetByteSize());
break;
+ case lldb_ymm0_x86_64:
+ case lldb_ymm1_x86_64:
+ case lldb_ymm2_x86_64:
+ case lldb_ymm3_x86_64:
+ case lldb_ymm4_x86_64:
+ case lldb_ymm5_x86_64:
+ case lldb_ymm6_x86_64:
+ case lldb_ymm7_x86_64:
+ case lldb_ymm8_x86_64:
+ case lldb_ymm9_x86_64:
+ case lldb_ymm10_x86_64:
+ case lldb_ymm11_x86_64:
+ case lldb_ymm12_x86_64:
+ case lldb_ymm13_x86_64:
+ case lldb_ymm14_x86_64:
+ case lldb_ymm15_x86_64:
+#ifdef HAVE_XSTATE
+ if (!(m_xstate_x86_64.xs_rfbm & XCR0_SSE) ||
+ !(m_xstate_x86_64.xs_rfbm & XCR0_YMM_Hi128)) {
+ error.SetErrorStringWithFormat("register \"%s\" not supported by CPU/kernel",
+ reg_info->name);
+ } else {
+ uint32_t reg_index = reg - lldb_ymm0_x86_64;
+ YMMReg ymm;
+ ::memcpy(ymm.bytes, reg_value.GetBytes(), reg_value.GetByteSize());
+ YMMToXState(ymm,
+ m_xstate_x86_64.xs_fxsave.fx_xmm[reg_index].xmm_bytes,
+ m_xstate_x86_64.xs_ymm_hi128.xs_ymm[reg_index].ymm_bytes);
+ }
+#else
+ error.SetErrorString("XState not supported by the kernel");
+#endif
+ break;
case lldb_dr0_x86_64:
case lldb_dr1_x86_64:
case lldb_dr2_x86_64:
@@ -637,10 +651,7 @@ Status NativeRegisterContextNetBSD_x86_64::WriteRegister(
break;
}
- if (WriteRegisterSet(set) != 0)
- error.SetErrorStringWithFormat("failed to write register set");
-
- return error;
+ return WriteRegisterSet(set);
}
Status NativeRegisterContextNetBSD_x86_64::ReadAllRegisterValues(
@@ -648,25 +659,11 @@ Status NativeRegisterContextNetBSD_x86_64::ReadAllRegisterValues(
Status error;
data_sp.reset(new DataBufferHeap(REG_CONTEXT_SIZE, 0));
- if (!data_sp) {
- error.SetErrorStringWithFormat(
- "failed to allocate DataBufferHeap instance of size %" PRIu64,
- REG_CONTEXT_SIZE);
- return error;
- }
-
- error = ReadGPR();
+ error = ReadRegisterSet(GPRegSet);
if (error.Fail())
return error;
uint8_t *dst = data_sp->GetBytes();
- if (dst == nullptr) {
- error.SetErrorStringWithFormat("DataBufferHeap instance of size %" PRIu64
- " returned a null pointer",
- REG_CONTEXT_SIZE);
- return error;
- }
-
::memcpy(dst, &m_gpr_x86_64, GetRegisterInfoInterface().GetGPRSize());
dst += GetRegisterInfoInterface().GetGPRSize();
@@ -707,7 +704,7 @@ Status NativeRegisterContextNetBSD_x86_64::WriteAllRegisterValues(
}
::memcpy(&m_gpr_x86_64, src, GetRegisterInfoInterface().GetGPRSize());
- error = WriteGPR();
+ error = WriteRegisterSet(GPRegSet);
if (error.Fail())
return error;
src += GetRegisterInfoInterface().GetGPRSize();
@@ -767,7 +764,7 @@ Status NativeRegisterContextNetBSD_x86_64::IsWatchpointVacant(uint32_t wp_index,
uint64_t control_bits = reg_value.GetAsUInt64();
- is_vacant = !(control_bits & (1 << (2 * wp_index)));
+ is_vacant = !(control_bits & (1 << (2 * wp_index + 1)));
return error;
}
@@ -806,7 +803,7 @@ Status NativeRegisterContextNetBSD_x86_64::SetHardwareWatchpointWithIndex(
return error;
// for watchpoints 0, 1, 2, or 3, respectively, set bits 1, 3, 5, or 7
- uint64_t enable_bit = 1 << (2 * wp_index);
+ uint64_t enable_bit = 1 << (2 * wp_index + 1);
// set bits 16-17, 20-21, 24-25, or 28-29
// with 0b01 for write, and 0b11 for read/write
diff --git a/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD_x86_64.h b/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD_x86_64.h
index c55ddfec6615..0fed16542a95 100644
--- a/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD_x86_64.h
+++ b/source/Plugins/Process/NetBSD/NativeRegisterContextNetBSD_x86_64.h
@@ -1,9 +1,8 @@
//===-- NativeRegisterContextNetBSD_x86_64.h --------------------*- C++ -*-===//
//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
@@ -15,6 +14,7 @@
// clang-format off
#include <sys/param.h>
#include <sys/types.h>
+#include <sys/ptrace.h>
#include <machine/reg.h>
// clang-format on
@@ -22,6 +22,10 @@
#include "Plugins/Process/Utility/RegisterContext_x86.h"
#include "Plugins/Process/Utility/lldb-x86-register-enums.h"
+#if defined(PT_GETXSTATE) && defined(PT_SETXSTATE)
+#define HAVE_XSTATE
+#endif
+
namespace lldb_private {
namespace process_netbsd {
@@ -67,24 +71,22 @@ public:
uint32_t NumSupportedHardwareWatchpoints() override;
-protected:
- void *GetGPRBuffer() override { return &m_gpr_x86_64; }
- void *GetFPRBuffer() override { return &m_fpr_x86_64; }
- void *GetDBRBuffer() override { return &m_dbr_x86_64; }
-
private:
// Private member types.
- enum { GPRegSet, FPRegSet, DBRegSet };
+ enum { GPRegSet, FPRegSet, DBRegSet, XStateRegSet };
// Private member variables.
struct reg m_gpr_x86_64;
struct fpreg m_fpr_x86_64;
struct dbreg m_dbr_x86_64;
+#ifdef HAVE_XSTATE
+ struct xstate m_xstate_x86_64;
+#endif
int GetSetForNativeRegNum(int reg_num) const;
- int ReadRegisterSet(uint32_t set);
- int WriteRegisterSet(uint32_t set);
+ Status ReadRegisterSet(uint32_t set);
+ Status WriteRegisterSet(uint32_t set);
};
} // namespace process_netbsd
diff --git a/source/Plugins/Process/NetBSD/NativeThreadNetBSD.cpp b/source/Plugins/Process/NetBSD/NativeThreadNetBSD.cpp
index 6f5d1120e40d..e25975c93446 100644
--- a/source/Plugins/Process/NetBSD/NativeThreadNetBSD.cpp
+++ b/source/Plugins/Process/NetBSD/NativeThreadNetBSD.cpp
@@ -1,9 +1,8 @@
//===-- NativeThreadNetBSD.cpp -------------------------------- -*- C++ -*-===//
//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
diff --git a/source/Plugins/Process/NetBSD/NativeThreadNetBSD.h b/source/Plugins/Process/NetBSD/NativeThreadNetBSD.h
index 72426244c112..015d8995db34 100644
--- a/source/Plugins/Process/NetBSD/NativeThreadNetBSD.h
+++ b/source/Plugins/Process/NetBSD/NativeThreadNetBSD.h
@@ -1,9 +1,8 @@
//===-- NativeThreadNetBSD.h ---------------------------------- -*- C++ -*-===//
//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
@@ -27,9 +26,7 @@ class NativeThreadNetBSD : public NativeThreadProtocol {
public:
NativeThreadNetBSD(NativeProcessNetBSD &process, lldb::tid_t tid);
- // ---------------------------------------------------------------------
// NativeThreadProtocol Interface
- // ---------------------------------------------------------------------
std::string GetName() override;
lldb::StateType GetState() override;
@@ -49,9 +46,7 @@ public:
Status RemoveHardwareBreakpoint(lldb::addr_t addr) override;
private:
- // ---------------------------------------------------------------------
// Interface for friend classes
- // ---------------------------------------------------------------------
void SetStoppedBySignal(uint32_t signo, const siginfo_t *info = nullptr);
void SetStoppedByBreakpoint();
@@ -62,9 +57,7 @@ private:
void SetRunning();
void SetStepping();
- // ---------------------------------------------------------------------
// Member Variables
- // ---------------------------------------------------------------------
lldb::StateType m_state;
ThreadStopInfo m_stop_info;
std::unique_ptr<NativeRegisterContext> m_reg_context_up;