RegisterContext.h revision 08d7d3ae16110aa68ed40c161eac8571aeb94cd9
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, uint32_t concrete_frame_idx);
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    ReadRegisterBytes (uint32_t reg, DataExtractor &data) = 0;
54
55    virtual bool
56    ReadAllRegisterValues (lldb::DataBufferSP &data_sp) = 0;
57
58    virtual bool
59    WriteRegisterBytes (uint32_t reg, DataExtractor &data, uint32_t data_offset = 0) = 0;
60
61    virtual bool
62    WriteAllRegisterValues (const lldb::DataBufferSP &data_sp) = 0;
63
64    virtual uint32_t
65    ConvertRegisterKindToRegisterNumber (uint32_t kind, uint32_t num) = 0;
66
67    //------------------------------------------------------------------
68    // Subclasses can override these functions if desired
69    //------------------------------------------------------------------
70    virtual bool
71    ReadRegisterValue (uint32_t reg, Scalar &value);
72
73    virtual bool
74    WriteRegisterValue (uint32_t reg, const Scalar &value);
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    Thread &
104    GetThread ()
105    {
106        return m_thread;
107    }
108
109    const lldb::RegisterInfo *
110    GetRegisterInfoByName (const char *reg_name, uint32_t start_idx = 0);
111
112    uint64_t
113    GetPC (uint64_t fail_value = LLDB_INVALID_ADDRESS);
114
115    bool
116    SetPC (uint64_t pc);
117
118    uint64_t
119    GetSP (uint64_t fail_value = LLDB_INVALID_ADDRESS);
120
121    bool
122    SetSP (uint64_t sp);
123
124    uint64_t
125    GetFP (uint64_t fail_value = LLDB_INVALID_ADDRESS);
126
127    bool
128    SetFP (uint64_t fp);
129
130    const char *
131    GetRegisterName (uint32_t reg);
132
133    uint64_t
134    GetReturnAddress (uint64_t fail_value = LLDB_INVALID_ADDRESS);
135
136    uint64_t
137    GetFlags (uint64_t fail_value = 0);
138
139    uint64_t
140    ReadRegisterAsUnsigned (uint32_t reg, uint64_t fail_value);
141
142    bool
143    WriteRegisterFromUnsigned (uint32_t reg, uint64_t uval);
144
145    bool
146    ConvertBetweenRegisterKinds (int source_rk, uint32_t source_regnum, int target_rk, uint32_t& target_regnum);
147
148    //------------------------------------------------------------------
149    // lldb::ExecutionContextScope pure virtual functions
150    //------------------------------------------------------------------
151    virtual Target *
152    CalculateTarget ();
153
154    virtual Process *
155    CalculateProcess ();
156
157    virtual Thread *
158    CalculateThread ();
159
160    virtual StackFrame *
161    CalculateStackFrame ();
162
163    virtual void
164    CalculateExecutionContext (ExecutionContext &exe_ctx);
165
166protected:
167    //------------------------------------------------------------------
168    // Classes that inherit from RegisterContext can see and modify these
169    //------------------------------------------------------------------
170    Thread &m_thread;               // The thread that this register context belongs to.
171    uint32_t m_concrete_frame_idx;    // The concrete frame index for this register context
172private:
173    //------------------------------------------------------------------
174    // For RegisterContext only
175    //------------------------------------------------------------------
176    DISALLOW_COPY_AND_ASSIGN (RegisterContext);
177};
178
179} // namespace lldb_private
180
181#endif  // liblldb_RegisterContext_h_
182