1 //===-- NativeRegisterContextLinux.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 #ifndef lldb_NativeRegisterContextLinux_h
10 #define lldb_NativeRegisterContextLinux_h
11 
12 #include "Plugins/Process/Utility/NativeRegisterContextRegisterInfo.h"
13 #include "lldb/Host/common/NativeThreadProtocol.h"
14 
15 namespace lldb_private {
16 namespace process_linux {
17 
18 class NativeRegisterContextLinux : public NativeRegisterContextRegisterInfo {
19 public:
20   NativeRegisterContextLinux(NativeThreadProtocol &native_thread,
21                              RegisterInfoInterface *reg_info_interface_p);
22 
23   // This function is implemented in the NativeRegisterContextLinux_* subclasses
24   // to create a new instance of the host specific NativeRegisterContextLinux.
25   // The implementations can't collide as only one NativeRegisterContextLinux_*
26   // variant should be compiled into the final executable.
27   static std::unique_ptr<NativeRegisterContextLinux>
28   CreateHostNativeRegisterContextLinux(const ArchSpec &target_arch,
29                                        NativeThreadProtocol &native_thread);
30 
31 protected:
32   lldb::ByteOrder GetByteOrder() const;
33 
34   virtual Status ReadRegisterRaw(uint32_t reg_index, RegisterValue &reg_value);
35 
36   virtual Status WriteRegisterRaw(uint32_t reg_index,
37                                   const RegisterValue &reg_value);
38 
39   virtual Status ReadRegisterSet(void *buf, size_t buf_size,
40                                  unsigned int regset);
41 
42   virtual Status WriteRegisterSet(void *buf, size_t buf_size,
43                                   unsigned int regset);
44 
45   virtual Status ReadGPR();
46 
47   virtual Status WriteGPR();
48 
49   virtual Status ReadFPR();
50 
51   virtual Status WriteFPR();
52 
53   virtual void *GetGPRBuffer() = 0;
54 
55   virtual size_t GetGPRSize() {
56     return GetRegisterInfoInterface().GetGPRSize();
57   }
58 
59   virtual void *GetFPRBuffer() = 0;
60 
61   virtual size_t GetFPRSize() = 0;
62 
63   virtual uint32_t GetPtraceOffset(uint32_t reg_index) {
64     return GetRegisterInfoAtIndex(reg_index)->byte_offset;
65   }
66 
67   // The Do*** functions are executed on the privileged thread and can perform
68   // ptrace
69   // operations directly.
70   virtual Status DoReadRegisterValue(uint32_t offset, const char *reg_name,
71                                      uint32_t size, RegisterValue &value);
72 
73   virtual Status DoWriteRegisterValue(uint32_t offset, const char *reg_name,
74                                       const RegisterValue &value);
75 };
76 
77 } // namespace process_linux
78 } // namespace lldb_private
79 
80 #endif // #ifndef lldb_NativeRegisterContextLinux_h
81