From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id kC+LDDdVvWlKfDEAWB0awg (envelope-from ) for ; Fri, 20 Mar 2026 10:09:59 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=AmnqAteu; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=+jCjLNsm; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=AmnqAteu; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=+jCjLNsm; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 1E41B1E08C; Fri, 20 Mar 2026 10:09:59 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 9DD6E1E08C for ; Fri, 20 Mar 2026 10:09:57 -0400 (EDT) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id E99EE4C31894 for ; Fri, 20 Mar 2026 14:09:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E99EE4C31894 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=AmnqAteu; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=+jCjLNsm; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=AmnqAteu; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=+jCjLNsm Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by sourceware.org (Postfix) with ESMTPS id 817354BAE7F1 for ; Fri, 20 Mar 2026 14:09:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 817354BAE7F1 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 817354BAE7F1 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1774015768; cv=none; b=sFiI4C3Z0IZeV2x5wePW1nYbdOsGHcFz+T/DSiMSFIjR4HMIRRIvIjtcTw+XrdClhAj+WdMNRSFgXiNuFF5V+2cFzCC6Gl2GoXqqdhRetwKY/lC5X21ec6mfH6Dw5xHLwAghzwLFVikTbz39KcJjb+lSSTzzv/cqnra4A9DH6vI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1774015768; c=relaxed/simple; bh=h/mOuLoYEO3bp5Fx4HXYov3lKBjULuxhOYmsyBCEj/E=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-ID:MIME-Version; b=QwUFXs/ii7KFQTxaCpKfHZe6RGXqEm4fM+sBRLo09eFbsvkvpWhW26k2XWRnfpKZwo9vQVG0R4Z9Hf1wbjC47mLS7rYSOP3rPIJdvoz9cULwonmszHW4Cgo5a9MfDzheZIZyFbAvQ3+0f90/B0bs1hhhAwWsFjaQAcNyCsZJ+a0= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 817354BAE7F1 Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 7A8B84D276 for ; Fri, 20 Mar 2026 14:09:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1774015767; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ynut8B2ib5LNdRKjzlO7uc1Yw0lU/ONaXgYSVHj1ujw=; b=AmnqAteuMWj07PnQ4EywGgBsrD/FWOxdPbOPIwhODGk4QQix4CjZxONdAnNHeEkduTI9iL kEaPLaIfDoS232DMixlBPcY00q20msJNIw31rGX9fAetvL+WLXEsiPZpVVTB7yR4LFKlvb Z+ErEUj9Flgb2QJqmknccBl+CG0neb8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1774015767; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ynut8B2ib5LNdRKjzlO7uc1Yw0lU/ONaXgYSVHj1ujw=; b=+jCjLNsmXRM9PB3w9ilvGzX7hOqU51CLie0swuFB6ywQIVHyJM1jvOAs1/MUjLc4ZMn2Z/ YnKvrc0Eykm6KUCg== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1774015767; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ynut8B2ib5LNdRKjzlO7uc1Yw0lU/ONaXgYSVHj1ujw=; b=AmnqAteuMWj07PnQ4EywGgBsrD/FWOxdPbOPIwhODGk4QQix4CjZxONdAnNHeEkduTI9iL kEaPLaIfDoS232DMixlBPcY00q20msJNIw31rGX9fAetvL+WLXEsiPZpVVTB7yR4LFKlvb Z+ErEUj9Flgb2QJqmknccBl+CG0neb8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1774015767; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ynut8B2ib5LNdRKjzlO7uc1Yw0lU/ONaXgYSVHj1ujw=; b=+jCjLNsmXRM9PB3w9ilvGzX7hOqU51CLie0swuFB6ywQIVHyJM1jvOAs1/MUjLc4ZMn2Z/ YnKvrc0Eykm6KUCg== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 6479042832 for ; Fri, 20 Mar 2026 14:09:27 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 6P06FxdVvWkBJgAAD6G6ig (envelope-from ) for ; Fri, 20 Mar 2026 14:09:27 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH] [gdb/remote] Reimplement escape_buffer Date: Fri, 20 Mar 2026 15:09:26 +0100 Message-ID: <20260320140926.3721875-1-tdevries@suse.de> X-Mailer: git-send-email 2.51.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spamd-Result: default: False [-3.30 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; RCVD_TLS_ALL(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TO_DN_NONE(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:mid] X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org With Fedora RH, using Tcl 9.0.2, I run into: ... (gdb) break -q main^M [remote] Sending packet: $qXfer:auxv:read::0,1000#6b^M [remote] Packet received: l!\000\000\000\000\000\000\000\000 ERROR: \ i_read(spawn_id fd=9): invalid or incomplete multibyte or wide character ... UNRESOLVED: gdb.server/bkpt-other-inferior.exp: inf 2: set breakpoint ... For reference, on openSUSE Leap 16.0, with Tcl 8.6.15 the initial part of the problematic string looks like: ... [remote] Packet received: l!\000\000\000\000\000\000\000\000`ü÷ÿ\177\000... ... With Tcl 9.0, something (dejagnu/expect/gdb testsuite infrastructure) has problems with gdb IO containing non-utf-8 chars. Having said that, I don't think having chars like 'ü' in the debug output is particularly helpful. The easiest and most robust approach would be to just print octal escape sequences, but that would mean we no longer print 'l', which indicates to us what kind of qXfer reply we're looking at [1]. Reimplement function escape_buffer in gdb/remote.c, to print std::isprint chars like the actual chars, and others like octal escape sequences, getting us instead: ... [remote] Packet received: \ l!\000\000\000\000\000\000\000\000`\374\367\377\177\000... ... Note that this is ambiguous, because one char '\0' and 4 chars '\\' '0' '0' '0' are printed the same: \000, but I guess that's a pre-existing problem. This also fixes test-case gdb.python/py-send-packet.exp, where we run into a similar problem with the "Sending packet:" line. Tested on x86_64-linux, with Tcl 9.0.2 and 8.6.15. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34012 [1] https://sourceware.org/gdb/current/onlinedocs/gdb.html/General-Query-Packets.html#index-qXfer-packet --- gdb/remote.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/gdb/remote.c b/gdb/remote.c index e84a0dc578b..d525fbe407b 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -84,6 +84,8 @@ #include "cli/cli-style.h" #include "gdbsupport/remote-args.h" #include "finish-thread-state.h" +#include +#include /* The remote target. */ @@ -10509,15 +10511,33 @@ remote_target::remote_serial_send_break () } /* Return a string representing an escaped version of BUF, of len N. - E.g. \n is converted to \\n, \t to \\t, etc. */ + E.g. '\0' is converted to "\000", etc. */ static std::string escape_buffer (const char *buf, int n) { - string_file stb; + std::string str; + std::ostringstream s; - stb.putstrn (buf, n, '\\'); - return stb.release (); + for (int i = 0; i < n; ++i) + { + char c = buf[i]; + if (isprint (c)) + { + str += c; + continue; + } + + s.str (""); + + /* Print 3-wide leading zero octal. */ + s << std::oct << std::setw (3) << std::setfill ('0') << (unsigned int)c; + + str.append ("\\"); + str.append (s.str ()); + } + + return str; } int base-commit: ebe694f0b28a2cfbb30aaf127eb7200e68871a5a -- 2.51.0