From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id qfDYGjt7GmkBuQoAWB0awg (envelope-from ) for ; Sun, 16 Nov 2025 20:32:43 -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=lsm6FbOm; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 695301E08D; Sun, 16 Nov 2025 20:32:43 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_INVALID,DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_BL_SPAMCOP_NET, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=no 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 BA5151E08D for ; Sun, 16 Nov 2025 20:32:42 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 518643858C60 for ; Mon, 17 Nov 2025 01:32:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 518643858C60 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=lsm6FbOm Received: from omta038.useast.a.cloudfilter.net (omta038.useast.a.cloudfilter.net [44.202.169.37]) by sourceware.org (Postfix) with ESMTPS id 528BA3858C42 for ; Mon, 17 Nov 2025 01:28:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 528BA3858C42 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 528BA3858C42 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=44.202.169.37 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1763342920; cv=none; b=JUjfDmvlQJSpc+WaXp3I1z6crO/b2ksWStP+0R7OnzBAjOVkJSwTQ5eW6AYBOoUlqNVn2NtSHWBSIouFcdZ5mGeXCrKW9qWvNhMFVWx00/6+uwLtv/HPQM1ul9+hKC4yMcc/GYUwsrYOtgqAyRn6ibguZ0A615JsnAQdEM1hgzQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1763342920; c=relaxed/simple; bh=Sfz9m4uhkhWvU8TWxPPSUkwdfjGMor8CILYCIkxFZTw=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=QD3uFx6XYOD62LUHngxDF1i8laK4+vqsfBiytQGiQCfHILWRe6lrBQ1Un2BP4L/NAS0p4/uhzbeqYSpjopVVoRRo+4spg7ZInYm5UyfeOGl7sJz+5965+XreKachdzxkeSELmsZLPijfdnezwsAGjUgCnE5vWXv2I10CJiMZoS4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 528BA3858C42 Received: from eig-obgw-5007b.ext.cloudfilter.net ([10.0.29.167]) by cmsmtp with ESMTPS id KlrNvx6w3SkcfKo2qv8QCp; Mon, 17 Nov 2025 01:28:40 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id Ko2pv2vgwJecrKo2pvKqFp; Mon, 17 Nov 2025 01:28:40 +0000 X-Authority-Analysis: v=2.4 cv=G8scE8k5 c=1 sm=1 tr=0 ts=691a7a48 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=6UeiqGixMTsA:10 a=ItBw4LHWJt0A:10 a=CCpqsmhAAAAA:8 a=9YJ8a5Ov8g9U6hBW-v0A: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=A9inuDX3i96AkltzT/RV7Q9st2TZpDUV5yfW13vGPkg=; b=lsm6FbOmRzEXtk8LCl0FaVUw6O UFWVfmwS+Su/ctrOpvQhUIT8qKPHki6HMRdNfm8EjNdO2eyhlsiD9HHFAufVXBAMb25OQ9kRbl5Da A7IHXA574apzLIvQjh0Lavuyh; 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 1vKo2i-00000000Q3v-2TVt; Sun, 16 Nov 2025 18:28:32 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 7/7] Rewrite the @selector code Date: Sun, 16 Nov 2025 18:27:06 -0700 Message-ID: <20251117012752.2657208-8-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: 1vKo2i-00000000Q3v-2TVt 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: 8 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfImK5LWv33K4K+P7gEI0QAuGl2FPI8ydOKgS3Eh4ZlINb86h/ehi8JE5eyjmoiHAb5hAhTJrhiqeCXtDoAGv84DJpT8MKT2bZlyYX1igpzuNo3OheVuE 5jW3O4DALjqKJCOX1kjukvaqOJWYLnw9yCb3kXO+DDIKVkW0SRg+0bCWGvdBNcCx1S8W0J9zoWJosM06kmZE09qQ+qH83JZOV+k= 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 This rewrites the Objective-C @selector implementation in c-exp.y, following a couple general comments in the patch supplied for bug 20503. I suspect something else changed in the Objective-C runtime, though, as most of the examples in that bug still do not work, even though this series (I believe) addresses all the same points. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=20503 --- gdb/c-exp.y | 53 +++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 8 deletions(-) diff --git a/gdb/c-exp.y b/gdb/c-exp.y index fadd735c517..829058027f3 100644 --- a/gdb/c-exp.y +++ b/gdb/c-exp.y @@ -224,7 +224,7 @@ static void c_print_token (FILE *file, int type, YYSTYPE value); %token STRING %token NSSTRING /* ObjC Foundation "NSString" literal */ -%token SELECTOR /* ObjC "@selector" pseudo-operator */ +%token SELECTOR /* ObjC "@selector" pseudo-operator */ %token CHAR %token NAME /* BLOCKNAME defined below to give it higher precedence. */ %token UNKNOWN_CPP_NAME @@ -918,10 +918,10 @@ exp : DOLLAR_VARIABLE } ; -exp : SELECTOR '(' name ')' +exp : SELECTOR { pstate->push_new - (copy_name ($3)); + (copy_name ($1)); } ; @@ -2664,6 +2664,43 @@ static bool last_was_structop; /* Depth of parentheses. */ static int paren_depth; +/* Lex an Objective-C @selector. Return true if lexed. In this case, + sets the resulting token and updates the lex pointer. Otherwise + returns false and updates nothing. */ + +static bool +lex_selector (const char **lex_ptr, struct stoken *token) +{ + const char *p = *lex_ptr; + + if (!startswith (p, "selector")) + return false; + + p += strlen ("selector"); + p = skip_spaces (p); + if (*p != '(') + return false; + ++p; + + /* The selector name matches [A-Za-z0-9:_-]+. We could probably be + a bit more refined but meh. */ + const char *start = p; + while (c_isalnum (*p) || *p == ':' || *p == '_' || *p == '-') + ++p; + if (p == start) + return false; + const char *end = p; + + p = skip_spaces (p); + if (*p != ')') + return false; + ++p; + + *lex_ptr = p; + *token = { start, (int) (end - start) }; + return true; +} + /* Read one token, getting characters through lexptr. */ static int @@ -2872,12 +2909,11 @@ lex_one_token (struct parser_state *par_state, bool *is_quoted_name) if (par_state->language ()->la_language == language_objc) { - size_t len = strlen ("selector"); - - if (strncmp (p, "selector", len) == 0 - && (p[len] == '\0' || c_isspace (p[len]))) + struct stoken sel_token; + if (lex_selector (&p, &sel_token)) { - pstate->lexptr = p + len; + pstate->lexptr = p; + yylval.sval = sel_token; return SELECTOR; } else if (*p == '"') @@ -3556,6 +3592,7 @@ c_print_token (FILE *file, int type, YYSTYPE value) case NSSTRING: case DOLLAR_VARIABLE: + case SELECTOR: parser_fprintf (file, "sval<%s>", copy_name (value.sval).c_str ()); break; -- 2.49.0