diff options
author | Boris Shingarov <shingarov@labware.com> | 2015-12-18 15:12:07 -0600 |
---|---|---|
committer | Boris Shingarov <shingarov@labware.com> | 2015-12-18 15:12:07 -0600 |
commit | d765dbf22cb3242c055b19b797b0f4cb39a43aae (patch) | |
tree | 55fade43c664a78e55823cdc43f7bcec1bf663a9 /src/base/remote_gdb.cc | |
parent | b5a54eb64ebce9c217c1d44cc93aebb7cb508c6d (diff) | |
download | gem5-d765dbf22cb3242c055b19b797b0f4cb39a43aae.tar.xz |
arm: remote GDB: rationalize structure of register offsets
Currently, the wire format of register values in g- and G-packets is
modelled using a union of uint8/16/32/64 arrays. The offset positions
of each register are expressed as a "register count" scaled according
to the width of the register in question. This results in counter-
intuitive and error-prone "register count arithmetic", and some
formats would even be altogether unrepresentable in such model, e.g.
a 64-bit register following a 32-bit one would have a fractional index
in the regs64 array.
Another difficulty is that the array is allocated before the actual
architecture of the workload is known (and therefore before the correct
size for the array can be calculated).
With this patch I propose a simpler mechanism for expressing the
register set structure. In the new code, GdbRegCache is an abstract
class; its subclasses contain straightforward structs reflecting the
register representation. The determination whether to use e.g. the
AArch32 vs. AArch64 register set (or SPARCv8 vs SPARCv9, etc.) is made
by polymorphically dispatching getregs() to the concrete subclass.
The subclass is not instantiated until it is needed for actual
g-/G-packet processing, when the mode is already known.
This patch is not meant to be merged in on its own, because it changes
the contract between src/base/remote_gdb.* and src/arch/*/remote_gdb.*,
so as it stands right now, it would break the other architectures.
In this patch only the base and the ARM code are provided for review;
once we agree on the structure, I will provide src/arch/*/remote_gdb.*
for the other architectures; those patches could then be merged in
together.
Review Request: http://reviews.gem5.org/r/3207/
Pushed by Joel Hestness <jthestness@gmail.com>
Diffstat (limited to 'src/base/remote_gdb.cc')
-rw-r--r-- | src/base/remote_gdb.cc | 60 |
1 files changed, 22 insertions, 38 deletions
diff --git a/src/base/remote_gdb.cc b/src/base/remote_gdb.cc index e603fb90f..e033bea9c 100644 --- a/src/base/remote_gdb.cc +++ b/src/base/remote_gdb.cc @@ -1,4 +1,5 @@ /* + * Copyright 2015 LabWare * Copyright 2014 Google, Inc. * Copyright (c) 2002-2005 The Regents of The University of Michigan * All rights reserved. @@ -27,6 +28,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * Authors: Nathan Binkert + * Boris Shingarov */ /* @@ -270,12 +272,11 @@ BaseRemoteGDB::SingleStepEvent::process() gdb->trap(SIGTRAP); } -BaseRemoteGDB::BaseRemoteGDB(System *_system, ThreadContext *c, - size_t cacheSize) : inputEvent(NULL), trapEvent(this), listener(NULL), +BaseRemoteGDB::BaseRemoteGDB(System *_system, ThreadContext *c) : + inputEvent(NULL), trapEvent(this), listener(NULL), number(-1), fd(-1), active(false), attached(false), system(_system), - context(c), gdbregs(cacheSize), singleStepEvent(this) + context(c), singleStepEvent(this) { - memset(gdbregs.regs, 0, gdbregs.bytes()); } BaseRemoteGDB::~BaseRemoteGDB() @@ -700,7 +701,9 @@ BaseRemoteGDB::trap(int type) if (!attached) return false; - bufferSize = gdbregs.bytes() * 2 + 256; + unique_ptr<BaseRemoteGDB::BaseGdbRegCache> regCache(gdbRegs()); + + bufferSize = regCache->size() * 2 + 256; buffer = (char*)malloc(bufferSize); DPRINTF(GDBMisc, "trap: PC=%s\n", context->pcState()); @@ -721,12 +724,12 @@ BaseRemoteGDB::trap(int type) active = true; } else { // Tell remote host that an exception has occurred. - snprintf((char *)buffer, bufferSize, "S%02x", type); + snprintf(buffer, bufferSize, "S%02x", type); send(buffer); } // Stick frame regs into our reg cache. - getregs(); + regCache->getRegs(context); for (;;) { datalen = recv(data, sizeof(data)); @@ -740,48 +743,29 @@ BaseRemoteGDB::trap(int type) // if this command came from a running gdb, answer it -- // the other guy has no way of knowing if we're in or out // of this loop when he issues a "remote-signal". - snprintf((char *)buffer, bufferSize, + snprintf(buffer, bufferSize, "S%02x", type); send(buffer); continue; case GDBRegR: - if (2 * gdbregs.bytes() > bufferSize) + if (2 * regCache->size() > bufferSize) panic("buffer too small"); - mem2hex(buffer, gdbregs.regs, gdbregs.bytes()); + mem2hex(buffer, regCache->data(), regCache->size()); send(buffer); continue; case GDBRegW: - p = hex2mem(gdbregs.regs, p, gdbregs.bytes()); + p = hex2mem(regCache->data(), p, regCache->size()); if (p == NULL || *p != '\0') send("E01"); else { - setregs(); + regCache->setRegs(context); send("OK"); } continue; -#if 0 - case GDBSetReg: - val = hex2i(&p); - if (*p++ != '=') { - send("E01"); - continue; - } - if (val < 0 && val >= KGDB_NUMREGS) { - send("E01"); - continue; - } - - gdbregs.regs[val] = hex2i(&p); - setregs(); - send("OK"); - - continue; -#endif - case GDBMemR: val = hex2i(&p); if (*p++ != ',') { @@ -802,7 +786,7 @@ BaseRemoteGDB::trap(int type) continue; } - if (read(val, (size_t)len, (char *)buffer)) { + if (read(val, (size_t)len, buffer)) { // variable length array would be nice, but C++ doesn't // officially support those... char *temp = new char[2*len+1]; @@ -838,7 +822,7 @@ BaseRemoteGDB::trap(int type) send("E0A"); continue; } - if (write(val, (size_t)len, (char *)buffer)) + if (write(val, (size_t)len, buffer)) send("OK"); else send("E0B"); @@ -1025,10 +1009,10 @@ BaseRemoteGDB::i2digit(int n) // Convert a byte array into an hex string. void -BaseRemoteGDB::mem2hex(void *vdst, const void *vsrc, int len) +BaseRemoteGDB::mem2hex(char *vdst, const char *vsrc, int len) { - char *dst = (char *)vdst; - const char *src = (const char *)vsrc; + char *dst = vdst; + const char *src = vsrc; while (len--) { *dst++ = i2digit(*src >> 4); @@ -1042,9 +1026,9 @@ BaseRemoteGDB::mem2hex(void *vdst, const void *vsrc, int len) // hex digit. If the string ends in the middle of a byte, NULL is // returned. const char * -BaseRemoteGDB::hex2mem(void *vdst, const char *src, int maxlen) +BaseRemoteGDB::hex2mem(char *vdst, const char *src, int maxlen) { - char *dst = (char *)vdst; + char *dst = vdst; int msb, lsb; while (*src && maxlen--) { |