RegisterContext.h revision 24943d2ee8bfaa7cf5893e4709143924157a5c1e
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 ExecutionContextScope
24{
25public:
26    //------------------------------------------------------------------
27    // Constructors and Destructors
28    //------------------------------------------------------------------
29    RegisterContext (Thread &thread, StackFrame *frame);
30
31    virtual
32    ~RegisterContext ();
33
34    //------------------------------------------------------------------
35    // Subclasses must override these functions
36    //------------------------------------------------------------------
37    virtual void
38    Invalidate () = 0;
39
40    virtual size_t
41    GetRegisterCount () = 0;
42
43    virtual const lldb::RegisterInfo *
44    GetRegisterInfoAtIndex (uint32_t reg) = 0;
45
46    virtual size_t
47    GetRegisterSetCount () = 0;
48
49    virtual const lldb::RegisterSet *
50    GetRegisterSet (uint32_t reg_set) = 0;
51
52    virtual bool
53    ReadRegisterValue (uint32_t reg, Scalar &value) = 0;
54
55    virtual bool
56    ReadRegisterBytes (uint32_t reg, DataExtractor &data) = 0;
57
58    virtual bool
59    ReadAllRegisterValues (lldb::DataBufferSP &data_sp) = 0;
60
61    virtual bool
62    WriteRegisterValue (uint32_t reg, const Scalar &value) = 0;
63
64    virtual bool
65    WriteRegisterBytes (uint32_t reg, DataExtractor &data, uint32_t data_offset = 0) = 0;
66
67    virtual bool
68    WriteAllRegisterValues (const lldb::DataBufferSP &data_sp) = 0;
69
70    virtual uint32_t
71    ConvertRegisterKindToRegisterNumber (uint32_t kind, uint32_t num) = 0;
72
73    //------------------------------------------------------------------
74    // Subclasses can override these functions if desired
75    //------------------------------------------------------------------
76    virtual uint32_t
77    NumSupportedHardwareBreakpoints ();
78
79    virtual uint32_t
80    SetHardwareBreakpoint (lldb::addr_t addr, size_t size);
81
82    virtual bool
83    ClearHardwareBreakpoint (uint32_t hw_idx);
84
85    virtual uint32_t
86    NumSupportedHardwareWatchpoints ();
87
88    virtual uint32_t
89    SetHardwareWatchpoint (lldb::addr_t addr, size_t size, bool read, bool write);
90
91    virtual bool
92    ClearHardwareWatchpoint (uint32_t hw_index);
93
94    virtual bool
95    HardwareSingleStep (bool enable);
96
97    //------------------------------------------------------------------
98    // Subclasses should not override these
99    //------------------------------------------------------------------
100    lldb::tid_t
101    GetThreadID() const;
102
103    const lldb::RegisterInfo *
104    GetRegisterInfoByName (const char *reg_name, uint32_t start_idx = 0);
105
106    uint64_t
107    GetPC (uint64_t fail_value = LLDB_INVALID_ADDRESS);
108
109    bool
110    SetPC (uint64_t pc);
111
112    uint64_t
113    GetSP (uint64_t fail_value = LLDB_INVALID_ADDRESS);
114
115    bool
116    SetSP (uint64_t sp);
117
118    uint64_t
119    GetFP (uint64_t fail_value = LLDB_INVALID_ADDRESS);
120
121    bool
122    SetFP (uint64_t fp);
123
124    const char *
125    GetRegisterName (uint32_t reg);
126
127    uint64_t
128    GetReturnAddress (uint64_t fail_value = LLDB_INVALID_ADDRESS);
129
130    uint64_t
131    GetFlags (uint64_t fail_value = 0);
132
133    uint64_t
134    ReadRegisterAsUnsigned (uint32_t reg, uint64_t fail_value);
135
136    bool
137    WriteRegisterFromUnsigned (uint32_t reg, uint64_t uval);
138
139    //------------------------------------------------------------------
140    // lldb::ExecutionContextScope pure virtual functions
141    //------------------------------------------------------------------
142    virtual Target *
143    CalculateTarget ();
144
145    virtual Process *
146    CalculateProcess ();
147
148    virtual Thread *
149    CalculateThread ();
150
151    virtual StackFrame *
152    CalculateStackFrame ();
153
154    virtual void
155    Calculate (ExecutionContext &exe_ctx);
156
157protected:
158    //------------------------------------------------------------------
159    // Classes that inherit from RegisterContext can see and modify these
160    //------------------------------------------------------------------
161    Thread &m_thread;       // The thread that this register context belongs to.
162    StackFrame *m_frame;    // The stack frame for this context, or NULL if this is the root context
163private:
164    //------------------------------------------------------------------
165    // For RegisterContext only
166    //------------------------------------------------------------------
167    DISALLOW_COPY_AND_ASSIGN (RegisterContext);
168};
169
170} // namespace lldb_private
171
172#endif  // liblldb_RegisterContext_h_
173