From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id eYYnEf1F4Wmy4xwAWB0awg (envelope-from ) for ; Thu, 16 Apr 2026 16:26:37 -0400 Received: by simark.ca (Postfix, from userid 112) id 3DEA61E0D1; Thu, 16 Apr 2026 16:26:37 -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 4233E1E0BC 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 DCD544C900FE for ; Thu, 16 Apr 2026 20:26:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DCD544C900FE Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 5D0F14C900FF for ; Thu, 16 Apr 2026 20:26:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5D0F14C900FF 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 5D0F14C900FF 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=xiOFRY2duc/V3TMuXsF+x9cNwLfnfj3s51dsUaa2w/hYfAa6XIRn2VkMIEwNGFC5S59YdBjAvTvNfMMa4JrhpiBA+UWljMRhY8WQtXfGwKpIhwpDM73uZNbMSBw++4MOSIB0jZx03vUE/KjxznPz75EQ0ZPyW18XR2DUYZ/3gh8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776371171; c=relaxed/simple; bh=Zdw6f7aYVdXnxtLNJ/iwSGoJ8tfRvg6iXzlvIGa4Ga0=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=ZyMtfi8IqIRKuaUiSyZ8mNOTOKj27S4GXKCdSw+x4/2OGACdVLbB0wM0AenWlTjpNIAdKobwtj1juPuqtV3uWJpBCmtIzZF/tTETfKdccuU/ql8MsVi7Wfj2J6fWVpa+lSE0/gWLc8j7A4D3KYdA38lJVudDcnjNdIBtc1HDPl8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5D0F14C900FF Received: by simark.ca (Postfix) id 0A6A81E04F; Thu, 16 Apr 2026 16:26:11 -0400 (EDT) From: Simon Marchi To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 08/11] gdb: split iterate_over_symtabs in for_each_symtab and find_symtab Date: Thu, 16 Apr 2026 16:16:18 -0400 Message-ID: <20260416202408.422441-9-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 Same rationale as the previous patches. For the moment, find_symtab is only needed internally in symtab.c, so keep it static there. Note that the interaction with objfile.map_symtabs_matching_filename gets cleaner in a subsequent patch. for_each_symtab is implemented using find_symtab, because the iteration behavior is not completely trivial. find_symtab_callback_ftype is in the header file, because it is used from another source file in the next patch. Change-Id: I6ab8342151eb735327fc2e7935e7a65cede5e1dd --- gdb/linespec.c | 5 ++--- gdb/symtab.c | 55 ++++++++++++++++++++++++++++++++++---------------- gdb/symtab.h | 19 +++++++++-------- 3 files changed, 51 insertions(+), 28 deletions(-) diff --git a/gdb/linespec.c b/gdb/linespec.c index 4170d4ecf2c4..0afe0c619a13 100644 --- a/gdb/linespec.c +++ b/gdb/linespec.c @@ -3613,7 +3613,6 @@ collect_symtabs_from_filename (const char *file, { if (symtab_table.insert (symtab).second) symtabs.push_back (symtab); - return iteration_status::keep_going; }; /* Find that file's data. */ @@ -3624,11 +3623,11 @@ collect_symtabs_from_filename (const char *file, if (pspace->executing_startup) continue; - iterate_over_symtabs (pspace, file, collector); + for_each_symtab (pspace, file, collector); } } else - iterate_over_symtabs (search_pspace, file, collector); + for_each_symtab (search_pspace, file, collector); /* It is tempting to use the unordered_dense 'extract' method here, and remove the separate vector -- but it's unclear if ordering diff --git a/gdb/symtab.c b/gdb/symtab.c index 5a39081dfc54..6a5c8c7058e4 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -629,12 +629,16 @@ compare_filenames_for_search (const char *filename, const char *search_name) && STRIP_DRIVE_SPEC (filename) == &filename[len - search_len])); } -/* See symtab.h. */ +/* Return the first symtab in PSPACE matching NAME. -void -iterate_over_symtabs (program_space *pspace, const char *name, - gdb::function_view callback) + See documentation for for_each_symtab for how exactly NAME is matched. */ + +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 @@ -645,11 +649,37 @@ iterate_over_symtabs (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 (), - callback) + map_callback) == iteration_status::stop) - return; + return result; + + return nullptr; +} + +/* See symtab.h. */ + +void +for_each_symtab (program_space *pspace, const char *name, + for_each_symtab_callback_ftype callback) +{ + find_symtab (pspace, name, [&] (symtab *symtab) + { + callback (symtab); + return false; + }); } /* See symtab.h. */ @@ -657,15 +687,7 @@ iterate_over_symtabs (program_space *pspace, const char *name, symtab * lookup_symtab (program_space *pspace, const char *name) { - struct symtab *result = NULL; - - iterate_over_symtabs (pspace, name, [&] (symtab *symtab) - { - result = symtab; - return iteration_status::stop; - }); - - return result; + return find_symtab (pspace, name, [&] (symtab *symtab) { return true; }); } @@ -6140,12 +6162,11 @@ collect_file_symbol_completion_matches (completion_tracker &tracker, /* Go through symtabs for SRCFILE and check the externs and statics for symbols which match. */ - iterate_over_symtabs (current_program_space, srcfile, [&] (symtab *s) + for_each_symtab (current_program_space, srcfile, [&] (symtab *s) { add_symtab_completions (s->compunit (), tracker, mode, lookup_name, sym_text, word, TYPE_CODE_UNDEF); - return iteration_status::keep_going; }); } diff --git a/gdb/symtab.h b/gdb/symtab.h index 9e45f087adda..3936052706f1 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -2789,16 +2789,19 @@ extern bool basenames_may_differ; bool compare_filenames_for_search (const char *filename, const char *search_name); -/* Check in PSPACE for a symtab of a specific name; first in symtabs, then in - psymtabs. *If* there is no '/' in the name, a match after a '/' in the - symtab filename will also work. +using for_each_symtab_callback_ftype = std::function; - Call CALLBACK with each symtab that is found. If CALLBACK returns - true, the search stops. */ +/* Check in PSPACE for a symtab of a specific name. *If* there is no '/' in + the name, a match after a '/' in the symtab filename will also work. -void iterate_over_symtabs - (program_space *pspace, const char *name, - gdb::function_view callback); + Call CALLBACK with each symtab that is found. */ + +void for_each_symtab (program_space *pspace, const char *name, + for_each_symtab_callback_ftype callback); + +/* Callback type for function find_symtab. */ + +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); -- 2.53.0