From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id oWmoILp6GmkBuQoAWB0awg (envelope-from ) for ; Sun, 16 Nov 2025 20:30:34 -0500 Authentication-Results: simark.ca; dkim=fail reason="signature verification failed" (768-bit key; unprotected) header.d=tromey.com header.i=@tromey.com header.a=rsa-sha256 header.s=default header.b=ws6f412x; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 81A701E0AB; Sun, 16 Nov 2025 20:30:34 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_INVALID,DKIM_SIGNED,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 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 025C21E08D for ; Sun, 16 Nov 2025 20:30:34 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8D31A3858C56 for ; Mon, 17 Nov 2025 01:30:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8D31A3858C56 Authentication-Results: sourceware.org; dkim=fail reason="signature verification failed" (768-bit key, unprotected) header.d=tromey.com header.i=@tromey.com header.a=rsa-sha256 header.s=default header.b=ws6f412x Received: from omta38.uswest2.a.cloudfilter.net (omta38.uswest2.a.cloudfilter.net [35.89.44.37]) by sourceware.org (Postfix) with ESMTPS id 7175D3858D20 for ; Mon, 17 Nov 2025 01:28:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7175D3858D20 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 7175D3858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=35.89.44.37 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1763342916; cv=none; b=ZQunxyKdfEwIlvWzgiePVg8NfZdMHowYpRegjN/I8OFM1SiXSfPzHE9Wx43RAggRM/p7dJ7YtHA9myTWttTLcF8Y/gXBayjj6VlpssRPyHZ8WXKeqiv0o//rG5MlysjHdlpmUpAC+E/AS0PuEGKPzzfWURjbiZEMXMVTM6+f0s4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1763342916; c=relaxed/simple; bh=yO5dP68mfLms3/bS3DV9h4eEPOLPpjZR7DL3Mm+SZvU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=aqhBdmV9tGLrivMCG9ZbOdPuZ4KnZRwC6Z6MZ7dzH5J6xUyPS44AMCWiMSQH8WGiaVIVzc/Qefk1nb5kUoJb2iY6i6Gq/sVgw7q5QOylF4uGBFDjMAwfez7WC0fr6FteikHARIUlz1SHRpnzuviG5u9QR0M50OSl4OEROAF5ifU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7175D3858D20 Received: from eig-obgw-5007b.ext.cloudfilter.net ([10.0.29.167]) by cmsmtp with ESMTPS id KlrNvta7BipkCKo2mvjMnp; Mon, 17 Nov 2025 01:28:36 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id Ko2lv2vdnJecrKo2lvKqCt; Mon, 17 Nov 2025 01:28:35 +0000 X-Authority-Analysis: v=2.4 cv=G8scE8k5 c=1 sm=1 tr=0 ts=691a7a44 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=6UeiqGixMTsA:10 a=ItBw4LHWJt0A:10 a=CCpqsmhAAAAA:8 a=5uRjTpvkDB-B1eXdI_UA:9 a=ul9cdbp4aOFLsgKbc677:22 a=VS4QxaUSPT0UtbFnIvSC:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=mqgpPduG7ZkOtYD3roMGO1pSIMBuPhnmgRzS2ZYNz4k=; b=ws6f412xChNbxjblLIX6MX3Okl yDtZ2H1HmWPRzNK+3wciQQPSRbWyuauy6sMDzfhIanNMkUPzsempUMaMgGmy4F0wDXMvYlcXNFLdf KFgHLTA9lgddMFgO1QQtebs93; Received: from 97-122-120-205.hlrn.qwest.net ([97.122.120.205]:41170 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1vKo2g-00000000Q3v-2HIH; Sun, 16 Nov 2025 18:28:30 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 6/7] Avoid crash with "NSString" literals Date: Sun, 16 Nov 2025 18:27:05 -0700 Message-ID: <20251117012752.2657208-7-tom@tromey.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20251117012752.2657208-1-tom@tromey.com> References: <20251117012752.2657208-1-tom@tromey.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 97.122.120.205 X-Source-L: No X-Exim-ID: 1vKo2g-00000000Q3v-2HIH X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-120-205.hlrn.qwest.net (localhost.localdomain) [97.122.120.205]:41170 X-Source-Auth: tom+tromey.com X-Email-Count: 7 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfA6NuvQD/DzdUo8dppqYTGJOIRiS9HEeXEx1GEDFm8tePdrf7ru+BIeg+LM2X7Dedp775Q8p9c7RKFi6yeNbPCClNLiKw4YzAD5npSAd9onWik/UGGEZ 5PplJ2eRTQFQP7qJvarIjzhGeGLnJuXuzIBehgCDHv4AVgPQJ5WyCPuont5MAF3ztGq1O1dx/fvB0xEJV6a3LkXgeqTHjEEuw08= 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 Evaluating an Objective-C "NSString" literal will cause gdb to crash. This patch fixes the crash. I think the result here still isn't correct -- I see a warning from the runtime ("autorelease called without pool for object") with the new code. However, not crashing is an improvement on its own. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=20501 --- gdb/c-exp.y | 10 +++++----- gdb/objc-lang.c | 3 ++- gdb/testsuite/gdb.objc/print.exp | 4 ++++ 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/gdb/c-exp.y b/gdb/c-exp.y index 6dd2b0800dd..fadd735c517 100644 --- a/gdb/c-exp.y +++ b/gdb/c-exp.y @@ -223,7 +223,7 @@ static void c_print_token (FILE *file, int type, YYSTYPE value); nonterminal "name", which matches either NAME or TYPENAME. */ %token STRING -%token NSSTRING /* ObjC Foundation "NSString" literal */ +%token NSSTRING /* ObjC Foundation "NSString" literal */ %token SELECTOR /* ObjC "@selector" pseudo-operator */ %token CHAR %token NAME /* BLOCKNAME defined below to give it higher precedence. */ @@ -1030,12 +1030,12 @@ exp : string_exp } ; -exp : NSSTRING /* ObjC NextStep NSString constant - * of the form '@' '"' string '"'. - */ +exp : NSSTRING { + /* ObjC NextStep NSString constant of the + form '@' '"' string '"'. */ pstate->push_new - (copy_name ($1)); + (std::string ($1.ptr, $1.length)); } ; diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c index a6abcd60089..9804f2c3963 100644 --- a/gdb/objc-lang.c +++ b/gdb/objc-lang.c @@ -169,7 +169,8 @@ objc_nsstring_operation::evaluate (struct type *expect_type, struct type *type; if (!target_has_execution ()) - return 0; /* Can't call into inferior to create NSString. */ + error (_("evaluation of this expression " + "requires the target program to be active")); stringValue[2] = value_string (str.c_str (), str.size () + 1, char_type); stringValue[2] = value_coerce_array (stringValue[2]); diff --git a/gdb/testsuite/gdb.objc/print.exp b/gdb/testsuite/gdb.objc/print.exp index e3f4177d997..2e9fee3b869 100644 --- a/gdb/testsuite/gdb.objc/print.exp +++ b/gdb/testsuite/gdb.objc/print.exp @@ -62,6 +62,10 @@ clean_restart if { [set_lang_objc] } { test_float_accepted test_float_rejected + + gdb_test {print @"hi"} \ + "evaluation of this expression requires the target program to be active" \ + "simple nsstring" } else { warning "Objective-c print tests suppressed" } -- 2.49.0