From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id GMSuFXDSZmg3dSoAWB0awg (envelope-from ) for ; Thu, 03 Jul 2025 14:56:48 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=NDzsQDZ6; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 542AB1E11E; Thu, 3 Jul 2025 14:56:48 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-9.1 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,RCVD_IN_VALIDITY_RPBL, RCVD_IN_VALIDITY_SAFE autolearn=ham autolearn_force=no version=4.0.1 Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (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 8A6321E0C2 for ; Thu, 3 Jul 2025 14:56:47 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1A1483852126 for ; Thu, 3 Jul 2025 18:56:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1A1483852126 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=NDzsQDZ6 Received: from mail-io1-xd43.google.com (mail-io1-xd43.google.com [IPv6:2607:f8b0:4864:20::d43]) by sourceware.org (Postfix) with ESMTPS id 8E2C9385213A for ; Thu, 3 Jul 2025 18:55:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8E2C9385213A Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 8E2C9385213A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::d43 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1751568928; cv=none; b=IQbmEt9GPzQRJfP0rqy/EKdwWYtYGSbscOz3uAyAAyyvjlnijaYyj62yqeJIvqrRvikDCBjR7+xRJH2cq/FvpUk3GrRefDNJWTOtlADDAD/RYolmgjtvGKQ6mDqK59K6DsOelazeNDGtKwT2FNcMCcKhriwV8YR2zP+Fw40gB9g= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1751568928; c=relaxed/simple; bh=3MKuvD7kXnVZrxXtj3yOhEHF9Ig8H9ngX4C+Q1ch9aM=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=o8YRXq6pQODeoa6MCsCLalPuEA7fo8csQLGUrmdrfnNqcB5/xuWrfCc2E6DS6AFmtIrtblwj+l3J6ldR6QPoeVbSsAnhtQYfqEOwSB76P3SgsizGicOx6QyOUgYnbwbpPuEWAQnNF03y3kvfmegEAIl2sK72cwkgSUAob1FKHNI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8E2C9385213A Received: by mail-io1-xd43.google.com with SMTP id ca18e2360f4ac-86d00ae076dso47189239f.0 for ; Thu, 03 Jul 2025 11:55:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1751568927; x=1752173727; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=6GTes8nUwn2CqjjJEGwEqhhoVmXQ++3bskQ+sJDin68=; b=NDzsQDZ6MVkDXZJeb8bR6nsJtUXAWUVAtmamqFRixWmjCp9kqh8KSeMhIm0JdZdEYN j4sWLGaM4V2VT1LRjifN5ijbxPxiZa0VQJANcSMK16JO0ok1pk64mGq/nIE2eh/EtH17 uRNxvtI0MSbEaclFlMoIaunJV3gLEJAj74B/hzg/AlaOklEuwGBlWJ66r6fNoKsMQ917 pmvFWd0g5CtAyKWzJSTUaMX8k8K8wiC0A9qrMX0LeK24I9kBr1zN0KefQGPaaPOF/Rkw AM+D6k1EicFJ7Z4vByaU28b7wWhqjbEp2Rkrn+FjPvl/onCqPZoBGKNa5HrmxVfqRqP+ WP4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751568927; x=1752173727; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=6GTes8nUwn2CqjjJEGwEqhhoVmXQ++3bskQ+sJDin68=; b=IwC32q+ikMrxCoTNwsYFYXoiMLyt4962fTkgtLpoQ4GqwzATsqCCMdcJzOi/io50+K nTLoRHa/HjrKFtoOe99FNE+2MfYr6ljBPAXCqtSxT0Zdxynb7Z7wVNNr5/Wnm6Z6mjvz QQb6TJoli5U5L3YYLlPV5G98XeIvKWfKaYIDhra1/aB6GAccNYEe3kE95VJJXAtywLxY 3ztRp9jstpZgt/TVzgdnsJ38Q0NjkI25O8Lb70tPUukson2LCCt4QTtalBWwkTxoQMyP TG/nlcZVBPFny60mBr7Xc+QTVewV5JqKpvGqZi8PMQxgYzBKwY80iZrtVu+dDlnCxeyu NDPw== X-Gm-Message-State: AOJu0YxLxrjbpPc39ZCmJwi4dFBeyI+QrRCD4QZiPo/0JxUaR4Ve0ohr cpZwZ+9bQpW/VYSTB4TVLzO3qJY218ML+Zn0ovvUmHlkmaJ8icSbJP0SDA+lVr1x4dYr43Bcnht Zg0B8azWeGzQ= X-Gm-Gg: ASbGncvIWiwtH5vWwPRQo265E1lXPXKXSDux6dv4gAXXsb7t6ouSoAJuBFbWPHwzu1K YmAA20OTsdHIFt1eKvuP6PB+I3XoN3+BQGHWFW1DY5ceIpwxeDX1DMsPccWIjb8kjFbWEqBZWl3 Xf075LUkDSv3mRfWjyMylZt6fQkNBa23H9TgwN9JIXLfMGuBARFGO8PGGO0XLYBLzAe+pne/Eq6 WDg3GFaXZJZKd1GgkqWM3ekLBw9pAlH8cFRR/USxxBcE74S6US+AirPBrociLa6YWtkdB/T0b7t a3EMyZJ6QnHmaMIcGuqJbin0THxI/HZpUZI4Zgot4TTylkq6fkHw4nDRm4qk7JVitgBh/F4YMR/ Oh3Mv0w== X-Google-Smtp-Source: AGHT+IHIFUhJxg5dtfU7LLtpv6yVU6fs68ruB6rm+7oTjRPGARiNeeqhtrI9RW65bKpO/rukHNSFjg== X-Received: by 2002:a05:6e02:3702:b0:3dd:f02d:2d26 with SMTP id e9e14a558f8ab-3e13477237dmr195655ab.2.1751568927446; Thu, 03 Jul 2025 11:55:27 -0700 (PDT) Received: from bapiya (97-118-59-152.hlrn.qwest.net. [97.118.59.152]) by smtp.gmail.com with ESMTPSA id e9e14a558f8ab-3e1004e9d6esm1201225ab.67.2025.07.03.11.55.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Jul 2025 11:55:27 -0700 (PDT) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Correctly handle L'\\' Date: Thu, 3 Jul 2025 12:55:25 -0600 Message-ID: <20250703185525.1309719-1-tromey@adacore.com> X-Mailer: git-send-email 2.50.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Hannes filed a bug that pointed out that: print L'\\' ... did not work correctly. The bug is in convert_escape, which simply transcribes the backslash character, rather than convert it between encodings. This patch fixes the error. I also turned a macro into a lambda to clean up this code a little. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33124 --- gdb/c-lang.c | 26 +++++++++++++++----------- gdb/testsuite/gdb.base/wchar.exp | 3 +++ 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/gdb/c-lang.c b/gdb/c-lang.c index f052401b8fd..9fccc1f7614 100644 --- a/gdb/c-lang.c +++ b/gdb/c-lang.c @@ -484,13 +484,6 @@ convert_hex (struct type *type, const char *p, return p; } -#define ADVANCE \ - do { \ - ++p; \ - if (p == limit) \ - error (_("Malformed escape sequence")); \ - } while (0) - /* Convert an escape sequence to a target format. TYPE is the target character type to use, and DEST_CHARSET is the name of the target character set. The backslash of the escape sequence is at *P, and @@ -502,18 +495,29 @@ static const char * convert_escape (struct type *type, const char *dest_charset, const char *p, const char *limit, struct obstack *output) { + auto advance = [&] () + { + ++p; + if (p == limit) + error (_("Malformed escape sequence")); + }; + /* Skip the backslash. */ - ADVANCE; + advance (); switch (*p) { case '\\': - obstack_1grow (output, '\\'); + /* Convert the backslash itself. This is probably overkill but + it doesn't hurt to do the full conversion. */ + convert_between_encodings (host_charset (), dest_charset, + (const gdb_byte *) p, 1, 1, + output, translit_none); ++p; break; case 'x': - ADVANCE; + advance (); if (!ISXDIGIT (*p)) error (_("\\x used with no following hex digits.")); p = convert_hex (type, p, limit, output); @@ -535,7 +539,7 @@ convert_escape (struct type *type, const char *dest_charset, { int length = *p == 'u' ? 4 : 8; - ADVANCE; + advance (); if (!ISXDIGIT (*p)) error (_("\\u used with no following hex digits")); p = convert_ucn (p, limit, dest_charset, output, length); diff --git a/gdb/testsuite/gdb.base/wchar.exp b/gdb/testsuite/gdb.base/wchar.exp index 70f738cb7fc..9a0d79ada77 100644 --- a/gdb/testsuite/gdb.base/wchar.exp +++ b/gdb/testsuite/gdb.base/wchar.exp @@ -72,3 +72,6 @@ gdb_test "print repeat_p" "= $hex L\"A$cent$cent\"\.\.\." \ # From PR cli/14977, but here because it requires wchar_t. gdb_test "printf \"%ls\\n\", 0" "\\(null\\)" + +# From PR exp/33124 - a bug when converting escapes. +gdb_test "print L'\\\\'" " = $decimal L'\\\\\\\\'" base-commit: 27e5f9c97599fa335f61340a726337cb4ce62804 -- 2.50.0