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 Status ReadRegister(const RegisterInfo *reg_info,
57 RegisterValue ®_value) = 0;
59 virtual Status WriteRegister(const RegisterInfo *reg_info,
60 const RegisterValue ®_value) = 0;
62 virtual Status ReadAllRegisterValues(lldb::DataBufferSP &data_sp) = 0;
64 virtual Status 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 Status ClearAllHardwareBreakpoints();
80 virtual Status GetHardwareBreakHitIndex(uint32_t &bp_index,
81 lldb::addr_t trap_addr);
83 virtual uint32_t NumSupportedHardwareWatchpoints();
85 virtual uint32_t SetHardwareWatchpoint(lldb::addr_t addr, size_t size,
86 uint32_t watch_flags);
88 virtual bool ClearHardwareWatchpoint(uint32_t hw_index);
90 virtual Status ClearAllHardwareWatchpoints();
92 virtual Status IsWatchpointHit(uint32_t wp_index, bool &is_hit);
94 virtual Status GetWatchpointHitIndex(uint32_t &wp_index,
95 lldb::addr_t trap_addr);
97 virtual Status IsWatchpointVacant(uint32_t wp_index, bool &is_vacant);
99 virtual lldb::addr_t GetWatchpointAddress(uint32_t wp_index);
101 // MIPS Linux kernel returns a masked address (last 3bits are masked)
102 // when a HW watchpoint is hit. However user may not have set a watchpoint
103 // on this address. This function emulates the instruction at PC and
104 // finds the base address used in the load/store instruction. This gives the
105 // exact address used to read/write the variable being watched.
107 // 'n' is at 0x120010d00 and 'm' is 0x120010d04. When a watchpoint is set at
109 // then watch exception is generated even when 'n' is read/written. This
111 // returns address of 'n' so that client can check whether a watchpoint is set
112 // on this address or not.
113 virtual lldb::addr_t GetWatchpointHitAddress(uint32_t wp_index);
115 virtual bool HardwareSingleStep(bool enable);
118 ReadRegisterValueFromMemory(const lldb_private::RegisterInfo *reg_info,
119 lldb::addr_t src_addr, size_t src_len,
120 RegisterValue ®_value);
123 WriteRegisterValueToMemory(const lldb_private::RegisterInfo *reg_info,
124 lldb::addr_t dst_addr, size_t dst_len,
125 const RegisterValue ®_value);
127 //------------------------------------------------------------------
128 // Subclasses should not override these
129 //------------------------------------------------------------------
130 virtual lldb::tid_t GetThreadID() const;
132 virtual NativeThreadProtocol &GetThread() { return m_thread; }
134 const RegisterInfo *GetRegisterInfoByName(llvm::StringRef reg_name,
135 uint32_t start_idx = 0);
137 const RegisterInfo *GetRegisterInfo(uint32_t reg_kind, uint32_t reg_num);
139 lldb::addr_t GetPC(lldb::addr_t fail_value = LLDB_INVALID_ADDRESS);
142 GetPCfromBreakpointLocation(lldb::addr_t fail_value = LLDB_INVALID_ADDRESS);
144 Status SetPC(lldb::addr_t pc);
146 lldb::addr_t GetSP(lldb::addr_t fail_value = LLDB_INVALID_ADDRESS);
148 Status SetSP(lldb::addr_t sp);
150 lldb::addr_t GetFP(lldb::addr_t fail_value = LLDB_INVALID_ADDRESS);
152 Status SetFP(lldb::addr_t fp);
154 const char *GetRegisterName(uint32_t reg);
156 lldb::addr_t GetReturnAddress(lldb::addr_t fail_value = LLDB_INVALID_ADDRESS);
158 lldb::addr_t GetFlags(lldb::addr_t fail_value = 0);
160 lldb::addr_t ReadRegisterAsUnsigned(uint32_t reg, lldb::addr_t fail_value);
162 lldb::addr_t ReadRegisterAsUnsigned(const RegisterInfo *reg_info,
163 lldb::addr_t fail_value);
165 Status WriteRegisterFromUnsigned(uint32_t reg, uint64_t uval);
167 Status WriteRegisterFromUnsigned(const RegisterInfo *reg_info, uint64_t uval);
170 // GetStopID () const
176 // SetStopID (uint32_t stop_id)
178 // m_stop_id = stop_id;
182 //------------------------------------------------------------------
183 // Classes that inherit from RegisterContext can see and modify these
184 //------------------------------------------------------------------
186 &m_thread; // The thread that this register context belongs to.
187 uint32_t m_concrete_frame_idx; // The concrete frame index for this register
189 // uint32_t m_stop_id; // The stop ID that any data in this
190 // context is valid for
193 //------------------------------------------------------------------
194 // For RegisterContext only
195 //------------------------------------------------------------------
196 DISALLOW_COPY_AND_ASSIGN(NativeRegisterContext);
199 } // namespace lldb_private
201 #endif // liblldb_NativeRegisterContext_h_