Merge with head.
[gem5.git] / src / base / remote_gdb.cc
index b1f50755b0d2df95dc0d622b51328ac9d61a0e52..d5095e7f96f069dd8d5e90221d86df2dfb683294 100644 (file)
@@ -461,8 +461,6 @@ BaseRemoteGDB::read(Addr vaddr, size_t size, char *data)
     port->readBlob(vaddr, (uint8_t*)data, size);
 #if FULL_SYSTEM
     context->delVirtPort(port);
-#else
-    delete port;
 #endif
 
 #if TRACING_ON
@@ -631,7 +629,8 @@ BaseRemoteGDB::trap(int type)
     uint64_t val;
     size_t datalen, len;
     char data[GDBPacketBufLen + 1];
-    char buffer[gdbregs.bytes() * 2 + 256];
+    char *buffer;
+    int bufferSize;
     const char *p;
     char command, subcmd;
     string var;
@@ -640,6 +639,9 @@ BaseRemoteGDB::trap(int type)
     if (!attached)
         return false;
 
+    bufferSize = gdbregs.bytes() * 2 + 256;
+    buffer = (char*)malloc(bufferSize);
+
     DPRINTF(GDBMisc, "trap: PC=%#x NPC=%#x\n",
             context->readPC(), context->readNextPC());
 
@@ -659,7 +661,7 @@ BaseRemoteGDB::trap(int type)
         active = true;
     else
         // Tell remote host that an exception has occurred.
-        snprintf((char *)buffer, sizeof(buffer), "S%02x", type);
+        snprintf((char *)buffer, bufferSize, "S%02x", type);
         send(buffer);
 
     // Stick frame regs into our reg cache.
@@ -677,13 +679,13 @@ 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, sizeof(buffer),
+            snprintf((char *)buffer, bufferSize,
                     "S%02x", type);
             send(buffer);
             continue;
 
           case GDBRegR:
-            if (2 * gdbregs.bytes() > sizeof(buffer))
+            if (2 * gdbregs.bytes() > bufferSize)
                 panic("buffer too small");
 
             mem2hex(buffer, gdbregs.regs, gdbregs.bytes());
@@ -730,7 +732,7 @@ BaseRemoteGDB::trap(int type)
                 send("E03");
                 continue;
             }
-            if (len > sizeof(buffer)) {
+            if (len > bufferSize) {
                 send("E04");
                 continue;
             }
@@ -766,7 +768,7 @@ BaseRemoteGDB::trap(int type)
                 send("E08");
                 continue;
             }
-            p = hex2mem(buffer, p, sizeof(buffer));
+            p = hex2mem(buffer, p, bufferSize);
             if (p == NULL) {
                 send("E09");
                 continue;
@@ -937,6 +939,7 @@ BaseRemoteGDB::trap(int type)
     }
 
   out:
+    free(buffer);
     return true;
 }