1275072Semaste//===-- NativeRegisterContext.h ---------------------------------*- C++ -*-===//
2275072Semaste//
3353358Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4353358Sdim// See https://llvm.org/LICENSE.txt for license information.
5353358Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6275072Semaste//
7275072Semaste//===----------------------------------------------------------------------===//
8275072Semaste
9275072Semaste#ifndef liblldb_NativeRegisterContext_h_
10275072Semaste#define liblldb_NativeRegisterContext_h_
11275072Semaste
12314564Sdim#include "lldb/Host/common/NativeWatchpointList.h"
13275072Semaste#include "lldb/lldb-private.h"
14275072Semaste
15275072Semastenamespace lldb_private {
16275072Semaste
17275072Semasteclass NativeThreadProtocol;
18275072Semaste
19314564Sdimclass NativeRegisterContext
20314564Sdim    : public std::enable_shared_from_this<NativeRegisterContext> {
21275072Semastepublic:
22314564Sdim  // Constructors and Destructors
23327952Sdim  NativeRegisterContext(NativeThreadProtocol &thread);
24275072Semaste
25314564Sdim  virtual ~NativeRegisterContext();
26275072Semaste
27314564Sdim  // void
28314564Sdim  // InvalidateIfNeeded (bool force);
29275072Semaste
30314564Sdim  // Subclasses must override these functions
31314564Sdim  // virtual void
32314564Sdim  // InvalidateAllRegisters () = 0;
33275072Semaste
34314564Sdim  virtual uint32_t GetRegisterCount() const = 0;
35275072Semaste
36314564Sdim  virtual uint32_t GetUserRegisterCount() const = 0;
37278425Semaste
38314564Sdim  virtual const RegisterInfo *GetRegisterInfoAtIndex(uint32_t reg) const = 0;
39275072Semaste
40314564Sdim  const char *GetRegisterSetNameForRegisterAtIndex(uint32_t reg_index) const;
41275072Semaste
42314564Sdim  virtual uint32_t GetRegisterSetCount() const = 0;
43275072Semaste
44314564Sdim  virtual const RegisterSet *GetRegisterSet(uint32_t set_index) const = 0;
45275072Semaste
46321369Sdim  virtual Status ReadRegister(const RegisterInfo *reg_info,
47321369Sdim                              RegisterValue &reg_value) = 0;
48275072Semaste
49321369Sdim  virtual Status WriteRegister(const RegisterInfo *reg_info,
50321369Sdim                               const RegisterValue &reg_value) = 0;
51275072Semaste
52321369Sdim  virtual Status ReadAllRegisterValues(lldb::DataBufferSP &data_sp) = 0;
53275072Semaste
54321369Sdim  virtual Status WriteAllRegisterValues(const lldb::DataBufferSP &data_sp) = 0;
55275072Semaste
56314564Sdim  uint32_t ConvertRegisterKindToRegisterNumber(uint32_t kind,
57314564Sdim                                               uint32_t num) const;
58275072Semaste
59314564Sdim  // Subclasses can override these functions if desired
60314564Sdim  virtual uint32_t NumSupportedHardwareBreakpoints();
61275072Semaste
62314564Sdim  virtual uint32_t SetHardwareBreakpoint(lldb::addr_t addr, size_t size);
63275072Semaste
64314564Sdim  virtual bool ClearHardwareBreakpoint(uint32_t hw_idx);
65275072Semaste
66321369Sdim  virtual Status ClearAllHardwareBreakpoints();
67321369Sdim
68321369Sdim  virtual Status GetHardwareBreakHitIndex(uint32_t &bp_index,
69321369Sdim                                          lldb::addr_t trap_addr);
70321369Sdim
71314564Sdim  virtual uint32_t NumSupportedHardwareWatchpoints();
72275072Semaste
73314564Sdim  virtual uint32_t SetHardwareWatchpoint(lldb::addr_t addr, size_t size,
74314564Sdim                                         uint32_t watch_flags);
75275072Semaste
76314564Sdim  virtual bool ClearHardwareWatchpoint(uint32_t hw_index);
77275072Semaste
78321369Sdim  virtual Status ClearAllHardwareWatchpoints();
79278425Semaste
80321369Sdim  virtual Status IsWatchpointHit(uint32_t wp_index, bool &is_hit);
81285101Semaste
82321369Sdim  virtual Status GetWatchpointHitIndex(uint32_t &wp_index,
83321369Sdim                                       lldb::addr_t trap_addr);
84285101Semaste
85321369Sdim  virtual Status IsWatchpointVacant(uint32_t wp_index, bool &is_vacant);
86285101Semaste
87314564Sdim  virtual lldb::addr_t GetWatchpointAddress(uint32_t wp_index);
88285101Semaste
89314564Sdim  // MIPS Linux kernel returns a masked address (last 3bits are masked)
90341825Sdim  // when a HW watchpoint is hit. However user may not have set a watchpoint on
91341825Sdim  // this address. This function emulates the instruction at PC and finds the
92341825Sdim  // base address used in the load/store instruction. This gives the exact
93341825Sdim  // address used to read/write the variable being watched. For example: 'n' is
94341825Sdim  // at 0x120010d00 and 'm' is 0x120010d04. When a watchpoint is set at 'm',
95314564Sdim  // then watch exception is generated even when 'n' is read/written. This
96341825Sdim  // function returns address of 'n' so that client can check whether a
97341825Sdim  // watchpoint is set on this address or not.
98314564Sdim  virtual lldb::addr_t GetWatchpointHitAddress(uint32_t wp_index);
99287521Sdim
100314564Sdim  virtual bool HardwareSingleStep(bool enable);
101275072Semaste
102321369Sdim  virtual Status
103314564Sdim  ReadRegisterValueFromMemory(const lldb_private::RegisterInfo *reg_info,
104314564Sdim                              lldb::addr_t src_addr, size_t src_len,
105314564Sdim                              RegisterValue &reg_value);
106275072Semaste
107321369Sdim  virtual Status
108314564Sdim  WriteRegisterValueToMemory(const lldb_private::RegisterInfo *reg_info,
109314564Sdim                             lldb::addr_t dst_addr, size_t dst_len,
110314564Sdim                             const RegisterValue &reg_value);
111275072Semaste
112314564Sdim  // Subclasses should not override these
113314564Sdim  virtual lldb::tid_t GetThreadID() const;
114275072Semaste
115314564Sdim  virtual NativeThreadProtocol &GetThread() { return m_thread; }
116275072Semaste
117314564Sdim  const RegisterInfo *GetRegisterInfoByName(llvm::StringRef reg_name,
118314564Sdim                                            uint32_t start_idx = 0);
119275072Semaste
120314564Sdim  const RegisterInfo *GetRegisterInfo(uint32_t reg_kind, uint32_t reg_num);
121275072Semaste
122314564Sdim  lldb::addr_t GetPC(lldb::addr_t fail_value = LLDB_INVALID_ADDRESS);
123275072Semaste
124314564Sdim  virtual lldb::addr_t
125314564Sdim  GetPCfromBreakpointLocation(lldb::addr_t fail_value = LLDB_INVALID_ADDRESS);
126285101Semaste
127321369Sdim  Status SetPC(lldb::addr_t pc);
128275072Semaste
129314564Sdim  lldb::addr_t GetSP(lldb::addr_t fail_value = LLDB_INVALID_ADDRESS);
130275072Semaste
131321369Sdim  Status SetSP(lldb::addr_t sp);
132275072Semaste
133314564Sdim  lldb::addr_t GetFP(lldb::addr_t fail_value = LLDB_INVALID_ADDRESS);
134275072Semaste
135321369Sdim  Status SetFP(lldb::addr_t fp);
136275072Semaste
137314564Sdim  const char *GetRegisterName(uint32_t reg);
138275072Semaste
139314564Sdim  lldb::addr_t GetReturnAddress(lldb::addr_t fail_value = LLDB_INVALID_ADDRESS);
140275072Semaste
141314564Sdim  lldb::addr_t GetFlags(lldb::addr_t fail_value = 0);
142275072Semaste
143314564Sdim  lldb::addr_t ReadRegisterAsUnsigned(uint32_t reg, lldb::addr_t fail_value);
144275072Semaste
145314564Sdim  lldb::addr_t ReadRegisterAsUnsigned(const RegisterInfo *reg_info,
146314564Sdim                                      lldb::addr_t fail_value);
147275072Semaste
148321369Sdim  Status WriteRegisterFromUnsigned(uint32_t reg, uint64_t uval);
149275072Semaste
150321369Sdim  Status WriteRegisterFromUnsigned(const RegisterInfo *reg_info, uint64_t uval);
151275072Semaste
152314564Sdim  // uint32_t
153314564Sdim  // GetStopID () const
154314564Sdim  // {
155314564Sdim  //     return m_stop_id;
156314564Sdim  // }
157275072Semaste
158314564Sdim  // void
159314564Sdim  // SetStopID (uint32_t stop_id)
160314564Sdim  // {
161314564Sdim  //     m_stop_id = stop_id;
162314564Sdim  // }
163275072Semaste
164275072Semasteprotected:
165314564Sdim  // Classes that inherit from RegisterContext can see and modify these
166314564Sdim  NativeThreadProtocol
167314564Sdim      &m_thread; // The thread that this register context belongs to.
168314564Sdim  // uint32_t m_stop_id;             // The stop ID that any data in this
169314564Sdim  // context is valid for
170275072Semaste
171275072Semasteprivate:
172314564Sdim  // For RegisterContext only
173314564Sdim  DISALLOW_COPY_AND_ASSIGN(NativeRegisterContext);
174275072Semaste};
175275072Semaste
176275072Semaste} // namespace lldb_private
177275072Semaste
178314564Sdim#endif // liblldb_NativeRegisterContext_h_
179