RegisterContext.h revision 341825
1254721Semaste//===-- RegisterContext.h ---------------------------------------*- C++ -*-===// 2254721Semaste// 3254721Semaste// The LLVM Compiler Infrastructure 4254721Semaste// 5254721Semaste// This file is distributed under the University of Illinois Open Source 6254721Semaste// License. See LICENSE.TXT for details. 7254721Semaste// 8254721Semaste//===----------------------------------------------------------------------===// 9254721Semaste 10254721Semaste#ifndef liblldb_RegisterContext_h_ 11254721Semaste#define liblldb_RegisterContext_h_ 12254721Semaste 13254721Semaste// C Includes 14254721Semaste// C++ Includes 15254721Semaste// Other libraries and framework includes 16254721Semaste// Project includes 17314564Sdim#include "lldb/Target/ExecutionContextScope.h" 18254721Semaste#include "lldb/lldb-private.h" 19254721Semaste 20254721Semastenamespace lldb_private { 21254721Semaste 22314564Sdimclass RegisterContext : public std::enable_shared_from_this<RegisterContext>, 23314564Sdim public ExecutionContextScope { 24254721Semastepublic: 25314564Sdim //------------------------------------------------------------------ 26314564Sdim // Constructors and Destructors 27314564Sdim //------------------------------------------------------------------ 28314564Sdim RegisterContext(Thread &thread, uint32_t concrete_frame_idx); 29254721Semaste 30314564Sdim ~RegisterContext() override; 31254721Semaste 32314564Sdim void InvalidateIfNeeded(bool force); 33254721Semaste 34314564Sdim //------------------------------------------------------------------ 35314564Sdim // Subclasses must override these functions 36314564Sdim //------------------------------------------------------------------ 37314564Sdim virtual void InvalidateAllRegisters() = 0; 38254721Semaste 39314564Sdim virtual size_t GetRegisterCount() = 0; 40254721Semaste 41314564Sdim virtual const RegisterInfo *GetRegisterInfoAtIndex(size_t reg) = 0; 42254721Semaste 43314564Sdim // Detect the register size dynamically. 44314564Sdim uint32_t UpdateDynamicRegisterSize(const lldb_private::ArchSpec &arch, 45314564Sdim RegisterInfo *reg_info); 46309124Sdim 47314564Sdim virtual size_t GetRegisterSetCount() = 0; 48254721Semaste 49314564Sdim virtual const RegisterSet *GetRegisterSet(size_t reg_set) = 0; 50254721Semaste 51314564Sdim virtual bool ReadRegister(const RegisterInfo *reg_info, 52314564Sdim RegisterValue ®_value) = 0; 53254721Semaste 54314564Sdim virtual bool WriteRegister(const RegisterInfo *reg_info, 55314564Sdim const RegisterValue ®_value) = 0; 56258884Semaste 57314564Sdim virtual bool ReadAllRegisterValues(lldb::DataBufferSP &data_sp) { 58314564Sdim return false; 59314564Sdim } 60276479Sdim 61314564Sdim virtual bool WriteAllRegisterValues(const lldb::DataBufferSP &data_sp) { 62314564Sdim return false; 63314564Sdim } 64254721Semaste 65314564Sdim // These two functions are used to implement "push" and "pop" of register 66341825Sdim // states. They are used primarily for expression evaluation, where we need 67341825Sdim // to push a new state (storing the old one in data_sp) and then restoring 68341825Sdim // the original state by passing the data_sp we got from ReadAllRegisters to 69341825Sdim // WriteAllRegisterValues. ReadAllRegisters will do what is necessary to 70341825Sdim // return a coherent set of register values for this thread, which may mean 71341825Sdim // e.g. interrupting a thread that is sitting in a kernel trap. That is a 72341825Sdim // somewhat disruptive operation, so these API's should only be used when 73341825Sdim // this behavior is needed. 74254721Semaste 75314564Sdim virtual bool 76314564Sdim ReadAllRegisterValues(lldb_private::RegisterCheckpoint ®_checkpoint); 77254721Semaste 78314564Sdim virtual bool WriteAllRegisterValues( 79314564Sdim const lldb_private::RegisterCheckpoint ®_checkpoint); 80254721Semaste 81314564Sdim bool CopyFromRegisterContext(lldb::RegisterContextSP context); 82254721Semaste 83314564Sdim //------------------------------------------------------------------ 84314564Sdim /// Convert from a given register numbering scheme to the lldb register 85314564Sdim /// numbering scheme 86314564Sdim /// 87314564Sdim /// There may be multiple ways to enumerate the registers for a given 88314564Sdim /// architecture. ABI references will specify one to be used with 89314564Sdim /// DWARF, the register numberings from process plugin, there may 90314564Sdim /// be a variation used for eh_frame unwind instructions (e.g. on Darwin), 91314564Sdim /// and so on. Register 5 by itself is meaningless - RegisterKind 92314564Sdim /// enumeration tells you what context that number should be translated as. 93314564Sdim /// 94314564Sdim /// Inside lldb, register numbers are in the eRegisterKindLLDB scheme; 95314564Sdim /// arguments which take a register number should take one in that 96314564Sdim /// scheme. 97314564Sdim /// 98314564Sdim /// eRegisterKindGeneric is a special numbering scheme which gives us 99314564Sdim /// constant values for the pc, frame register, stack register, etc., for 100314564Sdim /// use within lldb. They may not be defined for all architectures but 101314564Sdim /// it allows generic code to translate these common registers into the 102314564Sdim /// lldb numbering scheme. 103314564Sdim /// 104314564Sdim /// This method translates a given register kind + register number into 105314564Sdim /// the eRegisterKindLLDB register numbering. 106314564Sdim /// 107314564Sdim /// @param [in] kind 108314564Sdim /// The register numbering scheme (RegisterKind) that the following 109314564Sdim /// register number is in. 110314564Sdim /// 111314564Sdim /// @param [in] num 112314564Sdim /// A register number in the 'kind' register numbering scheme. 113314564Sdim /// 114314564Sdim /// @return 115314564Sdim /// The equivalent register number in the eRegisterKindLLDB 116314564Sdim /// numbering scheme, if possible, else LLDB_INVALID_REGNUM. 117314564Sdim //------------------------------------------------------------------ 118314564Sdim virtual uint32_t ConvertRegisterKindToRegisterNumber(lldb::RegisterKind kind, 119314564Sdim uint32_t num) = 0; 120254721Semaste 121314564Sdim //------------------------------------------------------------------ 122314564Sdim // Subclasses can override these functions if desired 123314564Sdim //------------------------------------------------------------------ 124314564Sdim virtual uint32_t NumSupportedHardwareBreakpoints(); 125254721Semaste 126314564Sdim virtual uint32_t SetHardwareBreakpoint(lldb::addr_t addr, size_t size); 127254721Semaste 128314564Sdim virtual bool ClearHardwareBreakpoint(uint32_t hw_idx); 129254721Semaste 130314564Sdim virtual uint32_t NumSupportedHardwareWatchpoints(); 131254721Semaste 132314564Sdim virtual uint32_t SetHardwareWatchpoint(lldb::addr_t addr, size_t size, 133314564Sdim bool read, bool write); 134254721Semaste 135314564Sdim virtual bool ClearHardwareWatchpoint(uint32_t hw_index); 136254721Semaste 137314564Sdim virtual bool HardwareSingleStep(bool enable); 138258054Semaste 139321369Sdim virtual Status 140314564Sdim ReadRegisterValueFromMemory(const lldb_private::RegisterInfo *reg_info, 141314564Sdim lldb::addr_t src_addr, uint32_t src_len, 142314564Sdim RegisterValue ®_value); 143254721Semaste 144321369Sdim virtual Status 145314564Sdim WriteRegisterValueToMemory(const lldb_private::RegisterInfo *reg_info, 146314564Sdim lldb::addr_t dst_addr, uint32_t dst_len, 147314564Sdim const RegisterValue ®_value); 148254721Semaste 149314564Sdim //------------------------------------------------------------------ 150314564Sdim // Subclasses should not override these 151314564Sdim //------------------------------------------------------------------ 152314564Sdim virtual lldb::tid_t GetThreadID() const; 153258054Semaste 154314564Sdim virtual Thread &GetThread() { return m_thread; } 155254721Semaste 156314564Sdim const RegisterInfo *GetRegisterInfoByName(llvm::StringRef reg_name, 157314564Sdim uint32_t start_idx = 0); 158254721Semaste 159314564Sdim const RegisterInfo *GetRegisterInfo(lldb::RegisterKind reg_kind, 160314564Sdim uint32_t reg_num); 161254721Semaste 162314564Sdim uint64_t GetPC(uint64_t fail_value = LLDB_INVALID_ADDRESS); 163254721Semaste 164314564Sdim bool SetPC(uint64_t pc); 165254721Semaste 166314564Sdim bool SetPC(Address addr); 167254721Semaste 168314564Sdim uint64_t GetSP(uint64_t fail_value = LLDB_INVALID_ADDRESS); 169254721Semaste 170314564Sdim bool SetSP(uint64_t sp); 171254721Semaste 172314564Sdim uint64_t GetFP(uint64_t fail_value = LLDB_INVALID_ADDRESS); 173254721Semaste 174314564Sdim bool SetFP(uint64_t fp); 175296417Sdim 176314564Sdim const char *GetRegisterName(uint32_t reg); 177254721Semaste 178314564Sdim uint64_t GetReturnAddress(uint64_t fail_value = LLDB_INVALID_ADDRESS); 179254721Semaste 180314564Sdim uint64_t GetFlags(uint64_t fail_value = 0); 181254721Semaste 182314564Sdim uint64_t ReadRegisterAsUnsigned(uint32_t reg, uint64_t fail_value); 183254721Semaste 184314564Sdim uint64_t ReadRegisterAsUnsigned(const RegisterInfo *reg_info, 185314564Sdim uint64_t fail_value); 186254721Semaste 187314564Sdim bool WriteRegisterFromUnsigned(uint32_t reg, uint64_t uval); 188314564Sdim 189314564Sdim bool WriteRegisterFromUnsigned(const RegisterInfo *reg_info, uint64_t uval); 190314564Sdim 191314564Sdim bool ConvertBetweenRegisterKinds(lldb::RegisterKind source_rk, 192314564Sdim uint32_t source_regnum, 193314564Sdim lldb::RegisterKind target_rk, 194314564Sdim uint32_t &target_regnum); 195314564Sdim 196314564Sdim //------------------------------------------------------------------ 197314564Sdim // lldb::ExecutionContextScope pure virtual functions 198314564Sdim //------------------------------------------------------------------ 199314564Sdim lldb::TargetSP CalculateTarget() override; 200314564Sdim 201314564Sdim lldb::ProcessSP CalculateProcess() override; 202314564Sdim 203314564Sdim lldb::ThreadSP CalculateThread() override; 204314564Sdim 205314564Sdim lldb::StackFrameSP CalculateStackFrame() override; 206314564Sdim 207314564Sdim void CalculateExecutionContext(ExecutionContext &exe_ctx) override; 208314564Sdim 209314564Sdim uint32_t GetStopID() const { return m_stop_id; } 210314564Sdim 211314564Sdim void SetStopID(uint32_t stop_id) { m_stop_id = stop_id; } 212314564Sdim 213254721Semasteprotected: 214314564Sdim //------------------------------------------------------------------ 215314564Sdim // Classes that inherit from RegisterContext can see and modify these 216314564Sdim //------------------------------------------------------------------ 217314564Sdim Thread &m_thread; // The thread that this register context belongs to. 218314564Sdim uint32_t m_concrete_frame_idx; // The concrete frame index for this register 219314564Sdim // context 220314564Sdim uint32_t m_stop_id; // The stop ID that any data in this context is valid for 221254721Semasteprivate: 222314564Sdim //------------------------------------------------------------------ 223314564Sdim // For RegisterContext only 224314564Sdim //------------------------------------------------------------------ 225314564Sdim DISALLOW_COPY_AND_ASSIGN(RegisterContext); 226254721Semaste}; 227254721Semaste 228254721Semaste} // namespace lldb_private 229254721Semaste 230296417Sdim#endif // liblldb_RegisterContext_h_ 231