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::ReadDBR() { 61 void *buf = GetDBRBuffer(); 62 if (!buf) 63 return Error("DBR buffer is NULL"); 64 65 return DoReadDBR(buf); 66 } 67 68 Error NativeRegisterContextNetBSD::WriteDBR() { 69 void *buf = GetDBRBuffer(); 70 if (!buf) 71 return Error("DBR buffer is NULL"); 72 73 return DoWriteDBR(buf); 74 } 75 76 Error NativeRegisterContextNetBSD::DoReadGPR(void *buf) { 77 return NativeProcessNetBSD::PtraceWrapper(PT_GETREGS, GetProcessPid(), buf, 78 m_thread.GetID()); 79 } 80 81 Error NativeRegisterContextNetBSD::DoWriteGPR(void *buf) { 82 return NativeProcessNetBSD::PtraceWrapper(PT_SETREGS, GetProcessPid(), buf, 83 m_thread.GetID()); 84 } 85 86 Error NativeRegisterContextNetBSD::DoReadFPR(void *buf) { 87 return NativeProcessNetBSD::PtraceWrapper(PT_GETFPREGS, GetProcessPid(), buf, 88 m_thread.GetID()); 89 } 90 91 Error NativeRegisterContextNetBSD::DoWriteFPR(void *buf) { 92 return NativeProcessNetBSD::PtraceWrapper(PT_SETFPREGS, GetProcessPid(), buf, 93 m_thread.GetID()); 94 } 95 96 Error NativeRegisterContextNetBSD::DoReadDBR(void *buf) { 97 return NativeProcessNetBSD::PtraceWrapper(PT_GETDBREGS, GetProcessPid(), buf, 98 m_thread.GetID()); 99 } 100 101 Error NativeRegisterContextNetBSD::DoWriteDBR(void *buf) { 102 return NativeProcessNetBSD::PtraceWrapper(PT_SETDBREGS, GetProcessPid(), buf, 103 m_thread.GetID()); 104 } 105 106 NativeProcessNetBSD &NativeRegisterContextNetBSD::GetProcess() { 107 auto process_sp = 108 std::static_pointer_cast<NativeProcessNetBSD>(m_thread.GetProcess()); 109 assert(process_sp); 110 return *process_sp; 111 } 112 113 ::pid_t NativeRegisterContextNetBSD::GetProcessPid() { 114 NativeProcessNetBSD &process = GetProcess(); 115 lldb::pid_t pid = process.GetID(); 116 117 return pid; 118 } 119