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