From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id SUSvLf5F4Wmy4xwAWB0awg (envelope-from ) for ; Thu, 16 Apr 2026 16:26:38 -0400 Received: by simark.ca (Postfix, from userid 112) id B1B2A1E0C3; Thu, 16 Apr 2026 16:26:38 -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 EEAEC1E0C3 for ; Thu, 16 Apr 2026 16:26:36 -0400 (EDT) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 8FAE04C318B0 for ; Thu, 16 Apr 2026 20:26:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8FAE04C318B0 Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 657EA4C900F9 for ; Thu, 16 Apr 2026 20:26:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 657EA4C900F9 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 657EA4C900F9 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=1776371171; cv=none; b=b7B2U9r7EmLmTaBu2OE5zlGVFTpfId/tV7XpAzg/b9/qSCQ95cN9t1BgWsDTJYnf4laNC2lO6G4nyaT8SUkmX2pHGgP3OoFttw/AdSwJO3imxzCbdZkVoDQSYVg7npEbf2krcpK92g2x9WKC1N7M+k9NawU5zfRLnH0qm5hUJXg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776371171; c=relaxed/simple; bh=o7a6vfy8FdkLhfmHcjMnhvPV3AjfOX8XAmmryrqtC30=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=YFGYn5F6bkgBXT5KHvwWfoyDWjBgLkJ6yW44QKcOt1vibTsJXINZeu0+tEnabriPRZOYUZF6nIUS5r64DZtTArfsm3tKn6ekspGG+F4Pd+BtkISz5OHRP2ajPMxux8rE6aa63rcwAKpRPIYM0lpvtfrNAIlnCCIKYzsHrHqgpws= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 657EA4C900F9 Received: by simark.ca (Postfix) id 100661E0BC; Thu, 16 Apr 2026 16:26:11 -0400 (EDT) From: Simon Marchi To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 09/11] gdb: change objfile::map_symtabs_matching_filename to find_symtab_matching_filename Date: Thu, 16 Apr 2026 16:16:19 -0400 Message-ID: <20260416202408.422441-10-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 The only user of objfile::map_symtabs_matching_filename uses that method to find the first matching symtab. It would therefore be more natural for that method to be a "find" method, returning the first symtab matching the predicate. Change map_symtabs_matching_filename to be find_symtab_in_compunit_symtab, and the internal iterate_over_one_compunit_symtab to be find_symtab_in_compunit_symtab. This makes function find_symtab simpler. Change-Id: Id14a95498fad243495d6eab18810d0c4ab8dbf90 --- gdb/objfiles.h | 16 +++----- gdb/symfile-debug.c | 89 +++++++++++++++++++++------------------------ gdb/symtab.c | 20 ++-------- 3 files changed, 52 insertions(+), 73 deletions(-) diff --git a/gdb/objfiles.h b/gdb/objfiles.h index 8ae54b37bb79..76d6130f5048 100644 --- a/gdb/objfiles.h +++ b/gdb/objfiles.h @@ -571,21 +571,17 @@ struct objfile : intrusive_list_node /* See quick_symbol_functions. */ void forget_cached_source_info (); - /* Expand and iterate over each "partial" symbol table in OBJFILE - where the source file is named NAME. + /* Find the first symtab where the source file matches NAME and REAL_PATH, + and for which CALLBACK returns true. If NAME is not absolute, a match after a '/' in the symbol table's file name will also work, REAL_PATH is NULL then. If NAME is absolute then REAL_PATH is non-NULL absolute file name as resolved - via gdb_realpath from NAME. + via gdb_realpath from NAME. */ - If a match is found, the "partial" symbol table is expanded. - Then, this calls iterate_over_some_symtabs (or equivalent) over - all newly-created symbol tables, passing CALLBACK to it. - The result of this call is returned. */ - iteration_status map_symtabs_matching_filename - (const char *name, const char *real_path, - gdb::function_view callback); + symtab *find_symtab_matching_filename (const char *name, + const char *real_path, + find_symtab_callback_ftype callback); /* Check to see if the symbol is defined in a "partial" symbol table of this objfile. BLOCK_INDEX should be either GLOBAL_BLOCK or diff --git a/gdb/symfile-debug.c b/gdb/symfile-debug.c index 8e4892649508..d90f400f379c 100644 --- a/gdb/symfile-debug.c +++ b/gdb/symfile-debug.c @@ -159,29 +159,30 @@ objfile::forget_cached_source_info () iter->forget_cached_source_info (this); } -/* Check for a symtab of a specific name by searching some symtabs. +/* Find the first symtab of CUST matching BASE_NAME, NAME and REAL_PATH, for + which CALLBACK returns true. If NAME is not absolute, then REAL_PATH is NULL If NAME is absolute, then REAL_PATH is the gdb_realpath form of NAME. The return value, NAME, REAL_PATH and CALLBACK are identical to the - `map_symtabs_matching_filename' method of quick_symbol_functions. + `find_symtab_matching_filename' method of quick_symbol_functions. CUST indicates which compunit symtab to search. Each symtab within the specified compunit symtab is also searched. */ -static iteration_status -iterate_over_one_compunit_symtab - (const char *base_name, const char *name, const char *real_path, - compunit_symtab *cust, - gdb::function_view callback) +static symtab * +find_symtab_in_compunit_symtab (const char *base_name, const char *name, + const char *real_path, compunit_symtab *cust, + find_symtab_callback_ftype callback) { for (symtab *s : cust->filetabs ()) { if (compare_filenames_for_search (s->filename (), name)) { - if (callback (s) == iteration_status::stop) - return iteration_status::stop; + if (callback (s)) + return s; + continue; } @@ -193,8 +194,9 @@ iterate_over_one_compunit_symtab if (compare_filenames_for_search (symtab_to_fullname (s), name)) { - if (callback (s) == iteration_status::stop) - return iteration_status::stop; + if (callback (s)) + return s; + continue; } @@ -211,30 +213,32 @@ iterate_over_one_compunit_symtab fullname = fullname_real_path.get (); if (FILENAME_CMP (real_path, fullname) == 0) { - if (callback (s) == iteration_status::stop) - return iteration_status::stop; + if (callback (s)) + return s; + continue; } } } for (compunit_symtab *iter : cust->includes) - if (iterate_over_one_compunit_symtab (base_name, name, real_path, iter, - callback) - == iteration_status::stop) - return iteration_status::stop; + if (symtab *result = find_symtab_in_compunit_symtab (base_name, name, + real_path, iter, + callback); + result != nullptr) + return result; - return iteration_status::keep_going; + return nullptr; } -iteration_status -objfile::map_symtabs_matching_filename - (const char *name, const char *real_path, - gdb::function_view callback) +symtab * +objfile::find_symtab_matching_filename (const char *name, + const char *real_path, + find_symtab_callback_ftype callback) { if (debug_symfile) gdb_printf (gdb_stdlog, - "qf->map_symtabs_matching_filename (%s, \"%s\", " + "qf->find_symtab_matching_filename (%s, \"%s\", " "\"%s\", %s)\n", objfile_debug_name (this), name, real_path ? real_path : NULL, @@ -254,6 +258,7 @@ objfile::map_symtabs_matching_filename return false; }; + symtab *result = nullptr; auto compunit_callback = [&] (compunit_symtab *symtab) { /* Skip included compunits, as they are searched by @@ -261,37 +266,27 @@ objfile::map_symtabs_matching_filename if (symtab->user != nullptr) return iteration_status::keep_going; - /* iterate_over_one_compunit_symtab returns true to stop, - convert to iteration_status. */ - if (iterate_over_one_compunit_symtab (name_basename, name, real_path, - symtab, callback) - == iteration_status::stop) + result = find_symtab_in_compunit_symtab (name_basename, name, real_path, + symtab, callback); + if (result == nullptr) + return iteration_status::keep_going; + else return iteration_status::stop; - - return iteration_status::keep_going; }; - iteration_status retval = iteration_status::keep_going; - for (const auto &iter : qf) - { - if (iter->search (this, match_one_filename, nullptr, nullptr, - compunit_callback, - SEARCH_GLOBAL_BLOCK | SEARCH_STATIC_BLOCK, - SEARCH_ALL_DOMAINS) - == iteration_status::stop) - { - retval = iteration_status::stop; - break; - } - } + if (iter->search (this, match_one_filename, nullptr, nullptr, + compunit_callback, + SEARCH_GLOBAL_BLOCK | SEARCH_STATIC_BLOCK, + SEARCH_ALL_DOMAINS) + == iteration_status::stop) + break; if (debug_symfile) - gdb_printf (gdb_stdlog, - "qf->map_symtabs_matching_filename (...) = %s\n", - iteration_status_str (retval)); + gdb_printf (gdb_stdlog, "qf->find_symtab_matching_filename (...) = %p\n", + result); - return retval; + return result; } struct compunit_symtab * diff --git a/gdb/symtab.c b/gdb/symtab.c index 6a5c8c7058e4..fd841318387e 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -637,8 +637,6 @@ static symtab * find_symtab (program_space *pspace, const char *name, find_symtab_callback_ftype callback) { - struct symtab *result = NULL; - gdb::unique_xmalloc_ptr real_path; /* Here we are interested in canonicalizing an absolute path, not @@ -649,21 +647,11 @@ find_symtab (program_space *pspace, const char *name, gdb_assert (IS_ABSOLUTE_PATH (real_path.get ())); } - auto map_callback = [&] (symtab *symtab) - { - if (callback (symtab)) - { - result = symtab; - return iteration_status::stop; - } - - return iteration_status::keep_going; - }; - for (objfile &objfile : pspace->objfiles ()) - if (objfile.map_symtabs_matching_filename (name, real_path.get (), - map_callback) - == iteration_status::stop) + if (symtab *result + = objfile.find_symtab_matching_filename (name, real_path.get (), + callback); + result != nullptr) return result; return nullptr; -- 2.53.0