1 //===-- NativeRegisterContext.h ---------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_NativeRegisterContext_h_
11 #define liblldb_NativeRegisterContext_h_
15 // Other libraries and framework includes
17 #include "lldb/lldb-private.h"
18 #include "lldb/Host/common/NativeWatchpointList.h"
20 namespace lldb_private {
22 class NativeThreadProtocol;
24 class NativeRegisterContext:
25 public std::enable_shared_from_this<NativeRegisterContext>
28 //------------------------------------------------------------------
29 // Constructors and Destructors
30 //------------------------------------------------------------------
31 NativeRegisterContext (NativeThreadProtocol &thread, uint32_t concrete_frame_idx);
34 ~NativeRegisterContext ();
37 // InvalidateIfNeeded (bool force);
39 //------------------------------------------------------------------
40 // Subclasses must override these functions
41 //------------------------------------------------------------------
43 // InvalidateAllRegisters () = 0;
46 GetRegisterCount () const = 0;
49 GetUserRegisterCount () const = 0;
51 virtual const RegisterInfo *
52 GetRegisterInfoAtIndex (uint32_t reg) const = 0;
55 GetRegisterSetNameForRegisterAtIndex (uint32_t reg_index) const;
58 GetRegisterSetCount () const = 0;
60 virtual const RegisterSet *
61 GetRegisterSet (uint32_t set_index) const = 0;
64 ReadRegister (const RegisterInfo *reg_info, RegisterValue ®_value) = 0;
67 WriteRegister (const RegisterInfo *reg_info, const RegisterValue ®_value) = 0;
70 ReadAllRegisterValues (lldb::DataBufferSP &data_sp) = 0;
73 WriteAllRegisterValues (const lldb::DataBufferSP &data_sp) = 0;
76 ConvertRegisterKindToRegisterNumber (uint32_t kind, uint32_t num) const;
78 //------------------------------------------------------------------
79 // Subclasses can override these functions if desired
80 //------------------------------------------------------------------
82 NumSupportedHardwareBreakpoints ();
85 SetHardwareBreakpoint (lldb::addr_t addr, size_t size);
88 ClearHardwareBreakpoint (uint32_t hw_idx);
91 NumSupportedHardwareWatchpoints ();
94 SetHardwareWatchpoint (lldb::addr_t addr, size_t size, uint32_t watch_flags);
97 ClearHardwareWatchpoint (uint32_t hw_index);
100 ClearAllHardwareWatchpoints ();
103 IsWatchpointHit(uint32_t wp_index, bool &is_hit);
106 GetWatchpointHitIndex(uint32_t &wp_index, lldb::addr_t trap_addr);
109 IsWatchpointVacant (uint32_t wp_index, bool &is_vacant);
112 GetWatchpointAddress (uint32_t wp_index);
114 // MIPS Linux kernel returns a masked address (last 3bits are masked)
115 // when a HW watchpoint is hit. However user may not have set a watchpoint
116 // on this address. This function emulates the instruction at PC and
117 // finds the base address used in the load/store instruction. This gives the
118 // exact address used to read/write the variable being watched.
120 // 'n' is at 0x120010d00 and 'm' is 0x120010d04. When a watchpoint is set at 'm',
121 // then watch exception is generated even when 'n' is read/written. This function
122 // returns address of 'n' so that client can check whether a watchpoint is set
123 // on this address or not.
125 GetWatchpointHitAddress (uint32_t wp_index);
128 HardwareSingleStep (bool enable);
131 ReadRegisterValueFromMemory (const lldb_private::RegisterInfo *reg_info, lldb::addr_t src_addr, size_t src_len, RegisterValue ®_value);
134 WriteRegisterValueToMemory (const lldb_private::RegisterInfo *reg_info, lldb::addr_t dst_addr, size_t dst_len, const RegisterValue ®_value);
136 //------------------------------------------------------------------
137 // Subclasses should not override these
138 //------------------------------------------------------------------
142 virtual NativeThreadProtocol &
149 GetRegisterInfoByName (const char *reg_name, uint32_t start_idx = 0);
152 GetRegisterInfo (uint32_t reg_kind, uint32_t reg_num);
155 GetPC (lldb::addr_t fail_value = LLDB_INVALID_ADDRESS);
158 GetPCfromBreakpointLocation (lldb::addr_t fail_value = LLDB_INVALID_ADDRESS);
161 SetPC (lldb::addr_t pc);
164 GetSP (lldb::addr_t fail_value = LLDB_INVALID_ADDRESS);
167 SetSP (lldb::addr_t sp);
170 GetFP (lldb::addr_t fail_value = LLDB_INVALID_ADDRESS);
173 SetFP (lldb::addr_t fp);
176 GetRegisterName (uint32_t reg);
179 GetReturnAddress (lldb::addr_t fail_value = LLDB_INVALID_ADDRESS);
182 GetFlags (lldb::addr_t fail_value = 0);
185 ReadRegisterAsUnsigned (uint32_t reg, lldb::addr_t fail_value);
188 ReadRegisterAsUnsigned (const RegisterInfo *reg_info, lldb::addr_t fail_value);
191 WriteRegisterFromUnsigned (uint32_t reg, uint64_t uval);
194 WriteRegisterFromUnsigned (const RegisterInfo *reg_info, uint64_t uval);
197 // GetStopID () const
203 // SetStopID (uint32_t stop_id)
205 // m_stop_id = stop_id;
209 //------------------------------------------------------------------
210 // Classes that inherit from RegisterContext can see and modify these
211 //------------------------------------------------------------------
212 NativeThreadProtocol &m_thread; // The thread that this register context belongs to.
213 uint32_t m_concrete_frame_idx; // The concrete frame index for this register context
214 // uint32_t m_stop_id; // The stop ID that any data in this context is valid for
217 //------------------------------------------------------------------
218 // For RegisterContext only
219 //------------------------------------------------------------------
220 DISALLOW_COPY_AND_ASSIGN (NativeRegisterContext);
223 } // namespace lldb_private
225 #endif // liblldb_NativeRegisterContext_h_