RegisterContext.h revision 289afcb5e26c2527a0d2e71f84e780b86bbcf90a
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
20namespace lldb_private {
21
22class RegisterContext :
23    public std::tr1::enable_shared_from_this<RegisterContext>,
24    public ExecutionContextScope
25{
26public:
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 (uint32_t reg) = 0;
49
50    virtual size_t
51    GetRegisterSetCount () = 0;
52
53    virtual const RegisterSet *
54    GetRegisterSet (uint32_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    virtual bool
63    ReadAllRegisterValues (lldb::DataBufferSP &data_sp) = 0;
64
65    virtual bool
66    WriteAllRegisterValues (const lldb::DataBufferSP &data_sp) = 0;
67
68    virtual uint32_t
69    ConvertRegisterKindToRegisterNumber (uint32_t kind, uint32_t num) = 0;
70
71    //------------------------------------------------------------------
72    // Subclasses can override these functions if desired
73    //------------------------------------------------------------------
74    virtual uint32_t
75    NumSupportedHardwareBreakpoints ();
76
77    virtual uint32_t
78    SetHardwareBreakpoint (lldb::addr_t addr, size_t size);
79
80    virtual bool
81    ClearHardwareBreakpoint (uint32_t hw_idx);
82
83    virtual uint32_t
84    NumSupportedHardwareWatchpoints ();
85
86    virtual uint32_t
87    SetHardwareWatchpoint (lldb::addr_t addr, size_t size, bool read, bool write);
88
89    virtual bool
90    ClearHardwareWatchpoint (uint32_t hw_index);
91
92    virtual bool
93    HardwareSingleStep (bool enable);
94
95    virtual Error
96    ReadRegisterValueFromMemory (const lldb_private::RegisterInfo *reg_info, lldb::addr_t src_addr, uint32_t src_len, RegisterValue &reg_value);
97
98    virtual Error
99    WriteRegisterValueToMemory (const lldb_private::RegisterInfo *reg_info, lldb::addr_t dst_addr, uint32_t dst_len, const RegisterValue &reg_value);
100
101    //------------------------------------------------------------------
102    // Subclasses should not override these
103    //------------------------------------------------------------------
104    lldb::tid_t
105    GetThreadID() const;
106
107    Thread &
108    GetThread ()
109    {
110        return m_thread;
111    }
112
113    const RegisterInfo *
114    GetRegisterInfoByName (const char *reg_name, uint32_t start_idx = 0);
115
116    uint64_t
117    GetPC (uint64_t fail_value = LLDB_INVALID_ADDRESS);
118
119    bool
120    SetPC (uint64_t pc);
121
122    uint64_t
123    GetSP (uint64_t fail_value = LLDB_INVALID_ADDRESS);
124
125    bool
126    SetSP (uint64_t sp);
127
128    uint64_t
129    GetFP (uint64_t fail_value = LLDB_INVALID_ADDRESS);
130
131    bool
132    SetFP (uint64_t fp);
133
134    const char *
135    GetRegisterName (uint32_t reg);
136
137    uint64_t
138    GetReturnAddress (uint64_t fail_value = LLDB_INVALID_ADDRESS);
139
140    uint64_t
141    GetFlags (uint64_t fail_value = 0);
142
143    uint64_t
144    ReadRegisterAsUnsigned (uint32_t reg, uint64_t fail_value);
145
146    uint64_t
147    ReadRegisterAsUnsigned (const RegisterInfo *reg_info, uint64_t fail_value);
148
149    bool
150    WriteRegisterFromUnsigned (uint32_t reg, uint64_t uval);
151
152    bool
153    WriteRegisterFromUnsigned (const RegisterInfo *reg_info, uint64_t uval);
154    bool
155    ConvertBetweenRegisterKinds (int source_rk, uint32_t source_regnum, int target_rk, uint32_t& target_regnum);
156
157    //------------------------------------------------------------------
158    // lldb::ExecutionContextScope pure virtual functions
159    //------------------------------------------------------------------
160    virtual lldb::TargetSP
161    CalculateTarget ();
162
163    virtual lldb::ProcessSP
164    CalculateProcess ();
165
166    virtual lldb::ThreadSP
167    CalculateThread ();
168
169    virtual lldb::StackFrameSP
170    CalculateStackFrame ();
171
172    virtual void
173    CalculateExecutionContext (ExecutionContext &exe_ctx);
174
175    uint32_t
176    GetStopID () const
177    {
178        return m_stop_id;
179    }
180
181    void
182    SetStopID (uint32_t stop_id)
183    {
184        m_stop_id = stop_id;
185    }
186
187protected:
188    //------------------------------------------------------------------
189    // Classes that inherit from RegisterContext can see and modify these
190    //------------------------------------------------------------------
191    Thread &m_thread;               // The thread that this register context belongs to.
192    uint32_t m_concrete_frame_idx;    // The concrete frame index for this register context
193    uint32_t m_stop_id;             // The stop ID that any data in this context is valid for
194private:
195    //------------------------------------------------------------------
196    // For RegisterContext only
197    //------------------------------------------------------------------
198    DISALLOW_COPY_AND_ASSIGN (RegisterContext);
199};
200
201} // namespace lldb_private
202
203#endif  // liblldb_RegisterContext_h_
204