From patchwork Fri Jan 20 21:46:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 63533 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BF42A393BA54 for ; Fri, 20 Jan 2023 21:48:23 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from outbound-ss-820.bluehost.com (outbound-ss-820.bluehost.com [69.89.24.241]) by sourceware.org (Postfix) with ESMTPS id A3209385B50D for ; Fri, 20 Jan 2023 21:46:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A3209385B50D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com Received: from cmgw11.mail.unifiedlayer.com (unknown [10.0.90.126]) by progateway2.mail.pro1.eigbox.com (Postfix) with ESMTP id D8A5010048535 for ; Fri, 20 Jan 2023 21:46:41 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id IzDdpoFsWJceRIzDdprVF7; Fri, 20 Jan 2023 21:46:41 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=Or6Kdwzt c=1 sm=1 tr=0 ts=63cb0bc1 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=RvmDmJFTN0MA:10:nop_rcvd_month_year a=Qbun_eYptAEA:10:endurance_base64_authed_username_1 a=aDYKaIEL3NOihMrxle4A:9 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=C37ThrxjuH1v1FoshSybIMG2xFn+O2t1fIuVUvZRmaI=; b=EA4KUtFCF5/9CwWXuzUA4IDdXb ZNnjLFZihBBjZesWXq5xWYVu0qtlOYYhV3RtiH7pNV0UkVa3HFvKifqCZ91r53FhiagVod7+RLcdO 8kyu6zN94kNdWPqAsZjdvoSJ/; Received: from 97-122-76-186.hlrn.qwest.net ([97.122.76.186]:60144 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1pIzDd-001GNx-I3; Fri, 20 Jan 2023 14:46:41 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 20/27] Remove ALL_BLOCK_SYMBOLS_WITH_NAME Date: Fri, 20 Jan 2023 14:46:11 -0700 Message-Id: <20230120214618.3236224-21-tom@tromey.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230120214618.3236224-1-tom@tromey.com> References: <20230120214618.3236224-1-tom@tromey.com> MIME-Version: 1.0 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.76.186 X-Source-L: No X-Exim-ID: 1pIzDd-001GNx-I3 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-76-186.hlrn.qwest.net (localhost.localdomain) [97.122.76.186]:60144 X-Source-Auth: tom+tromey.com X-Email-Count: 21 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3027.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" This removes ALL_BLOCK_SYMBOLS_WITH_NAME in favor of foreach. --- gdb/block.c | 12 +++--------- gdb/block.h | 10 ---------- gdb/cp-support.c | 5 +---- gdb/python/py-block.c | 22 ++++++++-------------- gdb/symtab.c | 5 +---- 5 files changed, 13 insertions(+), 41 deletions(-) diff --git a/gdb/block.c b/gdb/block.c index e7a51af8cea..0870793dcd4 100644 --- a/gdb/block.c +++ b/gdb/block.c @@ -692,16 +692,13 @@ block_lookup_symbol (const struct block *block, const char *name, symbol_name_match_type match_type, const domain_enum domain) { - struct block_iterator iter; - struct symbol *sym; - lookup_name_info lookup_name (name, match_type); if (!block->function ()) { struct symbol *other = NULL; - ALL_BLOCK_SYMBOLS_WITH_NAME (block, lookup_name, iter, sym) + for (struct symbol *sym : block_iterator_range (block, &lookup_name)) { /* See comment related to PR gcc/debug/91507 in block_lookup_symbol_primary. */ @@ -730,7 +727,7 @@ block_lookup_symbol (const struct block *block, const char *name, struct symbol *sym_found = NULL; - ALL_BLOCK_SYMBOLS_WITH_NAME (block, lookup_name, iter, sym) + for (struct symbol *sym : block_iterator_range (block, &lookup_name)) { if (symbol_matches_domain (sym->language (), sym->domain (), domain)) @@ -815,16 +812,13 @@ block_find_symbol (const struct block *block, const char *name, const domain_enum domain, block_symbol_matcher_ftype *matcher, void *data) { - struct block_iterator iter; - struct symbol *sym; - lookup_name_info lookup_name (name, symbol_name_match_type::FULL); /* Verify BLOCK is STATIC_BLOCK or GLOBAL_BLOCK. */ gdb_assert (block->superblock () == NULL || block->superblock ()->superblock () == NULL); - ALL_BLOCK_SYMBOLS_WITH_NAME (block, lookup_name, iter, sym) + for (struct symbol *sym : block_iterator_range (block, &lookup_name)) { /* MATCHER is deliberately called second here so that it never sees a non-domain-matching symbol. */ diff --git a/gdb/block.h b/gdb/block.h index 7341d03a07e..35c41377f2c 100644 --- a/gdb/block.h +++ b/gdb/block.h @@ -604,16 +604,6 @@ extern int block_find_non_opaque_type_preferred (struct symbol *sym, (sym); \ (sym) = block_iterator_next (&(iter))) -/* Macro to loop through all symbols in BLOCK with a name that matches - NAME, in no particular order. ITER helps keep track of the - iteration, and must be a struct block_iterator. SYM points to the - current symbol. */ - -#define ALL_BLOCK_SYMBOLS_WITH_NAME(block, name, iter, sym) \ - for ((sym) = block_iterator_first ((block), &(iter), &(name)); \ - (sym) != NULL; \ - (sym) = block_iterator_next (&(iter))) - /* Given a vector of pairs, allocate and build an obstack allocated blockranges struct for a block. */ struct blockranges *make_blockranges (struct objfile *objfile, diff --git a/gdb/cp-support.c b/gdb/cp-support.c index cdaf5fd3e8e..52510543f00 100644 --- a/gdb/cp-support.c +++ b/gdb/cp-support.c @@ -1273,12 +1273,9 @@ add_symbol_overload_list_block (const char *name, const struct block *block, std::vector *overload_list) { - struct block_iterator iter; - struct symbol *sym; - lookup_name_info lookup_name (name, symbol_name_match_type::FULL); - ALL_BLOCK_SYMBOLS_WITH_NAME (block, lookup_name, iter, sym) + for (struct symbol *sym : block_iterator_range (block, &lookup_name)) overload_list_add_symbol (sym, name, overload_list); } diff --git a/gdb/python/py-block.c b/gdb/python/py-block.c index bd2ce7fc181..da33d4cdd94 100644 --- a/gdb/python/py-block.c +++ b/gdb/python/py-block.c @@ -265,24 +265,18 @@ blpy_getitem (PyObject *self, PyObject *key) lookup_name_info lookup_name (name.get(), symbol_name_match_type::FULL); - /* We use ALL_BLOCK_SYMBOLS_WITH_NAME instead of block_lookup_symbol so - that we can look up symbols irrespective of the domain, matching the - iterator. It would be confusing if the iterator returns symbols you - can't find via getitem. */ - struct block_iterator iter; - struct symbol *sym = nullptr; - ALL_BLOCK_SYMBOLS_WITH_NAME (block, lookup_name, iter, sym) + /* We use an iterator instead of block_lookup_symbol so that we can + look up symbols irrespective of the domain, matching the + iterator. It would be confusing if the iterator returns symbols + you can't find via getitem. */ + for (struct symbol *sym : block_iterator_range (block, &lookup_name)) { /* Just stop at the first match */ - break; + return symbol_to_symbol_object (sym); } - if (sym == nullptr) - { - PyErr_SetObject (PyExc_KeyError, key); - return nullptr; - } - return symbol_to_symbol_object (sym); + PyErr_SetObject (PyExc_KeyError, key); + return nullptr; } static void diff --git a/gdb/symtab.c b/gdb/symtab.c index dd9cc7d5163..511299233ad 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -2797,10 +2797,7 @@ iterate_over_symbols (const struct block *block, const domain_enum domain, gdb::function_view callback) { - struct block_iterator iter; - struct symbol *sym; - - ALL_BLOCK_SYMBOLS_WITH_NAME (block, name, iter, sym) + for (struct symbol *sym : block_iterator_range (block, &name)) { if (symbol_matches_domain (sym->language (), sym->domain (), domain)) {