remote_gdb.hh (10601:6efb37480d87) remote_gdb.hh (11274:d9a0136ab8cc)
1/*
1/*
2 * Copyright 2015 LabWare
2 * Copyright 2014 Google, Inc.
3 * Copyright (c) 2002-2005 The Regents of The University of Michigan
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met: redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer;

--- 12 unchanged lines hidden (view full) ---

22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 *
29 * Authors: Nathan Binkert
3 * Copyright 2014 Google, Inc.
4 * Copyright (c) 2002-2005 The Regents of The University of Michigan
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
9 * met: redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer;

--- 12 unchanged lines hidden (view full) ---

23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 *
30 * Authors: Nathan Binkert
31 * Boris Shingarov
30 */
31
32#ifndef __REMOTE_GDB_HH__
33#define __REMOTE_GDB_HH__
34
35#include <sys/signal.h>
36
37#include <map>

--- 56 unchanged lines hidden (view full) ---

94 //Helper functions
95 protected:
96 int digit2i(char);
97 char i2digit(int);
98 Addr hex2i(const char **);
99 //Address formats, break types, and gdb commands may change
100 //between architectures, so they're defined as virtual
101 //functions.
32 */
33
34#ifndef __REMOTE_GDB_HH__
35#define __REMOTE_GDB_HH__
36
37#include <sys/signal.h>
38
39#include <map>

--- 56 unchanged lines hidden (view full) ---

96 //Helper functions
97 protected:
98 int digit2i(char);
99 char i2digit(int);
100 Addr hex2i(const char **);
101 //Address formats, break types, and gdb commands may change
102 //between architectures, so they're defined as virtual
103 //functions.
102 virtual void mem2hex(void *, const void *, int);
103 virtual const char * hex2mem(void *, const char *, int);
104 virtual void mem2hex(char *, const char *, int);
105 virtual const char * hex2mem(char *, const char *, int);
104 virtual const char * break_type(char c);
105 virtual const char * gdb_command(char cmd);
106
107 protected:
108 class InputEvent : public PollEvent
109 {
110 protected:
111 BaseRemoteGDB *gdb;

--- 33 unchanged lines hidden (view full) ---

145#endif
146 bool active;
147 bool attached;
148
149 System *system;
150 ThreadContext *context;
151
152 protected:
106 virtual const char * break_type(char c);
107 virtual const char * gdb_command(char cmd);
108
109 protected:
110 class InputEvent : public PollEvent
111 {
112 protected:
113 BaseRemoteGDB *gdb;

--- 33 unchanged lines hidden (view full) ---

147#endif
148 bool active;
149 bool attached;
150
151 System *system;
152 ThreadContext *context;
153
154 protected:
153 class GdbRegCache
155 /**
156 * Concrete subclasses of this abstract class represent how the
157 * register values are transmitted on the wire. Usually each
158 * architecture should define one subclass, but there can be more
159 * if there is more than one possible wire format. For example,
160 * ARM defines both AArch32GdbRegCache and AArch64GdbRegCache.
161 */
162 class BaseGdbRegCache
154 {
155 public:
163 {
164 public:
156 GdbRegCache(size_t newSize) :
157 regs64(new uint64_t[divCeil(newSize, sizeof(uint64_t))]),
158 size(newSize)
165
166 /**
167 * Return the pointer to the raw bytes buffer containing the
168 * register values. Each byte of this buffer is literally
169 * encoded as two hex digits in the g or G RSP packet.
170 */
171 virtual char *data() const = 0;
172
173 /**
174 * Return the size of the raw buffer, in bytes
175 * (i.e., half of the number of digits in the g/G packet).
176 */
177 virtual size_t size() const = 0;
178
179 /**
180 * Fill the raw buffer from the registers in the ThreadContext.
181 */
182 virtual void getRegs(ThreadContext*) = 0;
183
184 /**
185 * Set the ThreadContext's registers from the values
186 * in the raw buffer.
187 */
188 virtual void setRegs(ThreadContext*) const = 0;
189
190 /**
191 * Return the name to use in places like DPRINTF.
192 * Having each concrete superclass redefine this member
193 * is useful in situations where the class of the regCache
194 * can change on the fly.
195 */
196 virtual const std::string name() const = 0;
197
198 BaseGdbRegCache(BaseRemoteGDB *g) : gdb(g)
159 {}
199 {}
160 ~GdbRegCache()
161 {
162 delete [] regs64;
163 }
164
200
165 union {
166 uint64_t *regs64;
167 uint32_t *regs32;
168 uint16_t *regs16;
169 uint8_t *regs8;
170 void *regs;
171 };
172 // Size of cache in bytes.
173 size_t size;
174 size_t bytes() { return size; }
201 protected:
202 BaseRemoteGDB *gdb;
175 };
176
203 };
204
177 GdbRegCache gdbregs;
178
179 protected:
180 uint8_t getbyte();
181 void putbyte(uint8_t b);
182
183 int recv(char *data, int len);
184 void send(const char *data);
185
186 protected:
187 // Machine memory
188 virtual bool read(Addr addr, size_t size, char *data);
189 virtual bool write(Addr addr, size_t size, const char *data);
190
191 template <class T> T read(Addr addr);
192 template <class T> void write(Addr addr, T data);
193
194 public:
205 protected:
206 uint8_t getbyte();
207 void putbyte(uint8_t b);
208
209 int recv(char *data, int len);
210 void send(const char *data);
211
212 protected:
213 // Machine memory
214 virtual bool read(Addr addr, size_t size, char *data);
215 virtual bool write(Addr addr, size_t size, const char *data);
216
217 template <class T> T read(Addr addr);
218 template <class T> void write(Addr addr, T data);
219
220 public:
195 BaseRemoteGDB(System *system, ThreadContext *context, size_t cacheSize);
221 BaseRemoteGDB(System *system, ThreadContext *context);
196 virtual ~BaseRemoteGDB();
222 virtual ~BaseRemoteGDB();
223 virtual BaseGdbRegCache *gdbRegs() = 0;
197
198 void replaceThreadContext(ThreadContext *tc) { context = tc; }
199
200 void attach(int fd);
201 void detach();
202 bool isattached();
203
204 virtual bool acc(Addr addr, size_t len) = 0;

--- 13 unchanged lines hidden (view full) ---

218 SingleStepEvent(BaseRemoteGDB *g) : gdb(g)
219 {}
220
221 void process();
222 };
223
224 SingleStepEvent singleStepEvent;
225
224
225 void replaceThreadContext(ThreadContext *tc) { context = tc; }
226
227 void attach(int fd);
228 void detach();
229 bool isattached();
230
231 virtual bool acc(Addr addr, size_t len) = 0;

--- 13 unchanged lines hidden (view full) ---

245 SingleStepEvent(BaseRemoteGDB *g) : gdb(g)
246 {}
247
248 void process();
249 };
250
251 SingleStepEvent singleStepEvent;
252
226 virtual void getregs() = 0;
227 virtual void setregs() = 0;
228
229 void clearSingleStep();
230 void setSingleStep();
231
232 PCEventQueue *getPcEventQueue();
233 EventQueue *getComInstEventQueue();
234
235 /// Schedule an event which will be triggered "delta" instructions later.
236 void scheduleInstCommitEvent(Event *ev, int delta);

--- 84 unchanged lines hidden ---
253 void clearSingleStep();
254 void setSingleStep();
255
256 PCEventQueue *getPcEventQueue();
257 EventQueue *getComInstEventQueue();
258
259 /// Schedule an event which will be triggered "delta" instructions later.
260 void scheduleInstCommitEvent(Event *ev, int delta);

--- 84 unchanged lines hidden ---