1 //===-- NativeRegisterContextNetBSD.cpp -------------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "NativeRegisterContextNetBSD.h" 10 11 #include "lldb/Host/common/NativeProcessProtocol.h" 12 13 using namespace lldb_private; 14 using namespace lldb_private::process_netbsd; 15 16 // clang-format off 17 #include <sys/types.h> 18 #include <sys/ptrace.h> 19 // clang-format on 20 21 NativeRegisterContextNetBSD::NativeRegisterContextNetBSD( 22 NativeThreadProtocol &native_thread, 23 RegisterInfoInterface *reg_info_interface_p) 24 : NativeRegisterContextRegisterInfo(native_thread, 25 reg_info_interface_p) {} 26 27 Status NativeRegisterContextNetBSD::ReadGPR() { 28 void *buf = GetGPRBuffer(); 29 if (!buf) 30 return Status("GPR buffer is NULL"); 31 32 return DoReadGPR(buf); 33 } 34 35 Status NativeRegisterContextNetBSD::WriteGPR() { 36 void *buf = GetGPRBuffer(); 37 if (!buf) 38 return Status("GPR buffer is NULL"); 39 40 return DoWriteGPR(buf); 41 } 42 43 Status NativeRegisterContextNetBSD::ReadFPR() { 44 void *buf = GetFPRBuffer(); 45 if (!buf) 46 return Status("FPR buffer is NULL"); 47 48 return DoReadFPR(buf); 49 } 50 51 Status NativeRegisterContextNetBSD::WriteFPR() { 52 void *buf = GetFPRBuffer(); 53 if (!buf) 54 return Status("FPR buffer is NULL"); 55 56 return DoWriteFPR(buf); 57 } 58 59 Status NativeRegisterContextNetBSD::ReadDBR() { 60 void *buf = GetDBRBuffer(); 61 if (!buf) 62 return Status("DBR buffer is NULL"); 63 64 return DoReadDBR(buf); 65 } 66 67 Status NativeRegisterContextNetBSD::WriteDBR() { 68 void *buf = GetDBRBuffer(); 69 if (!buf) 70 return Status("DBR buffer is NULL"); 71 72 return DoWriteDBR(buf); 73 } 74 75 Status NativeRegisterContextNetBSD::DoReadGPR(void *buf) { 76 return NativeProcessNetBSD::PtraceWrapper(PT_GETREGS, GetProcessPid(), buf, 77 m_thread.GetID()); 78 } 79 80 Status NativeRegisterContextNetBSD::DoWriteGPR(void *buf) { 81 return NativeProcessNetBSD::PtraceWrapper(PT_SETREGS, GetProcessPid(), buf, 82 m_thread.GetID()); 83 } 84 85 Status NativeRegisterContextNetBSD::DoReadFPR(void *buf) { 86 return NativeProcessNetBSD::PtraceWrapper(PT_GETFPREGS, GetProcessPid(), buf, 87 m_thread.GetID()); 88 } 89 90 Status NativeRegisterContextNetBSD::DoWriteFPR(void *buf) { 91 return NativeProcessNetBSD::PtraceWrapper(PT_SETFPREGS, GetProcessPid(), buf, 92 m_thread.GetID()); 93 } 94 95 Status NativeRegisterContextNetBSD::DoReadDBR(void *buf) { 96 return NativeProcessNetBSD::PtraceWrapper(PT_GETDBREGS, GetProcessPid(), buf, 97 m_thread.GetID()); 98 } 99 100 Status NativeRegisterContextNetBSD::DoWriteDBR(void *buf) { 101 return NativeProcessNetBSD::PtraceWrapper(PT_SETDBREGS, GetProcessPid(), buf, 102 m_thread.GetID()); 103 } 104 105 NativeProcessNetBSD &NativeRegisterContextNetBSD::GetProcess() { 106 return static_cast<NativeProcessNetBSD &>(m_thread.GetProcess()); 107 } 108 109 ::pid_t NativeRegisterContextNetBSD::GetProcessPid() { 110 return GetProcess().GetID(); 111 } 112