1 //===-- NativeRegisterContextNetBSD_x86_64.h --------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #if defined(__i386__) || defined(__x86_64__)
10 
11 #ifndef lldb_NativeRegisterContextNetBSD_x86_64_h
12 #define lldb_NativeRegisterContextNetBSD_x86_64_h
13 
14 // clang-format off
15 #include <sys/param.h>
16 #include <sys/types.h>
17 #include <sys/ptrace.h>
18 #include <machine/reg.h>
19 // clang-format on
20 
21 #include "Plugins/Process/NetBSD/NativeRegisterContextNetBSD.h"
22 #include "Plugins/Process/Utility/RegisterContext_x86.h"
23 #include "Plugins/Process/Utility/lldb-x86-register-enums.h"
24 
25 #if defined(PT_GETXSTATE) && defined(PT_SETXSTATE)
26 #define HAVE_XSTATE
27 #endif
28 
29 namespace lldb_private {
30 namespace process_netbsd {
31 
32 class NativeProcessNetBSD;
33 
34 class NativeRegisterContextNetBSD_x86_64 : public NativeRegisterContextNetBSD {
35 public:
36   NativeRegisterContextNetBSD_x86_64(const ArchSpec &target_arch,
37                                      NativeThreadProtocol &native_thread);
38   uint32_t GetRegisterSetCount() const override;
39 
40   const RegisterSet *GetRegisterSet(uint32_t set_index) const override;
41 
42   Status ReadRegister(const RegisterInfo *reg_info,
43                       RegisterValue &reg_value) override;
44 
45   Status WriteRegister(const RegisterInfo *reg_info,
46                        const RegisterValue &reg_value) override;
47 
48   Status ReadAllRegisterValues(lldb::DataBufferSP &data_sp) override;
49 
50   Status WriteAllRegisterValues(const lldb::DataBufferSP &data_sp) override;
51 
52   Status IsWatchpointHit(uint32_t wp_index, bool &is_hit) override;
53 
54   Status GetWatchpointHitIndex(uint32_t &wp_index,
55                                lldb::addr_t trap_addr) override;
56 
57   Status IsWatchpointVacant(uint32_t wp_index, bool &is_vacant) override;
58 
59   bool ClearHardwareWatchpoint(uint32_t wp_index) override;
60 
61   Status ClearWatchpointHit(uint32_t wp_index) override;
62 
63   Status ClearAllHardwareWatchpoints() override;
64 
65   Status SetHardwareWatchpointWithIndex(lldb::addr_t addr, size_t size,
66                                         uint32_t watch_flags,
67                                         uint32_t wp_index);
68 
69   uint32_t SetHardwareWatchpoint(lldb::addr_t addr, size_t size,
70                                  uint32_t watch_flags) override;
71 
72   lldb::addr_t GetWatchpointAddress(uint32_t wp_index) override;
73 
74   uint32_t NumSupportedHardwareWatchpoints() override;
75 
76   Status
77   CopyHardwareWatchpointsFrom(NativeRegisterContextNetBSD &source) override;
78 
79 private:
80   // Private member types.
81   enum { GPRegSet, FPRegSet, XStateRegSet, DBRegSet };
82 
83   // Private member variables.
84   struct reg m_gpr;
85 #if defined(__x86_64__)
86   struct fpreg m_fpr;
87 #else
88   struct xmmregs m_fpr;
89 #endif
90   struct dbreg m_dbr;
91 #ifdef HAVE_XSTATE
92   struct xstate m_xstate;
93 #endif
94 
95   int GetSetForNativeRegNum(int reg_num) const;
96   int GetDR(int num) const;
97 
98   Status ReadRegisterSet(uint32_t set);
99   Status WriteRegisterSet(uint32_t set);
100 };
101 
102 } // namespace process_netbsd
103 } // namespace lldb_private
104 
105 #endif // #ifndef lldb_NativeRegisterContextNetBSD_x86_64_h
106 
107 #endif // defined(__x86_64__)
108