]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Host/common/NativeRegisterContext.h
file: update to 5.34
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / Host / common / NativeRegisterContext.h
1 //===-- NativeRegisterContext.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 liblldb_NativeRegisterContext_h_
11 #define liblldb_NativeRegisterContext_h_
12
13 // C Includes
14 // C++ Includes
15 // Other libraries and framework includes
16 // Project includes
17 #include "lldb/Host/common/NativeWatchpointList.h"
18 #include "lldb/lldb-private.h"
19
20 namespace lldb_private {
21
22 class NativeThreadProtocol;
23
24 class NativeRegisterContext
25     : public std::enable_shared_from_this<NativeRegisterContext> {
26 public:
27   //------------------------------------------------------------------
28   // Constructors and Destructors
29   //------------------------------------------------------------------
30   NativeRegisterContext(NativeThreadProtocol &thread);
31
32   virtual ~NativeRegisterContext();
33
34   // void
35   // InvalidateIfNeeded (bool force);
36
37   //------------------------------------------------------------------
38   // Subclasses must override these functions
39   //------------------------------------------------------------------
40   // virtual void
41   // InvalidateAllRegisters () = 0;
42
43   virtual uint32_t GetRegisterCount() const = 0;
44
45   virtual uint32_t GetUserRegisterCount() const = 0;
46
47   virtual const RegisterInfo *GetRegisterInfoAtIndex(uint32_t reg) const = 0;
48
49   const char *GetRegisterSetNameForRegisterAtIndex(uint32_t reg_index) const;
50
51   virtual uint32_t GetRegisterSetCount() const = 0;
52
53   virtual const RegisterSet *GetRegisterSet(uint32_t set_index) const = 0;
54
55   virtual Status ReadRegister(const RegisterInfo *reg_info,
56                               RegisterValue &reg_value) = 0;
57
58   virtual Status WriteRegister(const RegisterInfo *reg_info,
59                                const RegisterValue &reg_value) = 0;
60
61   virtual Status ReadAllRegisterValues(lldb::DataBufferSP &data_sp) = 0;
62
63   virtual Status WriteAllRegisterValues(const lldb::DataBufferSP &data_sp) = 0;
64
65   uint32_t ConvertRegisterKindToRegisterNumber(uint32_t kind,
66                                                uint32_t num) const;
67
68   //------------------------------------------------------------------
69   // Subclasses can override these functions if desired
70   //------------------------------------------------------------------
71   virtual uint32_t NumSupportedHardwareBreakpoints();
72
73   virtual uint32_t SetHardwareBreakpoint(lldb::addr_t addr, size_t size);
74
75   virtual bool ClearHardwareBreakpoint(uint32_t hw_idx);
76
77   virtual Status ClearAllHardwareBreakpoints();
78
79   virtual Status GetHardwareBreakHitIndex(uint32_t &bp_index,
80                                           lldb::addr_t trap_addr);
81
82   virtual uint32_t NumSupportedHardwareWatchpoints();
83
84   virtual uint32_t SetHardwareWatchpoint(lldb::addr_t addr, size_t size,
85                                          uint32_t watch_flags);
86
87   virtual bool ClearHardwareWatchpoint(uint32_t hw_index);
88
89   virtual Status ClearAllHardwareWatchpoints();
90
91   virtual Status IsWatchpointHit(uint32_t wp_index, bool &is_hit);
92
93   virtual Status GetWatchpointHitIndex(uint32_t &wp_index,
94                                        lldb::addr_t trap_addr);
95
96   virtual Status IsWatchpointVacant(uint32_t wp_index, bool &is_vacant);
97
98   virtual lldb::addr_t GetWatchpointAddress(uint32_t wp_index);
99
100   // MIPS Linux kernel returns a masked address (last 3bits are masked)
101   // when a HW watchpoint is hit. However user may not have set a watchpoint
102   // on this address. This function emulates the instruction at PC and
103   // finds the base address used in the load/store instruction. This gives the
104   // exact address used to read/write the variable being watched.
105   // For example:
106   // 'n' is at 0x120010d00 and 'm' is 0x120010d04. When a watchpoint is set at
107   // 'm',
108   // then watch exception is generated even when 'n' is read/written. This
109   // function
110   // returns address of 'n' so that client can check whether a watchpoint is set
111   // on this address or not.
112   virtual lldb::addr_t GetWatchpointHitAddress(uint32_t wp_index);
113
114   virtual bool HardwareSingleStep(bool enable);
115
116   virtual Status
117   ReadRegisterValueFromMemory(const lldb_private::RegisterInfo *reg_info,
118                               lldb::addr_t src_addr, size_t src_len,
119                               RegisterValue &reg_value);
120
121   virtual Status
122   WriteRegisterValueToMemory(const lldb_private::RegisterInfo *reg_info,
123                              lldb::addr_t dst_addr, size_t dst_len,
124                              const RegisterValue &reg_value);
125
126   //------------------------------------------------------------------
127   // Subclasses should not override these
128   //------------------------------------------------------------------
129   virtual lldb::tid_t GetThreadID() const;
130
131   virtual NativeThreadProtocol &GetThread() { return m_thread; }
132
133   const RegisterInfo *GetRegisterInfoByName(llvm::StringRef reg_name,
134                                             uint32_t start_idx = 0);
135
136   const RegisterInfo *GetRegisterInfo(uint32_t reg_kind, uint32_t reg_num);
137
138   lldb::addr_t GetPC(lldb::addr_t fail_value = LLDB_INVALID_ADDRESS);
139
140   virtual lldb::addr_t
141   GetPCfromBreakpointLocation(lldb::addr_t fail_value = LLDB_INVALID_ADDRESS);
142
143   Status SetPC(lldb::addr_t pc);
144
145   lldb::addr_t GetSP(lldb::addr_t fail_value = LLDB_INVALID_ADDRESS);
146
147   Status SetSP(lldb::addr_t sp);
148
149   lldb::addr_t GetFP(lldb::addr_t fail_value = LLDB_INVALID_ADDRESS);
150
151   Status SetFP(lldb::addr_t fp);
152
153   const char *GetRegisterName(uint32_t reg);
154
155   lldb::addr_t GetReturnAddress(lldb::addr_t fail_value = LLDB_INVALID_ADDRESS);
156
157   lldb::addr_t GetFlags(lldb::addr_t fail_value = 0);
158
159   lldb::addr_t ReadRegisterAsUnsigned(uint32_t reg, lldb::addr_t fail_value);
160
161   lldb::addr_t ReadRegisterAsUnsigned(const RegisterInfo *reg_info,
162                                       lldb::addr_t fail_value);
163
164   Status WriteRegisterFromUnsigned(uint32_t reg, uint64_t uval);
165
166   Status WriteRegisterFromUnsigned(const RegisterInfo *reg_info, uint64_t uval);
167
168   // uint32_t
169   // GetStopID () const
170   // {
171   //     return m_stop_id;
172   // }
173
174   // void
175   // SetStopID (uint32_t stop_id)
176   // {
177   //     m_stop_id = stop_id;
178   // }
179
180 protected:
181   //------------------------------------------------------------------
182   // Classes that inherit from RegisterContext can see and modify these
183   //------------------------------------------------------------------
184   NativeThreadProtocol
185       &m_thread; // The thread that this register context belongs to.
186   // uint32_t m_stop_id;             // The stop ID that any data in this
187   // context is valid for
188
189 private:
190   //------------------------------------------------------------------
191   // For RegisterContext only
192   //------------------------------------------------------------------
193   DISALLOW_COPY_AND_ASSIGN(NativeRegisterContext);
194 };
195
196 } // namespace lldb_private
197
198 #endif // liblldb_NativeRegisterContext_h_