From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id iad0LkRG4Wmy4xwAWB0awg (envelope-from ) for ; Thu, 16 Apr 2026 16:27:48 -0400 Received: by simark.ca (Postfix, from userid 112) id BB7571E0C3; Thu, 16 Apr 2026 16:27: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=-2.3 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, 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 A33021E04F for ; Thu, 16 Apr 2026 16:27:47 -0400 (EDT) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 3E1714BA2E04 for ; Thu, 16 Apr 2026 20:27:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3E1714BA2E04 Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 6D93C4C900FE for ; Thu, 16 Apr 2026 20:26:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6D93C4C900FE Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=efficios.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=efficios.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6D93C4C900FE Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=158.69.221.121 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776371172; cv=none; b=O2Ql28+fv8v5z/UHDM+heDyQgGdnfy0KIv6RsH7duzTrEIrSn/vsXB+PTmZDEVGw5ihq9Jh8cSoVEx+xhlurE1G2Tv1SgHQ+JvLzoXBweL1uhJ2a/jKNHCr9pm/GPDeZVabdRmHMWgAiJULxbHLjnzPD/f4lRNKobcZA3JWOpLA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776371172; c=relaxed/simple; bh=x+U3l6Q9XhkgiANJgBEXlKjwbd0T4ISlPjadEoOf6fw=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=vTdewsknxonVTqiT7KY6BjsbNv1kcRMJ+3CszttEiKgC75rUaOyu9p47eY3I3f4+hJtxmHXmLE9LHNHGCEe3bNjylYSrw9iai1KnKxlebDawtABWBFrZFRX41/jB/vijHrdknfFSpUNA4H+3cvSxM4n8xuysOtWOm00QODgoKic= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6D93C4C900FE Received: by simark.ca (Postfix) id 0DA3A1E0CA; Thu, 16 Apr 2026 16:26:12 -0400 (EDT) From: Simon Marchi To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 11/11] gdb: make iterate_over_symbols return void, rename to for_each_symbol Date: Thu, 16 Apr 2026 16:16:21 -0400 Message-ID: <20260416202408.422441-12-simon.marchi@efficios.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260416202408.422441-1-simon.marchi@efficios.com> References: <20260416202408.422441-1-simon.marchi@efficios.com> 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 From: Simon Marchi Nothing really uses the return value of iterate_over_symbols and language::iterate_over_symbols. Also, all provided callback always return true, iterating on all matching symbols. Simplify them to not return a value and not have the "stop iterating" feature. Rename to for_each_symbol, just to be consistent with previous patches. Also rename symbol_found_callback_ftype to for_each_symbol_callback_ftype for consistency. Change-Id: I55ff3162098bb069dc1de1afca10dd9abfc05c34 --- gdb/ada-lang.c | 26 ++++++++------------------ gdb/language.h | 13 ++++--------- gdb/linespec.c | 38 ++++++++++++++++---------------------- gdb/symtab.c | 23 +++++++++-------------- gdb/symtab.h | 22 +++++++--------------- 5 files changed, 44 insertions(+), 78 deletions(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index d388a301fa1a..593f1eb63fa6 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -5427,7 +5427,7 @@ struct match_data } DISABLE_COPY_AND_ASSIGN (match_data); - bool operator() (struct block_symbol *bsym); + void operator() (struct block_symbol *bsym); void finish (const block *block); @@ -5452,14 +5452,14 @@ match_data::finish (const block *block) /* A callback for add_nonlocal_symbols that adds symbol, found in BSYM, to a list of symbols. */ -bool +void match_data::operator() (struct block_symbol *bsym) { const struct block *block = bsym->block; struct symbol *sym = bsym->symbol; if (sym->loc_class () == LOC_UNRESOLVED) - return true; + return; else if (sym->is_argument ()) arg_sym = sym; else @@ -5467,8 +5467,6 @@ match_data::operator() (struct block_symbol *bsym) found_sym = true; add_defn_to_vec (*resultp, sym, block); } - - return true; } /* Helper for add_nonlocal_symbols. Find symbols in DOMAIN which are @@ -5563,10 +5561,7 @@ map_matching_symbols (struct objfile *objfile, { const struct block *block = symtab->blockvector ()->block (block_kind); - /* match_data::operator() always returns true; we ignore the - result but assert just to be future-proof. */ - bool result = iterate_over_symbols (block, lookup_name, domain, data); - gdb_assert (result); + for_each_symbol (block, lookup_name, domain, data); data.finish (block); return iteration_status::keep_going; }; @@ -5665,7 +5660,7 @@ ada_add_all_symbols (std::vector &result, else { /* In the !full_search case we're are being called by - iterate_over_symbols, and we don't want to search + for_each_symbol, and we don't want to search superblocks. */ ada_add_block_symbols (result, block, lookup_name, domain, NULL); } @@ -13702,20 +13697,15 @@ class ada_language : public language_defn /* See language.h. */ - bool iterate_over_symbols + void for_each_symbol (const struct block *block, const lookup_name_info &name, domain_search_flags domain, - symbol_found_callback_ftype callback) const override + for_each_symbol_callback_ftype callback) const override { std::vector results = ada_lookup_symbol_list_worker (name, block, domain, 0); for (block_symbol &sym : results) - { - if (!callback (&sym)) - return false; - } - - return true; + callback (&sym); } /* See language.h. */ diff --git a/gdb/language.h b/gdb/language.h index 0cc075f8a295..b43dae661071 100644 --- a/gdb/language.h +++ b/gdb/language.h @@ -353,18 +353,13 @@ struct language_defn The caller is responsible for iterating up through superblocks if desired. - For each one, call CALLBACK with the symbol. If CALLBACK - returns false, the iteration ends at that point. - - This field may not be NULL. If the language does not need any - special processing here, 'iterate_over_symbols' should be - used as the definition. */ - virtual bool iterate_over_symbols + For each one, call CALLBACK with the symbol. */ + virtual void for_each_symbol (const struct block *block, const lookup_name_info &name, domain_search_flags domain, - symbol_found_callback_ftype callback) const + for_each_symbol_callback_ftype callback) const { - return ::iterate_over_symbols (block, name, domain, callback); + ::for_each_symbol (block, name, domain, callback); } /* Return a pointer to the function that should be used to match a diff --git a/gdb/linespec.c b/gdb/linespec.c index bfdd075ac825..45e12e092725 100644 --- a/gdb/linespec.c +++ b/gdb/linespec.c @@ -237,17 +237,14 @@ struct collect_info std::vector *minimal_symbols; /* Possibly add a symbol to the results. */ - bool add_symbol (block_symbol *bsym); + void add_symbol (block_symbol *bsym); }; -bool +void collect_info::add_symbol (block_symbol *bsym) { if (record_all || bsym->symbol->loc_class () == LOC_BLOCK) this->symbols->push_back (*bsym); - - /* Continue iterating. */ - return true; } /* Token types */ @@ -363,7 +360,7 @@ struct linespec_parser static void iterate_over_file_blocks (struct symtab *symtab, const lookup_name_info &name, domain_search_flags domain, - symbol_found_callback_ftype callback); + for_each_symbol_callback_ftype callback); static void initialize_defaults (struct symtab **default_symtab, int *default_line); @@ -1128,7 +1125,7 @@ iterate_over_all_matching_symtabs const lookup_name_info &lookup_name, const domain_search_flags domain, struct program_space *search_pspace, bool include_inline, - symbol_found_callback_ftype callback) + for_each_symbol_callback_ftype callback) { for (struct program_space *pspace : program_spaces) { @@ -1156,15 +1153,14 @@ iterate_over_all_matching_symtabs for (i = FIRST_LOCAL_BLOCK; i < bv->num_blocks (); i++) { block = bv->block (i); - state->language->iterate_over_symbols + state->language->for_each_symbol (block, lookup_name, domain, [&] (block_symbol *bsym) { /* Restrict calls to CALLBACK to symbols representing inline symbols only. */ if (bsym->symbol->is_inlined ()) - return callback (bsym); - return true; + callback (bsym); }); } } @@ -1196,14 +1192,14 @@ static void iterate_over_file_blocks (struct symtab *symtab, const lookup_name_info &name, domain_search_flags domain, - symbol_found_callback_ftype callback) + for_each_symbol_callback_ftype callback) { const struct block *block; for (block = symtab->compunit ()->blockvector ()->static_block (); block != NULL; block = block->superblock ()) - current_language->iterate_over_symbols (block, name, domain, callback); + current_language->for_each_symbol (block, name, domain, callback); } /* A helper for find_method. This finds all methods in type T of @@ -3325,8 +3321,8 @@ decode_objc (struct linespec_state *self, linespec *ls, const char *arg) namespace { -/* A function object that serves as symbol_found_callback_ftype - callback for iterate_over_symbols. This is used by +/* A function object that serves as for_each_symbol_callback_ftype + callback for for_each_symbol. This is used by lookup_prefix_sym to collect type symbols. */ class decode_compound_collector { @@ -3341,8 +3337,8 @@ class decode_compound_collector return std::move (m_symbols); } - /* Callable as a symbol_found_callback_ftype callback. */ - bool operator () (block_symbol *bsym); + /* Callable as a for_each_symbol_callback_ftype callback. */ + void operator () (block_symbol *bsym); private: /* A hash table of all symbols we found. We use this to avoid @@ -3353,26 +3349,24 @@ class decode_compound_collector std::vector m_symbols; }; -bool +void decode_compound_collector::operator () (block_symbol *bsym) { struct type *t; struct symbol *sym = bsym->symbol; if (sym->loc_class () != LOC_TYPEDEF) - return true; /* Continue iterating. */ + return; t = sym->type (); t = check_typedef (t); if (t->code () != TYPE_CODE_STRUCT && t->code () != TYPE_CODE_UNION && t->code () != TYPE_CODE_NAMESPACE) - return true; /* Continue iterating. */ + return; if (m_unique_syms.insert (sym).second) m_symbols.push_back (*bsym); - - return true; /* Continue iterating. */ } } // namespace @@ -4245,7 +4239,7 @@ add_matching_symbols_to_info (const char *name, auto add_symbol = [&] (block_symbol *bsym) { - return info->add_symbol (bsym); + info->add_symbol (bsym); }; for (const auto &elt : info->file_symtabs) diff --git a/gdb/symtab.c b/gdb/symtab.c index 62d9ecf0ee0a..f20deecb2a03 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -2696,23 +2696,18 @@ lookup_transparent_type (const char *name, domain_search_flags flags) /* See symtab.h. */ -bool -iterate_over_symbols (const struct block *block, - const lookup_name_info &name, - const domain_search_flags domain, - symbol_found_callback_ftype callback) +void +for_each_symbol (const struct block *block, const lookup_name_info &name, + const domain_search_flags domain, + for_each_symbol_callback_ftype callback) { for (struct symbol *sym : block_iterator_range (block, &name)) - { - if (sym->matches (domain)) - { - struct block_symbol block_sym = {sym, block}; + if (sym->matches (domain)) + { + block_symbol block_sym = { sym, block }; - if (!callback (&block_sym)) - return false; - } - } - return true; + callback (&block_sym); + } } /* Find the compunit symtab associated with PC and SECTION. diff --git a/gdb/symtab.h b/gdb/symtab.h index 3217d00914ce..68c02e07e397 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -2806,26 +2806,18 @@ using find_symtab_callback_ftype = std::function; std::vector find_linetable_entries_for_symtab_line (struct symtab *symtab, int line, const linetable_entry **best_entry); -/* Prototype for callbacks for LA_ITERATE_OVER_SYMBOLS. The callback - is called once per matching symbol SYM. The callback should return - true to indicate that LA_ITERATE_OVER_SYMBOLS should continue - iterating, or false to indicate that the iteration should end. */ +/* Callback type for function for_each_symbol. */ -using symbol_found_callback_ftype = gdb::function_view; +using for_each_symbol_callback_ftype + = gdb::function_view; /* Iterate over the symbols named NAME, matching DOMAIN, in BLOCK. - For each symbol that matches, CALLBACK is called. The symbol is - passed to the callback. + For each symbol that matches, call CALLBACK with the symbol. */ - If CALLBACK returns false, the iteration ends and this function - returns false. Otherwise, the search continues, and the function - eventually returns true. */ - -bool iterate_over_symbols (const struct block *block, - const lookup_name_info &name, - const domain_search_flags domain, - symbol_found_callback_ftype callback); +void for_each_symbol (const struct block *block, const lookup_name_info &name, + const domain_search_flags domain, + for_each_symbol_callback_ftype callback); /* Storage type used by demangle_for_lookup. demangle_for_lookup either returns a const char * pointer that points to either of the -- 2.53.0