xref: /openbsd-src/gnu/llvm/lldb/source/Plugins/Process/OpenBSD/NativeRegisterContextOpenBSD.cpp (revision 061da546b983eb767bad15e67af1174fb0bcf31c)
1 //===-- NativeRegisterContextOpenBSD.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 "NativeRegisterContextOpenBSD.h"
11 
12 #include "lldb/Host/common/NativeProcessProtocol.h"
13 
14 using namespace lldb_private;
15 using namespace lldb_private::process_openbsd;
16 
17 // clang-format off
18 #include <sys/types.h>
19 #include <sys/ptrace.h>
20 // clang-format on
21 
NativeRegisterContextOpenBSD(NativeThreadProtocol & native_thread,RegisterInfoInterface * reg_info_interface_p)22 NativeRegisterContextOpenBSD::NativeRegisterContextOpenBSD(
23     NativeThreadProtocol &native_thread,
24     RegisterInfoInterface *reg_info_interface_p)
25     : NativeRegisterContextRegisterInfo(native_thread,
26                                         reg_info_interface_p) {}
27 
ReadGPR()28 Status NativeRegisterContextOpenBSD::ReadGPR() {
29   void *buf = GetGPRBuffer();
30   if (!buf)
31     return Status("GPR buffer is NULL");
32 
33   return DoReadGPR(buf);
34 }
35 
WriteGPR()36 Status NativeRegisterContextOpenBSD::WriteGPR() {
37   void *buf = GetGPRBuffer();
38   if (!buf)
39     return Status("GPR buffer is NULL");
40 
41   return DoWriteGPR(buf);
42 }
43 
ReadFPR()44 Status NativeRegisterContextOpenBSD::ReadFPR() {
45   void *buf = GetFPRBuffer();
46   if (!buf)
47     return Status("FPR buffer is NULL");
48 
49   return DoReadFPR(buf);
50 }
51 
WriteFPR()52 Status NativeRegisterContextOpenBSD::WriteFPR() {
53   void *buf = GetFPRBuffer();
54   if (!buf)
55     return Status("FPR buffer is NULL");
56 
57   return DoWriteFPR(buf);
58 }
59 
DoReadGPR(void * buf)60 Status NativeRegisterContextOpenBSD::DoReadGPR(void *buf) {
61 #ifdef PT_GETREGS
62   return NativeProcessOpenBSD::PtraceWrapper(PT_GETREGS, GetProcessPid(), buf,
63                                             m_thread.GetID());
64 #else
65   return Status("PT_GETREGS not supported on this platform");
66 #endif
67 }
68 
DoWriteGPR(void * buf)69 Status NativeRegisterContextOpenBSD::DoWriteGPR(void *buf) {
70 #ifdef PT_SETREGS
71   return NativeProcessOpenBSD::PtraceWrapper(PT_SETREGS, GetProcessPid(), buf,
72                                             m_thread.GetID());
73 #else
74   return Status("PT_SETREGS not supported on this platform");
75 #endif
76 }
77 
DoReadFPR(void * buf)78 Status NativeRegisterContextOpenBSD::DoReadFPR(void *buf) {
79 #ifdef PT_GETFPREGS
80   return NativeProcessOpenBSD::PtraceWrapper(PT_GETFPREGS, GetProcessPid(), buf,
81                                             m_thread.GetID());
82 #else
83   return Status("PT_GETFPREGS not supported on this platform");
84 #endif
85 }
86 
DoWriteFPR(void * buf)87 Status NativeRegisterContextOpenBSD::DoWriteFPR(void *buf) {
88 #ifdef PT_SETFPREGS
89   return NativeProcessOpenBSD::PtraceWrapper(PT_SETFPREGS, GetProcessPid(), buf,
90                                             m_thread.GetID());
91 #else
92   return Status("PT_SETFPREGS not supported on this platform");
93 #endif
94 }
95 
GetProcess()96 NativeProcessOpenBSD &NativeRegisterContextOpenBSD::GetProcess() {
97   return static_cast<NativeProcessOpenBSD &>(m_thread.GetProcess());
98 }
99 
GetProcessPid()100 ::pid_t NativeRegisterContextOpenBSD::GetProcessPid() {
101   return GetProcess().GetID();
102 }
103