]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Bypass GDB bug which asks to read packet slightly too big
authorPhilippe Waroquiers <philippe.waroquiers@skynet.be>
Thu, 25 Jul 2013 22:37:02 +0000 (22:37 +0000)
committerPhilippe Waroquiers <philippe.waroquiers@skynet.be>
Thu, 25 Jul 2013 22:37:02 +0000 (22:37 +0000)
GDB sometimes asks slightly too big read packets
(no taking into account the packet overhead).
Bypass the problem by allocating slightly more than needed
if GDB would only ask the correct maximum size.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@13472

coregrind/m_gdbserver/remote-utils.c
coregrind/m_gdbserver/server.c

index 59a698effa94b6bebbe2b0f8f89999bacdfa591f..3c208deccf72eca6dbb2ca887b0c97b0bfc44697 100644 (file)
@@ -695,7 +695,8 @@ int putpkt_binary (char *buf, int cnt)
    char *p;
    int cc;
 
-   buf2 = malloc (PBUFSIZ);
+   buf2 = malloc (PBUFSIZ+POVERHSIZ);
+   // should malloc PBUFSIZ, but bypass GDB bug (see gdbserver_init in server.c)
 
    /* Copy the packet into buffer BUF2, encapsulating it
       and giving it a checksum.  */
index d53033012bad80e93c286a03fdd3d21d6f1257e4..5e79fd017fb00317e3cb637bbcdd0b63a831a454 100644 (file)
@@ -799,9 +799,14 @@ void gdbserver_init (void)
    // After a fork, gdbserver_init can be called again.
    // We do not have to re-malloc the buffers in such a case.
    if (own_buf == NULL)
-      own_buf = malloc (PBUFSIZ);
+      own_buf = malloc (PBUFSIZ+POVERHSIZ);
    if (mem_buf == NULL)
-      mem_buf = malloc (PBUFSIZ);
+      mem_buf = malloc (PBUFSIZ+POVERHSIZ);
+   // Note: normally, we should only malloc PBUFSIZ. However,
+   // GDB has a bug, and in some cases, sends e.g. 'm' packets
+   // asking for slightly more than the PacketSize given at
+   // connection initialisation. So, we bypass the GDB bug
+   // by allocating slightly more.
 }
 
 void gdbserver_terminate (void)