1254721Semaste//===-- RegisterContext.h ---------------------------------------*- C++ -*-===// 2254721Semaste// 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 6254721Semaste// 7254721Semaste//===----------------------------------------------------------------------===// 8254721Semaste 9254721Semaste#ifndef liblldb_RegisterContext_h_ 10254721Semaste#define liblldb_RegisterContext_h_ 11254721Semaste 12314564Sdim#include "lldb/Target/ExecutionContextScope.h" 13254721Semaste#include "lldb/lldb-private.h" 14254721Semaste 15254721Semastenamespace lldb_private { 16254721Semaste 17314564Sdimclass RegisterContext : public std::enable_shared_from_this<RegisterContext>, 18314564Sdim public ExecutionContextScope { 19254721Semastepublic: 20314564Sdim // Constructors and Destructors 21314564Sdim RegisterContext(Thread &thread, uint32_t concrete_frame_idx); 22254721Semaste 23314564Sdim ~RegisterContext() override; 24254721Semaste 25314564Sdim void InvalidateIfNeeded(bool force); 26254721Semaste 27314564Sdim // Subclasses must override these functions 28314564Sdim virtual void InvalidateAllRegisters() = 0; 29254721Semaste 30314564Sdim virtual size_t GetRegisterCount() = 0; 31254721Semaste 32314564Sdim virtual const RegisterInfo *GetRegisterInfoAtIndex(size_t reg) = 0; 33254721Semaste 34314564Sdim // Detect the register size dynamically. 35314564Sdim uint32_t UpdateDynamicRegisterSize(const lldb_private::ArchSpec &arch, 36314564Sdim RegisterInfo *reg_info); 37309124Sdim 38314564Sdim virtual size_t GetRegisterSetCount() = 0; 39254721Semaste 40314564Sdim virtual const RegisterSet *GetRegisterSet(size_t reg_set) = 0; 41254721Semaste 42314564Sdim virtual bool ReadRegister(const RegisterInfo *reg_info, 43314564Sdim RegisterValue ®_value) = 0; 44254721Semaste 45314564Sdim virtual bool WriteRegister(const RegisterInfo *reg_info, 46314564Sdim const RegisterValue ®_value) = 0; 47258884Semaste 48314564Sdim virtual bool ReadAllRegisterValues(lldb::DataBufferSP &data_sp) { 49314564Sdim return false; 50314564Sdim } 51276479Sdim 52314564Sdim virtual bool WriteAllRegisterValues(const lldb::DataBufferSP &data_sp) { 53314564Sdim return false; 54314564Sdim } 55254721Semaste 56314564Sdim // These two functions are used to implement "push" and "pop" of register 57341825Sdim // states. They are used primarily for expression evaluation, where we need 58341825Sdim // to push a new state (storing the old one in data_sp) and then restoring 59341825Sdim // the original state by passing the data_sp we got from ReadAllRegisters to 60341825Sdim // WriteAllRegisterValues. ReadAllRegisters will do what is necessary to 61341825Sdim // return a coherent set of register values for this thread, which may mean 62341825Sdim // e.g. interrupting a thread that is sitting in a kernel trap. That is a 63341825Sdim // somewhat disruptive operation, so these API's should only be used when 64341825Sdim // this behavior is needed. 65254721Semaste 66314564Sdim virtual bool 67314564Sdim ReadAllRegisterValues(lldb_private::RegisterCheckpoint ®_checkpoint); 68254721Semaste 69314564Sdim virtual bool WriteAllRegisterValues( 70314564Sdim const lldb_private::RegisterCheckpoint ®_checkpoint); 71254721Semaste 72314564Sdim bool CopyFromRegisterContext(lldb::RegisterContextSP context); 73254721Semaste 74314564Sdim /// Convert from a given register numbering scheme to the lldb register 75314564Sdim /// numbering scheme 76314564Sdim /// 77314564Sdim /// There may be multiple ways to enumerate the registers for a given 78314564Sdim /// architecture. ABI references will specify one to be used with 79314564Sdim /// DWARF, the register numberings from process plugin, there may 80314564Sdim /// be a variation used for eh_frame unwind instructions (e.g. on Darwin), 81314564Sdim /// and so on. Register 5 by itself is meaningless - RegisterKind 82314564Sdim /// enumeration tells you what context that number should be translated as. 83314564Sdim /// 84314564Sdim /// Inside lldb, register numbers are in the eRegisterKindLLDB scheme; 85314564Sdim /// arguments which take a register number should take one in that 86314564Sdim /// scheme. 87314564Sdim /// 88314564Sdim /// eRegisterKindGeneric is a special numbering scheme which gives us 89314564Sdim /// constant values for the pc, frame register, stack register, etc., for 90314564Sdim /// use within lldb. They may not be defined for all architectures but 91314564Sdim /// it allows generic code to translate these common registers into the 92314564Sdim /// lldb numbering scheme. 93314564Sdim /// 94314564Sdim /// This method translates a given register kind + register number into 95314564Sdim /// the eRegisterKindLLDB register numbering. 96314564Sdim /// 97353358Sdim /// \param [in] kind 98314564Sdim /// The register numbering scheme (RegisterKind) that the following 99314564Sdim /// register number is in. 100314564Sdim /// 101353358Sdim /// \param [in] num 102314564Sdim /// A register number in the 'kind' register numbering scheme. 103314564Sdim /// 104353358Sdim /// \return 105314564Sdim /// The equivalent register number in the eRegisterKindLLDB 106314564Sdim /// numbering scheme, if possible, else LLDB_INVALID_REGNUM. 107314564Sdim virtual uint32_t ConvertRegisterKindToRegisterNumber(lldb::RegisterKind kind, 108314564Sdim uint32_t num) = 0; 109254721Semaste 110314564Sdim // Subclasses can override these functions if desired 111314564Sdim virtual uint32_t NumSupportedHardwareBreakpoints(); 112254721Semaste 113314564Sdim virtual uint32_t SetHardwareBreakpoint(lldb::addr_t addr, size_t size); 114254721Semaste 115314564Sdim virtual bool ClearHardwareBreakpoint(uint32_t hw_idx); 116254721Semaste 117314564Sdim virtual uint32_t NumSupportedHardwareWatchpoints(); 118254721Semaste 119314564Sdim virtual uint32_t SetHardwareWatchpoint(lldb::addr_t addr, size_t size, 120314564Sdim bool read, bool write); 121254721Semaste 122314564Sdim virtual bool ClearHardwareWatchpoint(uint32_t hw_index); 123254721Semaste 124314564Sdim virtual bool HardwareSingleStep(bool enable); 125258054Semaste 126321369Sdim virtual Status 127314564Sdim ReadRegisterValueFromMemory(const lldb_private::RegisterInfo *reg_info, 128314564Sdim lldb::addr_t src_addr, uint32_t src_len, 129314564Sdim RegisterValue ®_value); 130254721Semaste 131321369Sdim virtual Status 132314564Sdim WriteRegisterValueToMemory(const lldb_private::RegisterInfo *reg_info, 133314564Sdim lldb::addr_t dst_addr, uint32_t dst_len, 134314564Sdim const RegisterValue ®_value); 135254721Semaste 136314564Sdim // Subclasses should not override these 137314564Sdim virtual lldb::tid_t GetThreadID() const; 138258054Semaste 139314564Sdim virtual Thread &GetThread() { return m_thread; } 140254721Semaste 141314564Sdim const RegisterInfo *GetRegisterInfoByName(llvm::StringRef reg_name, 142314564Sdim uint32_t start_idx = 0); 143254721Semaste 144314564Sdim const RegisterInfo *GetRegisterInfo(lldb::RegisterKind reg_kind, 145314564Sdim uint32_t reg_num); 146254721Semaste 147314564Sdim uint64_t GetPC(uint64_t fail_value = LLDB_INVALID_ADDRESS); 148254721Semaste 149314564Sdim bool SetPC(uint64_t pc); 150254721Semaste 151314564Sdim bool SetPC(Address addr); 152254721Semaste 153314564Sdim uint64_t GetSP(uint64_t fail_value = LLDB_INVALID_ADDRESS); 154254721Semaste 155314564Sdim bool SetSP(uint64_t sp); 156254721Semaste 157314564Sdim uint64_t GetFP(uint64_t fail_value = LLDB_INVALID_ADDRESS); 158254721Semaste 159314564Sdim bool SetFP(uint64_t fp); 160296417Sdim 161314564Sdim const char *GetRegisterName(uint32_t reg); 162254721Semaste 163314564Sdim uint64_t GetReturnAddress(uint64_t fail_value = LLDB_INVALID_ADDRESS); 164254721Semaste 165314564Sdim uint64_t GetFlags(uint64_t fail_value = 0); 166254721Semaste 167314564Sdim uint64_t ReadRegisterAsUnsigned(uint32_t reg, uint64_t fail_value); 168254721Semaste 169314564Sdim uint64_t ReadRegisterAsUnsigned(const RegisterInfo *reg_info, 170314564Sdim uint64_t fail_value); 171254721Semaste 172314564Sdim bool WriteRegisterFromUnsigned(uint32_t reg, uint64_t uval); 173314564Sdim 174314564Sdim bool WriteRegisterFromUnsigned(const RegisterInfo *reg_info, uint64_t uval); 175314564Sdim 176314564Sdim bool ConvertBetweenRegisterKinds(lldb::RegisterKind source_rk, 177314564Sdim uint32_t source_regnum, 178314564Sdim lldb::RegisterKind target_rk, 179314564Sdim uint32_t &target_regnum); 180314564Sdim 181314564Sdim // lldb::ExecutionContextScope pure virtual functions 182314564Sdim lldb::TargetSP CalculateTarget() override; 183314564Sdim 184314564Sdim lldb::ProcessSP CalculateProcess() override; 185314564Sdim 186314564Sdim lldb::ThreadSP CalculateThread() override; 187314564Sdim 188314564Sdim lldb::StackFrameSP CalculateStackFrame() override; 189314564Sdim 190314564Sdim void CalculateExecutionContext(ExecutionContext &exe_ctx) override; 191314564Sdim 192314564Sdim uint32_t GetStopID() const { return m_stop_id; } 193314564Sdim 194314564Sdim void SetStopID(uint32_t stop_id) { m_stop_id = stop_id; } 195314564Sdim 196254721Semasteprotected: 197314564Sdim // Classes that inherit from RegisterContext can see and modify these 198314564Sdim Thread &m_thread; // The thread that this register context belongs to. 199314564Sdim uint32_t m_concrete_frame_idx; // The concrete frame index for this register 200314564Sdim // context 201314564Sdim uint32_t m_stop_id; // The stop ID that any data in this context is valid for 202254721Semasteprivate: 203314564Sdim // For RegisterContext only 204314564Sdim DISALLOW_COPY_AND_ASSIGN(RegisterContext); 205254721Semaste}; 206254721Semaste 207254721Semaste} // namespace lldb_private 208254721Semaste 209296417Sdim#endif // liblldb_RegisterContext_h_ 210