Home | History | Annotate | Download | only in Target
      1 //===-- RegisterContext.h ---------------------------------------*- C++ -*-===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 #ifndef liblldb_RegisterContext_h_
     11 #define liblldb_RegisterContext_h_
     12 
     13 // C Includes
     14 // C++ Includes
     15 // Other libraries and framework includes
     16 // Project includes
     17 #include "lldb/lldb-private.h"
     18 #include "lldb/Target/ExecutionContextScope.h"
     19 
     20 namespace lldb_private {
     21 
     22 class RegisterContext :
     23     public std::enable_shared_from_this<RegisterContext>,
     24     public ExecutionContextScope
     25 {
     26 public:
     27     //------------------------------------------------------------------
     28     // Constructors and Destructors
     29     //------------------------------------------------------------------
     30     RegisterContext (Thread &thread, uint32_t concrete_frame_idx);
     31 
     32     virtual
     33     ~RegisterContext ();
     34 
     35     void
     36     InvalidateIfNeeded (bool force);
     37 
     38     //------------------------------------------------------------------
     39     // Subclasses must override these functions
     40     //------------------------------------------------------------------
     41     virtual void
     42     InvalidateAllRegisters () = 0;
     43 
     44     virtual size_t
     45     GetRegisterCount () = 0;
     46 
     47     virtual const RegisterInfo *
     48     GetRegisterInfoAtIndex (size_t reg) = 0;
     49 
     50     virtual size_t
     51     GetRegisterSetCount () = 0;
     52 
     53     virtual const RegisterSet *
     54     GetRegisterSet (size_t reg_set) = 0;
     55 
     56     virtual bool
     57     ReadRegister (const RegisterInfo *reg_info, RegisterValue &reg_value) = 0;
     58 
     59     virtual bool
     60     WriteRegister (const RegisterInfo *reg_info, const RegisterValue &reg_value) = 0;
     61 
     62     // These two functions are used to implement "push" and "pop" of register states.  They are used primarily
     63     // for expression evaluation, where we need to push a new state (storing the old one in data_sp) and then
     64     // restoring the original state by passing the data_sp we got from ReadAllRegisters to WriteAllRegisterValues.
     65     // ReadAllRegisters will do what is necessary to return a coherent set of register values for this thread, which
     66     // may mean e.g. interrupting a thread that is sitting in a kernel trap.  That is a somewhat disruptive operation,
     67     // so these API's should only be used when this behavior is needed.
     68 
     69     virtual bool
     70     ReadAllRegisterValues (lldb::DataBufferSP &data_sp) = 0;
     71 
     72     virtual bool
     73     WriteAllRegisterValues (const lldb::DataBufferSP &data_sp) = 0;
     74 
     75     bool
     76     CopyFromRegisterContext (lldb::RegisterContextSP context);
     77 
     78     virtual uint32_t
     79     ConvertRegisterKindToRegisterNumber (uint32_t kind, uint32_t num) = 0;
     80 
     81     //------------------------------------------------------------------
     82     // Subclasses can override these functions if desired
     83     //------------------------------------------------------------------
     84     virtual uint32_t
     85     NumSupportedHardwareBreakpoints ();
     86 
     87     virtual uint32_t
     88     SetHardwareBreakpoint (lldb::addr_t addr, size_t size);
     89 
     90     virtual bool
     91     ClearHardwareBreakpoint (uint32_t hw_idx);
     92 
     93     virtual uint32_t
     94     NumSupportedHardwareWatchpoints ();
     95 
     96     virtual uint32_t
     97     SetHardwareWatchpoint (lldb::addr_t addr, size_t size, bool read, bool write);
     98 
     99     virtual bool
    100     ClearHardwareWatchpoint (uint32_t hw_index);
    101 
    102     virtual bool
    103     HardwareSingleStep (bool enable);
    104 
    105     virtual Error
    106     ReadRegisterValueFromMemory (const lldb_private::RegisterInfo *reg_info, lldb::addr_t src_addr, uint32_t src_len, RegisterValue &reg_value);
    107 
    108     virtual Error
    109     WriteRegisterValueToMemory (const lldb_private::RegisterInfo *reg_info, lldb::addr_t dst_addr, uint32_t dst_len, const RegisterValue &reg_value);
    110 
    111     //------------------------------------------------------------------
    112     // Subclasses should not override these
    113     //------------------------------------------------------------------
    114     virtual lldb::tid_t
    115     GetThreadID() const;
    116 
    117     virtual Thread &
    118     GetThread ()
    119     {
    120         return m_thread;
    121     }
    122 
    123     const RegisterInfo *
    124     GetRegisterInfoByName (const char *reg_name, uint32_t start_idx = 0);
    125 
    126     uint64_t
    127     GetPC (uint64_t fail_value = LLDB_INVALID_ADDRESS);
    128 
    129     bool
    130     SetPC (uint64_t pc);
    131 
    132     uint64_t
    133     GetSP (uint64_t fail_value = LLDB_INVALID_ADDRESS);
    134 
    135     bool
    136     SetSP (uint64_t sp);
    137 
    138     uint64_t
    139     GetFP (uint64_t fail_value = LLDB_INVALID_ADDRESS);
    140 
    141     bool
    142     SetFP (uint64_t fp);
    143 
    144     const char *
    145     GetRegisterName (uint32_t reg);
    146 
    147     uint64_t
    148     GetReturnAddress (uint64_t fail_value = LLDB_INVALID_ADDRESS);
    149 
    150     uint64_t
    151     GetFlags (uint64_t fail_value = 0);
    152 
    153     uint64_t
    154     ReadRegisterAsUnsigned (uint32_t reg, uint64_t fail_value);
    155 
    156     uint64_t
    157     ReadRegisterAsUnsigned (const RegisterInfo *reg_info, uint64_t fail_value);
    158 
    159     bool
    160     WriteRegisterFromUnsigned (uint32_t reg, uint64_t uval);
    161 
    162     bool
    163     WriteRegisterFromUnsigned (const RegisterInfo *reg_info, uint64_t uval);
    164     bool
    165     ConvertBetweenRegisterKinds (int source_rk, uint32_t source_regnum, int target_rk, uint32_t& target_regnum);
    166 
    167     //------------------------------------------------------------------
    168     // lldb::ExecutionContextScope pure virtual functions
    169     //------------------------------------------------------------------
    170     virtual lldb::TargetSP
    171     CalculateTarget ();
    172 
    173     virtual lldb::ProcessSP
    174     CalculateProcess ();
    175 
    176     virtual lldb::ThreadSP
    177     CalculateThread ();
    178 
    179     virtual lldb::StackFrameSP
    180     CalculateStackFrame ();
    181 
    182     virtual void
    183     CalculateExecutionContext (ExecutionContext &exe_ctx);
    184 
    185     uint32_t
    186     GetStopID () const
    187     {
    188         return m_stop_id;
    189     }
    190 
    191     void
    192     SetStopID (uint32_t stop_id)
    193     {
    194         m_stop_id = stop_id;
    195     }
    196 
    197 protected:
    198     //------------------------------------------------------------------
    199     // Classes that inherit from RegisterContext can see and modify these
    200     //------------------------------------------------------------------
    201     Thread &m_thread;               // The thread that this register context belongs to.
    202     uint32_t m_concrete_frame_idx;    // The concrete frame index for this register context
    203     uint32_t m_stop_id;             // The stop ID that any data in this context is valid for
    204 private:
    205     //------------------------------------------------------------------
    206     // For RegisterContext only
    207     //------------------------------------------------------------------
    208     DISALLOW_COPY_AND_ASSIGN (RegisterContext);
    209 };
    210 
    211 } // namespace lldb_private
    212 
    213 #endif  // liblldb_RegisterContext_h_
    214