From: Alexandra Petlanova Hajkova Date: Wed, 29 Nov 2023 10:40:13 +0000 (-0500) Subject: vgdb.c: Encode the qRcmd reply as hex string X-Git-Tag: VALGRIND_3_23_0~233 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=aed6de1a943d2beae5ba6180552d410922f9b8bd;p=thirdparty%2Fvalgrind.git vgdb.c: Encode the qRcmd reply as hex string 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 --- diff --git a/NEWS b/NEWS index cdbf8b957c..188c510750 100644 --- 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 diff --git a/coregrind/vgdb.c b/coregrind/vgdb.c index dce85b5c96..5bdc6d2d99 100644 --- a/coregrind/vgdb.c +++ b/coregrind/vgdb.c @@ -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);