LLDB  mainline
NativeRegisterContext.h
Go to the documentation of this file.
1 //===-- NativeRegisterContext.h ---------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef liblldb_NativeRegisterContext_h_
10 #define liblldb_NativeRegisterContext_h_
11 
13 #include "lldb/lldb-private.h"
14 
15 namespace lldb_private {
16 
17 class NativeThreadProtocol;
18 
20  : public std::enable_shared_from_this<NativeRegisterContext> {
21 public:
22  // Constructors and Destructors
24 
25  virtual ~NativeRegisterContext();
26 
27  // void
28  // InvalidateIfNeeded (bool force);
29 
30  // Subclasses must override these functions
31  // virtual void
32  // InvalidateAllRegisters () = 0;
33 
34  virtual uint32_t GetRegisterCount() const = 0;
35 
36  virtual uint32_t GetUserRegisterCount() const = 0;
37 
38  virtual const RegisterInfo *GetRegisterInfoAtIndex(uint32_t reg) const = 0;
39 
40  const char *GetRegisterSetNameForRegisterAtIndex(uint32_t reg_index) const;
41 
42  virtual uint32_t GetRegisterSetCount() const = 0;
43 
44  virtual const RegisterSet *GetRegisterSet(uint32_t set_index) const = 0;
45 
46  virtual Status ReadRegister(const RegisterInfo *reg_info,
47  RegisterValue &reg_value) = 0;
48 
49  virtual Status WriteRegister(const RegisterInfo *reg_info,
50  const RegisterValue &reg_value) = 0;
51 
52  virtual Status ReadAllRegisterValues(lldb::DataBufferSP &data_sp) = 0;
53 
54  virtual Status WriteAllRegisterValues(const lldb::DataBufferSP &data_sp) = 0;
55 
57  uint32_t num) const;
58 
59  // Subclasses can override these functions if desired
61 
62  virtual uint32_t SetHardwareBreakpoint(lldb::addr_t addr, size_t size);
63 
64  virtual bool ClearHardwareBreakpoint(uint32_t hw_idx);
65 
67 
68  virtual Status GetHardwareBreakHitIndex(uint32_t &bp_index,
69  lldb::addr_t trap_addr);
70 
72 
73  virtual uint32_t SetHardwareWatchpoint(lldb::addr_t addr, size_t size,
74  uint32_t watch_flags);
75 
76  virtual bool ClearHardwareWatchpoint(uint32_t hw_index);
77 
79 
80  virtual Status IsWatchpointHit(uint32_t wp_index, bool &is_hit);
81 
82  virtual Status GetWatchpointHitIndex(uint32_t &wp_index,
83  lldb::addr_t trap_addr);
84 
85  virtual Status IsWatchpointVacant(uint32_t wp_index, bool &is_vacant);
86 
87  virtual lldb::addr_t GetWatchpointAddress(uint32_t wp_index);
88 
89  // MIPS Linux kernel returns a masked address (last 3bits are masked)
90  // when a HW watchpoint is hit. However user may not have set a watchpoint on
91  // this address. This function emulates the instruction at PC and finds the
92  // base address used in the load/store instruction. This gives the exact
93  // address used to read/write the variable being watched. For example: 'n' is
94  // at 0x120010d00 and 'm' is 0x120010d04. When a watchpoint is set at 'm',
95  // then watch exception is generated even when 'n' is read/written. This
96  // function returns address of 'n' so that client can check whether a
97  // watchpoint is set on this address or not.
99 
100  virtual bool HardwareSingleStep(bool enable);
101 
102  virtual Status
103  ReadRegisterValueFromMemory(const lldb_private::RegisterInfo *reg_info,
104  lldb::addr_t src_addr, size_t src_len,
105  RegisterValue &reg_value);
106 
107  virtual Status
108  WriteRegisterValueToMemory(const lldb_private::RegisterInfo *reg_info,
109  lldb::addr_t dst_addr, size_t dst_len,
110  const RegisterValue &reg_value);
111 
112  // Subclasses should not override these
113  virtual lldb::tid_t GetThreadID() const;
114 
115  virtual NativeThreadProtocol &GetThread() { return m_thread; }
116 
117  const RegisterInfo *GetRegisterInfoByName(llvm::StringRef reg_name,
118  uint32_t start_idx = 0);
119 
120  const RegisterInfo *GetRegisterInfo(uint32_t reg_kind, uint32_t reg_num);
121 
123 
124  virtual lldb::addr_t
126 
128 
130 
132 
134 
136 
137  const char *GetRegisterName(uint32_t reg);
138 
140 
141  lldb::addr_t GetFlags(lldb::addr_t fail_value = 0);
142 
144 
145  lldb::addr_t ReadRegisterAsUnsigned(const RegisterInfo *reg_info,
146  lldb::addr_t fail_value);
147 
148  Status WriteRegisterFromUnsigned(uint32_t reg, uint64_t uval);
149 
150  Status WriteRegisterFromUnsigned(const RegisterInfo *reg_info, uint64_t uval);
151 
152  // uint32_t
153  // GetStopID () const
154  // {
155  // return m_stop_id;
156  // }
157 
158  // void
159  // SetStopID (uint32_t stop_id)
160  // {
161  // m_stop_id = stop_id;
162  // }
163 
164 protected:
165  // Classes that inherit from RegisterContext can see and modify these
167  &m_thread; // The thread that this register context belongs to.
168  // uint32_t m_stop_id; // The stop ID that any data in this
169  // context is valid for
170 
171 private:
172  // For RegisterContext only
173  DISALLOW_COPY_AND_ASSIGN(NativeRegisterContext);
174 };
175 
176 } // namespace lldb_private
177 
178 #endif // liblldb_NativeRegisterContext_h_
Status WriteRegisterFromUnsigned(uint32_t reg, uint64_t uval)
uint32_t ConvertRegisterKindToRegisterNumber(uint32_t kind, uint32_t num) const
lldb::addr_t GetFlags(lldb::addr_t fail_value=0)
virtual uint32_t GetRegisterCount() const =0
virtual lldb::addr_t GetWatchpointHitAddress(uint32_t wp_index)
lldb::addr_t ReadRegisterAsUnsigned(uint32_t reg, lldb::addr_t fail_value)
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
lldb::addr_t GetFP(lldb::addr_t fail_value=LLDB_INVALID_ADDRESS)
virtual NativeThreadProtocol & GetThread()
virtual Status WriteAllRegisterValues(const lldb::DataBufferSP &data_sp)=0
NativeRegisterContext(NativeThreadProtocol &thread)
virtual Status IsWatchpointHit(uint32_t wp_index, bool &is_hit)
virtual const RegisterInfo * GetRegisterInfoAtIndex(uint32_t reg) const =0
virtual Status GetWatchpointHitIndex(uint32_t &wp_index, lldb::addr_t trap_addr)
virtual bool ClearHardwareWatchpoint(uint32_t hw_index)
lldb::addr_t GetSP(lldb::addr_t fail_value=LLDB_INVALID_ADDRESS)
virtual lldb::addr_t GetPCfromBreakpointLocation(lldb::addr_t fail_value=LLDB_INVALID_ADDRESS)
virtual uint32_t SetHardwareWatchpoint(lldb::addr_t addr, size_t size, uint32_t watch_flags)
lldb::addr_t GetReturnAddress(lldb::addr_t fail_value=LLDB_INVALID_ADDRESS)
virtual Status ReadRegister(const RegisterInfo *reg_info, RegisterValue &reg_value)=0
#define LLDB_INVALID_ADDRESS
Invalid value definitions.
Definition: lldb-defines.h:85
lldb::addr_t GetPC(lldb::addr_t fail_value=LLDB_INVALID_ADDRESS)
const RegisterInfo * GetRegisterInfoByName(llvm::StringRef reg_name, uint32_t start_idx=0)
const char * GetRegisterSetNameForRegisterAtIndex(uint32_t reg_index) const
uint64_t tid_t
Definition: lldb-types.h:86
virtual uint32_t GetUserRegisterCount() const =0
virtual Status WriteRegisterValueToMemory(const lldb_private::RegisterInfo *reg_info, lldb::addr_t dst_addr, size_t dst_len, const RegisterValue &reg_value)
uint64_t addr_t
Definition: lldb-types.h:83
virtual uint32_t SetHardwareBreakpoint(lldb::addr_t addr, size_t size)
virtual bool ClearHardwareBreakpoint(uint32_t hw_idx)
virtual lldb::addr_t GetWatchpointAddress(uint32_t wp_index)
virtual Status IsWatchpointVacant(uint32_t wp_index, bool &is_vacant)
virtual const RegisterSet * GetRegisterSet(uint32_t set_index) const =0
virtual bool HardwareSingleStep(bool enable)
virtual Status ReadRegisterValueFromMemory(const lldb_private::RegisterInfo *reg_info, lldb::addr_t src_addr, size_t src_len, RegisterValue &reg_value)
virtual Status GetHardwareBreakHitIndex(uint32_t &bp_index, lldb::addr_t trap_addr)
virtual Status ReadAllRegisterValues(lldb::DataBufferSP &data_sp)=0
virtual Status WriteRegister(const RegisterInfo *reg_info, const RegisterValue &reg_value)=0
const char * GetRegisterName(uint32_t reg)
virtual uint32_t GetRegisterSetCount() const =0
const RegisterInfo * GetRegisterInfo(uint32_t reg_kind, uint32_t reg_num)
An error handling class.
Definition: Status.h:44