1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
|
//===-- GDBRemoteRegisterContext.h ------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef lldb_GDBRemoteRegisterContext_h_
#define lldb_GDBRemoteRegisterContext_h_
// C Includes
// C++ Includes
#include <vector>
// Other libraries and framework includes
// Project includes
#include "lldb/lldb-private.h"
#include "lldb/lldb-enumerations.h"
#include "lldb/Core/ConstString.h"
#include "lldb/Core/DataExtractor.h"
#include "lldb/Target/RegisterContext.h"
class ThreadGDBRemote;
class ProcessGDBRemote;
class StringExtractor;
class GDBRemoteDynamicRegisterInfo
{
public:
GDBRemoteDynamicRegisterInfo () :
m_regs (),
m_sets (),
m_set_reg_nums (),
m_reg_names (),
m_reg_alt_names (),
m_set_names (),
m_reg_data_byte_size (0)
{
}
~GDBRemoteDynamicRegisterInfo ()
{
}
void
AddRegister (lldb::RegisterInfo ®_info, lldb_private::ConstString ®_name, lldb_private::ConstString ®_alt_name, lldb_private::ConstString &set_name)
{
const uint32_t reg_num = m_regs.size();
m_reg_names.push_back (reg_name);
m_reg_alt_names.push_back (reg_alt_name);
reg_info.name = reg_name.AsCString();
assert (reg_info.name);
reg_info.alt_name = reg_alt_name.AsCString(NULL);
m_regs.push_back (reg_info);
uint32_t set = GetRegisterSetIndexByName (set_name, true);
assert (set < m_sets.size());
assert (set < m_set_reg_nums.size());
assert (set < m_set_names.size());
m_set_reg_nums[set].push_back(reg_num);
size_t end_reg_offset = reg_info.byte_offset + reg_info.byte_size;
if (m_reg_data_byte_size < end_reg_offset)
m_reg_data_byte_size = end_reg_offset;
}
void
Finalize ()
{
for (uint32_t set = 0; set < m_sets.size(); ++set)
{
assert (m_sets.size() == m_set_reg_nums.size());
m_sets[set].num_registers = m_set_reg_nums[set].size();
m_sets[set].registers = &m_set_reg_nums[set][0];
}
}
size_t
GetNumRegisters() const
{
return m_regs.size();
}
size_t
GetNumRegisterSets() const
{
return m_sets.size();
}
size_t
GetRegisterDataByteSize() const
{
return m_reg_data_byte_size;
}
const lldb::RegisterInfo *
GetRegisterInfoAtIndex (uint32_t i) const
{
if (i < m_regs.size())
return &m_regs[i];
return NULL;
}
const lldb::RegisterSet *
GetRegisterSet (uint32_t i) const
{
if (i < m_sets.size())
return &m_sets[i];
return NULL;
}
uint32_t
GetRegisterSetIndexByName (lldb_private::ConstString &set_name, bool can_create)
{
name_collection::iterator pos, end = m_set_names.end();
for (pos = m_set_names.begin(); pos != end; ++pos)
{
if (*pos == set_name)
return std::distance (m_set_names.begin(), pos);
}
m_set_names.push_back(set_name);
m_set_reg_nums.resize(m_set_reg_nums.size()+1);
lldb::RegisterSet new_set = { set_name.AsCString(), NULL, 0, NULL };
m_sets.push_back (new_set);
return m_sets.size() - 1;
}
uint32_t
ConvertRegisterKindToRegisterNumber (uint32_t kind, uint32_t num) const
{
reg_collection::const_iterator pos, end = m_regs.end();
for (pos = m_regs.begin(); pos != end; ++pos)
{
if (pos->kinds[kind] == num)
return std::distance (m_regs.begin(), pos);
}
return LLDB_INVALID_REGNUM;
}
void
Clear()
{
m_regs.clear();
m_sets.clear();
m_set_reg_nums.clear();
m_reg_names.clear();
m_reg_alt_names.clear();
m_set_names.clear();
}
void
HardcodeARMRegisters();
protected:
//------------------------------------------------------------------
// Classes that inherit from GDBRemoteRegisterContext can see and modify these
//------------------------------------------------------------------
typedef std::vector <lldb::RegisterInfo> reg_collection;
typedef std::vector <lldb::RegisterSet> set_collection;
typedef std::vector <uint32_t> reg_num_collection;
typedef std::vector <reg_num_collection> set_reg_num_collection;
typedef std::vector <lldb_private::ConstString> name_collection;
reg_collection m_regs;
set_collection m_sets;
set_reg_num_collection m_set_reg_nums;
name_collection m_reg_names;
name_collection m_reg_alt_names;
name_collection m_set_names;
size_t m_reg_data_byte_size; // The number of bytes required to store all registers
};
class GDBRemoteRegisterContext : public lldb_private::RegisterContext
{
public:
//------------------------------------------------------------------
// Constructors and Destructors
//------------------------------------------------------------------
GDBRemoteRegisterContext (ThreadGDBRemote &thread,
uint32_t concrete_frame_idx,
GDBRemoteDynamicRegisterInfo ®_info,
bool read_all_at_once);
virtual
~GDBRemoteRegisterContext ();
//------------------------------------------------------------------
// Subclasses must override these functions
//------------------------------------------------------------------
virtual void
InvalidateAllRegisters ();
virtual size_t
GetRegisterCount ();
virtual const lldb::RegisterInfo *
GetRegisterInfoAtIndex (uint32_t reg);
virtual size_t
GetRegisterSetCount ();
virtual const lldb::RegisterSet *
GetRegisterSet (uint32_t reg_set);
virtual bool
ReadRegisterValue (uint32_t reg, lldb_private::Scalar &value);
virtual bool
ReadRegisterBytes (uint32_t reg, lldb_private::DataExtractor &data);
virtual bool
ReadAllRegisterValues (lldb::DataBufferSP &data_sp);
virtual bool
WriteRegisterValue (uint32_t reg, const lldb_private::Scalar &value);
virtual bool
WriteRegisterBytes (uint32_t reg, lldb_private::DataExtractor &data, uint32_t data_offset);
virtual bool
WriteAllRegisterValues (const lldb::DataBufferSP &data_sp);
virtual uint32_t
ConvertRegisterKindToRegisterNumber (uint32_t kind, uint32_t num);
protected:
friend class ThreadGDBRemote;
bool
PrivateSetRegisterValue (uint32_t reg, StringExtractor &response);
void
SetAllRegisterValid (bool b);
ProcessGDBRemote &
GetGDBProcess();
ThreadGDBRemote &
GetGDBThread();
GDBRemoteDynamicRegisterInfo &m_reg_info;
std::vector<bool> m_reg_valid;
lldb_private::DataExtractor m_reg_data;
bool m_read_all_at_once;
private:
//------------------------------------------------------------------
// For GDBRemoteRegisterContext only
//------------------------------------------------------------------
DISALLOW_COPY_AND_ASSIGN (GDBRemoteRegisterContext);
};
#endif // lldb_GDBRemoteRegisterContext_h_
|