1f678e45dSDimitry Andric //===-- NativeRegisterContextNetBSD.cpp -------------------------*- C++ -*-===//
2f678e45dSDimitry Andric //
3f678e45dSDimitry Andric //                     The LLVM Compiler Infrastructure
4f678e45dSDimitry Andric //
5f678e45dSDimitry Andric // This file is distributed under the University of Illinois Open Source
6f678e45dSDimitry Andric // License. See LICENSE.TXT for details.
7f678e45dSDimitry Andric //
8f678e45dSDimitry Andric //===----------------------------------------------------------------------===//
9f678e45dSDimitry Andric 
10f678e45dSDimitry Andric #include "NativeRegisterContextNetBSD.h"
11f678e45dSDimitry Andric 
12f678e45dSDimitry Andric #include "lldb/Host/common/NativeProcessProtocol.h"
13f678e45dSDimitry Andric 
14f678e45dSDimitry Andric using namespace lldb_private;
15f678e45dSDimitry Andric using namespace lldb_private::process_netbsd;
16f678e45dSDimitry Andric 
17f678e45dSDimitry Andric // clang-format off
18f678e45dSDimitry Andric #include <sys/types.h>
19f678e45dSDimitry Andric #include <sys/ptrace.h>
20f678e45dSDimitry Andric // clang-format on
21f678e45dSDimitry Andric 
NativeRegisterContextNetBSD(NativeThreadProtocol & native_thread,RegisterInfoInterface * reg_info_interface_p)22f678e45dSDimitry Andric NativeRegisterContextNetBSD::NativeRegisterContextNetBSD(
23*acac075bSDimitry Andric     NativeThreadProtocol &native_thread,
24f678e45dSDimitry Andric     RegisterInfoInterface *reg_info_interface_p)
25*acac075bSDimitry Andric     : NativeRegisterContextRegisterInfo(native_thread,
26f678e45dSDimitry Andric                                         reg_info_interface_p) {}
27f678e45dSDimitry Andric 
ReadGPR()285517e702SDimitry Andric Status NativeRegisterContextNetBSD::ReadGPR() {
29f678e45dSDimitry Andric   void *buf = GetGPRBuffer();
30f678e45dSDimitry Andric   if (!buf)
315517e702SDimitry Andric     return Status("GPR buffer is NULL");
32f678e45dSDimitry Andric 
33f678e45dSDimitry Andric   return DoReadGPR(buf);
34f678e45dSDimitry Andric }
35f678e45dSDimitry Andric 
WriteGPR()365517e702SDimitry Andric Status NativeRegisterContextNetBSD::WriteGPR() {
37f678e45dSDimitry Andric   void *buf = GetGPRBuffer();
38f678e45dSDimitry Andric   if (!buf)
395517e702SDimitry Andric     return Status("GPR buffer is NULL");
40f678e45dSDimitry Andric 
41f678e45dSDimitry Andric   return DoWriteGPR(buf);
42f678e45dSDimitry Andric }
43f678e45dSDimitry Andric 
ReadFPR()445517e702SDimitry Andric Status NativeRegisterContextNetBSD::ReadFPR() {
45f678e45dSDimitry Andric   void *buf = GetFPRBuffer();
46f678e45dSDimitry Andric   if (!buf)
475517e702SDimitry Andric     return Status("FPR buffer is NULL");
48f678e45dSDimitry Andric 
49f678e45dSDimitry Andric   return DoReadFPR(buf);
50f678e45dSDimitry Andric }
51f678e45dSDimitry Andric 
WriteFPR()525517e702SDimitry Andric Status NativeRegisterContextNetBSD::WriteFPR() {
53f678e45dSDimitry Andric   void *buf = GetFPRBuffer();
54f678e45dSDimitry Andric   if (!buf)
555517e702SDimitry Andric     return Status("FPR buffer is NULL");
56f678e45dSDimitry Andric 
57f678e45dSDimitry Andric   return DoWriteFPR(buf);
58f678e45dSDimitry Andric }
59f678e45dSDimitry Andric 
ReadDBR()605517e702SDimitry Andric Status NativeRegisterContextNetBSD::ReadDBR() {
616bc11b14SDimitry Andric   void *buf = GetDBRBuffer();
626bc11b14SDimitry Andric   if (!buf)
635517e702SDimitry Andric     return Status("DBR buffer is NULL");
646bc11b14SDimitry Andric 
656bc11b14SDimitry Andric   return DoReadDBR(buf);
666bc11b14SDimitry Andric }
676bc11b14SDimitry Andric 
WriteDBR()685517e702SDimitry Andric Status NativeRegisterContextNetBSD::WriteDBR() {
696bc11b14SDimitry Andric   void *buf = GetDBRBuffer();
706bc11b14SDimitry Andric   if (!buf)
715517e702SDimitry Andric     return Status("DBR buffer is NULL");
726bc11b14SDimitry Andric 
736bc11b14SDimitry Andric   return DoWriteDBR(buf);
746bc11b14SDimitry Andric }
756bc11b14SDimitry Andric 
DoReadGPR(void * buf)765517e702SDimitry Andric Status NativeRegisterContextNetBSD::DoReadGPR(void *buf) {
77f678e45dSDimitry Andric   return NativeProcessNetBSD::PtraceWrapper(PT_GETREGS, GetProcessPid(), buf,
78f678e45dSDimitry Andric                                             m_thread.GetID());
79f678e45dSDimitry Andric }
80f678e45dSDimitry Andric 
DoWriteGPR(void * buf)815517e702SDimitry Andric Status NativeRegisterContextNetBSD::DoWriteGPR(void *buf) {
82f678e45dSDimitry Andric   return NativeProcessNetBSD::PtraceWrapper(PT_SETREGS, GetProcessPid(), buf,
83f678e45dSDimitry Andric                                             m_thread.GetID());
84f678e45dSDimitry Andric }
85f678e45dSDimitry Andric 
DoReadFPR(void * buf)865517e702SDimitry Andric Status NativeRegisterContextNetBSD::DoReadFPR(void *buf) {
87f678e45dSDimitry Andric   return NativeProcessNetBSD::PtraceWrapper(PT_GETFPREGS, GetProcessPid(), buf,
88f678e45dSDimitry Andric                                             m_thread.GetID());
89f678e45dSDimitry Andric }
90f678e45dSDimitry Andric 
DoWriteFPR(void * buf)915517e702SDimitry Andric Status NativeRegisterContextNetBSD::DoWriteFPR(void *buf) {
92f678e45dSDimitry Andric   return NativeProcessNetBSD::PtraceWrapper(PT_SETFPREGS, GetProcessPid(), buf,
93f678e45dSDimitry Andric                                             m_thread.GetID());
94f678e45dSDimitry Andric }
95f678e45dSDimitry Andric 
DoReadDBR(void * buf)965517e702SDimitry Andric Status NativeRegisterContextNetBSD::DoReadDBR(void *buf) {
976bc11b14SDimitry Andric   return NativeProcessNetBSD::PtraceWrapper(PT_GETDBREGS, GetProcessPid(), buf,
986bc11b14SDimitry Andric                                             m_thread.GetID());
996bc11b14SDimitry Andric }
1006bc11b14SDimitry Andric 
DoWriteDBR(void * buf)1015517e702SDimitry Andric Status NativeRegisterContextNetBSD::DoWriteDBR(void *buf) {
1026bc11b14SDimitry Andric   return NativeProcessNetBSD::PtraceWrapper(PT_SETDBREGS, GetProcessPid(), buf,
1036bc11b14SDimitry Andric                                             m_thread.GetID());
1046bc11b14SDimitry Andric }
1056bc11b14SDimitry Andric 
GetProcess()106f678e45dSDimitry Andric NativeProcessNetBSD &NativeRegisterContextNetBSD::GetProcess() {
107b40b48b8SDimitry Andric   return static_cast<NativeProcessNetBSD &>(m_thread.GetProcess());
108f678e45dSDimitry Andric }
109f678e45dSDimitry Andric 
GetProcessPid()110f678e45dSDimitry Andric ::pid_t NativeRegisterContextNetBSD::GetProcessPid() {
111b40b48b8SDimitry Andric   return GetProcess().GetID();
112f678e45dSDimitry Andric }
113