1 //===-- RegisterContext.h ---------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_RegisterContext_h_
11 #define liblldb_RegisterContext_h_
15 // Other libraries and framework includes
17 #include "lldb/lldb-private.h"
18 #include "lldb/Target/ExecutionContextScope.h"
20 namespace lldb_private {
22 class RegisterContext :
23 public std::enable_shared_from_this<RegisterContext>,
24 public ExecutionContextScope
27 //------------------------------------------------------------------
28 // Constructors and Destructors
29 //------------------------------------------------------------------
30 RegisterContext (Thread &thread, uint32_t concrete_frame_idx);
36 InvalidateIfNeeded (bool force);
38 //------------------------------------------------------------------
39 // Subclasses must override these functions
40 //------------------------------------------------------------------
42 InvalidateAllRegisters () = 0;
45 GetRegisterCount () = 0;
47 virtual const RegisterInfo *
48 GetRegisterInfoAtIndex (size_t reg) = 0;
51 GetRegisterSetCount () = 0;
53 virtual const RegisterSet *
54 GetRegisterSet (size_t reg_set) = 0;
57 ReadRegister (const RegisterInfo *reg_info, RegisterValue ®_value) = 0;
60 WriteRegister (const RegisterInfo *reg_info, const RegisterValue ®_value) = 0;
63 ReadAllRegisterValues (lldb::DataBufferSP &data_sp)
69 WriteAllRegisterValues (const lldb::DataBufferSP &data_sp)
74 // These two functions are used to implement "push" and "pop" of register states. They are used primarily
75 // for expression evaluation, where we need to push a new state (storing the old one in data_sp) and then
76 // restoring the original state by passing the data_sp we got from ReadAllRegisters to WriteAllRegisterValues.
77 // ReadAllRegisters will do what is necessary to return a coherent set of register values for this thread, which
78 // may mean e.g. interrupting a thread that is sitting in a kernel trap. That is a somewhat disruptive operation,
79 // so these API's should only be used when this behavior is needed.
82 ReadAllRegisterValues (lldb_private::RegisterCheckpoint ®_checkpoint);
85 WriteAllRegisterValues (const lldb_private::RegisterCheckpoint ®_checkpoint);
88 CopyFromRegisterContext (lldb::RegisterContextSP context);
91 ConvertRegisterKindToRegisterNumber (uint32_t kind, uint32_t num) = 0;
93 //------------------------------------------------------------------
94 // Subclasses can override these functions if desired
95 //------------------------------------------------------------------
97 NumSupportedHardwareBreakpoints ();
100 SetHardwareBreakpoint (lldb::addr_t addr, size_t size);
103 ClearHardwareBreakpoint (uint32_t hw_idx);
106 NumSupportedHardwareWatchpoints ();
109 SetHardwareWatchpoint (lldb::addr_t addr, size_t size, bool read, bool write);
112 ClearHardwareWatchpoint (uint32_t hw_index);
115 HardwareSingleStep (bool enable);
118 ReadRegisterValueFromMemory (const lldb_private::RegisterInfo *reg_info, lldb::addr_t src_addr, uint32_t src_len, RegisterValue ®_value);
121 WriteRegisterValueToMemory (const lldb_private::RegisterInfo *reg_info, lldb::addr_t dst_addr, uint32_t dst_len, const RegisterValue ®_value);
123 //------------------------------------------------------------------
124 // Subclasses should not override these
125 //------------------------------------------------------------------
136 GetRegisterInfoByName (const char *reg_name, uint32_t start_idx = 0);
139 GetRegisterInfo (uint32_t reg_kind, uint32_t reg_num);
142 GetPC (uint64_t fail_value = LLDB_INVALID_ADDRESS);
147 bool SetPC (Address addr);
150 GetSP (uint64_t fail_value = LLDB_INVALID_ADDRESS);
156 GetFP (uint64_t fail_value = LLDB_INVALID_ADDRESS);
162 GetRegisterName (uint32_t reg);
165 GetReturnAddress (uint64_t fail_value = LLDB_INVALID_ADDRESS);
168 GetFlags (uint64_t fail_value = 0);
171 ReadRegisterAsUnsigned (uint32_t reg, uint64_t fail_value);
174 ReadRegisterAsUnsigned (const RegisterInfo *reg_info, uint64_t fail_value);
177 WriteRegisterFromUnsigned (uint32_t reg, uint64_t uval);
180 WriteRegisterFromUnsigned (const RegisterInfo *reg_info, uint64_t uval);
182 ConvertBetweenRegisterKinds (int source_rk, uint32_t source_regnum, int target_rk, uint32_t& target_regnum);
184 //------------------------------------------------------------------
185 // lldb::ExecutionContextScope pure virtual functions
186 //------------------------------------------------------------------
187 virtual lldb::TargetSP
190 virtual lldb::ProcessSP
193 virtual lldb::ThreadSP
196 virtual lldb::StackFrameSP
197 CalculateStackFrame ();
200 CalculateExecutionContext (ExecutionContext &exe_ctx);
209 SetStopID (uint32_t stop_id)
215 //------------------------------------------------------------------
216 // Classes that inherit from RegisterContext can see and modify these
217 //------------------------------------------------------------------
218 Thread &m_thread; // The thread that this register context belongs to.
219 uint32_t m_concrete_frame_idx; // The concrete frame index for this register context
220 uint32_t m_stop_id; // The stop ID that any data in this context is valid for
222 //------------------------------------------------------------------
223 // For RegisterContext only
224 //------------------------------------------------------------------
225 DISALLOW_COPY_AND_ASSIGN (RegisterContext);
228 } // namespace lldb_private
230 #endif // liblldb_RegisterContext_h_