1 //===-- NativeRegisterContextNetBSD.cpp -------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "NativeRegisterContextNetBSD.h" 11 12 #include "lldb/Host/common/NativeProcessProtocol.h" 13 14 using namespace lldb_private; 15 using namespace lldb_private::process_netbsd; 16 17 // clang-format off 18 #include <sys/types.h> 19 #include <sys/ptrace.h> 20 // clang-format on 21 22 NativeRegisterContextNetBSD::NativeRegisterContextNetBSD( 23 NativeThreadProtocol &native_thread, uint32_t concrete_frame_idx, 24 RegisterInfoInterface *reg_info_interface_p) 25 : NativeRegisterContextRegisterInfo(native_thread, concrete_frame_idx, 26 reg_info_interface_p) {} 27 28 Error NativeRegisterContextNetBSD::ReadGPR() { 29 void *buf = GetGPRBuffer(); 30 if (!buf) 31 return Error("GPR buffer is NULL"); 32 33 return DoReadGPR(buf); 34 } 35 36 Error NativeRegisterContextNetBSD::WriteGPR() { 37 void *buf = GetGPRBuffer(); 38 if (!buf) 39 return Error("GPR buffer is NULL"); 40 41 return DoWriteGPR(buf); 42 } 43 44 Error NativeRegisterContextNetBSD::ReadFPR() { 45 void *buf = GetFPRBuffer(); 46 if (!buf) 47 return Error("FPR buffer is NULL"); 48 49 return DoReadFPR(buf); 50 } 51 52 Error NativeRegisterContextNetBSD::WriteFPR() { 53 void *buf = GetFPRBuffer(); 54 if (!buf) 55 return Error("FPR buffer is NULL"); 56 57 return DoWriteFPR(buf); 58 } 59 60 Error NativeRegisterContextNetBSD::DoReadGPR(void *buf) { 61 return NativeProcessNetBSD::PtraceWrapper(PT_GETREGS, GetProcessPid(), buf, 62 m_thread.GetID()); 63 } 64 65 Error NativeRegisterContextNetBSD::DoWriteGPR(void *buf) { 66 return NativeProcessNetBSD::PtraceWrapper(PT_SETREGS, GetProcessPid(), buf, 67 m_thread.GetID()); 68 } 69 70 Error NativeRegisterContextNetBSD::DoReadFPR(void *buf) { 71 return NativeProcessNetBSD::PtraceWrapper(PT_GETFPREGS, GetProcessPid(), buf, 72 m_thread.GetID()); 73 } 74 75 Error NativeRegisterContextNetBSD::DoWriteFPR(void *buf) { 76 return NativeProcessNetBSD::PtraceWrapper(PT_SETFPREGS, GetProcessPid(), buf, 77 m_thread.GetID()); 78 } 79 80 NativeProcessNetBSD &NativeRegisterContextNetBSD::GetProcess() { 81 auto process_sp = 82 std::static_pointer_cast<NativeProcessNetBSD>(m_thread.GetProcess()); 83 assert(process_sp); 84 return *process_sp; 85 } 86 87 ::pid_t NativeRegisterContextNetBSD::GetProcessPid() { 88 NativeProcessNetBSD &process = GetProcess(); 89 lldb::pid_t pid = process.GetID(); 90 91 return pid; 92 } 93