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