1 //===-- GDBRemoteRegisterContext.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 lldb_GDBRemoteRegisterContext_h_
11 #define lldb_GDBRemoteRegisterContext_h_
12 
13 // C Includes
14 // C++ Includes
15 #include <vector>
16 
17 // Other libraries and framework includes
18 // Project includes
19 #include "lldb/lldb-private.h"
20 #include "lldb/lldb-enumerations.h"
21 #include "lldb/Core/ConstString.h"
22 #include "lldb/Core/DataExtractor.h"
23 #include "lldb/Target/RegisterContext.h"
24 #include "Plugins/Process/Utility/DynamicRegisterInfo.h"
25 
26 #include "GDBRemoteCommunicationClient.h"
27 
28 class ThreadGDBRemote;
29 class ProcessGDBRemote;
30 class StringExtractor;
31 
32 class GDBRemoteDynamicRegisterInfo :
33     public DynamicRegisterInfo
34 {
35 public:
36     GDBRemoteDynamicRegisterInfo () :
37         DynamicRegisterInfo()
38     {
39     }
40 
41     ~GDBRemoteDynamicRegisterInfo ()
42     {
43     }
44 
45     void
46     HardcodeARMRegisters(bool from_scratch);
47 
48 };
49 
50 class GDBRemoteRegisterContext : public lldb_private::RegisterContext
51 {
52 public:
53     //------------------------------------------------------------------
54     // Constructors and Destructors
55     //------------------------------------------------------------------
56     GDBRemoteRegisterContext (ThreadGDBRemote &thread,
57                               uint32_t concrete_frame_idx,
58                               GDBRemoteDynamicRegisterInfo &reg_info,
59                               bool read_all_at_once);
60 
61     virtual
62     ~GDBRemoteRegisterContext ();
63 
64     //------------------------------------------------------------------
65     // Subclasses must override these functions
66     //------------------------------------------------------------------
67     virtual void
68     InvalidateAllRegisters ();
69 
70     virtual size_t
71     GetRegisterCount ();
72 
73     virtual const lldb_private::RegisterInfo *
74     GetRegisterInfoAtIndex (size_t reg);
75 
76     virtual size_t
77     GetRegisterSetCount ();
78 
79     virtual const lldb_private::RegisterSet *
80     GetRegisterSet (size_t reg_set);
81 
82     virtual bool
83     ReadRegister (const lldb_private::RegisterInfo *reg_info, lldb_private::RegisterValue &value);
84 
85     virtual bool
86     WriteRegister (const lldb_private::RegisterInfo *reg_info, const lldb_private::RegisterValue &value);
87 
88     virtual bool
89     ReadAllRegisterValues (lldb::DataBufferSP &data_sp);
90 
91     virtual bool
92     WriteAllRegisterValues (const lldb::DataBufferSP &data_sp);
93 
94     virtual uint32_t
95     ConvertRegisterKindToRegisterNumber (uint32_t kind, uint32_t num);
96 
97 protected:
98     friend class ThreadGDBRemote;
99 
100     bool
101     ReadRegisterBytes (const lldb_private::RegisterInfo *reg_info,
102                        lldb_private::DataExtractor &data);
103 
104     bool
105     WriteRegisterBytes (const lldb_private::RegisterInfo *reg_info,
106                         lldb_private::DataExtractor &data,
107                         uint32_t data_offset);
108 
109     bool
110     PrivateSetRegisterValue (uint32_t reg, StringExtractor &response);
111 
112     void
113     SetAllRegisterValid (bool b);
114 
115     bool
116     GetRegisterIsValid (uint32_t reg) const
117     {
118 #if defined (LLDB_CONFIGURATION_DEBUG)
119         assert (reg < m_reg_valid.size());
120 #endif
121         if (reg < m_reg_valid.size())
122             return m_reg_valid[reg];
123         return false;
124     }
125 
126     void
127     SetRegisterIsValid (const lldb_private::RegisterInfo *reg_info, bool valid)
128     {
129         if (reg_info)
130             return SetRegisterIsValid (reg_info->kinds[lldb::eRegisterKindLLDB], valid);
131     }
132 
133     void
134     SetRegisterIsValid (uint32_t reg, bool valid)
135     {
136 #if defined (LLDB_CONFIGURATION_DEBUG)
137         assert (reg < m_reg_valid.size());
138 #endif
139         if (reg < m_reg_valid.size())
140             m_reg_valid[reg] = valid;
141     }
142 
143     void
144     SyncThreadState(lldb_private::Process *process);  // Assumes the sequence mutex has already been acquired.
145 
146     GDBRemoteDynamicRegisterInfo &m_reg_info;
147     std::vector<bool> m_reg_valid;
148     lldb_private::DataExtractor m_reg_data;
149     bool m_read_all_at_once;
150 
151 private:
152     // Helper function for ReadRegisterBytes().
153     bool GetPrimordialRegister(const lldb_private::RegisterInfo *reg_info,
154                                GDBRemoteCommunicationClient &gdb_comm);
155     // Helper function for WriteRegisterBytes().
156     bool SetPrimordialRegister(const lldb_private::RegisterInfo *reg_info,
157                                GDBRemoteCommunicationClient &gdb_comm);
158 
159     //------------------------------------------------------------------
160     // For GDBRemoteRegisterContext only
161     //------------------------------------------------------------------
162     DISALLOW_COPY_AND_ASSIGN (GDBRemoteRegisterContext);
163 };
164 
165 #endif  // lldb_GDBRemoteRegisterContext_h_
166