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::DoReadGPR(void *buf) { 45 return NativeProcessNetBSD::PtraceWrapper(PT_GETREGS, GetProcessPid(), buf, 46 m_thread.GetID()); 47 } 48 49 Error NativeRegisterContextNetBSD::DoWriteGPR(void *buf) { 50 return NativeProcessNetBSD::PtraceWrapper(PT_SETREGS, GetProcessPid(), buf, 51 m_thread.GetID()); 52 } 53 54 NativeProcessNetBSD &NativeRegisterContextNetBSD::GetProcess() { 55 auto process_sp = 56 std::static_pointer_cast<NativeProcessNetBSD>(m_thread.GetProcess()); 57 assert(process_sp); 58 return *process_sp; 59 } 60 61 ::pid_t NativeRegisterContextNetBSD::GetProcessPid() { 62 NativeProcessNetBSD &process = GetProcess(); 63 lldb::pid_t pid = process.GetID(); 64 65 return pid; 66 } 67