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/Host/common/NativeWatchpointList.h"
18 #include "lldb/lldb-private.h"
20 namespace lldb_private {
22 class NativeThreadProtocol;
24 class NativeRegisterContext
25 : public std::enable_shared_from_this<NativeRegisterContext> {
27 //------------------------------------------------------------------
28 // Constructors and Destructors
29 //------------------------------------------------------------------
30 NativeRegisterContext(NativeThreadProtocol &thread,
31 uint32_t concrete_frame_idx);
33 virtual ~NativeRegisterContext();
36 // InvalidateIfNeeded (bool force);
38 //------------------------------------------------------------------
39 // Subclasses must override these functions
40 //------------------------------------------------------------------
42 // InvalidateAllRegisters () = 0;
44 virtual uint32_t GetRegisterCount() const = 0;
46 virtual uint32_t GetUserRegisterCount() const = 0;
48 virtual const RegisterInfo *GetRegisterInfoAtIndex(uint32_t reg) const = 0;
50 const char *GetRegisterSetNameForRegisterAtIndex(uint32_t reg_index) const;
52 virtual uint32_t GetRegisterSetCount() const = 0;
54 virtual const RegisterSet *GetRegisterSet(uint32_t set_index) const = 0;
56 virtual Error ReadRegister(const RegisterInfo *reg_info,
57 RegisterValue ®_value) = 0;
59 virtual Error WriteRegister(const RegisterInfo *reg_info,
60 const RegisterValue ®_value) = 0;
62 virtual Error ReadAllRegisterValues(lldb::DataBufferSP &data_sp) = 0;
64 virtual Error WriteAllRegisterValues(const lldb::DataBufferSP &data_sp) = 0;
66 uint32_t ConvertRegisterKindToRegisterNumber(uint32_t kind,
69 //------------------------------------------------------------------
70 // Subclasses can override these functions if desired
71 //------------------------------------------------------------------
72 virtual uint32_t NumSupportedHardwareBreakpoints();
74 virtual uint32_t SetHardwareBreakpoint(lldb::addr_t addr, size_t size);
76 virtual bool ClearHardwareBreakpoint(uint32_t hw_idx);
78 virtual uint32_t NumSupportedHardwareWatchpoints();
80 virtual uint32_t SetHardwareWatchpoint(lldb::addr_t addr, size_t size,
81 uint32_t watch_flags);
83 virtual bool ClearHardwareWatchpoint(uint32_t hw_index);
85 virtual Error ClearAllHardwareWatchpoints();
87 virtual Error IsWatchpointHit(uint32_t wp_index, bool &is_hit);
89 virtual Error GetWatchpointHitIndex(uint32_t &wp_index,
90 lldb::addr_t trap_addr);
92 virtual Error IsWatchpointVacant(uint32_t wp_index, bool &is_vacant);
94 virtual lldb::addr_t GetWatchpointAddress(uint32_t wp_index);
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.
102 // 'n' is at 0x120010d00 and 'm' is 0x120010d04. When a watchpoint is set at
104 // then watch exception is generated even when 'n' is read/written. This
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);
110 virtual bool HardwareSingleStep(bool enable);
113 ReadRegisterValueFromMemory(const lldb_private::RegisterInfo *reg_info,
114 lldb::addr_t src_addr, size_t src_len,
115 RegisterValue ®_value);
118 WriteRegisterValueToMemory(const lldb_private::RegisterInfo *reg_info,
119 lldb::addr_t dst_addr, size_t dst_len,
120 const RegisterValue ®_value);
122 //------------------------------------------------------------------
123 // Subclasses should not override these
124 //------------------------------------------------------------------
125 virtual lldb::tid_t GetThreadID() const;
127 virtual NativeThreadProtocol &GetThread() { return m_thread; }
129 const RegisterInfo *GetRegisterInfoByName(llvm::StringRef reg_name,
130 uint32_t start_idx = 0);
132 const RegisterInfo *GetRegisterInfo(uint32_t reg_kind, uint32_t reg_num);
134 lldb::addr_t GetPC(lldb::addr_t fail_value = LLDB_INVALID_ADDRESS);
137 GetPCfromBreakpointLocation(lldb::addr_t fail_value = LLDB_INVALID_ADDRESS);
139 Error SetPC(lldb::addr_t pc);
141 lldb::addr_t GetSP(lldb::addr_t fail_value = LLDB_INVALID_ADDRESS);
143 Error SetSP(lldb::addr_t sp);
145 lldb::addr_t GetFP(lldb::addr_t fail_value = LLDB_INVALID_ADDRESS);
147 Error SetFP(lldb::addr_t fp);
149 const char *GetRegisterName(uint32_t reg);
151 lldb::addr_t GetReturnAddress(lldb::addr_t fail_value = LLDB_INVALID_ADDRESS);
153 lldb::addr_t GetFlags(lldb::addr_t fail_value = 0);
155 lldb::addr_t ReadRegisterAsUnsigned(uint32_t reg, lldb::addr_t fail_value);
157 lldb::addr_t ReadRegisterAsUnsigned(const RegisterInfo *reg_info,
158 lldb::addr_t fail_value);
160 Error WriteRegisterFromUnsigned(uint32_t reg, uint64_t uval);
162 Error WriteRegisterFromUnsigned(const RegisterInfo *reg_info, uint64_t uval);
165 // GetStopID () const
171 // SetStopID (uint32_t stop_id)
173 // m_stop_id = stop_id;
177 //------------------------------------------------------------------
178 // Classes that inherit from RegisterContext can see and modify these
179 //------------------------------------------------------------------
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
184 // uint32_t m_stop_id; // The stop ID that any data in this
185 // context is valid for
188 //------------------------------------------------------------------
189 // For RegisterContext only
190 //------------------------------------------------------------------
191 DISALLOW_COPY_AND_ASSIGN(NativeRegisterContext);
194 } // namespace lldb_private
196 #endif // liblldb_NativeRegisterContext_h_