From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id kaZKH6hF4Wll4xwAWB0awg (envelope-from ) for ; Thu, 16 Apr 2026 16:25:12 -0400 Received: by simark.ca (Postfix, from userid 112) id 7BB7A1E0C3; Thu, 16 Apr 2026 16:25:12 -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 C37621E04F for ; Thu, 16 Apr 2026 16:25:11 -0400 (EDT) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 61B9C4C900C7 for ; Thu, 16 Apr 2026 20:25:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 61B9C4C900C7 Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 691A14C318B4 for ; Thu, 16 Apr 2026 20:24:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 691A14C318B4 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 691A14C318B4 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=1776371053; cv=none; b=euKwpn+qExIFDol+gsuui1T5FGElOVKfXT+jw3+9CdeecPDm+ffDbt6Vw/OU48S6dhArjwNPD70njpmCXVvf+m1NYL2Ikm3W66VTQxKlxyQ+FNNweQp8FLU4VO4grGFFp0DDhG2kaIhMDn+d8KPsTTaQDlcEtUJydX/D98oTwFI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776371053; c=relaxed/simple; bh=zQfCiC9tizkVs/rnIruC7hcK4ltweSxl1dJW3GHzHeM=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=wY8lYF8cJlv66W01oBz4I4J63rAJJSo469c9P7jQnUMaB6kpv5H0u0n9DxRcs0ORlJNP6HB8mXJIqRxbdg6cCM1Q0Q6XheXujeIAMqKgwHwImllcUkYWqLS7ej6qS1zn4BLjCYe8qU5Uvvj97W74SCPAjNkqu34VnxETIuVJXA8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 691A14C318B4 Received: by simark.ca (Postfix) id 8B4A41E0EA; Thu, 16 Apr 2026 16:24:10 -0400 (EDT) From: Simon Marchi To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 07/11] gdb: split iterate_over_minimal_symbols in for_each_minimal_symbol and find_minimal_symbol Date: Thu, 16 Apr 2026 16:16:17 -0400 Message-ID: <20260416202408.422441-8-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 Based on the same rationale as the previous patches, split iterate_over_minimal_symbols in two. Implement for_each_minimal_symbol using find_minimal_symbol, since that one is really not trivial. Change-Id: Ie02e67278359454f7aa583200ec68d2f429f7ebe --- gdb/linespec.c | 35 ++++++++++++++++------------------- gdb/minsyms.c | 25 ++++++++++++++++++++----- gdb/minsyms.h | 37 +++++++++++++++++++++++++++++-------- gdb/symtab.c | 18 +++++++++--------- 4 files changed, 74 insertions(+), 41 deletions(-) diff --git a/gdb/linespec.c b/gdb/linespec.c index 4ea6d597a093..4170d4ecf2c4 100644 --- a/gdb/linespec.c +++ b/gdb/linespec.c @@ -4150,33 +4150,30 @@ search_minsyms_for_name (struct collect_info *info, set_current_program_space (pspace); for (objfile &objfile : pspace->objfiles ()) - { - iterate_over_minimal_symbols (&objfile, name, - [&] (struct minimal_symbol *msym) - { - add_minsym (msym, &objfile, nullptr, - info->state->list_mode, - &minsyms); - return false; - }); - } + for_each_minimal_symbol (&objfile, name, + [&] (minimal_symbol *msym) + { + add_minsym (msym, &objfile, nullptr, + info->state->list_mode, + &minsyms); + }); } } else { - program_space *pspace = symtab->compunit ()->objfile ()->pspace (); + objfile &objfile = *symtab->compunit ()->objfile (); + program_space *pspace = objfile.pspace (); if (search_pspace == NULL || pspace == search_pspace) { set_current_program_space (pspace); - iterate_over_minimal_symbols - (symtab->compunit ()->objfile (), name, - [&] (struct minimal_symbol *msym) - { - add_minsym (msym, symtab->compunit ()->objfile (), symtab, - info->state->list_mode, &minsyms); - return false; - }); + for_each_minimal_symbol (&objfile, name, + [&] (minimal_symbol *msym) + { + add_minsym (msym, &objfile, symtab, + info->state->list_mode, + &minsyms); + }); } } diff --git a/gdb/minsyms.c b/gdb/minsyms.c index 0d6ea53aecf6..4eafc7890478 100644 --- a/gdb/minsyms.c +++ b/gdb/minsyms.c @@ -496,9 +496,22 @@ linkage_name_str (const lookup_name_info &lookup_name) /* See minsyms.h. */ void -iterate_over_minimal_symbols - (struct objfile *objf, const lookup_name_info &lookup_name, - gdb::function_view callback) +for_each_minimal_symbol (struct objfile *objf, const lookup_name_info &name, + for_each_minimal_symbol_callback_ftype callback) +{ + find_minimal_symbol (objf, name, + [&] (struct minimal_symbol *msym) + { + callback (msym); + return false; + }); +} + +/* See minsyms.h. */ + +minimal_symbol * +find_minimal_symbol (struct objfile *objf, const lookup_name_info &lookup_name, + find_minimal_symbol_callback_ftype callback) { /* The first pass is over the ordinary hash table. */ { @@ -515,7 +528,7 @@ iterate_over_minimal_symbols { if (mangled_cmp (iter->linkage_name (), name) == 0) if (callback (iter)) - return; + return iter; } } @@ -539,8 +552,10 @@ iterate_over_minimal_symbols iter = iter->demangled_hash_next) if (name_match (iter->search_name (), lookup_name, NULL)) if (callback (iter)) - return; + return iter; } + + return nullptr; } /* See minsyms.h. */ diff --git a/gdb/minsyms.h b/gdb/minsyms.h index 8f38cc7137fc..c44d5b20aec8 100644 --- a/gdb/minsyms.h +++ b/gdb/minsyms.h @@ -20,6 +20,7 @@ #ifndef GDB_MINSYMS_H #define GDB_MINSYMS_H +#include "gdbsupport/function-view.h" #include struct program_space; @@ -279,16 +280,36 @@ bound_minimal_symbol lookup_minimal_symbol_by_pc_section bound_minimal_symbol lookup_minimal_symbol_by_pc (CORE_ADDR); -/* Iterate over all the minimal symbols in the objfile OBJF which - match NAME. Both the ordinary and demangled names of each symbol - are considered. The caller is responsible for canonicalizing NAME, - should that need to be done. +/* Callback type for function for_each_minimal_symbol. */ - For each matching symbol, CALLBACK is called with the symbol. */ +using for_each_minimal_symbol_callback_ftype + = gdb::function_view; -void iterate_over_minimal_symbols - (struct objfile *objf, const lookup_name_info &name, - gdb::function_view callback); +/* Call CALLBACK for all minimal symbols in objfile OBJF which match NAME. + + Both the ordinary and demangled names of each symbol are considered. The + caller is responsible for canonicalizing NAME, should that need to be + done. */ + +void for_each_minimal_symbol (struct objfile *objf, + const lookup_name_info &name, + for_each_minimal_symbol_callback_ftype callback); + +/* Callback type for function find_minimal_symbol. */ + +using find_minimal_symbol_callback_ftype + = gdb::function_view; + +/* Find the first minimal symbol for objfile OBJF which matches NAME and for + which CALLBACK returns true. + + Both the ordinary and demangled names of each symbol are considered. The + caller is responsible for canonicalizing NAME, should that need to be + done. */ + +minimal_symbol *find_minimal_symbol + (struct objfile *objf, const lookup_name_info &name, + find_minimal_symbol_callback_ftype callback); /* Compute the upper bound of MINSYM. The upper bound is the last address thought to be part of the symbol. If the symbol has a diff --git a/gdb/symtab.c b/gdb/symtab.c index d22dd81a246a..5a39081dfc54 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -5782,32 +5782,32 @@ find_gnu_ifunc (const symbol *sym) struct objfile *objfile = sym->objfile (); CORE_ADDR address = sym->value_block ()->entry_pc (); - minimal_symbol *ifunc = NULL; - - iterate_over_minimal_symbols (objfile, lookup_name, - [&] (minimal_symbol *minsym) + minimal_symbol *ifunc + = find_minimal_symbol (objfile, lookup_name, + [&] (minimal_symbol *minsym) { if (minsym->type () == mst_text_gnu_ifunc || minsym->type () == mst_data_gnu_ifunc) { CORE_ADDR msym_addr = minsym->value_address (objfile); + if (minsym->type () == mst_data_gnu_ifunc) { struct gdbarch *gdbarch = objfile->arch (); msym_addr = gdbarch_convert_from_func_ptr_addr (gdbarch, msym_addr, current_inferior ()->top_target ()); } + if (msym_addr == address) - { - ifunc = minsym; - return true; - } + return true; } + return false; }); - if (ifunc != NULL) + if (ifunc != nullptr) return {ifunc, objfile}; + return {}; } -- 2.53.0