]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
vgdb.c: Encode the qRcmd reply as hex string
authorAlexandra Petlanova Hajkova <ahajkova@redhat.com>
Wed, 29 Nov 2023 10:40:13 +0000 (05:40 -0500)
committerMark Wielaard <mark@klomp.org>
Sat, 2 Dec 2023 00:15:31 +0000 (01:15 +0100)
When vgdb replies to qRcmd packet recieved from GDB, it
used to send the reply as simple string. This is wrong,
GDB expects to get a hex encoded string.

https://bugs.kde.org/show_bug.cgi?id=477719

NEWS
coregrind/vgdb.c

diff --git a/NEWS b/NEWS
index cdbf8b957ce2aaee20a4bbe28e4dc4cb27629ecd..188c5107503d4ddfb0641b617e248bc87e82b685 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -44,6 +44,7 @@ are not entered into bugzilla tend to get forgotten about or ignored.
 476887  WARNING: unhandled amd64-freebsd syscall: 578
 477628  Add mremap support for Solaris
 477630  Include ucontext.h rather than sys/ucontext.h in Solaris sources
+477719  vgdb incorrectly replies to qRcmd packet
 
 To see details of a given bug, visit
   https://bugs.kde.org/show_bug.cgi?id=XXXXXX
index dce85b5c960160ff63ab2df5eb0539a106053f77..5bdc6d2d9903ec75ec626000866bb31e25ecdcca 100644 (file)
@@ -913,6 +913,22 @@ int tohex (int nib)
       return 'a' + nib - 10;
 }
 
+static int hexify (char *hex, const char *bin, int count)
+{
+   int i;
+
+   /* May use a length, or a nul-terminated string as input. */
+   if (count == 0)
+      count = strlen (bin);
+
+  for (i = 0; i < count; i++) {
+     *hex++ = tohex ((*bin >> 4) & 0xf);
+     *hex++ = tohex (*bin++ & 0xf);
+  }
+  *hex = 0;
+  return i;
+}
+
 /* Returns an allocated hex-decoded string from the buf. Stops decoding
    at end of buf (zero) or when seeing the delim char.  */
 static
@@ -1406,7 +1422,12 @@ void do_multi_mode(int check_trials, int in_port)
           send_packet ("", noackmode);
        }
        else if (strncmp(QRCMD, buf, strlen(QRCMD)) == 0) {
-          send_packet ("No running target, monitor commands not available yet.", noackmode);
+           static const char *no_running_str =
+              "No running target, monitor commands not available yet.\n";
+           int str_count = strlen (no_running_str);
+           char hex[2 * str_count + 1];
+           hexify(hex, no_running_str, str_count);
+           send_packet(hex, noackmode);
 
           char *decoded_string = decode_hexstring (buf, strlen (QRCMD) + 1, 0);
           DEBUG(1, "qRcmd decoded: %s\n", decoded_string);