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 LLDB_HOST_COMMON_NATIVEREGISTERCONTEXT_H
10 #define LLDB_HOST_COMMON_NATIVEREGISTERCONTEXT_H
11 
13 #include "lldb/lldb-private.h"
14 
15 namespace lldb_private {
16 
17 class NativeThreadProtocol;
18 
19 enum class ExpeditedRegs { Minimal, Full };
20 
22  : public std::enable_shared_from_this<NativeRegisterContext> {
23 public:
24  // Constructors and Destructors
26 
27  virtual ~NativeRegisterContext();
28 
29  // void
30  // InvalidateIfNeeded (bool force);
31 
32  // Subclasses must override these functions
33  // virtual void
34  // InvalidateAllRegisters () = 0;
35 
36  virtual uint32_t GetRegisterCount() const = 0;
37 
38  virtual uint32_t GetUserRegisterCount() const = 0;
39 
40  virtual const RegisterInfo *GetRegisterInfoAtIndex(uint32_t reg) const = 0;
41 
42  const char *GetRegisterSetNameForRegisterAtIndex(uint32_t reg_index) const;
43 
44  virtual uint32_t GetRegisterSetCount() const = 0;
45 
46  virtual const RegisterSet *GetRegisterSet(uint32_t set_index) const = 0;
47 
48  virtual Status ReadRegister(const RegisterInfo *reg_info,
49  RegisterValue &reg_value) = 0;
50 
51  virtual Status WriteRegister(const RegisterInfo *reg_info,
52  const RegisterValue &reg_value) = 0;
53 
54  virtual Status ReadAllRegisterValues(lldb::DataBufferSP &data_sp) = 0;
55 
56  virtual Status WriteAllRegisterValues(const lldb::DataBufferSP &data_sp) = 0;
57 
59  uint32_t num) const;
60 
61  // Subclasses can override these functions if desired
63 
64  virtual uint32_t SetHardwareBreakpoint(lldb::addr_t addr, size_t size);
65 
66  virtual bool ClearHardwareBreakpoint(uint32_t hw_idx);
67 
69 
70  virtual Status GetHardwareBreakHitIndex(uint32_t &bp_index,
71  lldb::addr_t trap_addr);
72 
74 
75  virtual uint32_t SetHardwareWatchpoint(lldb::addr_t addr, size_t size,
76  uint32_t watch_flags);
77 
78  virtual bool ClearHardwareWatchpoint(uint32_t hw_index);
79 
80  virtual Status ClearWatchpointHit(uint32_t hw_index);
81 
83 
84  virtual Status IsWatchpointHit(uint32_t wp_index, bool &is_hit);
85 
86  virtual Status GetWatchpointHitIndex(uint32_t &wp_index,
87  lldb::addr_t trap_addr);
88 
89  virtual Status IsWatchpointVacant(uint32_t wp_index, bool &is_vacant);
90 
91  virtual lldb::addr_t GetWatchpointAddress(uint32_t wp_index);
92 
93  // MIPS Linux kernel returns a masked address (last 3bits are masked)
94  // when a HW watchpoint is hit. However user may not have set a watchpoint on
95  // this address. This function emulates the instruction at PC and finds the
96  // base address used in the load/store instruction. This gives the exact
97  // address used to read/write the variable being watched. For example: 'n' is
98  // at 0x120010d00 and 'm' is 0x120010d04. When a watchpoint is set at 'm',
99  // then watch exception is generated even when 'n' is read/written. This
100  // function returns address of 'n' so that client can check whether a
101  // watchpoint is set on this address or not.
103 
104  virtual bool HardwareSingleStep(bool enable);
105 
106  virtual Status
107  ReadRegisterValueFromMemory(const lldb_private::RegisterInfo *reg_info,
108  lldb::addr_t src_addr, size_t src_len,
109  RegisterValue &reg_value);
110 
111  virtual Status
112  WriteRegisterValueToMemory(const lldb_private::RegisterInfo *reg_info,
113  lldb::addr_t dst_addr, size_t dst_len,
114  const RegisterValue &reg_value);
115 
116  // Subclasses should not override these
117  virtual lldb::tid_t GetThreadID() const;
118 
119  virtual NativeThreadProtocol &GetThread() { return m_thread; }
120 
121  virtual std::vector<uint32_t>
122  GetExpeditedRegisters(ExpeditedRegs expType) const;
123 
124  virtual bool RegisterOffsetIsDynamic() const { return false; }
125 
126  const RegisterInfo *GetRegisterInfoByName(llvm::StringRef reg_name,
127  uint32_t start_idx = 0);
128 
129  const RegisterInfo *GetRegisterInfo(uint32_t reg_kind, uint32_t reg_num);
130 
132 
133  virtual lldb::addr_t
135 
137 
139 
141 
143 
145 
146  const char *GetRegisterName(uint32_t reg);
147 
149 
150  lldb::addr_t GetFlags(lldb::addr_t fail_value = 0);
151 
153 
154  lldb::addr_t ReadRegisterAsUnsigned(const RegisterInfo *reg_info,
155  lldb::addr_t fail_value);
156 
157  Status WriteRegisterFromUnsigned(uint32_t reg, uint64_t uval);
158 
159  Status WriteRegisterFromUnsigned(const RegisterInfo *reg_info, uint64_t uval);
160 
161  // uint32_t
162  // GetStopID () const
163  // {
164  // return m_stop_id;
165  // }
166 
167  // void
168  // SetStopID (uint32_t stop_id)
169  // {
170  // m_stop_id = stop_id;
171  // }
172 
173 protected:
174  // Classes that inherit from RegisterContext can see and modify these
176  &m_thread; // The thread that this register context belongs to.
177  // uint32_t m_stop_id; // The stop ID that any data in this
178  // context is valid for
179 
180 private:
181  // For RegisterContext only
183  const NativeRegisterContext &
184  operator=(const NativeRegisterContext &) = delete;
185 };
186 
187 } // namespace lldb_private
188 
189 #endif // LLDB_HOST_COMMON_NATIVEREGISTERCONTEXT_H
lldb_private::NativeRegisterContext::GetRegisterCount
virtual uint32_t GetRegisterCount() const =0
lldb_private::NativeRegisterContext::ClearHardwareWatchpoint
virtual bool ClearHardwareWatchpoint(uint32_t hw_index)
Definition: NativeRegisterContext.cpp:277
lldb_private::NativeRegisterContext::HardwareSingleStep
virtual bool HardwareSingleStep(bool enable)
Definition: NativeRegisterContext.cpp:314
lldb_private::NativeRegisterContext::GetWatchpointHitIndex
virtual Status GetWatchpointHitIndex(uint32_t &wp_index, lldb::addr_t trap_addr)
Definition: NativeRegisterContext.cpp:294
lldb_private::NativeRegisterContext::ReadRegister
virtual Status ReadRegister(const RegisterInfo *reg_info, RegisterValue &reg_value)=0
lldb_private::RegisterValue
Definition: RegisterValue.h:28
lldb_private::NativeThreadProtocol
Definition: NativeThreadProtocol.h:20
lldb_private::NativeRegisterContext::WriteRegisterFromUnsigned
Status WriteRegisterFromUnsigned(uint32_t reg, uint64_t uval)
Definition: NativeRegisterContext.cpp:223
lldb_private::NativeRegisterContext::IsWatchpointVacant
virtual Status IsWatchpointVacant(uint32_t wp_index, bool &is_vacant)
Definition: NativeRegisterContext.cpp:300
lldb_private::NativeRegisterContext::SetHardwareBreakpoint
virtual uint32_t SetHardwareBreakpoint(lldb::addr_t addr, size_t size)
Definition: NativeRegisterContext.cpp:250
lldb_private::NativeRegisterContext::GetRegisterInfoByName
const RegisterInfo * GetRegisterInfoByName(llvm::StringRef reg_name, uint32_t start_idx=0)
Definition: NativeRegisterContext.cpp:54
lldb_private::NativeRegisterContext::RegisterOffsetIsDynamic
virtual bool RegisterOffsetIsDynamic() const
Definition: NativeRegisterContext.h:124
lldb_private::ExpeditedRegs::Minimal
@ Minimal
lldb_private::NativeRegisterContext::ClearAllHardwareBreakpoints
virtual Status ClearAllHardwareBreakpoints()
Definition: NativeRegisterContext.cpp:255
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
pc
@ pc
Definition: CompactUnwindInfo.cpp:1250
NativeWatchpointList.h
lldb_private::NativeRegisterContext::ClearWatchpointHit
virtual Status ClearWatchpointHit(uint32_t hw_index)
Definition: NativeRegisterContext.cpp:281
lldb_private::NativeRegisterContext::NativeRegisterContext
NativeRegisterContext(NativeThreadProtocol &thread)
Definition: NativeRegisterContext.cpp:21
lldb_private::NativeRegisterContext::SetPC
Status SetPC(lldb::addr_t pc)
Definition: NativeRegisterContext.cpp:147
lldb_private::NativeRegisterContext::GetRegisterName
const char * GetRegisterName(uint32_t reg)
Definition: NativeRegisterContext.cpp:90
lldb_private::NativeRegisterContext::GetThread
virtual NativeThreadProtocol & GetThread()
Definition: NativeRegisterContext.h:119
lldb_private::NativeRegisterContext::ReadRegisterAsUnsigned
lldb::addr_t ReadRegisterAsUnsigned(uint32_t reg, lldb::addr_t fail_value)
Definition: NativeRegisterContext.cpp:190
lldb_private::NativeRegisterContext::GetRegisterInfo
const RegisterInfo * GetRegisterInfo(uint32_t reg_kind, uint32_t reg_num)
Definition: NativeRegisterContext.cpp:82
lldb_private::NativeRegisterContext::ConvertRegisterKindToRegisterNumber
uint32_t ConvertRegisterKindToRegisterNumber(uint32_t kind, uint32_t num) const
Definition: NativeRegisterContext.cpp:425
lldb_private::NativeRegisterContext::GetWatchpointHitAddress
virtual lldb::addr_t GetWatchpointHitAddress(uint32_t wp_index)
Definition: NativeRegisterContext.cpp:310
lldb_private::NativeRegisterContext::GetSP
lldb::addr_t GetSP(lldb::addr_t fail_value=LLDB_INVALID_ADDRESS)
Definition: NativeRegisterContext.cpp:153
lldb_private::NativeRegisterContext::GetRegisterInfoAtIndex
virtual const RegisterInfo * GetRegisterInfoAtIndex(uint32_t reg) const =0
lldb_private::NativeRegisterContext::SetFP
Status SetFP(lldb::addr_t fp)
Definition: NativeRegisterContext.cpp:171
lldb_private::NativeRegisterContext::GetRegisterSetNameForRegisterAtIndex
const char * GetRegisterSetNameForRegisterAtIndex(uint32_t reg_index) const
Definition: NativeRegisterContext.cpp:97
lldb_private::NativeRegisterContext::ReadRegisterValueFromMemory
virtual Status ReadRegisterValueFromMemory(const lldb_private::RegisterInfo *reg_info, lldb::addr_t src_addr, size_t src_len, RegisterValue &reg_value)
Definition: NativeRegisterContext.cpp:316
lldb_private::NativeRegisterContext::GetExpeditedRegisters
virtual std::vector< uint32_t > GetExpeditedRegisters(ExpeditedRegs expType) const
Definition: NativeRegisterContext.cpp:441
lldb_private::NativeRegisterContext::SetSP
Status SetSP(lldb::addr_t sp)
Definition: NativeRegisterContext.cpp:159
lldb_private::NativeRegisterContext::NumSupportedHardwareBreakpoints
virtual uint32_t NumSupportedHardwareBreakpoints()
Definition: NativeRegisterContext.cpp:248
sp
@ sp
Definition: CompactUnwindInfo.cpp:1249
lldb_private::NativeRegisterContext::ReadAllRegisterValues
virtual Status ReadAllRegisterValues(lldb::DataBufferSP &data_sp)=0
lldb_private::NativeRegisterContext::GetRegisterSet
virtual const RegisterSet * GetRegisterSet(uint32_t set_index) const =0
lldb_private::NativeRegisterContext::operator=
const NativeRegisterContext & operator=(const NativeRegisterContext &)=delete
lldb-private.h
lldb_private::NativeRegisterContext::~NativeRegisterContext
virtual ~NativeRegisterContext()
lldb_private::NativeRegisterContext::ClearHardwareBreakpoint
virtual bool ClearHardwareBreakpoint(uint32_t hw_idx)
Definition: NativeRegisterContext.cpp:259
lldb_private::Status
Definition: Status.h:44
lldb_private::NativeRegisterContext::WriteRegisterValueToMemory
virtual Status WriteRegisterValueToMemory(const lldb_private::RegisterInfo *reg_info, lldb::addr_t dst_addr, size_t dst_len, const RegisterValue &reg_value)
Definition: NativeRegisterContext.cpp:386
uint32_t
lldb_private::NativeRegisterContext::GetFP
lldb::addr_t GetFP(lldb::addr_t fail_value=LLDB_INVALID_ADDRESS)
Definition: NativeRegisterContext.cpp:165
lldb_private::NativeRegisterContext::GetRegisterSetCount
virtual uint32_t GetRegisterSetCount() const =0
lldb_private::NativeRegisterContext::GetUserRegisterCount
virtual uint32_t GetUserRegisterCount() const =0
lldb_private::NativeRegisterContext::GetHardwareBreakHitIndex
virtual Status GetHardwareBreakHitIndex(uint32_t &bp_index, lldb::addr_t trap_addr)
Definition: NativeRegisterContext.cpp:263
LLDB_INVALID_ADDRESS
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:86
lldb_private::NativeRegisterContext::GetPC
lldb::addr_t GetPC(lldb::addr_t fail_value=LLDB_INVALID_ADDRESS)
Definition: NativeRegisterContext.cpp:124
lldb_private::NativeRegisterContext::ClearAllHardwareWatchpoints
virtual Status ClearAllHardwareWatchpoints()
Definition: NativeRegisterContext.cpp:285
lldb_private::NativeRegisterContext::NumSupportedHardwareWatchpoints
virtual uint32_t NumSupportedHardwareWatchpoints()
Definition: NativeRegisterContext.cpp:269
lldb_private::NativeRegisterContext::m_thread
NativeThreadProtocol & m_thread
Definition: NativeRegisterContext.h:176
lldb_private::NativeRegisterContext::GetPCfromBreakpointLocation
virtual lldb::addr_t GetPCfromBreakpointLocation(lldb::addr_t fail_value=LLDB_INVALID_ADDRESS)
Definition: NativeRegisterContext.cpp:143
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::NativeRegisterContext::WriteRegister
virtual Status WriteRegister(const RegisterInfo *reg_info, const RegisterValue &reg_value)=0
lldb_private::NativeRegisterContext::GetThreadID
virtual lldb::tid_t GetThreadID() const
Definition: NativeRegisterContext.cpp:244
lldb_private::NativeRegisterContext
Definition: NativeRegisterContext.h:21
lldb_private::NativeRegisterContext::GetFlags
lldb::addr_t GetFlags(lldb::addr_t fail_value=0)
Definition: NativeRegisterContext.cpp:183
fp
@ fp
Definition: CompactUnwindInfo.cpp:1247
lldb_private::NativeRegisterContext::SetHardwareWatchpoint
virtual uint32_t SetHardwareWatchpoint(lldb::addr_t addr, size_t size, uint32_t watch_flags)
Definition: NativeRegisterContext.cpp:271
lldb_private::NativeRegisterContext::WriteAllRegisterValues
virtual Status WriteAllRegisterValues(const lldb::DataBufferSP &data_sp)=0
lldb_private::NativeRegisterContext::IsWatchpointHit
virtual Status IsWatchpointHit(uint32_t wp_index, bool &is_hit)
Definition: NativeRegisterContext.cpp:289
lldb_private::NativeRegisterContext::GetWatchpointAddress
virtual lldb::addr_t GetWatchpointAddress(uint32_t wp_index)
Definition: NativeRegisterContext.cpp:306
lldb_private::NativeRegisterContext::GetReturnAddress
lldb::addr_t GetReturnAddress(lldb::addr_t fail_value=LLDB_INVALID_ADDRESS)
Definition: NativeRegisterContext.cpp:177
lldb::tid_t
uint64_t tid_t
Definition: lldb-types.h:86
lldb_private::ExpeditedRegs
ExpeditedRegs
Definition: NativeRegisterContext.h:19
lldb_private::ExpeditedRegs::Full
@ Full